mx4j/src/core/javax/management/modelmbean ModelMBeanAttributeInfo.java,1.9,1.10 ModelMBeanConstructorInfo.java,1.8,1.9 ModelMBeanNotificationInfo.java,1.6,1.7

Simone Bordet <[email protected]> Mon, 30 Aug 2004 14:04:50 +0000
Newsgroups gmane.comp.java.mx4j.cvs
Message-ID <[email protected]>
Update of /cvsroot/mx4j/mx4j/src/core/javax/management/modelmbean
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5334/src/core/javax/management/modelmbean

Modified Files:
	ModelMBeanAttributeInfo.java ModelMBeanConstructorInfo.java 
	ModelMBeanNotificationInfo.java 
Log Message:
Cosmetics

Index: ModelMBeanNotificationInfo.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/modelmbean/ModelMBeanNotificationInfo.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** ModelMBeanNotificationInfo.java	7 Nov 2003 02:31:06 -0000	1.6
--- ModelMBeanNotificationInfo.java	30 Aug 2004 14:04:47 -0000	1.7
***************
*** 9,22 ****
  package javax.management.modelmbean;
  
- import java.util.List;
  import java.util.Arrays;
! 
! import javax.management.MBeanNotificationInfo;
! import javax.management.DescriptorAccess;
  import javax.management.Descriptor;
  import javax.management.RuntimeOperationsException;
  
  /**
-  *
   * @author <a href="mailto:[email protected]">Simone Bordet</a>
   * @version $Revision$
--- 9,20 ----
  package javax.management.modelmbean;
  
  import java.util.Arrays;
! import java.util.List;
  import javax.management.Descriptor;
+ import javax.management.DescriptorAccess;
+ import javax.management.MBeanNotificationInfo;
  import javax.management.RuntimeOperationsException;
  
  /**
   * @author <a href="mailto:[email protected]">Simone Bordet</a>
   * @version $Revision$
***************
*** 24,150 ****
  public class ModelMBeanNotificationInfo extends MBeanNotificationInfo implements DescriptorAccess
  {
! 	private static final long serialVersionUID = -7445681389570207141L;
  
! 	private Descriptor notificationDescriptor;
  
! 	public ModelMBeanNotificationInfo(String[] types, String name, String description)
! 	{
! 		this(types, name, description, null);
! 	}
! 	public ModelMBeanNotificationInfo(String[] types, String name, String description, Descriptor descriptor)
! 	{
! 		super(types, name, description);
! 		checkAndSetDescriptor(descriptor);
! 	}
! 	public ModelMBeanNotificationInfo(ModelMBeanNotificationInfo copy)
! 	{
! 		super(copy.getNotifTypes(), copy.getName(), copy.getDescription());
! 		checkAndSetDescriptor(copy.getDescriptor());
! 	}
  
! 	public Descriptor getDescriptor()
! 	{
! 		return (Descriptor)notificationDescriptor.clone();
! 	}
  
! 	public void setDescriptor(Descriptor descriptor)
! 	{
!         if (descriptor == null)
! 		{
! 			notificationDescriptor = createDefaultDescriptor();
! 		}
! 		else
! 		{
!             if (isDescriptorValid(descriptor))
! 			{
! 				notificationDescriptor = (Descriptor)descriptor.clone();
! 			}
! 			else
! 			{
! 				// Not sure what to do here: javadoc says IllegalArgument, but for example ModelMBeanInfo throws RuntimeOperations
! 				// which is consistent with the fact that all exception thrown by the JMX implementation should be JMX exceptions
  //				throw new IllegalArgumentException("Invalid descriptor");
! 				throw new RuntimeOperationsException(new IllegalArgumentException("Invalid descriptor"));
! 			}
! 		}
! 	}
  
! 	private void checkAndSetDescriptor(Descriptor descriptor)
! 	{
! 		if (descriptor == null)
! 		{
! 			notificationDescriptor = createDefaultDescriptor();
! 		}
! 		else if (isDescriptorValid(descriptor))
! 		{
! 			notificationDescriptor = (Descriptor)descriptor.clone();
! 			if (notificationDescriptor.getFieldValue("displayname") == null)
! 			{
! 				notificationDescriptor.setField("displayname", getName());
! 			}
! 		}
! 		else
! 		{
! 			throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor"));
! 		}
! 	}
  
! 	private boolean isDescriptorValid(Descriptor descriptor)
! 	{
! 		if (!descriptor.isValid()) {return false;}
  
! 		// Spec compliance checks
  
! 		// Mandatory fields are: name, descriptorType, severity, messageId(?), log(?), logFile(?)
! 		List names = Arrays.asList(descriptor.getFieldNames());
  
! 		// Remember that names are lower case
! 		if (!names.contains("name") ||
! 			!names.contains("descriptortype") ||
! 			!names.contains("severity")/* ||
! 			!names.contains("messageid") ||
! 			!names.contains("log")/* ||
! 			!names.contains("logfile")*/) {return false;}
! 		// Case sensitive name
! 		String name = getName();
! 		if (name == null) {return false;}
! 		if (!name.equals(descriptor.getFieldValue("name"))) {return false;}
! 		// Descriptor type must be 'notification'
! 		String desctype = (String) descriptor.getFieldValue("descriptortype");
! 		if (desctype.compareToIgnoreCase("notification") != 0) return false;
! 		// Severity needn't be checked. It was checked in
! 		// descriptor.isValid()
! 		int severity = objectToInt(descriptor.getFieldValue("severity"));
! 		if (severity < 0 || severity > 6) {return false;}
  
