jdk/src/java.management/share/classes/javax/management/modelmbean/ModelMBeanConstructorInfo.java
changeset 43235 da1786d695b6
parent 25859 3317bb8137f4
child 44858 7183899b064b
equal deleted inserted replaced
43234:cb2a6851b837 43235:da1786d695b6
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2013, 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
    37 import java.io.ObjectInputStream;
    37 import java.io.ObjectInputStream;
    38 import java.io.ObjectOutputStream;
    38 import java.io.ObjectOutputStream;
    39 import java.io.ObjectStreamField;
    39 import java.io.ObjectStreamField;
    40 import java.lang.reflect.Constructor;
    40 import java.lang.reflect.Constructor;
    41 import java.security.AccessController;
    41 import java.security.AccessController;
    42 import java.util.logging.Level;
    42 import java.lang.System.Logger.Level;
    43 
    43 
    44 import javax.management.Descriptor;
    44 import javax.management.Descriptor;
    45 import javax.management.DescriptorAccess;
    45 import javax.management.DescriptorAccess;
    46 import javax.management.DescriptorKey;
    46 import javax.management.DescriptorKey;
    47 import javax.management.MBeanConstructorInfo;
    47 import javax.management.MBeanConstructorInfo;
   162         */
   162         */
   163         public ModelMBeanConstructorInfo(String description,
   163         public ModelMBeanConstructorInfo(String description,
   164                                          Constructor<?> constructorMethod)
   164                                          Constructor<?> constructorMethod)
   165     {
   165     {
   166                 super(description, constructorMethod);
   166                 super(description, constructorMethod);
   167                 if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   167                 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   168                     MODELMBEAN_LOGGER.logp(Level.FINER,
   168                     MODELMBEAN_LOGGER.log(Level.TRACE,
   169                             ModelMBeanConstructorInfo.class.getName(),
   169                             "ModelMBeanConstructorInfo(String,Constructor) " +
   170                             "ModelMBeanConstructorInfo(String,Constructor)",
       
   171                             "Entry");
   170                             "Entry");
   172                 }
   171                 }
   173                 consDescriptor = validDescriptor(null);
   172                 consDescriptor = validDescriptor(null);
   174 
   173 
   175                 // put getter and setter methods in constructors list
   174                 // put getter and setter methods in constructors list
   207                                          Descriptor descriptor)
   206                                          Descriptor descriptor)
   208         {
   207         {
   209 
   208 
   210                 super(description, constructorMethod);
   209                 super(description, constructorMethod);
   211                 // put getter and setter methods in constructors list
   210                 // put getter and setter methods in constructors list
   212                 if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   211                 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   213                     MODELMBEAN_LOGGER.logp(Level.FINER,
   212                     MODELMBEAN_LOGGER.log(Level.TRACE,
   214                             ModelMBeanConstructorInfo.class.getName(),
       
   215                             "ModelMBeanConstructorInfo(" +
   213                             "ModelMBeanConstructorInfo(" +
   216                             "String,Constructor,Descriptor)", "Entry");
   214                             "String,Constructor,Descriptor) Entry");
   217                 }
   215                 }
   218                 consDescriptor = validDescriptor(descriptor);
   216                 consDescriptor = validDescriptor(descriptor);
   219         }
   217         }
   220         /**
   218         /**
   221         * Constructs a ModelMBeanConstructorInfo object with a default descriptor.
   219         * Constructs a ModelMBeanConstructorInfo object with a default descriptor.
   230                                          MBeanParameterInfo[] signature)
   228                                          MBeanParameterInfo[] signature)
   231         {
   229         {
   232 
   230 
   233                 super(name, description, signature);
   231                 super(name, description, signature);
   234                 // create default descriptor
   232                 // create default descriptor
   235                 if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   233                 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   236                     MODELMBEAN_LOGGER.logp(Level.FINER,
   234                     MODELMBEAN_LOGGER.log(Level.TRACE,
   237                             ModelMBeanConstructorInfo.class.getName(),
       
   238                             "ModelMBeanConstructorInfo(" +
   235                             "ModelMBeanConstructorInfo(" +
   239                             "String,String,MBeanParameterInfo[])", "Entry");
   236                             "String,String,MBeanParameterInfo[]) Entry");
   240                 }
   237                 }
   241                 consDescriptor = validDescriptor(null);
   238                 consDescriptor = validDescriptor(null);
   242         }
   239         }
   243         /**
   240         /**
   244         * Constructs a ModelMBeanConstructorInfo object.
   241         * Constructs a ModelMBeanConstructorInfo object.
   263                                          String description,
   260                                          String description,
   264                                          MBeanParameterInfo[] signature,
   261                                          MBeanParameterInfo[] signature,
   265                                          Descriptor descriptor)
   262                                          Descriptor descriptor)
   266         {
   263         {
   267                 super(name, description, signature);
   264                 super(name, description, signature);
   268                 if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   265                 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   269                     MODELMBEAN_LOGGER.logp(Level.FINER,
   266                     MODELMBEAN_LOGGER.log(Level.TRACE,
   270                             ModelMBeanConstructorInfo.class.getName(),
       
   271                             "ModelMBeanConstructorInfo(" +
   267                             "ModelMBeanConstructorInfo(" +
   272                             "String,String,MBeanParameterInfo[],Descriptor)",
   268                             "String,String,MBeanParameterInfo[],Descriptor) " +
   273                             "Entry");
   269                             "Entry");
   274                 }
   270                 }
   275                 consDescriptor = validDescriptor(descriptor);
   271                 consDescriptor = validDescriptor(descriptor);
   276         }
   272         }
   277 
   273 
   282          *
   278          *
   283          */
   279          */
   284         ModelMBeanConstructorInfo(ModelMBeanConstructorInfo old)
   280         ModelMBeanConstructorInfo(ModelMBeanConstructorInfo old)
   285         {
   281         {
   286                 super(old.getName(), old.getDescription(), old.getSignature());
   282                 super(old.getName(), old.getDescription(), old.getSignature());
   287                 if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   283                 if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   288                     MODELMBEAN_LOGGER.logp(Level.FINER,
   284                     MODELMBEAN_LOGGER.log(Level.TRACE,
   289                             ModelMBeanConstructorInfo.class.getName(),
       
   290                             "ModelMBeanConstructorInfo(" +
   285                             "ModelMBeanConstructorInfo(" +
   291                             "ModelMBeanConstructorInfo)", "Entry");
   286                             "ModelMBeanConstructorInfo) Entry");
   292                 }
   287                 }
   293                 consDescriptor = validDescriptor(consDescriptor);
   288                 consDescriptor = validDescriptor(consDescriptor);
   294         }
   289         }
   295 
   290 
   296         /**
   291         /**
   298         *
   293         *
   299         */
   294         */
   300         @Override
   295         @Override
   301         public Object clone ()
   296         public Object clone ()
   302         {
   297         {
   303             if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   298             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   304                 MODELMBEAN_LOGGER.logp(Level.FINER,
   299                 MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
   305                         ModelMBeanConstructorInfo.class.getName(),
       
   306                         "clone()", "Entry");
       
   307             }
   300             }
   308                 return(new ModelMBeanConstructorInfo(this)) ;
   301                 return(new ModelMBeanConstructorInfo(this)) ;
   309         }
   302         }
   310 
   303 
   311         /**
   304         /**
   319 
   312 
   320 
   313 
   321         @Override
   314         @Override
   322         public Descriptor getDescriptor()
   315         public Descriptor getDescriptor()
   323         {
   316         {
   324             if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   317             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   325                 MODELMBEAN_LOGGER.logp(Level.FINER,
   318                 MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
   326                         ModelMBeanConstructorInfo.class.getName(),
       
   327                         "getDescriptor()", "Entry");
       
   328             }
   319             }
   329             if (consDescriptor == null){
   320             if (consDescriptor == null){
   330                 consDescriptor = validDescriptor(null);
   321                 consDescriptor = validDescriptor(null);
   331             }
   322             }
   332             return((Descriptor)consDescriptor.clone());
   323             return((Descriptor)consDescriptor.clone());
   354         *
   345         *
   355         * @see #getDescriptor
   346         * @see #getDescriptor
   356         */
   347         */
   357         public void setDescriptor(Descriptor inDescriptor)
   348         public void setDescriptor(Descriptor inDescriptor)
   358         {
   349         {
   359             if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   350             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   360                 MODELMBEAN_LOGGER.logp(Level.FINER,
   351                 MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
   361                         ModelMBeanConstructorInfo.class.getName(),
       
   362                         "setDescriptor()", "Entry");
       
   363             }
   352             }
   364             consDescriptor = validDescriptor(inDescriptor);
   353             consDescriptor = validDescriptor(inDescriptor);
   365         }
   354         }
   366 
   355 
   367         /**
   356         /**
   368         * Returns a string containing the entire contents of the ModelMBeanConstructorInfo in human readable form.
   357         * Returns a string containing the entire contents of the ModelMBeanConstructorInfo in human readable form.
   369         */
   358         */
   370         @Override
   359         @Override
   371         public String toString()
   360         public String toString()
   372         {
   361         {
   373             if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   362             if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
   374                 MODELMBEAN_LOGGER.logp(Level.FINER,
   363                 MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
   375                         ModelMBeanConstructorInfo.class.getName(),
       
   376                         "toString()", "Entry");
       
   377             }
   364             }
   378                 String retStr =
   365                 String retStr =
   379                     "ModelMBeanConstructorInfo: " + this.getName() +
   366                     "ModelMBeanConstructorInfo: " + this.getName() +
   380                     " ; Description: " + this.getDescription() +
   367                     " ; Description: " + this.getDescription() +
   381                     " ; Descriptor: " + this.getDescriptor() +
   368                     " ; Descriptor: " + this.getDescriptor() +
   406         private Descriptor validDescriptor(final Descriptor in) throws RuntimeOperationsException {
   393         private Descriptor validDescriptor(final Descriptor in) throws RuntimeOperationsException {
   407             Descriptor clone;
   394             Descriptor clone;
   408             boolean defaulted = (in == null);
   395             boolean defaulted = (in == null);
   409             if (defaulted) {
   396             if (defaulted) {
   410                 clone = new DescriptorSupport();
   397                 clone = new DescriptorSupport();
   411                 MODELMBEAN_LOGGER.finer("Null Descriptor, creating new.");
   398                 MODELMBEAN_LOGGER.log(Level.TRACE, "Null Descriptor, creating new.");
   412             } else {
   399             } else {
   413                 clone = (Descriptor) in.clone();
   400                 clone = (Descriptor) in.clone();
   414             }
   401             }
   415 
   402 
   416             //Setting defaults.
   403             //Setting defaults.
   417             if (defaulted && clone.getFieldValue("name")==null) {
   404             if (defaulted && clone.getFieldValue("name")==null) {
   418                 clone.setField("name", this.getName());
   405                 clone.setField("name", this.getName());
   419                 MODELMBEAN_LOGGER.finer("Defaulting Descriptor name to " + this.getName());
   406                 MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting Descriptor name to " + this.getName());
   420             }
   407             }
   421             if (defaulted && clone.getFieldValue("descriptorType")==null) {
   408             if (defaulted && clone.getFieldValue("descriptorType")==null) {
   422                 clone.setField("descriptorType", "operation");
   409                 clone.setField("descriptorType", "operation");
   423                 MODELMBEAN_LOGGER.finer("Defaulting descriptorType to \"operation\"");
   410                 MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting descriptorType to \"operation\"");
   424             }
   411             }
   425             if (clone.getFieldValue("displayName") == null) {
   412             if (clone.getFieldValue("displayName") == null) {
   426                 clone.setField("displayName",this.getName());
   413                 clone.setField("displayName",this.getName());
   427                 MODELMBEAN_LOGGER.finer("Defaulting Descriptor displayName to " + this.getName());
   414                 MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting Descriptor displayName to " + this.getName());
   428             }
   415             }
   429             if (clone.getFieldValue("role") == null) {
   416             if (clone.getFieldValue("role") == null) {
   430                 clone.setField("role","constructor");
   417                 clone.setField("role","constructor");
   431                 MODELMBEAN_LOGGER.finer("Defaulting Descriptor role field to \"constructor\"");
   418                 MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting Descriptor role field to \"constructor\"");
   432             }
   419             }
   433 
   420 
   434             //Checking validity
   421             //Checking validity
   435             if (!clone.isValid()) {
   422             if (!clone.isValid()) {
   436                  throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
   423                  throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),