User: juhalindfors
  Date: 02/03/08 07:28:16

  Modified:    src/main/javax/management/modelmbean
                        ModelMBeanAttributeInfo.java
  Log:
  fix for missing default constructors, clone, javadoc
  
  Revision  Changes    Path
  1.2       +127 -20   
jmx/src/main/javax/management/modelmbean/ModelMBeanAttributeInfo.java
  
  Index: ModelMBeanAttributeInfo.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jmx/src/main/javax/management/modelmbean/ModelMBeanAttributeInfo.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ModelMBeanAttributeInfo.java      10 Dec 2001 17:24:35 -0000      1.1
  +++ ModelMBeanAttributeInfo.java      8 Mar 2002 15:28:16 -0000       1.2
  @@ -13,13 +13,15 @@
   import javax.management.MBeanAttributeInfo;
   import javax.management.IntrospectionException;
   
  +import org.jboss.mx.modelmbean.ModelMBeanConstants;
  +
   /**
    * Represents a Model MBean's management attribute.
    *
    * @see javax.management.MBeanAttributeInfo
    *
    * @author  <a href="mailto:[EMAIL PROTECTED]";>Juha Lindfors</a>.
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    *   
    */
   public class ModelMBeanAttributeInfo
  @@ -28,58 +30,153 @@
   {
   
      // Attributes ----------------------------------------------------
  +   /**
  +    * The descriptor associated with this attribute.
  +    */   
      private Descriptor descriptor = null;
      
      // Constructors --------------------------------------------------
  +   /**
  +    * Creates a new attribute info with a default descriptor.
  +    *
  +    * @param  name name of the attribute
  +    * @param  description human readable description string
  +    * @param  getter a <tt>Method</tt> instance representing a read method for this 
attribute
  +    * @param  setter a <tt>Method</tt> instance representing a write method for 
this attribute
  +    *
  +    * @throws IntrospectionException if the accessor methods are not valid for this 
attribute
  +    */
      public ModelMBeanAttributeInfo(String name, String description, Method getter, 
Method setter)
  -   throws IntrospectionException
  +         throws IntrospectionException
      {
         super(name, description, getter, setter);
  +      setDescriptor(createDefaultDescriptor());
      }
   
  +   /**
  +    * Creates a new attribute info object.
  +    *
  +    * @param  name name of the attribute
  +    * @param  description human readable description string
  +    * @param  getter a <tt>Method</tt> instance representing a read method for this 
attribute
  +    * @param  setter a <tt>Method</tt> instance representing a write method for 
this attribute
  +    * @param  descriptor a descriptor to associate with this attribute
  +    *
  +    * @throws IntrospectionException if the accessor methods are not valid for this 
attribute
  +    */
      public ModelMBeanAttributeInfo(String name, String description, Method getter, 
Method setter, Descriptor descriptor)
  -   throws IntrospectionException
  +         throws IntrospectionException
      {
         this(name, description, getter, setter);
  -      this.descriptor = descriptor;
  -   }
  -   
  +      
  +      if (descriptor == null || !descriptor.isValid())
  +         setDescriptor(createDefaultDescriptor());
  +      else
  +         setDescriptor(descriptor);
  +   }
  +   
  +   /**
  +    * Creates a new attribute info object with a default descriptor.
  +    *
  +    * @param   name  name of the attribute
  +    * @param   type  fully qualified class name of the attribute's type
  +    * @param   description human readable description string
  +    * @param   isReadable true if attribute is readable; false otherwise
  +    * @param   isWritable true if attribute is writable; false otherwise
  +    * @param   isIs (not used for Model MBeans; false)
  +    */
      public ModelMBeanAttributeInfo(String name, String type, String description,
                                     boolean isReadable, boolean isWritable, boolean 
isIs)
      {
  -      super(name, type, description, isReadable, isWritable, isIs);
  -   }
  -   
  +      // JPL:  As far as I can tell, the isIs boolean has no use in the Model MBean
  +      //       attribute info (since attributes will map to methods through 