! 		return true;
! 	}
  
! 	private Descriptor createDefaultDescriptor()
! 	{
! 		String[] names = new String[] {"name", "descriptorType", "severity", "displayName"/*, "messageId", "log", "logfile"*/};
! 		Object[] values = new Object[] {getName(), "notification", "5", getName()/*, "0", "???", "???"*/};
! 		return new DescriptorSupport(names, values);
! 	}
  
! 	private int objectToInt(Object value)
! 	{
! 		if (value == null) {return -1;}
  
! 		if (value instanceof Number)
! 		{
! 			return ((Number)value).intValue();
! 		}
! 		else
! 		{
! 			try
! 			{
! 				return Integer.parseInt(value.toString());
! 			}
! 			catch (NumberFormatException x)
! 			{
! 				return -1;
! 			}
! 		}
! 	}
  }
--- 22,168 ----
  public class ModelMBeanNotificationInfo extends MBeanNotificationInfo implements DescriptorAccess
  {
!    private static final long serialVersionUID = -7445681389570207141L;
  
!    private Descriptor notificationDescriptor;
  
!    public ModelMBeanNotificationInfo(String[] types, String name, String description)
!    {
!       this(types, name, description, null);
!    }
  
!    public ModelMBeanNotificationInfo(String[] types, String name, String description, Descriptor descriptor)
!    {
!       super(types, name, description);
!       checkAndSetDescriptor(descriptor);
!    }
  
!    public ModelMBeanNotificationInfo(ModelMBeanNotificationInfo copy)
!    {
!       super(copy.getNotifTypes(), copy.getName(), copy.getDescription());
!       checkAndSetDescriptor(copy.getDescriptor());
!    }
! 
!    public Descriptor getDescriptor()
!    {
!       return (Descriptor)notificationDescriptor.clone();
!    }
! 
!    public void setDescriptor(Descriptor descriptor)
!    {
!       if (descriptor == null)
!       {
!          notificationDescriptor = createDefaultDescriptor();
!       }
!       else
!       {
!          if (isDescriptorValid(descriptor))
!          {
!             notificationDescriptor = (Descriptor)descriptor.clone();
!          }
!          else
!          {
!             // Not sure what to do here: javadoc says IllegalArgument, but for example ModelMBeanInfo throws RuntimeOperations
!             // which is consistent with the fact that all exception thrown by the JMX implementation should be JMX exceptions
  //				throw new IllegalArgumentException("Invalid descriptor");
!             throw new RuntimeOperationsException(new IllegalArgumentException("Invalid descriptor"));
!          }
!       }
!    }
  
!    private void checkAndSetDescriptor(Descriptor descriptor)
!    {
!       if (descriptor == null)
!       {
!          notificationDescriptor = createDefaultDescriptor();
!       }
!       else if (isDescriptorValid(descriptor))
!       {
!          notificationDescriptor = (Descriptor)descriptor.clone();
!          if (notificationDescriptor.getFieldValue("displayname") == null)
!          {
!             notificationDescriptor.setField("displayname", getName());
!          }
!       }
!       else
!       {
!          throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor"));
!       }
!    }
  
!    private boolean isDescriptorValid(Descriptor descriptor)
!    {
!       if (!descriptor.isValid())
!       {
!          return false;
!       }
  
!       // Spec compliance checks
  
!       // Mandatory fields are: name, descriptorType, severity, messageId(?), log(?), logFile(?)
!       List names = Arrays.asList(descriptor.getFieldNames());
  
!       // Remember that names are lower case
!       if (!names.contains("name") ||
!           !names.contains("descriptortype") ||
!           !names.contains("severity")/* ||
!          !names.contains("messageid") ||
!          !names.contains("log")/* ||
!          !names.contains("logfile")*/)
!       {
!          return false;
!       }
!       // Case sensitive name
!       String name = getName();
!       if (name == null)
!       {
!          return false;
!       }
!       if (!name.equals(descriptor.getFieldValue("name")))
!       {
!          return false;
!       }
!       // Descriptor type must be 'notification'
!       String desctype = (String)descriptor.getFieldValue("descriptortype");
!       if (desctype.compareToIgnoreCase("notification") != 0) return false;
!       // Severity needn't be checked. It was checked in
!       // descriptor.isValid()
!       int severity = objectToInt(descriptor.getFieldValue("severity"));
!       if (severity < 0 || severity > 6)
!       {
!          return false;
!       }
  
!       return true;
!    }
  
!    private Descriptor createDefaultDescriptor()
!    {
!       String[] names = new String[]{"name", "descriptorType", "severity", "displayName"/*, "messageId", "log", "logfile"*/};
!       Object[] values = new Object[]{getName(), "notification", "5", getName()/*, "0", "???", "???"*/};
!       return new DescriptorSupport(names, values);
!    }
  
!    private int objectToInt(Object value)
!    {
!       if (value == null)
!       {
!          return -1;
!       }
  
!       if (value instanceof Number)
!       {
!          return ((Number)value).intValue();
!       }
!       else
!       {
!          try
!          {
!             return Integer.parseInt(value.toString());
!          }
!          catch (NumberFormatException x)
!          {
!             return -1;
!          }
!       }
!    }
  }

