User: juhalindfors
  Date: 02/02/20 22:38:37

  Modified:    src/main/javax/management/modelmbean DescriptorSupport.java
                        ModelMBeanConstructorInfo.java
                        ModelMBeanInfoSupport.java
                        ModelMBeanOperationInfo.java
  Log:
  bunch of FIXMEs corrected for javax.management.modelmbean
  
  Revision  Changes    Path
  1.3       +70 -16    jmx/src/main/javax/management/modelmbean/DescriptorSupport.java
  
  Index: DescriptorSupport.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jmx/src/main/javax/management/modelmbean/DescriptorSupport.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DescriptorSupport.java    16 Jan 2002 11:25:48 -0000      1.2
  +++ DescriptorSupport.java    21 Feb 2002 06:38:37 -0000      1.3
  @@ -9,38 +9,79 @@
   import java.util.Iterator;
   import java.util.Map;
   import java.util.HashMap;
  +import java.util.Collections;
   
   import javax.management.Descriptor;
   import javax.management.MBeanException;
   import javax.management.RuntimeOperationsException;
   
  +
   /**
    * Support class for creating descriptors.
    *
    * @see javax.management.Descriptor
    *
    * @author  <a href="mailto:[EMAIL PROTECTED]";>Juha Lindfors</a>.
  - * @version $Revision: 1.2 $  
  + * @version $Revision: 1.3 $  
    */
   public class DescriptorSupport
            implements Descriptor, Cloneable
   {
   
      // Attributes ----------------------------------------------------
  +   
  +   // JPL: this is some RI hack with no javadoc
      public String currClass;
  -   private Map fieldMap = new HashMap();
  +   
  +   /**
  +    * Map for the descriptor field -> value.
  +    */
  +   // JPL: notice that the oswego concurrent map do not allow null for values -> NPE
  +   //      so using heavy locking here
  +   private Map fieldMap = Collections.synchronizedMap(new HashMap(20));
   
  +   
      // Constructors --------------------------------------------------
  +   /**
  +    * Default constructor.
  +    */
      public DescriptorSupport()
      {}
   
  -   public DescriptorSupport(int initNumFields) throws MBeanException, 
RuntimeOperationsException
  -      { }
  -
  -   public DescriptorSupport(DescriptorSupport inDescr)
  -   {
  -      // FIXME
  -      throw new Error("NYI: copy constructor");
  +   /**
  +    * Creates descriptor instance with a given initial size.
  +    *
  +    * @param   initialSize initial size of the descriptor
  +    * @throws  MBeanException this exception is never thrown but is declared here
  +    *          for Sun RI API compatibility
  +    * @throws  RuntimeOperationsException if the <tt>initialSize<tt> is zero or 
negative. The target
  +    *          exception wrapped by this exception is an instace of 
<tt>IllegalArgumentException</tt> class.
  +    */
  +   public DescriptorSupport(int initialSize) throws MBeanException
  +   { 
  +      if (initialSize <= 0)
  +         // required by RI javadoc
  +         throw new RuntimeOperationsException(new 
IllegalArgumentException("initialSize <= 0"));
  +         
  +      fieldMap = Collections.synchronizedMap(new HashMap(initialSize));
  +   }
  +
  +   /**
  +    * Copy constructor.
  +    *
  +    * @param   descriptor the descriptor to be copied
  +    * @throws  RuntimeOperationsException if descriptor is null. The target 
exception wrapped by this
  +    *          exception is an instance of <tt>IllegalArgumentException</tt> class.
  +    */
  +   public DescriptorSupport(DescriptorSupport descriptor)
  +   {
  +      //JPL: the javadoc says that if the descriptor parameter is null an empty 
copy will be created. It then
  +      //     goes on to say that if the descriptor paramter is null a 
RuntimeOperationsException will be thrown.
  +      //     Go figure.
  +      //
  +      //     RI accepts null argument so I guess we will too
  +      if (descriptor != null)
  +         this.setFields(descriptor.getFieldNames(), 
descriptor.getFieldValues(descriptor.getFieldNames()));
      }
   
   
  @@ -98,11 +139,24 @@
   
      public Object[] getFieldValues(String[] fieldNames)
      {
  -      return fieldMap.values().toArray();
  -   }
  -
  -   public void setFields(String[] fieldNames, Object[] fieldValues) throws 
RuntimeOperationsException
  -   {
  +      Object[] values = new Object[fieldNames.length];
  +      for (int i = 0; i < fieldNames.length; ++i)
  +         values[i] = fieldMap.get(fieldNames[i]);
  +         
  +      return values;
  +   }
  +
  +   public void setFields(String[] fieldNames, Object[] fieldValues)
  +   {
  +      if (fieldNames == null || fieldValues == null)
  +         throw new RuntimeOperationsException(new 
IllegalArgumentException("fieldNames or fieldValues was null."));
  +         
  +      if (fieldNames.length == 0 || fieldValues.length == 0)
  +         return;
  +         
  +      if (fieldNames.length != fieldValues.length)
  +         throw new RuntimeOperationsException(new 
IllegalArgumentException("fieldNames and fieldValues array size must match."));
  +         
         for (int i = 0; i < fieldNames.length; ++i)
         {
            String name = fieldNames[i];
  @@ -134,8 +188,8 @@
   
      public boolean isValid() throws RuntimeOperationsException
      {
  -      // FIXME: NYI
  -      throw new Error("NYI");
  +      // FIXME FIXME: basic validation for descriptors
  +      return true;
      }
   
      // Object overrides ----------------------------------------------
  
  
  
  1.3       +93 -14    
jmx/src/main/javax/management/modelmbean/ModelMBeanConstructorInfo.java
  
  Index: ModelMBeanConstructorInfo.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jmx/src/main/javax/management/modelmbean/ModelMBeanConstructorInfo.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ModelMBeanConstructorInfo.java    15 Dec 2001 01:12:38 -0000      1.2
  +++ ModelMBeanConstructorInfo.java    21 Feb 2002 06:38:37 -0000      1.3
  @@ -13,6 +13,8 @@
   import javax.management.MBeanConstructorInfo;
   import javax.management.MBeanParameterInfo;
   
  +import org.jboss.mx.modelmbean.ModelMBeanConstants;
  +
   /**
    * Represents constructor.
    *
  @@ -20,7 +22,7 @@
    * @see javax.management.modelmbean.ModelMBeanInfoSupport
    *
    * @author  <a href="mailto:[EMAIL PROTECTED]";>Juha Lindfors</a>.
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    *   
    */
   public class ModelMBeanConstructorInfo
  @@ -29,53 +31,116 @@
   {
   
      // Attributes ----------------------------------------------------
  +   
  +   /**
  +    * The descriptor associated with this constructor.
  +    */
      private Descriptor descriptor = null;
      
      // Constructors --------------------------------------------------
  +   /**
  +    * Creates a new constructor info with a default descriptor.
  +    *
  +    * @param   description human readable description string
  +    * @param   constructorMethod a <tt>Constructor</tt> instance representing the 
MBean constructor
  +    */
      public ModelMBeanConstructorInfo(String description, Constructor 
constructorMethod)
      {
         super(description, constructorMethod);
  -      // FIXME: create default descriptor
  +      setDescriptor(createDefaultDescriptor());
      }
   
  -   public ModelMBeanConstructorInfo(String description, Constructor 
constructorMethod,
  -                                    Descriptor descriptor)
  +   /**
  +    * Creates a new constructor info 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 
constructor.
  +    *
  +    * @param   description human readable description string
  +    * @param   constructorMethod a <tt>Constructor</tt> instance representing the 
MBean constructor
  +    * @param   descriptor a descriptor to associate with this constructor
  +    */
  +   public ModelMBeanConstructorInfo(String description, Constructor 
constructorMethod, Descriptor descriptor)
      {
         this(description, constructorMethod);
  -      setDescriptor(descriptor);
  +      
  +      if (descriptor == null || !descriptor.isValid())
  +         setDescriptor(createDefaultDescriptor());
  +      else 
  +         setDescriptor(descriptor);
      }
   
  +   /**
  +    * Creates a new constructor info with default descriptor.
  +    *
  +    * @param   name  name for the constructor
  +    * @param   description human readable description string
  +    * @param   signature constructor signature
  +    */
      public ModelMBeanConstructorInfo(String name, String description, 
MBeanParameterInfo[] signature)
      {
         super(name, description, signature);
  -      // FIXME: create default descriptor
  +      setDescriptor(createDefaultDescriptor());
      }
   
  +   /**
  +    * Creates a new constructor info 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 
constructor.
  +    *
  +    * @param name name for the constructor
  +    * @param description human readable description string
  +    * @param signature constructor signature
  +    * @param descriptor a descriptor to associate with this constructor
  +    */
      public ModelMBeanConstructorInfo(String name, String description, 
MBeanParameterInfo[] signature,
                                       Descriptor descriptor)
      {
         this(name, description, signature);
  -      setDescriptor(descriptor);
  +      
  +      if (descriptor == null || !descriptor.isValid())
  +         setDescriptor(createDefaultDescriptor());
  +      else
  +         setDescriptor(descriptor);
      }
      
  -   // Public --------------------------------------------------------
  +   // DescriptorAccess implementation -------------------------------
  +   
  +   /**
  +    * Returns a copy of the descriptor associated with this constructor.
  +    *
  +    * @return a copy of this constructor's descriptor instance
  +    */
      public Descriptor getDescriptor()
      {
         return (Descriptor)descriptor.clone();
      }
      
  +   /**
  +    * Replaces the descriptor associated with this constructor. If the 
<tt>inDescriptor</tt>
  +    * argument is <tt>null</tt> then the existing descriptor is replaced with a 
default
  +    * descriptor.
  +    *
  +    * @param   inDescriptor   descriptor used for replacing the existing 
constructor descriptor
  +    * @throws  IllegalArgumentException if the new descriptor is not valid
  +    */
      public void setDescriptor(Descriptor inDescriptor)
      {
  -      // FIXME: if null inDescriptor, create default descriptor
  -      // FIXME: if invalid descriptor (fields name, descriptionType, role required) 
throw IllegalArgumentException
  -      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()
  +   
  +   public synchronized Object clone() throws CloneNotSupportedException
      {
  -      // FIXME: NYI
  -      throw new Error("NYI");
  +      ModelMBeanConstructorInfo clone = (ModelMBeanConstructorInfo)super.clone();
  +      clone.descriptor = (Descriptor)this.descriptor.clone();
  +      
  +      return clone;
      }
      
      // Object overrides ----------------------------------------------
  @@ -84,4 +149,18 @@
         // FIXME: human readable string
         return super.toString();
      }
  +   
  +   // Private -------------------------------------------------------
  +   private Descriptor createDefaultDescriptor()
  +   {
  +      DescriptorSupport descr = new DescriptorSupport();
  +      descr.setField(ModelMBeanConstants.NAME, super.getName());
  +      descr.setField(ModelMBeanConstants.DESCRIPTOR_TYPE, 
ModelMBeanConstants.CONSTRUCTOR_DESCRIPTOR);
  +      descr.setField(ModelMBeanConstants.ROLE, ModelMBeanConstants.CONSTRUCTOR);
  +      
  +      // FIXME: check the spec for all mandatory fields!
  +      
  +      return descr;
  +   }
  +   
   }
  
  
  
  1.5       +4 -3      
jmx/src/main/javax/management/modelmbean/ModelMBeanInfoSupport.java
  
  Index: ModelMBeanInfoSupport.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jmx/src/main/javax/management/modelmbean/ModelMBeanInfoSupport.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ModelMBeanInfoSupport.java        23 Jan 2002 21:36:02 -0000      1.4
  +++ ModelMBeanInfoSupport.java        21 Feb 2002 06:38:37 -0000      1.5
  @@ -10,6 +10,7 @@
   import java.util.HashMap;
   import java.util.List;
   import java.util.ArrayList;
  +import java.io.Serializable;
   
   import javax.management.MBeanInfo;
   import javax.management.Descriptor;
  @@ -33,11 +34,11 @@
    * @see javax.management.modelmbean.ModelMBeanInfo
    *
    * @author  <a href="mailto:[EMAIL PROTECTED]";>Juha Lindfors</a>.
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public class ModelMBeanInfoSupport
  -         extends MBeanInfo
  -         implements ModelMBeanInfo, java.io.Serializable
  +      extends MBeanInfo
  +      implements ModelMBeanInfo, Serializable
   {
   
      // Attributes ----------------------------------------------------
  
  
  
  1.3       +104 -16   
jmx/src/main/javax/management/modelmbean/ModelMBeanOperationInfo.java
  
  Index: ModelMBeanOperationInfo.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jmx/src/main/javax/management/modelmbean/ModelMBeanOperationInfo.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ModelMBeanOperationInfo.java      15 Dec 2001 01:12:38 -0000      1.2
  +++ ModelMBeanOperationInfo.java      21 Feb 2002 06:38:37 -0000      1.3
  @@ -13,6 +13,8 @@
   import javax.management.DescriptorAccess;
   import javax.management.Descriptor;
   
  +import org.jboss.mx.modelmbean.ModelMBeanConstants;
  +
   /**
    * Represents Model MBean operation.
    *
  @@ -20,7 +22,7 @@
    * @see javax.management.modelmbean.ModelMBeanInfoSupport
    *
    * @author  <a href="mailto:[EMAIL PROTECTED]";>Juha Lindfors</a>.
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public class ModelMBeanOperationInfo
      extends MBeanOperationInfo
  @@ -28,61 +30,136 @@
   {
      
      // Attributes ----------------------------------------------------
  +   
  +   /**
  +    * The descriptor associated with this operation.
  +    */
      private Descriptor descriptor = null;
   
      // Constructors --------------------------------------------------
  +   /**
  +    * Creates a new operation info with a default descriptor.
  +    *
  +    * @param   description human readable description string
  +    * @param   operationMethod a <tt>Method</tt> instance representing the
  +    *          management operation
  +    */
      public ModelMBeanOperationInfo(String description, Method operationMethod)
      {
         super(description, operationMethod);
  -      // FIXME: build default descriptor
  +      setDescriptor(createDefaultDescriptor());
      }
  -   public ModelMBeanOperationInfo(String description, Method operationMethod,
  -                                  Descriptor descriptor)
  +   
  +   /**
  +    * Creates a new operation info with a given descriptor. If a <tt>null</tt> or
  +    * invalid descriptor is passed as a paramter, a default descriptor will be 
created
  +    * for the operation.
  +    *
  +    * @param   description human readable description string
  +    * @param   operationMethod a <tt>Method</tt> instance representing the 
management
  +    *          operation
  +    * @param   descriptor a descriptor to associate with this operation
  +    */
  +   public ModelMBeanOperationInfo(String description, Method operationMethod, 
Descriptor descriptor)
      {
         this(description, operationMethod);
  -      setDescriptor(descriptor);
  -   }
  -
  +      
  +      if (descriptor == null || !descriptor.isValid())
  +         setDescriptor(createDefaultDescriptor());
  +      else
  +         setDescriptor(descriptor);
  +   }
  +
  +   /**
  +    * Creates a new operation info with a default descriptor.
  +    *
  +    * @param   name name of the operation
  +    * @param   description human readable description string
  +    * @param   signature operation signature
  +    * @param   type a fully qualified name of the operations return type
  +    * @param   impact operation impact: {@link #INFO INFO}, {@link #ACTION ACTION}, 
{@link #ACTION_INFO ACTION_INFO}, {@link #UNKNOWN UNKNOWN} 
  +    */
      public ModelMBeanOperationInfo(String name, String description, 
MBeanParameterInfo[] signature,
                                     String type, int impact)
      {
         super(name, description, signature, type, impact);
  -      // FIXME: build default descriptor
  +      setDescriptor(createDefaultDescriptor());
      }
   
  +   /**
  +    * Creates a new operation info 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 operation.
  +    *
  +    * @param   name name of the operation
  +    * @param   description human readable description string
  +    * @param   signature operation signature
  +    * @param   type a fully qualified name of the oeprations return type
  +    * @param   impact operation impact: {@link #INFO INFO}, {@link #ACTION ACTION}, 
{@link #ACTION_INFO ACTION_INFO}, {@link #UNKNOWN UNKNOWN} 
  +    * @param   descriptor a descriptor to associate with this operation
  +    */
      public ModelMBeanOperationInfo(String name, String description, 
MBeanParameterInfo[] signature,
                                     String type, int impact, Descriptor descriptor)
      {
         this(name, description, signature, type, impact);
  -      setDescriptor(descriptor);
  +      
  +      if (descriptor == null || !descriptor.isValid())
  +         setDescriptor(createDefaultDescriptor());
  +      else
  +         setDescriptor(descriptor);
      }
   
  +   /**
  +    * Copy constructor.
  +    *
  +    * @param   inInfo the operation info to copy
  +    */
      public ModelMBeanOperationInfo(ModelMBeanOperationInfo inInfo)
      {
  +      // FIXME: NYI
         super("", "", null, "", 0);
  -      // FIXME: why do we need a copy constructor if we implement Cloneable? This 
ain't C++.
         throw new Error("NYI");
      }
   
  -   // Public --------------------------------------------------------
  +   // DescriptorAccess implementation -------------------------------
  +   
  +   /**
  +    * Returns a copy of the descriptor associated with this operation.
  +    *
  +    * @return a copy of this operation's associated descriptor
  +    */
      public Descriptor getDescriptor()
      {
         return (Descriptor)descriptor.clone();
      }
   
  +   /**
  +    * Replaces the descriptor associated with this operation. If the 
<tt>inDescriptor</tt>
  +    * argument is <tt>null</tt> then the existing descriptor is replaced with a 
default
  +    * descriptor.
  +    *
  +    * @param   inDescriptor   descriptor used for replacing the existing operation 
descriptor
  +    * @throws IllegalArgumentException if the new descriptor is not valid
  +    */
      public void setDescriptor(Descriptor inDescriptor)
      {
  -      // FIXME: if null, create default descriptor
  -      // FIXME: check vailidty, fields name, descriptorType and role are required
  +      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()
  +   public synchronized Object clone() throws CloneNotSupportedException
      {
  -      // FIXME: NYI
  -      throw new Error("NYI");
  +      ModelMBeanOperationInfo clone = (ModelMBeanOperationInfo)super.clone();
  +      clone.descriptor = (Descriptor)this.descriptor.clone();
  +      
  +      return clone;
      }
   
      // Object overrides ----------------------------------------------
  @@ -92,5 +169,16 @@
         return super.toString();
      }
   
  +   // Private -------------------------------------------------------
  +   private Descriptor createDefaultDescriptor()
  +   {
  +      DescriptorSupport descr = new DescriptorSupport();
  +      descr.setField(ModelMBeanConstants.NAME, super.getName());
  +      descr.setField(ModelMBeanConstants.DESCRIPTOR_TYPE, 
ModelMBeanConstants.OPERATION_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