[JBoss-dev] CVS update: jmx/src/main/org/jboss/mx/server StandardMBean.java
User: juhalindfors Date: 01/12/06 14:50:53 Modified:src/main/org/jboss/mx/server StandardMBean.java Log: Revision ChangesPath 1.2 +108 -150 jmx/src/main/org/jboss/mx/server/StandardMBean.java Index: StandardMBean.java === RCS file: /cvsroot/jboss/jmx/src/main/org/jboss/mx/server/StandardMBean.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- StandardMBean.java2001/12/05 14:24:55 1.1 +++ StandardMBean.java2001/12/06 22:50:53 1.2 @@ -1,5 +1,8 @@ /* - * LGPL + * JBoss, the OpenSource J2EE webOS + * + * Distributable under LGPL license. + * See terms of license at gnu.org. */ package org.jboss.mx.server; @@ -26,198 +29,153 @@ import javax.management.loading.DefaultLoaderRepository; import org.jboss.mx.metadata.StandardMetaData; +import org.jboss.mx.interceptor.Interceptor; +import org.jboss.mx.interceptor.Invocation; +import org.jboss.mx.interceptor.StandardMBeanInterceptor; +import org.jboss.mx.interceptor.LogInterceptor; +import org.jboss.mx.interceptor.SecurityInterceptor; +import org.jboss.mx.interceptor.InvocationException; + + +/** + * Represents standard MBean in the server. + * + * @see org.jboss.mx.interceptor.StandardMBeanInterceptor + * + * @author mailto:[EMAIL PROTECTED]";>Juha Lindfors. + * @version $Revision: 1.2 $ + * + */ +public class StandardMBean + implements DynamicMBean +{ -public class StandardMBean implements DynamicMBean { - - public static Class getMBeanInterface(Object resource) { + // Attributes + private MBeanInfo info = null; + private Object resource = null; + private Interceptor stack = null; + + // Constructors -- + public StandardMBean(Object resource) throws NotCompliantMBeanException, ReflectionException + { + this.resource = resource; + this.info = new StandardMetaData(resource).build(); + Interceptor security = new SecurityInterceptor(); + security.insertLast(new LogInterceptor()); + security.insertLast(new StandardMBeanInterceptor(resource, info)); + stack = security; + } + + // Public + public static Class getMBeanInterface(Object resource) + { Class clazz = resource.getClass(); - - while (clazz != null) { + + while (clazz != null) + { Class[] interfaces = clazz.getInterfaces(); - - for (int i = 0; i < interfaces.length; ++i) { - + + for (int i = 0; i < interfaces.length; ++i) + { if (interfaces[i].getName().equals(clazz.getName() + "MBean")) return interfaces[i]; - + Class[] superInterfaces = interfaces[i].getInterfaces(); -for (int j = 0; j < superInterfaces.length; ++j) { +for (int j = 0; j < superInterfaces.length; ++j) +{ if (superInterfaces[j].getName().equals(clazz.getName() + "MBean")) return superInterfaces[j]; } - } - clazz = clazz.getSuperclass(); - } - - return null; - } - - public static Class[] getSignatureAsClassArray(MBeanParameterInfo[] signature, ClassLoader cl) throws ClassNotFoundException { - - Class[] sign = new Class[signature.length]; - for (int i = 0; i < signature.length; ++i) { - try { -String type = signature[i].getType(); -if (isPrimitive(type)) - sign[i] = getPrimitive(type); -else - sign[i] = cl.loadClass(signature[i].getName()); - } - catch (ClassNotFoundException e) { -// if the explicit CL fails, go to the repository... allow CNFE to be thrown -DefaultLoaderRepository.loadClass(signature[i].getName()); } + clazz = clazz.getSuperclass(); } - return sign; - } - - public static boolean isPrimitive(String type) { - if (int.class.getName().equals(type)) return true; - else if (float.class.getName().equals(type))return true; - else if (double.class.getName().equals(type)) return true; - else if (long.class.getName().equals(type)) return true; - else if (byte.class.getName().equals(type)) return true; - else if (boolean.class.getName().equals(type)) return true; - else if (char.class.getName().equals(type)) return true; - else if (void.class.getName().equals(type)) return true; - else i
[JBoss-dev] CVS update: jmx/src/main/org/jboss/mx/server StandardMBean.java
User: juhalindfors Date: 01/12/08 08:03:50 Modified:src/main/org/jboss/mx/server StandardMBean.java Log: standard attributes Revision ChangesPath 1.3 +56 -18jmx/src/main/org/jboss/mx/server/StandardMBean.java Index: StandardMBean.java === RCS file: /cvsroot/jboss/jmx/src/main/org/jboss/mx/server/StandardMBean.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- StandardMBean.java2001/12/06 22:50:53 1.2 +++ StandardMBean.java2001/12/08 16:03:50 1.3 @@ -43,7 +43,7 @@ * @see org.jboss.mx.interceptor.StandardMBeanInterceptor * * @author mailto:[EMAIL PROTECTED]";>Juha Lindfors. - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * */ public class StandardMBean @@ -95,18 +95,70 @@ } // DynamicMBean implementation --- + public Object invoke(String operationName, Object[] args, String[] signature) throws MBeanException, ReflectionException + { + try { + Invocation invocation = new Invocation( + operationName, + Invocation.OPERATION, + 0, args, signature, null + ); + return stack.invoke(invocation); + } + catch (InvocationException e) { + // FIXME: bad exception handling + if (e.getTargetException() instanceof Exception) +throw new MBeanException((Exception)e.getTargetException(), e.getTargetException().toString()); + else +throw new RuntimeErrorException((Error)e.getTargetException(), e.getTargetException().toString()); + } + } + public Object getAttribute(java.lang.String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException { - throw new Error("NYI"); - // FIXME: deal with runtime exceptions and errors from the resource + try { + Invocation invocation = new Invocation( + attribute, + Invocation.ATTRIBUTE, + Invocation.READ, + null, null, null + ); + return stack.invoke(invocation); + } + catch (InvocationException e) { + // FIXME: bad exception handling + if (e.getTargetException() instanceof Exception) { +MBeanException mbe = new MBeanException((Exception)e.getTargetException(), e.getTargetException().toString()); +mbe.fillInStackTrace(); +throw mbe; + } + else +throw new RuntimeErrorException((Error)e.getTargetException(), e.getTargetException().toString()); + } } public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { - throw new Error("NYI"); - // FIXME: deal with runtime exceptions and errors from the resource + try { + Invocation invocation = new Invocation( + attribute.getName(), + Invocation.ATTRIBUTE, + Invocation.WRITE, + new Object[] { attribute.getValue() }, + new String[] { attribute.getValue().getClass().getName() }, + null + ); + stack.invoke(invocation); + } + catch (InvocationException e) { + // FIXME: bad exception handling + if (e.getTargetException() instanceof Exception) +throw new MBeanException((Exception)e.getTargetException(), e.getTargetException().toString()); + else +throw new RuntimeErrorException((Error)e.getTargetException(), e.getTargetException().toString()); + } } public AttributeList getAttributes(java.lang.String[] attributes) @@ -162,20 +214,6 @@ return info; } - // Interceptor overrides - - public Object invoke(String operationName, Object[] args, String[] signature) throws MBeanException, ReflectionException - { - try { - Invocation invocation = new Invocation(operationName, Invocation.OPERATION, 0, args, signature, null); - return stack.invoke(invocation); - } - catch (InvocationException e) { - if (e.getTargetException() instanceof Exception) -throw new MBeanException((Exception)e.getTargetException(), e.getTargetException().toString()); - else -throw new RuntimeErrorException((Error)e.getTargetException(), e.getTargetException().toString()); - } - } } ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo
[JBoss-dev] CVS update: jmx/src/main/org/jboss/mx/server StandardMBean.java
User: juhalindfors Date: 01/12/12 15:51:25 Removed: src/main/org/jboss/mx/server StandardMBean.java Log: renamed to StandardMbeanInvoker ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development