Index: ModelMBeanConstructorInfo.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/modelmbean/ModelMBeanConstructorInfo.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** ModelMBeanConstructorInfo.java	7 Nov 2003 02:01:21 -0000	1.8
--- ModelMBeanConstructorInfo.java	30 Aug 2004 14:04:47 -0000	1.9
***************
*** 12,24 ****
  import java.util.Arrays;
  import java.util.List;
- 
- import javax.management.MBeanConstructorInfo;
- import javax.management.DescriptorAccess;
  import javax.management.Descriptor;
  import javax.management.MBeanParameterInfo;
  import javax.management.RuntimeOperationsException;
  
  /**
-  *
   * @author <a href="mailto:[email protected]">Simone Bordet</a>
   * @version $Revision$
--- 12,22 ----
  import java.util.Arrays;
  import java.util.List;
  import javax.management.Descriptor;
+ import javax.management.DescriptorAccess;
+ import javax.management.MBeanConstructorInfo;
  import javax.management.MBeanParameterInfo;
  import javax.management.RuntimeOperationsException;
  
  /**
   * @author <a href="mailto:[email protected]">Simone Bordet</a>
   * @version $Revision$
***************
*** 26,138 ****
  public class ModelMBeanConstructorInfo extends MBeanConstructorInfo implements DescriptorAccess
  {
! 	private static final long serialVersionUID = 3862947819818064362L;
  
! 	private Descriptor consDescriptor;
  
! 	public ModelMBeanConstructorInfo(String description, Constructor constructor)
! 	{
! 		this(description, constructor, null);
! 	}
  
     public ModelMBeanConstructorInfo(String description, Constructor constructor, Descriptor descriptor)
! 	{
! 		super(description, constructor);
! 		checkAndSetDescriptor(descriptor);
! 	}
  
     public ModelMBeanConstructorInfo(String name, String description, MBeanParameterInfo[] params)
! 	{
! 		this(name, description, params, null);
! 	}
  
     public ModelMBeanConstructorInfo(String name, String description, MBeanParameterInfo[] params, Descriptor descriptor)
! 	{
! 		super(name, description, params);
! 		checkAndSetDescriptor(descriptor);
! 	}
  
! 	public Descriptor getDescriptor()
! 	{
! 		return (Descriptor)consDescriptor.clone();
! 	}
  
! 	public void setDescriptor(Descriptor descriptor)
! 	{
!         if (descriptor == null)
! 		{
! 			consDescriptor = createDefaultDescriptor();
! 		}
! 		else
! 		{
!             if (isDescriptorValid(descriptor))
! 			{
! 				consDescriptor = (Descriptor)descriptor.clone();
! 			}
! 			else
! 			{
! 				// Not sure what to do here: javadoc says IllegalArgument, but for example ModelMBeanInfo throws RuntimeOperations
! 				// which is consistent with the fact that all exception thrown by the JMX implementation should be JMX exceptions
  //				throw new IllegalArgumentException("Invalid descriptor");
! 				throw new RuntimeOperationsException(new IllegalArgumentException("Invalid descriptor"));
! 			}
! 		}
! 	}
  
! 	private void checkAndSetDescriptor(Descriptor descriptor)
! 	{
! 		if (descriptor == null)
! 		{
! 			consDescriptor = createDefaultDescriptor();
! 		}
! 		else if (isDescriptorValid(descriptor))
! 		{
! 			consDescriptor = (Descriptor)descriptor.clone();
! 			if (consDescriptor.getFieldValue("displayName") == null) 
! 			{
! 				consDescriptor.setField("displayName", getName());
! 			}
! 		}
! 		else
! 		{
! 			throw new RuntimeOperationsException(new IllegalArgumentException("Invalid descriptor"));
! 		}
! 	}
  
! 	private boolean isDescriptorValid(Descriptor descriptor)
! 	{
! 		if (!descriptor.isValid()) {return false;}
  
! 		// Spec compliance checks
  
! 		// Mandatory fields are: name, descriptorType, role
! 		List names = Arrays.asList(descriptor.getFieldNames());
  
!         // Remember that names are lower case
! 		if (!names.contains("name") ||
! 			!names.contains("descriptortype") ||
! 			!names.contains("role")) {return false;}
! 		
! 		if (names.contains("persistpolicy") ||
! 			names.contains("currencytimelimit")) {return false;}
! 		
! 		// Case sensitive name
! 		String name = getName();
! 		if (name == null) {return false;}
! 		if (!name.equals(descriptor.getFieldValue("name"))) {return false;}
! 		// Descriptor type must be 'operation'
! 		String desctype = (String) descriptor.getFieldValue("descriptortype");
! 		if (desctype.compareToIgnoreCase("operation") != 0) return false;
! 		// Role must be 'constructor'
! 		String role = (String) descriptor.getFieldValue("role");
! 		if (role.compareTo("constructor") != 0) return false;
  
! 		return true;
! 	}
  
! 	private Descriptor createDefaultDescriptor()
! 	{
! 		String[] names = new String[] {"name", "descriptorType", "role", "displayName"/*, "lastReturnedTimeStamp"*/};
! 		Object[] values = new Object[] {getName(), "operation", "constructor", getName()/*, "0"*/};
! 		return new DescriptorSupport(names, values);
! 	}
  }
