User: juhalindfors
Date: 02/03/20 08:52:09
Modified: src/main/org/jboss/mx/metadata Tag: BranchMX_1_0
MBeanInfoConversion.java
Log:
create automatic attribute->operation mapping for model mbean resources
that are created with standard mbean naming convention:
* operation with 'role=getter' for readable attributes where operation
name is either getAttributeName or isAttributeName depending on the
attribute's type
* operation with 'role=setter' for writable attributes where operation
name is getAttributeName
Descriptors for MMB attributes link to these operations with setMethod and
getMethod descriptor fields.
Revision Changes Path
No revision
No revision
1.1.2.1 +89 -2 jmx/src/main/org/jboss/mx/metadata/MBeanInfoConversion.java
Index: MBeanInfoConversion.java
===================================================================
RCS file:
/cvsroot/jboss/jmx/src/main/org/jboss/mx/metadata/MBeanInfoConversion.java,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -u -r1.1 -r1.1.2.1
--- MBeanInfoConversion.java 26 Feb 2002 02:02:59 -0000 1.1
+++ MBeanInfoConversion.java 20 Mar 2002 16:52:09 -0000 1.1.2.1
@@ -7,35 +7,54 @@
package org.jboss.mx.metadata;
+import javax.management.Descriptor;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanOperationInfo;
+import javax.management.MBeanParameterInfo;
+
+import javax.management.modelmbean.DescriptorSupport;
import javax.management.modelmbean.ModelMBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanConstructorInfo;
import javax.management.modelmbean.ModelMBeanInfo;
import javax.management.modelmbean.ModelMBeanInfoSupport;
import javax.management.modelmbean.ModelMBeanNotificationInfo;
import javax.management.modelmbean.ModelMBeanOperationInfo;
+
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
+
+import org.jboss.mx.modelmbean.ModelMBeanConstants;
/**
* Routines for converting MBeanInfo to ModelMBeanInfoSupport and stripping
ModelMBeanOperationInfos that
* are referred to in ModelMBeanAttributeInfos
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
+ * @version $Revision: 1.1.2.1 $
*/
public class MBeanInfoConversion
+ implements ModelMBeanConstants
{
/**
* Convert regular MBeanInfo into ModelMBeanInfo
*/
public static ModelMBeanInfoSupport toModelMBeanInfo(MBeanInfo info)
{
+ return toModelMBeanInfo(info, false);
+ }
+
+ public static ModelMBeanInfoSupport toModelMBeanInfo(MBeanInfo info, boolean
createAttributeOperationMapping)
+ {
MBeanAttributeInfo[] attributes = info.getAttributes();
ModelMBeanAttributeInfo[] mmbAttributes = new
ModelMBeanAttributeInfo[attributes.length];
-
+ List accessorOperations = new ArrayList();
+
for (int i = 0; i < attributes.length; ++i)
{
mmbAttributes[i] = new ModelMBeanAttributeInfo(
@@ -46,10 +65,75 @@
attributes[i].isWritable(),
attributes[i].isIs()
);
+
+ if (createAttributeOperationMapping)
+ {
+ String getterOperationName = null;
+ String setterOperationName = null;
+ Descriptor getterDescriptor = null;
+ Descriptor setterDescriptor = null;
+
+ if (attributes[i].isReadable())
+ {
+ if (attributes[i].isIs())
+ getterOperationName = "is" + attributes[i].getName();
+ else
+ getterOperationName = "get" + attributes[i].getName();
+
+ getterDescriptor = new DescriptorSupport();
+ getterDescriptor.setField(NAME, getterOperationName);
+ getterDescriptor.setField(DESCRIPTOR_TYPE, OPERATION_DESCRIPTOR);
+ getterDescriptor.setField(ROLE, GETTER);
+
+ ModelMBeanOperationInfo opInfo = new ModelMBeanOperationInfo(
+ getterOperationName,
+ "Read accessor operation for '" + attributes[i].getName() + "'
attribute.",
+ new MBeanParameterInfo[0], // void signature
+ attributes[i].getType(), // return type
+ MBeanOperationInfo.INFO, // impact
+ getterDescriptor
+ );
+
+ Descriptor attrDescriptor = mmbAttributes[i].getDescriptor();
+ attrDescriptor.setField(GET_METHOD, getterOperationName);
+ mmbAttributes[i].setDescriptor(attrDescriptor);
+
+ accessorOperations.add(opInfo);
+ }
+
+ if (attributes[i].isWritable())
+ {
+ setterOperationName = "set" + attributes[i].getName();
+
+ setterDescriptor = new DescriptorSupport();
+ setterDescriptor.setField(NAME, setterOperationName);
+ setterDescriptor.setField(DESCRIPTOR_TYPE, OPERATION_DESCRIPTOR);
+ setterDescriptor.setField(ROLE, SETTER);
+
+ ModelMBeanOperationInfo opInfo = new ModelMBeanOperationInfo(
+ setterOperationName,
+ "Write accessor operation for '" + attributes[i].getName() +
"' attribute.",
+
+ new MBeanParameterInfo[] {
+ new MBeanParameterInfo("value", attributes[i].getType(),
"Attribute's value.")
+ },
+
+ Void.TYPE.getName(),
+ MBeanOperationInfo.ACTION,
+ setterDescriptor
+ );
+
+ Descriptor attrDescriptor = mmbAttributes[i].getDescriptor();
+ attrDescriptor.setField(SET_METHOD, setterOperationName);
+ mmbAttributes[i].setDescriptor(attrDescriptor);
+
+ accessorOperations.add(opInfo);
+ }
+ }
}
MBeanOperationInfo[] operations = info.getOperations();
- ModelMBeanOperationInfo[] mmbOperations = new
ModelMBeanOperationInfo[operations.length];
+ ModelMBeanOperationInfo[] mmbOperations = new
ModelMBeanOperationInfo[operations.length + accessorOperations.size()];
for (int i = 0; i < operations.length; ++i)
{
@@ -61,6 +145,9 @@
operations[i].getImpact()
);
}
+
+ for (int i = operations.length; i < mmbOperations.length; ++i)
+ mmbOperations[i] = (ModelMBeanOperationInfo)accessorOperations.get(i -
operations.length);
MBeanConstructorInfo[] constructors = info.getConstructors();
ModelMBeanConstructorInfo[] mmbConstructors = new
ModelMBeanConstructorInfo[constructors.length];
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development