User: juhalindfors Date: 01/12/12 15:56:18 Added: src/main/org/jboss/mx/server MBeanInvoker.java Log: superclass for mbean type specific invokers implements DMBean except for the getMBeanInfo (getMI() won't travel through the interceptor stack yet) Revision Changes Path 1.1 jmx/src/main/org/jboss/mx/server/MBeanInvoker.java Index: MBeanInvoker.java =================================================================== /* * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.mx.server; import java.util.Map; import java.util.HashMap; import java.util.Iterator; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; import javax.management.DynamicMBean; import javax.management.Attribute; import javax.management.AttributeList; import javax.management.MBeanInfo; import javax.management.MBeanOperationInfo; import javax.management.MBeanParameterInfo; import javax.management.JMException; import javax.management.NotCompliantMBeanException; import javax.management.ReflectionException; import javax.management.RuntimeErrorException; import javax.management.MBeanException; import javax.management.AttributeNotFoundException; import javax.management.InvalidAttributeValueException; 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; /** * * * @see * * @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>. * @version $Revision: 1.1 $ * */ public abstract class MBeanInvoker implements DynamicMBean { // Attributes ---------------------------------------------------- protected Interceptor stack = null; // Public -------------------------------------------------------- // 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 { 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 { 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) { if (attributes == null) // FIXME: runtimeoperationsexception? throw new IllegalArgumentException("null array"); AttributeList list = new AttributeList(); for (int i = 0; i < attributes.length; ++i) { try { list.add(new Attribute(attributes[i], getAttribute(attributes[i]))); } catch (JMException ignored) { // if the attribute could not be retrieved, skip it } } return list; } public AttributeList setAttributes(AttributeList attributes) { if (attributes == null) // FIXME: runtimeoperationsexception? throw new IllegalArgumentException("null list"); AttributeList results = new AttributeList(); Iterator it = attributes.iterator(); while (it.hasNext()) { try { Attribute attr = (Attribute)it.next(); setAttribute(attr); results.add(attr); } catch (JMException ignored) { // if unable to set the attribute, skip it } } return results; } }
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
