< prev index next >

src/java.management/share/classes/javax/management/modelmbean/DescriptorSupport.java

Print this page
rev 52881 : 8214971: Replace use of string.equals("") with isEmpty()
Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad


 426      * field Names or field Values.  The field must contain an
 427      * "=". "=fieldValue", "fieldName", and "fieldValue" are illegal.
 428      * FieldName cannot be null.  "fieldName=" will cause the value to
 429      * be null.  If the descriptor construction fails for any reason,
 430      * this exception will be thrown.
 431      *
 432      */
 433     public DescriptorSupport(String... fields)
 434     {
 435         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 436             MODELMBEAN_LOGGER.log(Level.TRACE,
 437                     "Descriptor(String... fields) Constructor");
 438         }
 439         init(null);
 440         if (( fields == null ) || ( fields.length == 0))
 441             return;
 442 
 443         init(null);
 444 
 445         for (int i=0; i < fields.length; i++) {
 446             if ((fields[i] == null) || (fields[i].equals(""))) {
 447                 continue;
 448             }
 449             int eq_separator = fields[i].indexOf('=');
 450             if (eq_separator < 0) {
 451                 // illegal if no = or is first character
 452                 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 453                     MODELMBEAN_LOGGER.log(Level.TRACE,
 454                             "Descriptor(String... fields) " +
 455                             "Illegal arguments: field does not have " +
 456                             "'=' as a name and value separator");
 457                 }
 458                 final String msg = "Field in invalid format: no equals sign";
 459                 final RuntimeException iae = new IllegalArgumentException(msg);
 460                 throw new RuntimeOperationsException(iae, msg);
 461             }
 462 
 463             String fieldName = fields[i].substring(0,eq_separator);
 464             String fieldValue = null;
 465             if (eq_separator < fields[i].length()) {
 466                 // = is not in last character
 467                 fieldValue = fields[i].substring(eq_separator+1);
 468             }
 469 
 470             if (fieldName.equals("")) {
 471                 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 472                     MODELMBEAN_LOGGER.log(Level.TRACE,
 473                             "Descriptor(String... fields) " +
 474                             "Illegal arguments: fieldName is empty");
 475                 }
 476 
 477                 final String msg = "Field in invalid format: no fieldName";
 478                 final RuntimeException iae = new IllegalArgumentException(msg);
 479                 throw new RuntimeOperationsException(iae, msg);
 480             }
 481 
 482             setField(fieldName,fieldValue);
 483         }
 484         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 485             MODELMBEAN_LOGGER.log(Level.TRACE,
 486                     "Descriptor(String... fields) Exit");
 487         }
 488     }
 489 
 490     private void init(Map<String, ?> initMap) {
 491         descriptorMap =
 492                 new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
 493         if (initMap != null)
 494             descriptorMap.putAll(initMap);
 495     }
 496 
 497     // Implementation of the Descriptor interface
 498 
 499 
 500     public synchronized Object getFieldValue(String fieldName)
 501             throws RuntimeOperationsException {
 502 
 503         if ((fieldName == null) || (fieldName.equals(""))) {
 504             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 505                 MODELMBEAN_LOGGER.log(Level.TRACE,
 506                         "Illegal arguments: null field name");
 507             }
 508             final String msg = "Fieldname requested is null";
 509             final RuntimeException iae = new IllegalArgumentException(msg);
 510             throw new RuntimeOperationsException(iae, msg);
 511         }
 512         Object retValue = descriptorMap.get(fieldName);
 513         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 514             MODELMBEAN_LOGGER.log(Level.TRACE,
 515                     "getFieldValue(String fieldName = " + fieldName + ") " +
 516                     "Returns '" + retValue + "'");
 517         }
 518         return(retValue);
 519     }
 520 
 521     public synchronized void setField(String fieldName, Object fieldValue)
 522             throws RuntimeOperationsException {
 523 
 524         // field name cannot be null or empty
 525         if ((fieldName == null) || (fieldName.equals(""))) {
 526             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 527                 MODELMBEAN_LOGGER.log(Level.TRACE,
 528                         "Illegal arguments: null or empty field name");
 529             }
 530 
 531             final String msg = "Field name to be set is null or empty";
 532             final RuntimeException iae = new IllegalArgumentException(msg);
 533             throw new RuntimeOperationsException(iae, msg);
 534         }
 535 
 536         if (!validateField(fieldName, fieldValue)) {
 537             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 538                 MODELMBEAN_LOGGER.log(Level.TRACE,
 539                         "Illegal arguments");
 540             }
 541 
 542             final String msg =
 543                 "Field value invalid: " + fieldName + "=" + fieldValue;
 544             final RuntimeException iae = new IllegalArgumentException(msg);
 545             throw new RuntimeOperationsException(iae, msg);


 647         }
 648         // if fieldNames == null return all values
 649         // if fieldNames is String[0] return no values
 650 
 651         final int numberOfEntries =
 652             (fieldNames == null) ? descriptorMap.size() : fieldNames.length;
 653         final Object[] responseFields = new Object[numberOfEntries];
 654 
 655         int i = 0;
 656 
 657         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 658             MODELMBEAN_LOGGER.log(Level.TRACE,
 659                     "Returning " + numberOfEntries + " fields");
 660         }
 661 
 662         if (fieldNames == null) {
 663             for (Object value : descriptorMap.values())
 664                 responseFields[i++] = value;
 665         } else {
 666             for (i=0; i < fieldNames.length; i++) {
 667                 if ((fieldNames[i] == null) || (fieldNames[i].equals(""))) {
 668                     responseFields[i] = null;
 669                 } else {
 670                     responseFields[i] = getFieldValue(fieldNames[i]);
 671                 }
 672             }
 673         }
 674 
 675         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 676             MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
 677         }
 678 
 679         return responseFields;
 680     }
 681 
 682     public synchronized void setFields(String[] fieldNames,
 683                                        Object[] fieldValues)
 684             throws RuntimeOperationsException {
 685 
 686         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 687             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
 688         }
 689 
 690         if ((fieldNames == null) || (fieldValues == null) ||
 691             (fieldNames.length != fieldValues.length)) {
 692             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 693                 MODELMBEAN_LOGGER.log(Level.TRACE,
 694                         "Illegal arguments");
 695             }
 696 
 697             final String msg = "fieldNames and fieldValues are null or invalid";
 698             final RuntimeException iae = new IllegalArgumentException(msg);
 699             throw new RuntimeOperationsException(iae, msg);
 700         }
 701 
 702         for (int i=0; i < fieldNames.length; i++) {
 703             if (( fieldNames[i] == null) || (fieldNames[i].equals(""))) {
 704                 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 705                     MODELMBEAN_LOGGER.log(Level.TRACE,
 706                             "Null field name encountered at element " + i);
 707                 }
 708                 final String msg = "fieldNames is null or invalid";
 709                 final RuntimeException iae = new IllegalArgumentException(msg);
 710                 throw new RuntimeOperationsException(iae, msg);
 711             }
 712             setField(fieldNames[i], fieldValues[i]);
 713         }
 714         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 715             MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
 716         }
 717     }
 718 
 719     /**
 720      * Returns a new Descriptor which is a duplicate of the Descriptor.
 721      *
 722      * @exception RuntimeOperationsException for illegal value for
 723      * field Names or field Values.  If the descriptor construction
 724      * fails for any reason, this exception will be thrown.
 725      */
 726 
 727     @Override
 728     public synchronized Object clone() throws RuntimeOperationsException {
 729         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 730             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
 731         }
 732         return(new DescriptorSupport(this));
 733     }
 734 
 735     public synchronized void removeField(String fieldName) {
 736         if ((fieldName == null) || (fieldName.equals(""))) {
 737             return;
 738         }
 739 
 740         descriptorMap.remove(fieldName);
 741     }
 742 
 743     /**
 744      * Compares this descriptor to the given object.  The objects are equal if
 745      * the given object is also a Descriptor, and if the two Descriptors have
 746      * the same field names (possibly differing in case) and the same
 747      * associated values.  The respective values for a field in the two
 748      * Descriptors are equal if the following conditions hold:
 749      *
 750      * <ul>
 751      * <li>If one value is null then the other must be too.</li>
 752      * <li>If one value is a primitive array then the other must be a primitive
 753      * array of the same type with the same elements.</li>
 754      * <li>If one value is an object array then the other must be too and
 755      * {@link java.util.Arrays#deepEquals(Object[],Object[]) Arrays.deepEquals}
 756      * must return true.</li>


 845     public synchronized boolean isValid() throws RuntimeOperationsException {
 846         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 847             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
 848         }
 849         // verify that the descriptor is valid, by iterating over each field...
 850 
 851         Set<Map.Entry<String, Object>> returnedSet = descriptorMap.entrySet();
 852 
 853         if (returnedSet == null) {   // null descriptor, not valid
 854             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 855                 MODELMBEAN_LOGGER.log(Level.TRACE,
 856                         "isValid() Returns false (null set)");
 857             }
 858             return false;
 859         }
 860         // must have a name and descriptor type field
 861         String thisName = (String)(this.getFieldValue("name"));
 862         String thisDescType = (String)(getFieldValue("descriptorType"));
 863 
 864         if ((thisName == null) || (thisDescType == null) ||
 865             (thisName.equals("")) || (thisDescType.equals(""))) {
 866             return false;
 867         }
 868 
 869         // According to the descriptor type we validate the fields contained
 870 
 871         for (Map.Entry<String, Object> currElement : returnedSet) {
 872             if (currElement != null) {
 873                 if (currElement.getValue() != null) {
 874                     // validate the field valued...
 875                     if (validateField((currElement.getKey()).toString(),
 876                                       (currElement.getValue()).toString())) {
 877                         continue;
 878                     } else {
 879                         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 880                             MODELMBEAN_LOGGER.log(Level.TRACE,
 881                                     "Field " + currElement.getKey() + "=" +
 882                                     currElement.getValue() + " is not valid");
 883                         }
 884                         return false;
 885                     }


 895         return true;
 896     }
 897 
 898 
 899     // worker routine for isValid()
 900     // name is not null
 901     // descriptorType is not null
 902     // getMethod and setMethod are not null
 903     // persistPeriod is numeric
 904     // currencyTimeLimit is numeric
 905     // lastUpdatedTimeStamp is numeric
 906     // visibility is 1-4
 907     // severity is 0-6
 908     // log is T or F
 909     // role is not null
 910     // class is not null
 911     // lastReturnedTimeStamp is numeric
 912 
 913 
 914     private boolean validateField(String fldName, Object fldValue) {
 915         if ((fldName == null) || (fldName.equals("")))
 916             return false;
 917         String SfldValue = "";
 918         boolean isAString = false;
 919         if ((fldValue != null) && (fldValue instanceof java.lang.String)) {
 920             SfldValue = (String) fldValue;
 921             isAString = true;
 922         }
 923 
 924         boolean nameOrDescriptorType =
 925             (fldName.equalsIgnoreCase("Name") ||
 926              fldName.equalsIgnoreCase("DescriptorType"));
 927         if (nameOrDescriptorType ||
 928             fldName.equalsIgnoreCase("SetMethod") ||
 929             fldName.equalsIgnoreCase("GetMethod") ||
 930             fldName.equalsIgnoreCase("Role") ||
 931             fldName.equalsIgnoreCase("Class")) {
 932             if (fldValue == null || !isAString)
 933                 return false;
 934             if (nameOrDescriptorType && SfldValue.equals(""))
 935                 return false;
 936             return true;
 937         } else if (fldName.equalsIgnoreCase("visibility")) {
 938             long v;
 939             if ((fldValue != null) && (isAString)) {
 940                 v = toNumeric(SfldValue);
 941             } else if (fldValue instanceof java.lang.Integer) {
 942                 v = ((Integer)fldValue).intValue();
 943             } else return false;
 944 
 945             if (v >= 1 &&  v <= 4)
 946                 return true;
 947             else
 948                 return false;
 949         } else if (fldName.equalsIgnoreCase("severity")) {
 950 
 951             long v;
 952             if ((fldValue != null) && (isAString)) {
 953                 v = toNumeric(SfldValue);
 954             } else if (fldValue instanceof java.lang.Integer) {




 426      * field Names or field Values.  The field must contain an
 427      * "=". "=fieldValue", "fieldName", and "fieldValue" are illegal.
 428      * FieldName cannot be null.  "fieldName=" will cause the value to
 429      * be null.  If the descriptor construction fails for any reason,
 430      * this exception will be thrown.
 431      *
 432      */
 433     public DescriptorSupport(String... fields)
 434     {
 435         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 436             MODELMBEAN_LOGGER.log(Level.TRACE,
 437                     "Descriptor(String... fields) Constructor");
 438         }
 439         init(null);
 440         if (( fields == null ) || ( fields.length == 0))
 441             return;
 442 
 443         init(null);
 444 
 445         for (int i=0; i < fields.length; i++) {
 446             if ((fields[i] == null) || (fields[i].isEmpty())) {
 447                 continue;
 448             }
 449             int eq_separator = fields[i].indexOf('=');
 450             if (eq_separator < 0) {
 451                 // illegal if no = or is first character
 452                 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 453                     MODELMBEAN_LOGGER.log(Level.TRACE,
 454                             "Descriptor(String... fields) " +
 455                             "Illegal arguments: field does not have " +
 456                             "'=' as a name and value separator");
 457                 }
 458                 final String msg = "Field in invalid format: no equals sign";
 459                 final RuntimeException iae = new IllegalArgumentException(msg);
 460                 throw new RuntimeOperationsException(iae, msg);
 461             }
 462 
 463             String fieldName = fields[i].substring(0,eq_separator);
 464             String fieldValue = null;
 465             if (eq_separator < fields[i].length()) {
 466                 // = is not in last character
 467                 fieldValue = fields[i].substring(eq_separator+1);
 468             }
 469 
 470             if (fieldName.isEmpty()) {
 471                 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 472                     MODELMBEAN_LOGGER.log(Level.TRACE,
 473                             "Descriptor(String... fields) " +
 474                             "Illegal arguments: fieldName is empty");
 475                 }
 476 
 477                 final String msg = "Field in invalid format: no fieldName";
 478                 final RuntimeException iae = new IllegalArgumentException(msg);
 479                 throw new RuntimeOperationsException(iae, msg);
 480             }
 481 
 482             setField(fieldName,fieldValue);
 483         }
 484         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 485             MODELMBEAN_LOGGER.log(Level.TRACE,
 486                     "Descriptor(String... fields) Exit");
 487         }
 488     }
 489 
 490     private void init(Map<String, ?> initMap) {
 491         descriptorMap =
 492                 new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
 493         if (initMap != null)
 494             descriptorMap.putAll(initMap);
 495     }
 496 
 497     // Implementation of the Descriptor interface
 498 
 499 
 500     public synchronized Object getFieldValue(String fieldName)
 501             throws RuntimeOperationsException {
 502 
 503         if ((fieldName == null) || (fieldName.isEmpty())) {
 504             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 505                 MODELMBEAN_LOGGER.log(Level.TRACE,
 506                         "Illegal arguments: null field name");
 507             }
 508             final String msg = "Fieldname requested is null";
 509             final RuntimeException iae = new IllegalArgumentException(msg);
 510             throw new RuntimeOperationsException(iae, msg);
 511         }
 512         Object retValue = descriptorMap.get(fieldName);
 513         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 514             MODELMBEAN_LOGGER.log(Level.TRACE,
 515                     "getFieldValue(String fieldName = " + fieldName + ") " +
 516                     "Returns '" + retValue + "'");
 517         }
 518         return(retValue);
 519     }
 520 
 521     public synchronized void setField(String fieldName, Object fieldValue)
 522             throws RuntimeOperationsException {
 523 
 524         // field name cannot be null or empty
 525         if ((fieldName == null) || (fieldName.isEmpty())) {
 526             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 527                 MODELMBEAN_LOGGER.log(Level.TRACE,
 528                         "Illegal arguments: null or empty field name");
 529             }
 530 
 531             final String msg = "Field name to be set is null or empty";
 532             final RuntimeException iae = new IllegalArgumentException(msg);
 533             throw new RuntimeOperationsException(iae, msg);
 534         }
 535 
 536         if (!validateField(fieldName, fieldValue)) {
 537             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 538                 MODELMBEAN_LOGGER.log(Level.TRACE,
 539                         "Illegal arguments");
 540             }
 541 
 542             final String msg =
 543                 "Field value invalid: " + fieldName + "=" + fieldValue;
 544             final RuntimeException iae = new IllegalArgumentException(msg);
 545             throw new RuntimeOperationsException(iae, msg);


 647         }
 648         // if fieldNames == null return all values
 649         // if fieldNames is String[0] return no values
 650 
 651         final int numberOfEntries =
 652             (fieldNames == null) ? descriptorMap.size() : fieldNames.length;
 653         final Object[] responseFields = new Object[numberOfEntries];
 654 
 655         int i = 0;
 656 
 657         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 658             MODELMBEAN_LOGGER.log(Level.TRACE,
 659                     "Returning " + numberOfEntries + " fields");
 660         }
 661 
 662         if (fieldNames == null) {
 663             for (Object value : descriptorMap.values())
 664                 responseFields[i++] = value;
 665         } else {
 666             for (i=0; i < fieldNames.length; i++) {
 667                 if ((fieldNames[i] == null) || (fieldNames[i].isEmpty())) {
 668                     responseFields[i] = null;
 669                 } else {
 670                     responseFields[i] = getFieldValue(fieldNames[i]);
 671                 }
 672             }
 673         }
 674 
 675         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 676             MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
 677         }
 678 
 679         return responseFields;
 680     }
 681 
 682     public synchronized void setFields(String[] fieldNames,
 683                                        Object[] fieldValues)
 684             throws RuntimeOperationsException {
 685 
 686         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 687             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
 688         }
 689 
 690         if ((fieldNames == null) || (fieldValues == null) ||
 691             (fieldNames.length != fieldValues.length)) {
 692             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 693                 MODELMBEAN_LOGGER.log(Level.TRACE,
 694                         "Illegal arguments");
 695             }
 696 
 697             final String msg = "fieldNames and fieldValues are null or invalid";
 698             final RuntimeException iae = new IllegalArgumentException(msg);
 699             throw new RuntimeOperationsException(iae, msg);
 700         }
 701 
 702         for (int i=0; i < fieldNames.length; i++) {
 703             if (( fieldNames[i] == null) || (fieldNames[i].isEmpty())) {
 704                 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 705                     MODELMBEAN_LOGGER.log(Level.TRACE,
 706                             "Null field name encountered at element " + i);
 707                 }
 708                 final String msg = "fieldNames is null or invalid";
 709                 final RuntimeException iae = new IllegalArgumentException(msg);
 710                 throw new RuntimeOperationsException(iae, msg);
 711             }
 712             setField(fieldNames[i], fieldValues[i]);
 713         }
 714         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 715             MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
 716         }
 717     }
 718 
 719     /**
 720      * Returns a new Descriptor which is a duplicate of the Descriptor.
 721      *
 722      * @exception RuntimeOperationsException for illegal value for
 723      * field Names or field Values.  If the descriptor construction
 724      * fails for any reason, this exception will be thrown.
 725      */
 726 
 727     @Override
 728     public synchronized Object clone() throws RuntimeOperationsException {
 729         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 730             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
 731         }
 732         return(new DescriptorSupport(this));
 733     }
 734 
 735     public synchronized void removeField(String fieldName) {
 736         if ((fieldName == null) || (fieldName.isEmpty())) {
 737             return;
 738         }
 739 
 740         descriptorMap.remove(fieldName);
 741     }
 742 
 743     /**
 744      * Compares this descriptor to the given object.  The objects are equal if
 745      * the given object is also a Descriptor, and if the two Descriptors have
 746      * the same field names (possibly differing in case) and the same
 747      * associated values.  The respective values for a field in the two
 748      * Descriptors are equal if the following conditions hold:
 749      *
 750      * <ul>
 751      * <li>If one value is null then the other must be too.</li>
 752      * <li>If one value is a primitive array then the other must be a primitive
 753      * array of the same type with the same elements.</li>
 754      * <li>If one value is an object array then the other must be too and
 755      * {@link java.util.Arrays#deepEquals(Object[],Object[]) Arrays.deepEquals}
 756      * must return true.</li>


 845     public synchronized boolean isValid() throws RuntimeOperationsException {
 846         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 847             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
 848         }
 849         // verify that the descriptor is valid, by iterating over each field...
 850 
 851         Set<Map.Entry<String, Object>> returnedSet = descriptorMap.entrySet();
 852 
 853         if (returnedSet == null) {   // null descriptor, not valid
 854             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 855                 MODELMBEAN_LOGGER.log(Level.TRACE,
 856                         "isValid() Returns false (null set)");
 857             }
 858             return false;
 859         }
 860         // must have a name and descriptor type field
 861         String thisName = (String)(this.getFieldValue("name"));
 862         String thisDescType = (String)(getFieldValue("descriptorType"));
 863 
 864         if ((thisName == null) || (thisDescType == null) ||
 865             (thisName.isEmpty()) || (thisDescType.isEmpty())) {
 866             return false;
 867         }
 868 
 869         // According to the descriptor type we validate the fields contained
 870 
 871         for (Map.Entry<String, Object> currElement : returnedSet) {
 872             if (currElement != null) {
 873                 if (currElement.getValue() != null) {
 874                     // validate the field valued...
 875                     if (validateField((currElement.getKey()).toString(),
 876                                       (currElement.getValue()).toString())) {
 877                         continue;
 878                     } else {
 879                         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
 880                             MODELMBEAN_LOGGER.log(Level.TRACE,
 881                                     "Field " + currElement.getKey() + "=" +
 882                                     currElement.getValue() + " is not valid");
 883                         }
 884                         return false;
 885                     }


 895         return true;
 896     }
 897 
 898 
 899     // worker routine for isValid()
 900     // name is not null
 901     // descriptorType is not null
 902     // getMethod and setMethod are not null
 903     // persistPeriod is numeric
 904     // currencyTimeLimit is numeric
 905     // lastUpdatedTimeStamp is numeric
 906     // visibility is 1-4
 907     // severity is 0-6
 908     // log is T or F
 909     // role is not null
 910     // class is not null
 911     // lastReturnedTimeStamp is numeric
 912 
 913 
 914     private boolean validateField(String fldName, Object fldValue) {
 915         if ((fldName == null) || (fldName.isEmpty()))
 916             return false;
 917         String SfldValue = "";
 918         boolean isAString = false;
 919         if ((fldValue != null) && (fldValue instanceof java.lang.String)) {
 920             SfldValue = (String) fldValue;
 921             isAString = true;
 922         }
 923 
 924         boolean nameOrDescriptorType =
 925             (fldName.equalsIgnoreCase("Name") ||
 926              fldName.equalsIgnoreCase("DescriptorType"));
 927         if (nameOrDescriptorType ||
 928             fldName.equalsIgnoreCase("SetMethod") ||
 929             fldName.equalsIgnoreCase("GetMethod") ||
 930             fldName.equalsIgnoreCase("Role") ||
 931             fldName.equalsIgnoreCase("Class")) {
 932             if (fldValue == null || !isAString)
 933                 return false;
 934             if (nameOrDescriptorType && SfldValue.isEmpty())
 935                 return false;
 936             return true;
 937         } else if (fldName.equalsIgnoreCase("visibility")) {
 938             long v;
 939             if ((fldValue != null) && (isAString)) {
 940                 v = toNumeric(SfldValue);
 941             } else if (fldValue instanceof java.lang.Integer) {
 942                 v = ((Integer)fldValue).intValue();
 943             } else return false;
 944 
 945             if (v >= 1 &&  v <= 4)
 946                 return true;
 947             else
 948                 return false;
 949         } else if (fldName.equalsIgnoreCase("severity")) {
 950 
 951             long v;
 952             if ((fldValue != null) && (isAString)) {
 953                 v = toNumeric(SfldValue);
 954             } else if (fldValue instanceof java.lang.Integer) {


< prev index next >