User: juhalindfors
  Date: 01/12/12 16:08:42

  Modified:    src/main/org/jboss/mx/metadata StandardMetaData.java
  Log:
  reformatting + stuff
  
  Revision  Changes    Path
  1.2       +120 -31   jmx/src/main/org/jboss/mx/metadata/StandardMetaData.java
  
  Index: StandardMetaData.java
  ===================================================================
  RCS file: /cvsroot/jboss/jmx/src/main/org/jboss/mx/metadata/StandardMetaData.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StandardMetaData.java     2001/12/05 14:22:30     1.1
  +++ StandardMetaData.java     2001/12/13 00:08:42     1.2
  @@ -20,32 +20,51 @@
   import javax.management.MBeanNotificationInfo;
   import javax.management.NotificationBroadcaster;
   
  -import org.jboss.mx.server.StandardMBean;
  +import javax.management.modelmbean.ModelMBeanAttributeInfo;
  +import javax.management.modelmbean.ModelMBeanOperationInfo;
  +import javax.management.modelmbean.ModelMBeanNotificationInfo;
  +import javax.management.modelmbean.ModelMBeanConstructorInfo;
  +import javax.management.modelmbean.ModelMBeanInfoSupport;
  +import javax.management.modelmbean.ModelMBeanInfo;
   
  -public class StandardMetaData implements MetaDataBuilder {
  -   
  -   
  +import org.jboss.mx.server.StandardMBeanInvoker;
  +
  +public class StandardMetaData implements MetaDataBuilder
  +{
  +
  +   // Attributes ----------------------------------------------------
      private Object resource = null;
  +   private boolean isModelMetaData = false;
      
  -   public StandardMetaData(Object resource) {
  -      this.resource = resource;   
  -      
  +   // Constructors --------------------------------------------------
  +   public StandardMetaData(Object resource)
  +   {
  +      this.resource = resource;
  +   }
  +
  +   public StandardMetaData(Object resource, boolean isModelMetaData) 
  +   {
  +      this(resource);
  +      this.isModelMetaData = isModelMetaData;
      }
      
  -   public MBeanInfo build() throws NotCompliantMBeanException {
  -      
  -      Class stdInterface = StandardMBean.getMBeanInterface(resource);
  -            
  +   // MetaDataBuilder implementation --------------------------------
  +   public MBeanInfo build() throws NotCompliantMBeanException
  +   {
  +      Class stdInterface = StandardMBeanInvoker.getMBeanInterface(resource);
  +
         Method[] methods = stdInterface.getMethods();
         HashMap getters = new HashMap();
         HashMap setters = new HashMap();
         List operInfo = new ArrayList();
         List attrInfo = new ArrayList();
         MBeanConstructorInfo[] constrInfo = null;
  -      
  -      try {
  -            
  -         for (int i = 0; i < methods.length; ++i) {
  +
  +      try
  +      {
  +
  +         for (int i = 0; i < methods.length; ++i)
  +         {
               String methodName = methods[i].getName();
               if (methodName.startsWith("set"))
                  setters.put(methodName.substring(3, methodName.length()), 
methods[i]);
  @@ -53,46 +72,116 @@
                  getters.put(methodName.substring(3, methodName.length()), 
methods[i]);
               else if (methodName.startsWith("is"))
                  getters.put(methodName.substring(2, methodName.length()), 
methods[i]);
  -            else operInfo.add(new MBeanOperationInfo("MBean Operation.", 
methods[i]));
  +            else
  +               operInfo.add(new MBeanOperationInfo("MBean Operation.", methods[i]));
            }
  -            
  +
            Object[] keys = getters.keySet().toArray();
  -         for (int i = 0; i < keys.length; ++i) {
  +         for (int i = 0; i < keys.length; ++i)
  +         {
               String attrName = (String)keys[i];
               Method getter = (Method)getters.remove(attrName);
               Method setter = (Method)setters.remove(attrName);
               attrInfo.add(new MBeanAttributeInfo(attrName, "MBean Attribute.", 
getter, setter));
            }
  -   
  +
            Iterator it = setters.keySet().iterator();
  -         while(it.hasNext()) {
  +         while(it.hasNext())
  +         {
               String attrName = (String)it.next();
               Method setter = (Method)setters.get(attrName);
               attrInfo.add(new MBeanAttributeInfo(attrName, "MBean Attribute.", null, 
setter));
            }
  -         
  +
            Constructor[] constructors = resource.getClass().getConstructors();
            constrInfo = new MBeanConstructorInfo[constructors.length];
  -         
  +
            for (int i = 0; i < constructors.length; ++i)
               constrInfo[i] = new MBeanConstructorInfo("MBean Constructor.", 
constructors[i]);
  -         
  +
            MBeanNotificationInfo[] notifInfo = null;
  -         
  -         if (resource instanceof NotificationBroadcaster) 
  +
  +         if (resource instanceof NotificationBroadcaster)
               notifInfo = ((NotificationBroadcaster)resource).getNotificationInfo();
  -         
  -         return new MBeanInfo(resource.getClass().getName(), 
resource.getClass().getName(),
  +
  +         MBeanInfo info = new MBeanInfo(
  +               resource.getClass().getName(), resource.getClass().getName(),
                  (MBeanAttributeInfo[])attrInfo.toArray(new MBeanAttributeInfo[0]),
                  constrInfo,
  -               (MBeanOperationInfo[])operInfo.toArray(new MBeanOperationInfo[0]), 
  +               (MBeanOperationInfo[])operInfo.toArray(new MBeanOperationInfo[0]),
                  notifInfo
            );
  +         
  +         if (isModelMetaData)
  +            return (MBeanInfo)convertMetaDataToModelMetaData(info);
  +         else
  +            return info; 
         }
  -      catch (IntrospectionException e) {
  +      catch (IntrospectionException e)
  +      {
            throw new NotCompliantMBeanException(e.getMessage());
         }
  -   };   
  -
  +   }
      
  +   // Private -------------------------------------------------------
  +   private ModelMBeanInfo convertMetaDataToModelMetaData(MBeanInfo mi) 
  +   {
  +      MBeanAttributeInfo[] attributes = mi.getAttributes();
  +      ModelMBeanAttributeInfo[] mmbAttributes = new 
ModelMBeanAttributeInfo[attributes.length];   
  +      
  +      for (int i = 0; i < attributes.length; ++i)
  +      {
  +         mmbAttributes[i] = new ModelMBeanAttributeInfo(
  +               attributes[i].getName(), 
  +               attributes[i].getType(),
  +               attributes[i].getDescription(),
  +               attributes[i].isReadable(),
  +               attributes[i].isWritable(),
  +               attributes[i].isIs()
  +         );
  +      }
  +      
  +      MBeanOperationInfo[] operations = mi.getOperations();
  +      ModelMBeanOperationInfo[] mmbOperations = new 
ModelMBeanOperationInfo[operations.length];
  +      
  +      for (int i = 0; i < operations.length; ++i)
  +      {
  +         mmbOperations[i] = new ModelMBeanOperationInfo(
  +               operations[i].getName(),
  +               operations[i].getDescription(),
  +               operations[i].getSignature(),
  +               operations[i].getReturnType(),
  +               operations[i].getImpact()
  +         );
  +      }
  +      
  +      MBeanConstructorInfo[] constructors = mi.getConstructors();
  +      ModelMBeanConstructorInfo[] mmbConstructors = new 
ModelMBeanConstructorInfo[constructors.length];
  +      
  +      for (int i = 0; i < constructors.length; ++i)
  +      {
  +         mmbConstructors[i] = new ModelMBeanConstructorInfo(
  +               constructors[i].getName(),
  +               constructors[i].getDescription(),
  +               constructors[i].getSignature()
  +         );
  +      }
  +      
  +      MBeanNotificationInfo[] notifications = mi.getNotifications();
  +      ModelMBeanNotificationInfo[] mmbNotifications = new 
ModelMBeanNotificationInfo[notifications.length];
  +   
  +      for (int i = 0; i < notifications.length; ++i)
  +      {
  +         mmbNotifications[i] = new ModelMBeanNotificationInfo(
  +               notifications[i].getNotifTypes(),
  +               notifications[i].getName(),
  +               notifications[i].getDescription()
  +         );
  +      }        
  +      
  +      return new ModelMBeanInfoSupport(mi.getClassName(), mi.getDescription(),
  +            mmbAttributes, mmbConstructors, mmbOperations, mmbNotifications); 
  +   }
  +   
   }
  +
  
  
  

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

Reply via email to