--- 24,151 ----
  public class ModelMBeanConstructorInfo extends MBeanConstructorInfo implements DescriptorAccess
  {
!    private static final long serialVersionUID = 3862947819818064362L;
  
!    private Descriptor consDescriptor;
  
!    public ModelMBeanConstructorInfo(String description, Constructor constructor)
!    {
!       this(description, constructor, null);
!    }
  
     public ModelMBeanConstructorInfo(String description, Constructor constructor, Descriptor descriptor)
!    {
!       super(description, constructor);
!       checkAndSetDescriptor(descriptor);
!    }
  
     public ModelMBeanConstructorInfo(String name, String description, MBeanParameterInfo[] params)
!    {
!       this(name, description, params, null);
!    }
  
     public ModelMBeanConstructorInfo(String name, String description, MBeanParameterInfo[] params, Descriptor descriptor)
!    {
!       super(name, description, params);
!       checkAndSetDescriptor(descriptor);
!    }
  
!    public Descriptor getDescriptor()
!    {
!       return (Descriptor)consDescriptor.clone();
!    }
  
!    public void setDescriptor(Descriptor descriptor)
!    {
!       if (descriptor == null)
!       {
!          consDescriptor = createDefaultDescriptor();
!       }
!       else
!       {
!          if (isDescriptorValid(descriptor))
!          {
!             consDescriptor = (Descriptor)descriptor.clone();
!          }
!          else
!          {
!             // Not sure what to do here: javadoc says IllegalArgument, but for example ModelMBeanInfo throws RuntimeOperations
!             // which is consistent with the fact that all exception thrown by the JMX implementation should be JMX exceptions
  //				throw new IllegalArgumentException("Invalid descriptor");
!             throw new RuntimeOperationsException(new IllegalArgumentException("Invalid descriptor"));
!          }
!       }
!    }
  
!    private void checkAndSetDescriptor(Descriptor descriptor)
!    {
!       if (descriptor == null)
!       {
!          consDescriptor = createDefaultDescriptor();
!       }
!       else if (isDescriptorValid(descriptor))
!       {
!          consDescriptor = (Descriptor)descriptor.clone();
!          if (consDescriptor.getFieldValue("displayName") == null)
!          {
!             consDescriptor.setField("displayName", getName());
!          }
!       }
!       else
!       {
!          throw new RuntimeOperationsException(new IllegalArgumentException("Invalid descriptor"));
!       }
!    }
  
!    private boolean isDescriptorValid(Descriptor descriptor)
!    {
!       if (!descriptor.isValid())
!       {
!          return false;
!       }
  
!       // Spec compliance checks
  
!       // Mandatory fields are: name, descriptorType, role
!       List names = Arrays.asList(descriptor.getFieldNames());
  
! // Remember that names are lower case
!       if (!names.contains("name") ||
!           !names.contains("descriptortype") ||
!           !names.contains("role"))
!       {
!          return false;
!       }
  
!       if (names.contains("persistpolicy") ||
!           names.contains("currencytimelimit"))
!       {
!          return false;
!       }
  
!       // Case sensitive name
!       String name = getName();
!       if (name == null)
!       {
!          return false;
!       }
!       if (!name.equals(descriptor.getFieldValue("name")))
!       {
!          return false;
!       }
!       // Descriptor type must be 'operation'
!       String desctype = (String)descriptor.getFieldValue("descriptortype");
!       if (desctype.compareToIgnoreCase("operation") != 0) return false;
!       // Role must be 'constructor'
!       String role = (String)descriptor.getFieldValue("role");
!       if (role.compareTo("constructor") != 0) return false;
! 
!       return true;
!    }
! 
!    private Descriptor createDefaultDescriptor()
!    {
!       String[] names = new String[]{"name", "descriptorType", "role", "displayName"/*, "lastReturnedTimeStamp"*/};
!       Object[] values = new Object[]{getName(), "operation", "constructor", getName()/*, "0"*/};
!       return new DescriptorSupport(names, values);
!    }
  }

