User: juhalindfors
  Date: 02/01/24 14:14:22

  Modified:    src/main/org/jboss/mx/server MBeanInvoker.java
  Log:
  fixed exception handling
  
  Revision  Changes    Path
  1.4       +92 -53    jmx/src/main/org/jboss/mx/server/MBeanInvoker.java
  
  Index: MBeanInvoker.java
  ===================================================================
  RCS file: /cvsroot/jboss/jmx/src/main/org/jboss/mx/server/MBeanInvoker.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MBeanInvoker.java 2002/01/12 20:10:53     1.3
  +++ MBeanInvoker.java 2002/01/24 22:14:22     1.4
  @@ -19,6 +19,7 @@
   import javax.management.MBeanInfo;
   import javax.management.MBeanOperationInfo;
   import javax.management.MBeanParameterInfo;
  +import javax.management.Descriptor;
   import javax.management.JMException;
   import javax.management.NotCompliantMBeanException;
   import javax.management.ReflectionException;
  @@ -42,86 +43,124 @@
    *
    *
    * @author  <a href="mailto:[EMAIL PROTECTED]";>Juha Lindfors</a>.
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    *   
    */
   public abstract class MBeanInvoker
  -   implements DynamicMBean
  +         implements DynamicMBean
   {
      // Attributes ----------------------------------------------------
  -   protected Interceptor stack = null;
  -   protected Object resource = null;
  -   
  -   // Public --------------------------------------------------------   
  -   public Object getResource() 
  +   protected Interceptor stack        = null;
  +   protected Object resource          = null;
  +   protected Descriptor[] descriptors = null;
  +
  +   // Public --------------------------------------------------------
  +   public Object getResource()
      {
         return resource;
      }
  -   
  +
      // DynamicMBean implementation -----------------------------------
      public Object invoke(String operationName, Object[] args, String[] signature) 
throws MBeanException, ReflectionException
      {
  -      try {
  +      try
  +      {
            Invocation invocation = new Invocation(
  -               operationName,
  -               Invocation.OPERATION,
  -               0, args, signature, null
  -         );
  +                                    operationName,
  +                                    Invocation.OPERATION,
  +                                    0, args, signature, descriptors
  +                                 );
            return stack.invoke(invocation);
  +      }
  +      catch (InvocationException e)
  +      {
  +         if (e.getTargetException() instanceof MBeanException)
  +            throw (MBeanException)e.getTargetException();
  +         else if (e.getTargetException() instanceof ReflectionException)
  +            throw (ReflectionException)e.getTargetException();
  +         else 
  +            throw (RuntimeException)e.getTargetException();
         }
  -      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());
  +      catch (Throwable t)
  +      {
  +         // this indicates an error in the server
  +         // FIXME: log
  +         System.out.println("SERVER ERROR: " + t.getMessage());
  +         t.printStackTrace();
  +         
  +         throw new Error(t.toString());
         }
      }
   
  -   public Object getAttribute(java.lang.String attribute)
  -   throws AttributeNotFoundException, MBeanException, ReflectionException
  +   public Object getAttribute(String attribute) throws AttributeNotFoundException, 
MBeanException, ReflectionException
      {
  -      try {
  +      try
  +      {
            Invocation invocation = new Invocation(
  -               attribute,
  -               Invocation.ATTRIBUTE,
  -               Invocation.READ,
  -               null, null, null
  -         );
  +                                    attribute,
  +                                    Invocation.ATTRIBUTE,
  +                                    Invocation.READ,
  +                                    null, null, descriptors
  +                                 );
            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());
  +      catch (InvocationException e)
  +      {
  +         if (e.getTargetException() instanceof AttributeNotFoundException)
  +            throw (AttributeNotFoundException)e.getTargetException();
  +         else if (e.getTargetException() instanceof MBeanException)
  +            throw (MBeanException)e.getTargetException();
  +         else if (e.getTargetException() instanceof ReflectionException)
  +            throw (ReflectionException)e.getTargetException();
  +         else 
  +            throw (RuntimeException)e.getTargetException();
         }
  +      catch (Throwable t)
  +      {
  +         // this indicates an error in the server
  +         // FIXME: log
  +         System.out.println("SERVER ERROR: " + t.getMessage());
  +         t.printStackTrace();
  +         
  +         throw new Error(t.toString());
  +      }
      }
   
  -   public void setAttribute(Attribute attribute)
  -   throws AttributeNotFoundException, InvalidAttributeValueException, 
MBeanException, ReflectionException
  +   public void setAttribute(Attribute attribute) throws AttributeNotFoundException, 
InvalidAttributeValueException, MBeanException, ReflectionException
      {
  -      try {
  +      try
  +      {
            Invocation invocation = new Invocation(
  -               attribute.getName(),
  -               Invocation.ATTRIBUTE,
  -               Invocation.WRITE,
  -               new Object[] { attribute.getValue() },
  -               new String[] { attribute.getValue().getClass().getName() },
  -               null
  -         );
  +                                    attribute.getName(),
  +                                    Invocation.ATTRIBUTE,
  +                                    Invocation.WRITE,
  +                                    new Object[] { attribute.getValue() },
  +                                    new String[] { 
attribute.getValue().getClass().getName() },
  +                                    descriptors
  +                                 );
            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());         
  +      }
  +      catch (InvocationException e)
  +      {
  +         // FIXME: InvalidAttributeValueException!
  +         
  +         if (e.getTargetException() instanceof AttributeNotFoundException)
  +            throw (AttributeNotFoundException)e.getTargetException();
  +         else if (e.getTargetException() instanceof MBeanException)
  +            throw (MBeanException)e.getTargetException();
  +         else if (e.getTargetException() instanceof ReflectionException)
  +            throw (ReflectionException)e.getTargetException();
  +         else 
  +            throw (RuntimeException)e.getTargetException();
  +      }
  +      catch (Throwable t)
  +      {
  +         // this indicates an error in the server
  +         // FIXME: log
  +         System.out.println("SERVER ERROR: " + t.getMessage());
  +         t.printStackTrace();
  +         
  +         throw new Error(t.toString());
         }
      }
   
  
  
  

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

Reply via email to