src/java.management/share/classes/javax/management/modelmbean/DescriptorSupport.java
equal
deleted
inserted
replaced
441 return; |
441 return; |
442 |
442 |
443 init(null); |
443 init(null); |
444 |
444 |
445 for (int i=0; i < fields.length; i++) { |
445 for (int i=0; i < fields.length; i++) { |
446 if ((fields[i] == null) || (fields[i].equals(""))) { |
446 if ((fields[i] == null) || (fields[i].isEmpty())) { |
447 continue; |
447 continue; |
448 } |
448 } |
449 int eq_separator = fields[i].indexOf('='); |
449 int eq_separator = fields[i].indexOf('='); |
450 if (eq_separator < 0) { |
450 if (eq_separator < 0) { |
451 // illegal if no = or is first character |
451 // illegal if no = or is first character |
465 if (eq_separator < fields[i].length()) { |
465 if (eq_separator < fields[i].length()) { |
466 // = is not in last character |
466 // = is not in last character |
467 fieldValue = fields[i].substring(eq_separator+1); |
467 fieldValue = fields[i].substring(eq_separator+1); |
468 } |
468 } |
469 |
469 |
470 if (fieldName.equals("")) { |
470 if (fieldName.isEmpty()) { |
471 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { |
471 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { |
472 MODELMBEAN_LOGGER.log(Level.TRACE, |
472 MODELMBEAN_LOGGER.log(Level.TRACE, |
473 "Descriptor(String... fields) " + |
473 "Descriptor(String... fields) " + |
474 "Illegal arguments: fieldName is empty"); |
474 "Illegal arguments: fieldName is empty"); |
475 } |
475 } |
498 |
498 |
499 |
499 |
500 public synchronized Object getFieldValue(String fieldName) |
500 public synchronized Object getFieldValue(String fieldName) |
501 throws RuntimeOperationsException { |
501 throws RuntimeOperationsException { |
502 |
502 |
503 if ((fieldName == null) || (fieldName.equals(""))) { |
503 if ((fieldName == null) || (fieldName.isEmpty())) { |
504 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { |
504 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { |
505 MODELMBEAN_LOGGER.log(Level.TRACE, |
505 MODELMBEAN_LOGGER.log(Level.TRACE, |
506 "Illegal arguments: null field name"); |
506 "Illegal arguments: null field name"); |
507 } |
507 } |
508 final String msg = "Fieldname requested is null"; |
508 final String msg = "Fieldname requested is null"; |
520 |
520 |
521 public synchronized void setField(String fieldName, Object fieldValue) |
521 public synchronized void setField(String fieldName, Object fieldValue) |
522 throws RuntimeOperationsException { |
522 throws RuntimeOperationsException { |
523 |
523 |
524 // field name cannot be null or empty |
524 // field name cannot be null or empty |
525 if ((fieldName == null) || (fieldName.equals(""))) { |
525 if ((fieldName == null) || (fieldName.isEmpty())) { |
526 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { |
526 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { |
527 MODELMBEAN_LOGGER.log(Level.TRACE, |
527 MODELMBEAN_LOGGER.log(Level.TRACE, |
528 "Illegal arguments: null or empty field name"); |
528 "Illegal arguments: null or empty field name"); |
529 } |
529 } |
530 |
530 |
662 if (fieldNames == null) { |
662 if (fieldNames == null) { |
663 for (Object value : descriptorMap.values()) |
663 for (Object value : descriptorMap.values()) |
664 responseFields[i++] = value; |
664 responseFields[i++] = value; |
665 } else { |
665 } else { |
666 for (i=0; i < fieldNames.length; i++) { |
666 for (i=0; i < fieldNames.length; i++) { |
667 if ((fieldNames[i] == null) || (fieldNames[i].equals(""))) { |
667 if ((fieldNames[i] == null) || (fieldNames[i].isEmpty())) { |
668 responseFields[i] = null; |
668 responseFields[i] = null; |
669 } else { |
669 } else { |
670 responseFields[i] = getFieldValue(fieldNames[i]); |
670 responseFields[i] = getFieldValue(fieldNames[i]); |
671 } |
671 } |
672 } |
672 } |
698 final RuntimeException iae = new IllegalArgumentException(msg); |
698 final RuntimeException iae = new IllegalArgumentException(msg); |
699 throw new RuntimeOperationsException(iae, msg); |
699 throw new RuntimeOperationsException(iae, msg); |
700 } |
700 } |
701 |
701 |
702 for (int i=0; i < fieldNames.length; i++) { |
702 for (int i=0; i < fieldNames.length; i++) { |
703 if (( fieldNames[i] == null) || (fieldNames[i].equals(""))) { |
703 if (( fieldNames[i] == null) || (fieldNames[i].isEmpty())) { |
704 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { |
704 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { |
705 MODELMBEAN_LOGGER.log(Level.TRACE, |
705 MODELMBEAN_LOGGER.log(Level.TRACE, |
706 "Null field name encountered at element " + i); |
706 "Null field name encountered at element " + i); |
707 } |
707 } |
708 final String msg = "fieldNames is null or invalid"; |
708 final String msg = "fieldNames is null or invalid"; |
731 } |
731 } |
732 return(new DescriptorSupport(this)); |
732 return(new DescriptorSupport(this)); |
733 } |
733 } |
734 |
734 |
735 public synchronized void removeField(String fieldName) { |
735 public synchronized void removeField(String fieldName) { |
736 if ((fieldName == null) || (fieldName.equals(""))) { |
736 if ((fieldName == null) || (fieldName.isEmpty())) { |
737 return; |
737 return; |
738 } |
738 } |
739 |
739 |
740 descriptorMap.remove(fieldName); |
740 descriptorMap.remove(fieldName); |
741 } |
741 } |
860 // must have a name and descriptor type field |
860 // must have a name and descriptor type field |
861 String thisName = (String)(this.getFieldValue("name")); |
861 String thisName = (String)(this.getFieldValue("name")); |
862 String thisDescType = (String)(getFieldValue("descriptorType")); |
862 String thisDescType = (String)(getFieldValue("descriptorType")); |
863 |
863 |
864 if ((thisName == null) || (thisDescType == null) || |
864 if ((thisName == null) || (thisDescType == null) || |
865 (thisName.equals("")) || (thisDescType.equals(""))) { |
865 (thisName.isEmpty()) || (thisDescType.isEmpty())) { |
866 return false; |
866 return false; |
867 } |
867 } |
868 |
868 |
869 // According to the descriptor type we validate the fields contained |
869 // According to the descriptor type we validate the fields contained |
870 |
870 |
910 // class is not null |
910 // class is not null |
911 // lastReturnedTimeStamp is numeric |
911 // lastReturnedTimeStamp is numeric |
912 |
912 |
913 |
913 |
914 private boolean validateField(String fldName, Object fldValue) { |
914 private boolean validateField(String fldName, Object fldValue) { |
915 if ((fldName == null) || (fldName.equals(""))) |
915 if ((fldName == null) || (fldName.isEmpty())) |
916 return false; |
916 return false; |
917 String SfldValue = ""; |
917 String SfldValue = ""; |
918 boolean isAString = false; |
918 boolean isAString = false; |
919 if ((fldValue != null) && (fldValue instanceof java.lang.String)) { |
919 if ((fldValue != null) && (fldValue instanceof java.lang.String)) { |
920 SfldValue = (String) fldValue; |
920 SfldValue = (String) fldValue; |
929 fldName.equalsIgnoreCase("GetMethod") || |
929 fldName.equalsIgnoreCase("GetMethod") || |
930 fldName.equalsIgnoreCase("Role") || |
930 fldName.equalsIgnoreCase("Role") || |
931 fldName.equalsIgnoreCase("Class")) { |
931 fldName.equalsIgnoreCase("Class")) { |
932 if (fldValue == null || !isAString) |
932 if (fldValue == null || !isAString) |
933 return false; |
933 return false; |
934 if (nameOrDescriptorType && SfldValue.equals("")) |
934 if (nameOrDescriptorType && SfldValue.isEmpty()) |
935 return false; |
935 return false; |
936 return true; |
936 return true; |
937 } else if (fldName.equalsIgnoreCase("visibility")) { |
937 } else if (fldName.equalsIgnoreCase("visibility")) { |
938 long v; |
938 long v; |
939 if ((fldValue != null) && (isAString)) { |
939 if ((fldValue != null) && (isAString)) { |