jdk/src/java.management/share/classes/javax/management/modelmbean/DescriptorSupport.java
changeset 43235 da1786d695b6
parent 35268 d5aa211825e1
equal deleted inserted replaced
43234:cb2a6851b837 43235:da1786d695b6
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    49 import java.util.Map;
    49 import java.util.Map;
    50 import java.util.Set;
    50 import java.util.Set;
    51 import java.util.SortedMap;
    51 import java.util.SortedMap;
    52 import java.util.StringTokenizer;
    52 import java.util.StringTokenizer;
    53 import java.util.TreeMap;
    53 import java.util.TreeMap;
    54 import java.util.logging.Level;
    54 import java.lang.System.Logger.Level;
    55 
    55 
    56 import javax.management.Descriptor;
    56 import javax.management.Descriptor;
    57 import javax.management.ImmutableDescriptor;
    57 import javax.management.ImmutableDescriptor;
    58 import javax.management.MBeanException;
    58 import javax.management.MBeanException;
    59 import javax.management.RuntimeOperationsException;
    59 import javax.management.RuntimeOperationsException;
   162      * Default initial descriptor size is 20.  It will grow as needed.<br>
   162      * Default initial descriptor size is 20.  It will grow as needed.<br>
   163      * Note that the created empty descriptor is not a valid descriptor
   163      * Note that the created empty descriptor is not a valid descriptor
   164      * (the method {@link #isValid isValid} returns <CODE>false</CODE>)
   164      * (the method {@link #isValid isValid} returns <CODE>false</CODE>)
   165      */
   165      */
   166     public DescriptorSupport() {
   166     public DescriptorSupport() {
   167         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   167         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   168             MODELMBEAN_LOGGER.logp(Level.FINEST,
   168             MODELMBEAN_LOGGER.log(Level.TRACE, "Constructor");
   169                     DescriptorSupport.class.getName(),
       
   170                     "DescriptorSupport()" , "Constructor");
       
   171         }
   169         }
   172         init(null);
   170         init(null);
   173     }
   171     }
   174 
   172 
   175     /**
   173     /**
   186      * initNumFields (&lt;= 0)
   184      * initNumFields (&lt;= 0)
   187      * @exception MBeanException Wraps a distributed communication Exception.
   185      * @exception MBeanException Wraps a distributed communication Exception.
   188      */
   186      */
   189     public DescriptorSupport(int initNumFields)
   187     public DescriptorSupport(int initNumFields)
   190             throws MBeanException, RuntimeOperationsException {
   188             throws MBeanException, RuntimeOperationsException {
   191         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   189         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   192             MODELMBEAN_LOGGER.logp(Level.FINEST,
   190             MODELMBEAN_LOGGER.log(Level.TRACE,
   193                     DescriptorSupport.class.getName(),
   191                     "Descriptor(initNumFields = " + initNumFields + ") " +
   194                     "Descriptor(initNumFields = " + initNumFields + ")",
       
   195                     "Constructor");
   192                     "Constructor");
   196         }
   193         }
   197         if (initNumFields <= 0) {
   194         if (initNumFields <= 0) {
   198             if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   195             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   199                 MODELMBEAN_LOGGER.logp(Level.FINEST,
   196                 MODELMBEAN_LOGGER.log(Level.TRACE,
   200                         DescriptorSupport.class.getName(),
       
   201                         "Descriptor(initNumFields)",
       
   202                         "Illegal arguments: initNumFields <= 0");
   197                         "Illegal arguments: initNumFields <= 0");
   203             }
   198             }
   204             final String msg =
   199             final String msg =
   205                 "Descriptor field limit invalid: " + initNumFields;
   200                 "Descriptor field limit invalid: " + initNumFields;
   206             final RuntimeException iae = new IllegalArgumentException(msg);
   201             final RuntimeException iae = new IllegalArgumentException(msg);
   217      * @param inDescr the descriptor to be used to initialize the
   212      * @param inDescr the descriptor to be used to initialize the
   218      * constructed descriptor. If it is null or contains no descriptor
   213      * constructed descriptor. If it is null or contains no descriptor
   219      * fields, an empty Descriptor will be created.
   214      * fields, an empty Descriptor will be created.
   220      */
   215      */
   221     public DescriptorSupport(DescriptorSupport inDescr) {
   216     public DescriptorSupport(DescriptorSupport inDescr) {
   222         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   217         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   223             MODELMBEAN_LOGGER.logp(Level.FINEST,
   218             MODELMBEAN_LOGGER.log(Level.TRACE,
   224                     DescriptorSupport.class.getName(),
   219                     "Descriptor(Descriptor) Constructor");
   225                     "Descriptor(Descriptor)", "Constructor");
       
   226         }
   220         }
   227         if (inDescr == null)
   221         if (inDescr == null)
   228             init(null);
   222             init(null);
   229         else
   223         else
   230             init(inDescr.descriptorMap);
   224             init(inDescr.descriptorMap);
   266     public DescriptorSupport(String inStr)
   260     public DescriptorSupport(String inStr)
   267             throws MBeanException, RuntimeOperationsException,
   261             throws MBeanException, RuntimeOperationsException,
   268                    XMLParseException {
   262                    XMLParseException {
   269         /* parse an XML-formatted string and populate internal
   263         /* parse an XML-formatted string and populate internal
   270          * structure with it */
   264          * structure with it */
   271         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   265         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   272             MODELMBEAN_LOGGER.logp(Level.FINEST,
   266             MODELMBEAN_LOGGER.log(Level.TRACE,
   273                     DescriptorSupport.class.getName(),
   267                     "Descriptor(String = '" + inStr + "') Constructor");
   274                     "Descriptor(String = '" + inStr + "')", "Constructor");
       
   275         }
   268         }
   276         if (inStr == null) {
   269         if (inStr == null) {
   277             if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   270             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   278                 MODELMBEAN_LOGGER.logp(Level.FINEST,
   271                 MODELMBEAN_LOGGER.log(Level.TRACE,
   279                         DescriptorSupport.class.getName(),
   272                         "Descriptor(String = null) Illegal arguments");
   280                         "Descriptor(String = null)", "Illegal arguments");
       
   281             }
   273             }
   282             final String msg = "String in parameter is null";
   274             final String msg = "String in parameter is null";
   283             final RuntimeException iae = new IllegalArgumentException(msg);
   275             final RuntimeException iae = new IllegalArgumentException(msg);
   284             throw new RuntimeOperationsException(iae, msg);
   276             throw new RuntimeOperationsException(iae, msg);
   285         }
   277         }
   348                         "Expected `keyword=value', got `" + tok + "'";
   340                         "Expected `keyword=value', got `" + tok + "'";
   349                     throw new XMLParseException(msg);
   341                     throw new XMLParseException(msg);
   350                 }
   342                 }
   351             }
   343             }
   352         }  // while tokens
   344         }  // while tokens
   353         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   345         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   354             MODELMBEAN_LOGGER.logp(Level.FINEST,
   346             MODELMBEAN_LOGGER.log(Level.TRACE,
   355                     DescriptorSupport.class.getName(),
   347                     "Descriptor(XMLString) Exit");
   356                     "Descriptor(XMLString)", "Exit");
       
   357         }
   348         }
   358     }
   349     }
   359 
   350 
   360     /**
   351     /**
   361      * Constructor taking field names and field values.  Neither array
   352      * Constructor taking field names and field values.  Neither array
   378      * exception will be thrown.
   369      * exception will be thrown.
   379      *
   370      *
   380      */
   371      */
   381     public DescriptorSupport(String[] fieldNames, Object[] fieldValues)
   372     public DescriptorSupport(String[] fieldNames, Object[] fieldValues)
   382             throws RuntimeOperationsException {
   373             throws RuntimeOperationsException {
   383         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   374         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   384             MODELMBEAN_LOGGER.logp(Level.FINEST,
   375             MODELMBEAN_LOGGER.log(Level.TRACE,
   385                     DescriptorSupport.class.getName(),
   376                     "Descriptor(fieldNames,fieldObjects) Constructor");
   386                     "Descriptor(fieldNames,fieldObjects)", "Constructor");
       
   387         }
   377         }
   388 
   378 
   389         if ((fieldNames == null) || (fieldValues == null) ||
   379         if ((fieldNames == null) || (fieldValues == null) ||
   390             (fieldNames.length != fieldValues.length)) {
   380             (fieldNames.length != fieldValues.length)) {
   391             if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   381             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   392                 MODELMBEAN_LOGGER.logp(Level.FINEST,
   382                 MODELMBEAN_LOGGER.log(Level.TRACE,
   393                         DescriptorSupport.class.getName(),
   383                         "Descriptor(fieldNames,fieldObjects)" +
   394                         "Descriptor(fieldNames,fieldObjects)",
   384                         " Illegal arguments");
   395                         "Illegal arguments");
       
   396             }
   385             }
   397 
   386 
   398             final String msg =
   387             final String msg =
   399                 "Null or invalid fieldNames or fieldValues";
   388                 "Null or invalid fieldNames or fieldValues";
   400             final RuntimeException iae = new IllegalArgumentException(msg);
   389             final RuntimeException iae = new IllegalArgumentException(msg);
   406         for (int i=0; i < fieldNames.length; i++) {
   395         for (int i=0; i < fieldNames.length; i++) {
   407             // setField will throw an exception if a fieldName is be null.
   396             // setField will throw an exception if a fieldName is be null.
   408             // the fieldName and fieldValue will be validated in setField.
   397             // the fieldName and fieldValue will be validated in setField.
   409             setField(fieldNames[i], fieldValues[i]);
   398             setField(fieldNames[i], fieldValues[i]);
   410         }
   399         }
   411         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   400         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   412             MODELMBEAN_LOGGER.logp(Level.FINEST,
   401             MODELMBEAN_LOGGER.log(Level.TRACE,
   413                     DescriptorSupport.class.getName(),
   402                     "Descriptor(fieldNames,fieldObjects) Exit");
   414                     "Descriptor(fieldNames,fieldObjects)", "Exit");
       
   415         }
   403         }
   416     }
   404     }
   417 
   405 
   418     /**
   406     /**
   419      * Constructor taking fields in the <i>fieldName=fieldValue</i>
   407      * Constructor taking fields in the <i>fieldName=fieldValue</i>
   442      * this exception will be thrown.
   430      * this exception will be thrown.
   443      *
   431      *
   444      */
   432      */
   445     public DescriptorSupport(String... fields)
   433     public DescriptorSupport(String... fields)
   446     {
   434     {
   447         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   435         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   448             MODELMBEAN_LOGGER.logp(Level.FINEST,
   436             MODELMBEAN_LOGGER.log(Level.TRACE,
   449                     DescriptorSupport.class.getName(),
   437                     "Descriptor(String... fields) Constructor");
   450                     "Descriptor(String... fields)", "Constructor");
       
   451         }
   438         }
   452         init(null);
   439         init(null);
   453         if (( fields == null ) || ( fields.length == 0))
   440         if (( fields == null ) || ( fields.length == 0))
   454             return;
   441             return;
   455 
   442 
   460                 continue;
   447                 continue;
   461             }
   448             }
   462             int eq_separator = fields[i].indexOf('=');
   449             int eq_separator = fields[i].indexOf('=');
   463             if (eq_separator < 0) {
   450             if (eq_separator < 0) {
   464                 // illegal if no = or is first character
   451                 // illegal if no = or is first character
   465                 if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   452                 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   466                     MODELMBEAN_LOGGER.logp(Level.FINEST,
   453                     MODELMBEAN_LOGGER.log(Level.TRACE,
   467                             DescriptorSupport.class.getName(),
   454                             "Descriptor(String... fields) " +
   468                             "Descriptor(String... fields)",
       
   469                             "Illegal arguments: field does not have " +
   455                             "Illegal arguments: field does not have " +
   470                             "'=' as a name and value separator");
   456                             "'=' as a name and value separator");
   471                 }
   457                 }
   472                 final String msg = "Field in invalid format: no equals sign";
   458                 final String msg = "Field in invalid format: no equals sign";
   473                 final RuntimeException iae = new IllegalArgumentException(msg);
   459                 final RuntimeException iae = new IllegalArgumentException(msg);
   480                 // = is not in last character
   466                 // = is not in last character
   481                 fieldValue = fields[i].substring(eq_separator+1);
   467                 fieldValue = fields[i].substring(eq_separator+1);
   482             }
   468             }
   483 
   469 
   484             if (fieldName.equals("")) {
   470             if (fieldName.equals("")) {
   485                 if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   471                 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   486                     MODELMBEAN_LOGGER.logp(Level.FINEST,
   472                     MODELMBEAN_LOGGER.log(Level.TRACE,
   487                             DescriptorSupport.class.getName(),
   473                             "Descriptor(String... fields) " +
   488                             "Descriptor(String... fields)",
       
   489                             "Illegal arguments: fieldName is empty");
   474                             "Illegal arguments: fieldName is empty");
   490                 }
   475                 }
   491 
   476 
   492                 final String msg = "Field in invalid format: no fieldName";
   477                 final String msg = "Field in invalid format: no fieldName";
   493                 final RuntimeException iae = new IllegalArgumentException(msg);
   478                 final RuntimeException iae = new IllegalArgumentException(msg);
   494                 throw new RuntimeOperationsException(iae, msg);
   479                 throw new RuntimeOperationsException(iae, msg);
   495             }
   480             }
   496 
   481 
   497             setField(fieldName,fieldValue);
   482             setField(fieldName,fieldValue);
   498         }
   483         }
   499         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   484         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   500             MODELMBEAN_LOGGER.logp(Level.FINEST,
   485             MODELMBEAN_LOGGER.log(Level.TRACE,
   501                     DescriptorSupport.class.getName(),
   486                     "Descriptor(String... fields) Exit");
   502                     "Descriptor(String... fields)", "Exit");
       
   503         }
   487         }
   504     }
   488     }
   505 
   489 
   506     private void init(Map<String, ?> initMap) {
   490     private void init(Map<String, ?> initMap) {
   507         descriptorMap =
   491         descriptorMap =
   515 
   499 
   516     public synchronized Object getFieldValue(String fieldName)
   500     public synchronized Object getFieldValue(String fieldName)
   517             throws RuntimeOperationsException {
   501             throws RuntimeOperationsException {
   518 
   502 
   519         if ((fieldName == null) || (fieldName.equals(""))) {
   503         if ((fieldName == null) || (fieldName.equals(""))) {
   520             if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   504             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   521                 MODELMBEAN_LOGGER.logp(Level.FINEST,
   505                 MODELMBEAN_LOGGER.log(Level.TRACE,
   522                         DescriptorSupport.class.getName(),
       
   523                         "getFieldValue(String fieldName)",
       
   524                         "Illegal arguments: null field name");
   506                         "Illegal arguments: null field name");
   525             }
   507             }
   526             final String msg = "Fieldname requested is null";
   508             final String msg = "Fieldname requested is null";
   527             final RuntimeException iae = new IllegalArgumentException(msg);
   509             final RuntimeException iae = new IllegalArgumentException(msg);
   528             throw new RuntimeOperationsException(iae, msg);
   510             throw new RuntimeOperationsException(iae, msg);
   529         }
   511         }
   530         Object retValue = descriptorMap.get(fieldName);
   512         Object retValue = descriptorMap.get(fieldName);
   531         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   513         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   532             MODELMBEAN_LOGGER.logp(Level.FINEST,
   514             MODELMBEAN_LOGGER.log(Level.TRACE,
   533                     DescriptorSupport.class.getName(),
   515                     "getFieldValue(String fieldName = " + fieldName + ") " +
   534                     "getFieldValue(String fieldName = " + fieldName + ")",
       
   535                     "Returns '" + retValue + "'");
   516                     "Returns '" + retValue + "'");
   536         }
   517         }
   537         return(retValue);
   518         return(retValue);
   538     }
   519     }
   539 
   520 
   540     public synchronized void setField(String fieldName, Object fieldValue)
   521     public synchronized void setField(String fieldName, Object fieldValue)
   541             throws RuntimeOperationsException {
   522             throws RuntimeOperationsException {
   542 
   523 
   543         // field name cannot be null or empty
   524         // field name cannot be null or empty
   544         if ((fieldName == null) || (fieldName.equals(""))) {
   525         if ((fieldName == null) || (fieldName.equals(""))) {
   545             if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   526             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   546                 MODELMBEAN_LOGGER.logp(Level.FINEST,
   527                 MODELMBEAN_LOGGER.log(Level.TRACE,
   547                         DescriptorSupport.class.getName(),
       
   548                         "setField(fieldName,fieldValue)",
       
   549                         "Illegal arguments: null or empty field name");
   528                         "Illegal arguments: null or empty field name");
   550             }
   529             }
   551 
   530 
   552             final String msg = "Field name to be set is null or empty";
   531             final String msg = "Field name to be set is null or empty";
   553             final RuntimeException iae = new IllegalArgumentException(msg);
   532             final RuntimeException iae = new IllegalArgumentException(msg);
   554             throw new RuntimeOperationsException(iae, msg);
   533             throw new RuntimeOperationsException(iae, msg);
   555         }
   534         }
   556 
   535 
   557         if (!validateField(fieldName, fieldValue)) {
   536         if (!validateField(fieldName, fieldValue)) {
   558             if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   537             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   559                 MODELMBEAN_LOGGER.logp(Level.FINEST,
   538                 MODELMBEAN_LOGGER.log(Level.TRACE,
   560                         DescriptorSupport.class.getName(),
       
   561                         "setField(fieldName,fieldValue)",
       
   562                         "Illegal arguments");
   539                         "Illegal arguments");
   563             }
   540             }
   564 
   541 
   565             final String msg =
   542             final String msg =
   566                 "Field value invalid: " + fieldName + "=" + fieldValue;
   543                 "Field value invalid: " + fieldName + "=" + fieldValue;
   567             final RuntimeException iae = new IllegalArgumentException(msg);
   544             final RuntimeException iae = new IllegalArgumentException(msg);
   568             throw new RuntimeOperationsException(iae, msg);
   545             throw new RuntimeOperationsException(iae, msg);
   569         }
   546         }
   570 
   547 
   571         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   548         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   572             MODELMBEAN_LOGGER.logp(Level.FINEST,
   549             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry: setting '"
   573                     DescriptorSupport.class.getName(),
       
   574                     "setField(fieldName,fieldValue)", "Entry: setting '"
       
   575                     + fieldName + "' to '" + fieldValue + "'");
   550                     + fieldName + "' to '" + fieldValue + "'");
   576         }
   551         }
   577 
   552 
   578         // Since we do not remove any existing entry with this name,
   553         // Since we do not remove any existing entry with this name,
   579         // the field will preserve whatever case it had, ignoring
   554         // the field will preserve whatever case it had, ignoring
   580         // any difference there might be in fieldName.
   555         // any difference there might be in fieldName.
   581         descriptorMap.put(fieldName, fieldValue);
   556         descriptorMap.put(fieldName, fieldValue);
   582     }
   557     }
   583 
   558 
   584     public synchronized String[] getFields() {
   559     public synchronized String[] getFields() {
   585         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   560         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   586             MODELMBEAN_LOGGER.logp(Level.FINEST,
   561             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
   587                     DescriptorSupport.class.getName(),
       
   588                     "getFields()", "Entry");
       
   589         }
   562         }
   590         int numberOfEntries = descriptorMap.size();
   563         int numberOfEntries = descriptorMap.size();
   591 
   564 
   592         String[] responseFields = new String[numberOfEntries];
   565         String[] responseFields = new String[numberOfEntries];
   593         Set<Map.Entry<String, Object>> returnedSet = descriptorMap.entrySet();
   566         Set<Map.Entry<String, Object>> returnedSet = descriptorMap.entrySet();
   594 
   567 
   595         int i = 0;
   568         int i = 0;
   596 
   569 
   597         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   570         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   598             MODELMBEAN_LOGGER.logp(Level.FINEST,
   571             MODELMBEAN_LOGGER.log(Level.TRACE,
   599                     DescriptorSupport.class.getName(),
   572                     "Returning " + numberOfEntries + " fields");
   600                     "getFields()", "Returning " + numberOfEntries + " fields");
       
   601         }
   573         }
   602         for (Iterator<Map.Entry<String, Object>> iter = returnedSet.iterator();
   574         for (Iterator<Map.Entry<String, Object>> iter = returnedSet.iterator();
   603              iter.hasNext(); i++) {
   575              iter.hasNext(); i++) {
   604             Map.Entry<String, Object> currElement = iter.next();
   576             Map.Entry<String, Object> currElement = iter.next();
   605 
   577 
   606             if (currElement == null) {
   578             if (currElement == null) {
   607                 if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   579                 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   608                     MODELMBEAN_LOGGER.logp(Level.FINEST,
   580                     MODELMBEAN_LOGGER.log(Level.TRACE,
   609                             DescriptorSupport.class.getName(),
   581                             "Element is null");
   610                             "getFields()", "Element is null");
       
   611                 }
   582                 }
   612             } else {
   583             } else {
   613                 Object currValue = currElement.getValue();
   584                 Object currValue = currElement.getValue();
   614                 if (currValue == null) {
   585                 if (currValue == null) {
   615                     responseFields[i] = currElement.getKey() + "=";
   586                     responseFields[i] = currElement.getKey() + "=";
   624                     }
   595                     }
   625                 }
   596                 }
   626             }
   597             }
   627         }
   598         }
   628 
   599 
   629         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   600         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   630             MODELMBEAN_LOGGER.logp(Level.FINEST,
   601             MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
   631                     DescriptorSupport.class.getName(),
       
   632                     "getFields()", "Exit");
       
   633         }
   602         }
   634 
   603 
   635         return responseFields;
   604         return responseFields;
   636     }
   605     }
   637 
   606 
   638     public synchronized String[] getFieldNames() {
   607     public synchronized String[] getFieldNames() {
   639         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   608         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   640             MODELMBEAN_LOGGER.logp(Level.FINEST,
   609             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
   641                     DescriptorSupport.class.getName(),
       
   642                     "getFieldNames()", "Entry");
       
   643         }
   610         }
   644         int numberOfEntries = descriptorMap.size();
   611         int numberOfEntries = descriptorMap.size();
   645 
   612 
   646         String[] responseFields = new String[numberOfEntries];
   613         String[] responseFields = new String[numberOfEntries];
   647         Set<Map.Entry<String, Object>> returnedSet = descriptorMap.entrySet();
   614         Set<Map.Entry<String, Object>> returnedSet = descriptorMap.entrySet();
   648 
   615 
   649         int i = 0;
   616         int i = 0;
   650 
   617 
   651         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   618         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   652             MODELMBEAN_LOGGER.logp(Level.FINEST,
   619             MODELMBEAN_LOGGER.log(Level.TRACE,
   653                     DescriptorSupport.class.getName(),
       
   654                     "getFieldNames()",
       
   655                     "Returning " + numberOfEntries + " fields");
   620                     "Returning " + numberOfEntries + " fields");
   656         }
   621         }
   657 
   622 
   658         for (Iterator<Map.Entry<String, Object>> iter = returnedSet.iterator();
   623         for (Iterator<Map.Entry<String, Object>> iter = returnedSet.iterator();
   659              iter.hasNext(); i++) {
   624              iter.hasNext(); i++) {
   660             Map.Entry<String, Object> currElement = iter.next();
   625             Map.Entry<String, Object> currElement = iter.next();
   661 
   626 
   662             if (( currElement == null ) || (currElement.getKey() == null)) {
   627             if (( currElement == null ) || (currElement.getKey() == null)) {
   663                 if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   628                 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   664                     MODELMBEAN_LOGGER.logp(Level.FINEST,
   629                     MODELMBEAN_LOGGER.log(Level.TRACE, "Field is null");
   665                             DescriptorSupport.class.getName(),
       
   666                             "getFieldNames()", "Field is null");
       
   667                 }
   630                 }
   668             } else {
   631             } else {
   669                 responseFields[i] = currElement.getKey().toString();
   632                 responseFields[i] = currElement.getKey().toString();
   670             }
   633             }
   671         }
   634         }
   672 
   635 
   673         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   636         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   674             MODELMBEAN_LOGGER.logp(Level.FINEST,
   637             MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
   675                     DescriptorSupport.class.getName(),
       
   676                     "getFieldNames()", "Exit");
       
   677         }
   638         }
   678 
   639 
   679         return responseFields;
   640         return responseFields;
   680     }
   641     }
   681 
   642 
   682 
   643 
   683     public synchronized Object[] getFieldValues(String... fieldNames) {
   644     public synchronized Object[] getFieldValues(String... fieldNames) {
   684         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   645         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   685             MODELMBEAN_LOGGER.logp(Level.FINEST,
   646             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
   686                     DescriptorSupport.class.getName(),
       
   687                     "getFieldValues(String... fieldNames)", "Entry");
       
   688         }
   647         }
   689         // if fieldNames == null return all values
   648         // if fieldNames == null return all values
   690         // if fieldNames is String[0] return no values
   649         // if fieldNames is String[0] return no values
   691 
   650 
   692         final int numberOfEntries =
   651         final int numberOfEntries =
   693             (fieldNames == null) ? descriptorMap.size() : fieldNames.length;
   652             (fieldNames == null) ? descriptorMap.size() : fieldNames.length;
   694         final Object[] responseFields = new Object[numberOfEntries];
   653         final Object[] responseFields = new Object[numberOfEntries];
   695 
   654 
   696         int i = 0;
   655         int i = 0;
   697 
   656 
   698         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   657         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   699             MODELMBEAN_LOGGER.logp(Level.FINEST,
   658             MODELMBEAN_LOGGER.log(Level.TRACE,
   700                     DescriptorSupport.class.getName(),
       
   701                     "getFieldValues(String... fieldNames)",
       
   702                     "Returning " + numberOfEntries + " fields");
   659                     "Returning " + numberOfEntries + " fields");
   703         }
   660         }
   704 
   661 
   705         if (fieldNames == null) {
   662         if (fieldNames == null) {
   706             for (Object value : descriptorMap.values())
   663             for (Object value : descriptorMap.values())
   713                     responseFields[i] = getFieldValue(fieldNames[i]);
   670                     responseFields[i] = getFieldValue(fieldNames[i]);
   714                 }
   671                 }
   715             }
   672             }
   716         }
   673         }
   717 
   674 
   718         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   675         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   719             MODELMBEAN_LOGGER.logp(Level.FINEST,
   676             MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
   720                     DescriptorSupport.class.getName(),
       
   721                     "getFieldValues(String... fieldNames)", "Exit");
       
   722         }
   677         }
   723 
   678 
   724         return responseFields;
   679         return responseFields;
   725     }
   680     }
   726 
   681 
   727     public synchronized void setFields(String[] fieldNames,
   682     public synchronized void setFields(String[] fieldNames,
   728                                        Object[] fieldValues)
   683                                        Object[] fieldValues)
   729             throws RuntimeOperationsException {
   684             throws RuntimeOperationsException {
   730 
   685 
   731         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   686         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   732             MODELMBEAN_LOGGER.logp(Level.FINEST,
   687             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
   733                     DescriptorSupport.class.getName(),
       
   734                     "setFields(fieldNames,fieldValues)", "Entry");
       
   735         }
   688         }
   736 
   689 
   737         if ((fieldNames == null) || (fieldValues == null) ||
   690         if ((fieldNames == null) || (fieldValues == null) ||
   738             (fieldNames.length != fieldValues.length)) {
   691             (fieldNames.length != fieldValues.length)) {
   739             if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   692             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   740                 MODELMBEAN_LOGGER.logp(Level.FINEST,
   693                 MODELMBEAN_LOGGER.log(Level.TRACE,
   741                         DescriptorSupport.class.getName(),
       
   742                         "setFields(fieldNames,fieldValues)",
       
   743                         "Illegal arguments");
   694                         "Illegal arguments");
   744             }
   695             }
   745 
   696 
   746             final String msg = "fieldNames and fieldValues are null or invalid";
   697             final String msg = "fieldNames and fieldValues are null or invalid";
   747             final RuntimeException iae = new IllegalArgumentException(msg);
   698             final RuntimeException iae = new IllegalArgumentException(msg);
   748             throw new RuntimeOperationsException(iae, msg);
   699             throw new RuntimeOperationsException(iae, msg);
   749         }
   700         }
   750 
   701 
   751         for (int i=0; i < fieldNames.length; i++) {
   702         for (int i=0; i < fieldNames.length; i++) {
   752             if (( fieldNames[i] == null) || (fieldNames[i].equals(""))) {
   703             if (( fieldNames[i] == null) || (fieldNames[i].equals(""))) {
   753                 if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   704                 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   754                     MODELMBEAN_LOGGER.logp(Level.FINEST,
   705                     MODELMBEAN_LOGGER.log(Level.TRACE,
   755                             DescriptorSupport.class.getName(),
       
   756                             "setFields(fieldNames,fieldValues)",
       
   757                             "Null field name encountered at element " + i);
   706                             "Null field name encountered at element " + i);
   758                 }
   707                 }
   759                 final String msg = "fieldNames is null or invalid";
   708                 final String msg = "fieldNames is null or invalid";
   760                 final RuntimeException iae = new IllegalArgumentException(msg);
   709                 final RuntimeException iae = new IllegalArgumentException(msg);
   761                 throw new RuntimeOperationsException(iae, msg);
   710                 throw new RuntimeOperationsException(iae, msg);
   762             }
   711             }
   763             setField(fieldNames[i], fieldValues[i]);
   712             setField(fieldNames[i], fieldValues[i]);
   764         }
   713         }
   765         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   714         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   766             MODELMBEAN_LOGGER.logp(Level.FINEST,
   715             MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
   767                     DescriptorSupport.class.getName(),
       
   768                     "setFields(fieldNames,fieldValues)", "Exit");
       
   769         }
   716         }
   770     }
   717     }
   771 
   718 
   772     /**
   719     /**
   773      * Returns a new Descriptor which is a duplicate of the Descriptor.
   720      * Returns a new Descriptor which is a duplicate of the Descriptor.
   777      * fails for any reason, this exception will be thrown.
   724      * fails for any reason, this exception will be thrown.
   778      */
   725      */
   779 
   726 
   780     @Override
   727     @Override
   781     public synchronized Object clone() throws RuntimeOperationsException {
   728     public synchronized Object clone() throws RuntimeOperationsException {
   782         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   729         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   783             MODELMBEAN_LOGGER.logp(Level.FINEST,
   730             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
   784                     DescriptorSupport.class.getName(),
       
   785                     "clone()", "Entry");
       
   786         }
   731         }
   787         return(new DescriptorSupport(this));
   732         return(new DescriptorSupport(this));
   788     }
   733     }
   789 
   734 
   790     public synchronized void removeField(String fieldName) {
   735     public synchronized void removeField(String fieldName) {
   896      * @exception RuntimeOperationsException If the validity checking
   841      * @exception RuntimeOperationsException If the validity checking
   897      * fails for any reason, this exception will be thrown.
   842      * fails for any reason, this exception will be thrown.
   898      */
   843      */
   899 
   844 
   900     public synchronized boolean isValid() throws RuntimeOperationsException {
   845     public synchronized boolean isValid() throws RuntimeOperationsException {
   901         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   846         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   902             MODELMBEAN_LOGGER.logp(Level.FINEST,
   847             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
   903                     DescriptorSupport.class.getName(),
       
   904                     "isValid()", "Entry");
       
   905         }
   848         }
   906         // verify that the descriptor is valid, by iterating over each field...
   849         // verify that the descriptor is valid, by iterating over each field...
   907 
   850 
   908         Set<Map.Entry<String, Object>> returnedSet = descriptorMap.entrySet();
   851         Set<Map.Entry<String, Object>> returnedSet = descriptorMap.entrySet();
   909 
   852 
   910         if (returnedSet == null) {   // null descriptor, not valid
   853         if (returnedSet == null) {   // null descriptor, not valid
   911             if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   854             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   912                 MODELMBEAN_LOGGER.logp(Level.FINEST,
   855                 MODELMBEAN_LOGGER.log(Level.TRACE,
   913                         DescriptorSupport.class.getName(),
   856                         "isValid() Returns false (null set)");
   914                         "isValid()", "Returns false (null set)");
       
   915             }
   857             }
   916             return false;
   858             return false;
   917         }
   859         }
   918         // must have a name and descriptor type field
   860         // must have a name and descriptor type field
   919         String thisName = (String)(this.getFieldValue("name"));
   861         String thisName = (String)(this.getFieldValue("name"));
   932                     // validate the field valued...
   874                     // validate the field valued...
   933                     if (validateField((currElement.getKey()).toString(),
   875                     if (validateField((currElement.getKey()).toString(),
   934                                       (currElement.getValue()).toString())) {
   876                                       (currElement.getValue()).toString())) {
   935                         continue;
   877                         continue;
   936                     } else {
   878                     } else {
   937                         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   879                         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   938                             MODELMBEAN_LOGGER.logp(Level.FINEST,
   880                             MODELMBEAN_LOGGER.log(Level.TRACE,
   939                                     DescriptorSupport.class.getName(),
       
   940                                     "isValid()",
       
   941                                     "Field " + currElement.getKey() + "=" +
   881                                     "Field " + currElement.getKey() + "=" +
   942                                     currElement.getValue() + " is not valid");
   882                                     currElement.getValue() + " is not valid");
   943                         }
   883                         }
   944                         return false;
   884                         return false;
   945                     }
   885                     }
   946                 }
   886                 }
   947             }
   887             }
   948         }
   888         }
   949 
   889 
   950         // fell through, all fields OK
   890         // fell through, all fields OK
   951         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
   891         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   952             MODELMBEAN_LOGGER.logp(Level.FINEST,
   892             MODELMBEAN_LOGGER.log(Level.TRACE,
   953                     DescriptorSupport.class.getName(),
   893                     "isValid() Returns true");
   954                     "isValid()", "Returns true");
       
   955         }
   894         }
   956         return true;
   895         return true;
   957     }
   896     }
   958 
   897 
   959 
   898 
  1285      * field Names or field Values.  If the descriptor string fails
  1224      * field Names or field Values.  If the descriptor string fails
  1286      * for any reason, this exception will be thrown.
  1225      * for any reason, this exception will be thrown.
  1287      */
  1226      */
  1288     @Override
  1227     @Override
  1289     public synchronized String toString() {
  1228     public synchronized String toString() {
  1290         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
  1229         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
  1291             MODELMBEAN_LOGGER.logp(Level.FINEST,
  1230             MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
  1292                     DescriptorSupport.class.getName(),
       
  1293                     "toString()", "Entry");
       
  1294         }
  1231         }
  1295 
  1232 
  1296         String respStr = "";
  1233         String respStr = "";
  1297         String[] fields = getFields();
  1234         String[] fields = getFields();
  1298 
  1235 
  1299         if ((fields == null) || (fields.length == 0)) {
  1236         if ((fields == null) || (fields.length == 0)) {
  1300             if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
  1237             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
  1301                 MODELMBEAN_LOGGER.logp(Level.FINEST,
  1238                 MODELMBEAN_LOGGER.log(Level.TRACE, "Empty Descriptor");
  1302                         DescriptorSupport.class.getName(),
       
  1303                         "toString()", "Empty Descriptor");
       
  1304             }
  1239             }
  1305             return respStr;
  1240             return respStr;
  1306         }
  1241         }
  1307 
  1242 
  1308         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
  1243         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
  1309             MODELMBEAN_LOGGER.logp(Level.FINEST,
  1244             MODELMBEAN_LOGGER.log(Level.TRACE,
  1310                     DescriptorSupport.class.getName(),
  1245                     "Printing " + fields.length + " fields");
  1311                     "toString()", "Printing " + fields.length + " fields");
       
  1312         }
  1246         }
  1313 
  1247 
  1314         for (int i=0; i < fields.length; i++) {
  1248         for (int i=0; i < fields.length; i++) {
  1315             if (i == (fields.length - 1)) {
  1249             if (i == (fields.length - 1)) {
  1316                 respStr = respStr.concat(fields[i]);
  1250                 respStr = respStr.concat(fields[i]);
  1317             } else {
  1251             } else {
  1318                 respStr = respStr.concat(fields[i] + ", ");
  1252                 respStr = respStr.concat(fields[i] + ", ");
  1319             }
  1253             }
  1320         }
  1254         }
  1321 
  1255 
  1322         if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
  1256         if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
  1323             MODELMBEAN_LOGGER.logp(Level.FINEST,
  1257             MODELMBEAN_LOGGER.log(Level.TRACE, "Exit returning " + respStr);
  1324                     DescriptorSupport.class.getName(),
       
  1325                     "toString()", "Exit returning " + respStr);
       
  1326         }
  1258         }
  1327 
  1259 
  1328         return respStr;
  1260         return respStr;
  1329     }
  1261     }
  1330 
  1262