jdk/src/share/classes/javax/management/modelmbean/ModelMBeanOperationInfo.java
changeset 4156 acaa49a2768a
parent 1513 d09513aaa9da
child 5506 202f599c92aa
equal deleted inserted replaced
4155:460e37d40f12 4156:acaa49a2768a
   206          * operation.
   206          * operation.
   207          * @param descriptor An instance of Descriptor containing the
   207          * @param descriptor An instance of Descriptor containing the
   208          * appropriate metadata for this instance of the
   208          * appropriate metadata for this instance of the
   209          * ModelMBeanOperationInfo.  If it is null a default
   209          * ModelMBeanOperationInfo.  If it is null a default
   210          * descriptor will be created. If the descriptor does not
   210          * descriptor will be created. If the descriptor does not
   211          * contain all the fields "name", "descriptorType",
   211          * contain the fields
   212          * "displayName", and "role", the missing ones are added with
   212          * "displayName" or "role", the missing ones are added with
   213          * their default values.
   213          * their default values.
   214          *
   214          *
   215          * @exception RuntimeOperationsException Wraps an
   215          * @exception RuntimeOperationsException Wraps an
   216          * IllegalArgumentException. The descriptor is invalid; or
   216          * IllegalArgumentException. The descriptor is invalid; or
   217          * descriptor field "name" is present but not equal to
   217          * descriptor field "name" is not equal to
   218          * operation name; or descriptor field "DescriptorType" is
   218          * operation name; or descriptor field "DescriptorType" is
   219          * present but not equal to "operation"; or descriptor
   219          * not equal to "operation"; or descriptor
   220          * optional field "role" is not equal to "operation",
   220          * optional field "role" is present but not equal to "operation",
   221          * "getter", or "setter".
   221          * "getter", or "setter".
   222          *
   222          *
   223          */
   223          */
   224 
   224 
   225         public ModelMBeanOperationInfo(String description,
   225         public ModelMBeanOperationInfo(String description,
   279         * @param impact The impact of the method, one of INFO, ACTION,
   279         * @param impact The impact of the method, one of INFO, ACTION,
   280         * ACTION_INFO, UNKNOWN.
   280         * ACTION_INFO, UNKNOWN.
   281         * @param descriptor An instance of Descriptor containing the
   281         * @param descriptor An instance of Descriptor containing the
   282         * appropriate metadata for this instance of the
   282         * appropriate metadata for this instance of the
   283         * MBeanOperationInfo. If it is null then a default descriptor
   283         * MBeanOperationInfo. If it is null then a default descriptor
   284         * will be created.  If the descriptor does not contain all the
   284         * will be created.  If the descriptor does not contain
   285         * fields "name", "descriptorType", "displayName", and "role",
   285         * fields "displayName" or "role",
   286         * the missing ones are added with their default values.
   286         * the missing ones are added with their default values.
   287         *
   287         *
   288         * @exception RuntimeOperationsException Wraps an
   288         * @exception RuntimeOperationsException Wraps an
   289         * IllegalArgumentException. The descriptor is invalid; or
   289         * IllegalArgumentException. The descriptor is invalid; or
   290         * descriptor field "name" is present but not equal to
   290         * descriptor field "name" is not equal to
   291         * operation name; or descriptor field "DescriptorType" is
   291         * operation name; or descriptor field "DescriptorType" is
   292         * present but not equal to "operation"; or descriptor optional
   292         * not equal to "operation"; or descriptor optional
   293         * field "role" is not equal to "operation", "getter", or
   293         * field "role" is present but not equal to "operation", "getter", or
   294         * "setter".
   294         * "setter".
   295         */
   295         */
   296 
   296 
   297         public ModelMBeanOperationInfo(String name,
   297         public ModelMBeanOperationInfo(String name,
   298                                        String description,
   298                                        String description,
   444          * @exception RuntimeOperationsException if Descriptor is invalid
   444          * @exception RuntimeOperationsException if Descriptor is invalid
   445          */
   445          */
   446         private Descriptor validDescriptor(final Descriptor in)
   446         private Descriptor validDescriptor(final Descriptor in)
   447         throws RuntimeOperationsException {
   447         throws RuntimeOperationsException {
   448             Descriptor clone;
   448             Descriptor clone;
   449             if (in == null) {
   449             boolean defaulted = (in == null);
       
   450             if (defaulted) {
   450                 clone = new DescriptorSupport();
   451                 clone = new DescriptorSupport();
   451                 MODELMBEAN_LOGGER.finer("Null Descriptor, creating new.");
   452                 MODELMBEAN_LOGGER.finer("Null Descriptor, creating new.");
   452             } else {
   453             } else {
   453                 clone = (Descriptor) in.clone();
   454                 clone = (Descriptor) in.clone();
   454             }
   455             }
   455 
   456 
   456             //Setting defaults.
   457             //Setting defaults.
   457             if (clone.getFieldValue("name")==null) {
   458             if (defaulted && clone.getFieldValue("name")==null) {
   458                 clone.setField("name", this.getName());
   459                 clone.setField("name", this.getName());
   459                 MODELMBEAN_LOGGER.finer("Defaulting Descriptor name to " + this.getName());
   460                 MODELMBEAN_LOGGER.finer("Defaulting Descriptor name to " + this.getName());
   460             }
   461             }
   461             if (clone.getFieldValue("descriptorType")==null) {
   462             if (defaulted && clone.getFieldValue("descriptorType")==null) {
   462                 clone.setField("descriptorType", "operation");
   463                 clone.setField("descriptorType", "operation");
   463                 MODELMBEAN_LOGGER.finer("Defaulting descriptorType to \"operation\"");
   464                 MODELMBEAN_LOGGER.finer("Defaulting descriptorType to \"operation\"");
   464             }
   465             }
   465             if (clone.getFieldValue("displayName") == null) {
   466             if (clone.getFieldValue("displayName") == null) {
   466                 clone.setField("displayName",this.getName());
   467                 clone.setField("displayName",this.getName());
   475             if (!clone.isValid()) {
   476             if (!clone.isValid()) {
   476                  throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
   477                  throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
   477                     "The isValid() method of the Descriptor object itself returned false,"+
   478                     "The isValid() method of the Descriptor object itself returned false,"+
   478                     "one or more required fields are invalid. Descriptor:" + clone.toString());
   479                     "one or more required fields are invalid. Descriptor:" + clone.toString());
   479             }
   480             }
   480             if (! ((String)clone.getFieldValue("name")).equalsIgnoreCase(this.getName())) {
   481             if (!getName().equalsIgnoreCase((String) clone.getFieldValue("name"))) {
   481                     throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
   482                     throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
   482                     "The Descriptor \"name\" field does not match the object described. " +
   483                     "The Descriptor \"name\" field does not match the object described. " +
   483                      " Expected: "+ this.getName() + " , was: " + clone.getFieldValue("name"));
   484                      " Expected: "+ this.getName() + " , was: " + clone.getFieldValue("name"));
   484             }
   485             }
   485             if (! ((String)clone.getFieldValue("descriptorType")).equalsIgnoreCase("operation")) {
   486             if (!"operation".equalsIgnoreCase((String) clone.getFieldValue("descriptorType"))) {
   486                      throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
   487                      throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
   487                     "The Descriptor \"descriptorType\" field does not match the object described. " +
   488                     "The Descriptor \"descriptorType\" field does not match the object described. " +
   488                      " Expected: \"attribute\" ," + " was: " + clone.getFieldValue("descriptorType"));
   489                      " Expected: \"operation\" ," + " was: " + clone.getFieldValue("descriptorType"));
   489             }
   490             }
   490             final String role = (String)clone.getFieldValue("role");
   491             final String role = (String)clone.getFieldValue("role");
   491             if (!(role.equalsIgnoreCase("operation") ||
   492             if (!(role.equalsIgnoreCase("operation") ||
   492                   role.equalsIgnoreCase("setter") ||
   493                   role.equalsIgnoreCase("setter") ||
   493                   role.equalsIgnoreCase("getter"))) {
   494                   role.equalsIgnoreCase("getter"))) {