Index: ModelMBeanAttributeInfo.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/modelmbean/ModelMBeanAttributeInfo.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** ModelMBeanAttributeInfo.java	12 Nov 2003 19:58:30 -0000	1.9
--- ModelMBeanAttributeInfo.java	30 Aug 2004 14:04:47 -0000	1.10
***************
*** 12,24 ****
  import java.util.Arrays;
  import java.util.List;
- 
- import javax.management.MBeanAttributeInfo;
- import javax.management.DescriptorAccess;
  import javax.management.Descriptor;
  import javax.management.IntrospectionException;
  import javax.management.RuntimeOperationsException;
  
  /**
-  *
   * @author <a href="mailto:[email protected]">Simone Bordet</a>
   * @version $Revision$
--- 12,22 ----
  import java.util.Arrays;
  import java.util.List;
  import javax.management.Descriptor;
+ import javax.management.DescriptorAccess;
  import javax.management.IntrospectionException;
+ import javax.management.MBeanAttributeInfo;
  import javax.management.RuntimeOperationsException;
  
  /**
   * @author <a href="mailto:[email protected]">Simone Bordet</a>
   * @version $Revision$
***************
*** 26,137 ****
  public class ModelMBeanAttributeInfo extends MBeanAttributeInfo implements DescriptorAccess
  {
! 	private static final long serialVersionUID = 6181543027787327345L;
  
! 	private Descriptor attrDescriptor;
  
! 	public ModelMBeanAttributeInfo(String name, String description, Method getter, Method setter) throws IntrospectionException
! 	{
! 		this(name, description, getter, setter, null);
! 	}
  
! 	public ModelMBeanAttributeInfo(String name, String description, Method getter, Method setter, Descriptor descriptor)  throws IntrospectionException
! 	{
! 		super(name, description, getter, setter);
! 		checkAndSetDescriptor(descriptor);
! 	}
  
! 	public ModelMBeanAttributeInfo(String name, String type, String description, boolean isReadable, boolean isWritable, boolean isIs)
! 	{
! 		this(name, type, description, isReadable, isWritable, isIs, null);
! 	}
  
! 	public ModelMBeanAttributeInfo(String name, String type, String description, boolean isReadable, boolean isWritable, boolean isIs, Descriptor descriptor)
! 	{
! 		super(name, type, description, isReadable, isWritable, isIs);
! 		checkAndSetDescriptor(descriptor);
! 	}
  
! 	public ModelMBeanAttributeInfo(ModelMBeanAttributeInfo copy)
! 	{
! 				super(copy.getName(), copy.getType(), copy.getDescription(), copy.isReadable(), copy.isWritable(), copy.isIs());
! 				checkAndSetDescriptor(copy.getDescriptor());
! 	}
  
! 	public Descriptor getDescriptor()
! 	{
! 		return (Descriptor)attrDescriptor.clone();
! 	}
  
! 	public void setDescriptor(Descriptor descriptor)
! 	{
! 		if (descriptor == null)
! 		{
! 			attrDescriptor = createDefaultDescriptor();
! 		}
! 		else
! 		{
! 			if (isDescriptorValid(descriptor))
! 			{
! 				attrDescriptor = (Descriptor)descriptor.clone();
! 			}
! 			else
! 			{
! 				// Not sure what to do here: javadoc says IllegalArgument, but for example ModelMBeanInfo throws RuntimeOperations
! 				// which is consistent with the fact that all exception thrown by the JMX implementation should be JMX exceptions
! 				throw new RuntimeOperationsException(new IllegalArgumentException("Invalid descriptor"));
  //				throw new IllegalArgumentException("Invalid descriptor");
! 			}
! 		}
! 	}
  
! 	private void checkAndSetDescriptor(Descriptor descriptor)
! 	{
! 		if (descriptor == null)
! 		{
! 			attrDescriptor = createDefaultDescriptor();
! 		}
! 		else if (isDescriptorValid(descriptor))
! 		{
! 			attrDescriptor = (Descriptor)descriptor.clone();
! 			if (attrDescriptor.getFieldValue("displayname") == null)
! 			{
! 				attrDescriptor.setField("displayname", this.getName());
! 			}
! 		}
! 		else
! 		{
! 			throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor"));
! 		}
! 	}
  
! 	private boolean isDescriptorValid(Descriptor descriptor)
! 	{
! 		if (!descriptor.isValid()) {return false;}
  
! 		// Spec compliance checks
  
! 		// Mandatory fields are: name, descriptorType
! 		List names = Arrays.asList(descriptor.getFieldNames());
  
! 		// Remember that names are lower case
! 		if (!names.contains("name") ||
! 			!names.contains("descriptortype")) {return false;}
  
! 		// Case sensitive name
! 		String name = getName();
! 		if (name == null) {return false;}
! 		if (!name.equals(descriptor.getFieldValue("name"))) {return false;}
! 		// Descriptor type must be 'attribute'
! 		String desctype = (String) descriptor.getFieldValue("descriptortype");
! 		if (desctype.compareToIgnoreCase("attribute") != 0) return false;
  
! 		return true;
! 	}
  
! 	private Descriptor createDefaultDescriptor()
! 	{
! 		String[] names = new String[] {"name", "descriptorType", "displayName"};
! 		Object[] values = new Object[] {getName(), "attribute", getName()};
! 		return new DescriptorSupport(names, values);
! 	}
  }
--- 24,147 ----
  public class ModelMBeanAttributeInfo extends MBeanAttributeInfo implements DescriptorAccess
  {
!    private static final long serialVersionUID = 6181543027787327345L;
  
!    private Descriptor attrDescriptor;
  
!    public ModelMBeanAttributeInfo(String name, String description, Method getter, Method setter) throws IntrospectionException
!    {
!       this(name, description, getter, setter, null);
!    }
  
!    public ModelMBeanAttributeInfo(String name, String description, Method getter, Method setter, Descriptor descriptor) throws IntrospectionException
!    {
!       super(name, description, getter, setter);
!       checkAndSetDescriptor(descriptor);
!    }
  
!    public ModelMBeanAttributeInfo(String name, String type, String description, boolean isReadable, boolean isWritable, boolean isIs)
!    {
!       this(name, type, description, isReadable, isWritable, isIs, null);
!    }
  
!    public ModelMBeanAttributeInfo(String name, String type, String description, boolean isReadable, boolean isWritable, boolean isIs, Descriptor descriptor)
!    {
!       super(name, type, description, isReadable, isWritable, isIs);
!       checkAndSetDescriptor(descriptor);
!    }
  
!    public ModelMBeanAttributeInfo(ModelMBeanAttributeInfo copy)
!    {
!       super(copy.getName(), copy.getType(), copy.getDescription(), copy.isReadable(), copy.isWritable(), copy.isIs());
!       checkAndSetDescriptor(copy.getDescriptor());
!    }
  
!    public Descriptor getDescriptor()
!    {
!       return (Descriptor)attrDescriptor.clone();
!    }
  
!    public void setDescriptor(Descriptor descriptor)
!    {
!       if (descriptor == null)
!       {
!          attrDescriptor = createDefaultDescriptor();
!       }
!       else
!       {
!          if (isDescriptorValid(descriptor))
!          {
!             attrDescriptor = (Descriptor)descriptor.clone();
!          }
!          else
!          {
!             // Not sure what to do here: javadoc says IllegalArgument, but for example ModelMBeanInfo throws RuntimeOperations
!             // which is consistent with the fact that all exception thrown by the JMX implementation should be JMX exceptions
!             throw new RuntimeOperationsException(new IllegalArgumentException("Invalid descriptor"));
  //				throw new IllegalArgumentException("Invalid descriptor");
!          }
!       }
!    }
  
!    private void checkAndSetDescriptor(Descriptor descriptor)
!    {
!       if (descriptor == null)
!       {
!          attrDescriptor = createDefaultDescriptor();
!       }
!       else if (isDescriptorValid(descriptor))
!       {
!          attrDescriptor = (Descriptor)descriptor.clone();
!          if (attrDescriptor.getFieldValue("displayname") == null)
!          {
!             attrDescriptor.setField("displayname", this.getName());
!          }
!       }
!       else
!       {
!          throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor"));
!       }
!    }
  
!    private boolean isDescriptorValid(Descriptor descriptor)
!    {
!       if (!descriptor.isValid())
!       {
!          return false;
!       }
  
!       // Spec compliance checks
  
!       // Mandatory fields are: name, descriptorType
!       List names = Arrays.asList(descriptor.getFieldNames());
  
!       // Remember that names are lower case
!       if (!names.contains("name") ||
!           !names.contains("descriptortype"))
!       {
!          return false;
!       }
  
!       // Case sensitive name
!       String name = getName();
!       if (name == null)
!       {
!          return false;
!       }
!       if (!name.equals(descriptor.getFieldValue("name")))
!       {
!          return false;
!       }
!       // Descriptor type must be 'attribute'
!       String desctype = (String)descriptor.getFieldValue("descriptortype");
!       if (desctype.compareToIgnoreCase("attribute") != 0) return false;
  
!       return true;
!    }
  
!    private Descriptor createDefaultDescriptor()
!    {
!       String[] names = new String[]{"name", "descriptorType", "displayName"};
!       Object[] values = new Object[]{getName(), "attribute", getName()};
!       return new DescriptorSupport(names, values);
!    }
  }



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click