operations)
  +      //       I'm setting this boolean to false, until someone complains.
  +      
  +      super(name, type, description, isReadable, isWritable, false /*isIs*/);
  +      setDescriptor(createDefaultDescriptor());
  +      
  +      if (isIs == true)
  +         // FIXME: log this
  +         System.out.println("WARNING: supplied isIS=true, set to false");
  +   }
  +   
  +   /**
  +    * Creates a new attribute info object with a given descriptor. If a 
<tt>null</tt> or invalid
  +    * descriptor is passed as a parameter, a default descriptor will be created for 
the attribute.
  +    *
  +    * @param  name   name of the attribute
  +    * @param  type   fully qualified class name of the attribute's type
  +    * @param  description human readable description string
  +    * @param  isReadable true if the attribute is readable; false otherwise
  +    * @param  isWritable true if the attribute is writable; false otherwise
  +    * @param  isIs  (not used for Model MBeans; false)
  +    */
      public ModelMBeanAttributeInfo(String name, String type, String description,
                                     boolean isReadable, boolean isWritable, boolean 
isIs, Descriptor descriptor)
      {
  -      this(name, type, description, isReadable, isWritable, isIs);
  -      this.descriptor = descriptor;
  +      // JPL:  As far as I can tell, the isIs boolean has no use in the Model MBean
  +      //       attribute info (since attributes will map to methods through 
operations)
  +      //       I'm setting this boolean to false, until someone complains.
  +      super(name, type, description, isReadable, isWritable, false/*isIs*/);
  +      
  +      if (descriptor == null || !descriptor.isValid())
  +         setDescriptor(createDefaultDescriptor());
  +      else
  +         setDescriptor(descriptor);
  +
  +      if (isIs == true)
  +         // FIXME: log this
  +         System.out.println("WARNING: supplied isIS=true, set to false");
      }
      
  +   /**
  +    * Copy constructor.
  +    *
  +    * @param   inInfo the attribute info to copy
  +    */
      public ModelMBeanAttributeInfo(ModelMBeanAttributeInfo inInfo)
      {
         super("", "", "", false, false, false);
  -      // FIXME: why do we need a copy constructor if we implement Cloneable? This 
ain't C++.
  +      // FIXME: NYI
         throw new Error("NYI");
      }
      
  -   // Public --------------------------------------------------------
  +   // DescriptorAccess implementation -------------------------------
  +   /**
  +    * Returns a copy of the descriptor associated with this attribute.
  +    *
  +    * @return a copy of this attribute's descriptor
  +    */
      public Descriptor getDescriptor()
      {
  -      return (Descriptor)descriptor.clone();
  +      return (Descriptor)descriptor.clone();    
      }
      
      public void setDescriptor(Descriptor inDescriptor)
      {
  -      this.descriptor = descriptor;
  +      if (inDescriptor == null)
  +         inDescriptor = createDefaultDescriptor();
  +         
  +      if (!inDescriptor.isValid())
  +         // FIXME: give more detailed error
  +         throw new IllegalArgumentException("Invalid descriptor.");
  +         
  +      this.descriptor = inDescriptor;
      }
      
      // Cloneable implementation --------------------------------------
  -   public Object clone()
  -   {
  -      // FIXME: NYI
  -      throw new Error("NYI");
  +   /**
  +    * Creates a copy of this object.
  +    *
  +    * @return clone of this object
  +    * @throws CloneNotSupportedException if there was a failure creating the copy
  +    */
  +   public synchronized Object clone() throws CloneNotSupportedException
  +   {
  +      ModelMBeanAttributeInfo clone = (ModelMBeanAttributeInfo)super.clone();
  +      clone.descriptor  = (Descriptor)this.descriptor.clone();
  +      
  +      return clone;
      }
      
      // Object override -----------------------------------------------
  @@ -89,7 +186,17 @@
         return super.toString();
      }
   
  -
  +   // Private -------------------------------------------------------
  +   private Descriptor createDefaultDescriptor()
  +   {
  +      DescriptorSupport descr = new DescriptorSupport();
  +      descr.setField(ModelMBeanConstants.NAME, super.getName());
  +      descr.setField(ModelMBeanConstants.DESCRIPTOR_TYPE, 
ModelMBeanConstants.ATTRIBUTE_DESCRIPTOR);
  +      
  +      // FIXME: check the spec for all required descriptor fields!
  +      
  +      return descr;
  +   }
   
   }
   
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to