User: juhalindfors Date: 01/12/05 06:22:30 Added: src/main/org/jboss/mx/metadata MetaDataBuilder.java StandardMetaData.java Log: builder interface and impl. for standard conventions Revision Changes Path 1.1 jmx/src/main/org/jboss/mx/metadata/MetaDataBuilder.java Index: MetaDataBuilder.java =================================================================== /* * LGPL */ package org.jboss.mx.metadata; import javax.management.MBeanInfo; import javax.management.NotCompliantMBeanException; public interface MetaDataBuilder { public MBeanInfo build() throws NotCompliantMBeanException; } 1.1 jmx/src/main/org/jboss/mx/metadata/StandardMetaData.java Index: StandardMetaData.java =================================================================== /* * LGPL */ package org.jboss.mx.metadata; import java.util.Map; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.ArrayList; import java.lang.reflect.Method; import java.lang.reflect.Constructor; import javax.management.NotCompliantMBeanException; import javax.management.IntrospectionException; import javax.management.MBeanInfo; import javax.management.MBeanAttributeInfo; import javax.management.MBeanOperationInfo; import javax.management.MBeanConstructorInfo; import javax.management.MBeanNotificationInfo; import javax.management.NotificationBroadcaster; import org.jboss.mx.server.StandardMBean; public class StandardMetaData implements MetaDataBuilder { private Object resource = null; public StandardMetaData(Object resource) { this.resource = resource; } public MBeanInfo build() throws NotCompliantMBeanException { Class stdInterface = StandardMBean.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) { String methodName = methods[i].getName(); if (methodName.startsWith("set")) setters.put(methodName.substring(3, methodName.length()), methods[i]); else if (methodName.startsWith("get")) 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])); } Object[] keys = getters.keySet().toArray(); 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()) { 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) notifInfo = ((NotificationBroadcaster)resource).getNotificationInfo(); return new MBeanInfo(resource.getClass().getName(), resource.getClass().getName(), (MBeanAttributeInfo[])attrInfo.toArray(new MBeanAttributeInfo[0]), constrInfo, (MBeanOperationInfo[])operInfo.toArray(new MBeanOperationInfo[0]), notifInfo ); } catch (IntrospectionException e) { throw new NotCompliantMBeanException(e.getMessage()); } }; }
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development