User: starksm 
  Date: 01/11/12 11:31:07

  Modified:    src/main/org/jboss/configuration Tag: Branch_2_4
                        ConfigurationService.java
  Log:
  Add support for a mbean/config element that allows an mbean to import an
  arbitrary XML configuration tree if it implements the importXml(Element)
  method.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.30.2.3  +125 -102  jboss/src/main/org/jboss/configuration/ConfigurationService.java
  
  Index: ConfigurationService.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/configuration/ConfigurationService.java,v
  retrieving revision 1.30.2.2
  retrieving revision 1.30.2.3
  diff -u -r1.30.2.2 -r1.30.2.3
  --- ConfigurationService.java 2001/10/19 01:31:29     1.30.2.2
  +++ ConfigurationService.java 2001/11/12 19:31:07     1.30.2.3
  @@ -8,7 +8,8 @@
   package org.jboss.configuration;
   
   import java.io.*;
  -import java.beans.*;
  +import java.beans.PropertyEditor;
  +import java.beans.PropertyEditorManager;
   import java.lang.reflect.Constructor;
   import java.lang.reflect.InvocationHandler;
   import java.lang.reflect.Method;
  @@ -19,11 +20,31 @@
   import java.util.Hashtable;
   import java.util.Iterator;
   
  -import javax.management.*;
  +import javax.management.Attribute;
  +import javax.management.InstanceNotFoundException;
  +import javax.management.JMException;
  +import javax.management.JMRuntimeException;
  +import javax.management.MalformedObjectNameException;
  +import javax.management.MBeanAttributeInfo;
  +import javax.management.MBeanInfo;
  +import javax.management.MBeanOperationInfo;
  +import javax.management.MBeanServer;
  +import javax.management.ObjectInstance;
  +import javax.management.ObjectName;
  +import javax.management.RuntimeErrorException;
  +import javax.management.RuntimeMBeanException;
  +import javax.management.RuntimeOperationsException;
  +import javax.management.MBeanException;
  +import javax.management.ReflectionException;
   
  -import org.w3c.dom.*;
  -import org.xml.sax.*;
  -import javax.xml.parsers.*;
  +import org.w3c.dom.Document;
  +import org.w3c.dom.Element;
  +import org.w3c.dom.NodeList;
  +import org.w3c.dom.Text;
  +import org.xml.sax.InputSource;
  +import org.xml.sax.SAXException;
  +import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.DocumentBuilderFactory;
   
   import org.jboss.logging.Log;
   import org.jboss.util.Service;
  @@ -46,11 +67,11 @@
    * @author  Rickard Öberg ([EMAIL PROTECTED])
    * @author  [EMAIL PROTECTED]
    * @author  Jason Dillon <a 
href="mailto:[EMAIL PROTECTED]";>&lt;[EMAIL PROTECTED]&gt;</a>
  - * @version $Revision: 1.30.2.2 $
  + * @version $Revision: 1.30.2.3 $
    */
   public class ConfigurationService
  -extends ServiceMBeanSupport
  -implements ConfigurationServiceMBean
  +   extends ServiceMBeanSupport
  +   implements ConfigurationServiceMBean
   {
      /** The name of the file initial configuration is read from. */
      public static final String CONFIGURATION_FILE = "jboss.jcml";
  @@ -187,18 +208,19 @@
               try
               {
                  info = server.getMBeanInfo(objectName);
  -            } catch (InstanceNotFoundException e)
  +            }
  +            catch (InstanceNotFoundException e)
               {
                  // The MBean is no longer available
                  // It's ok, skip to next one
                  continue;
               }
  -            
  +
               // Set attributes
               NodeList attrs = mbeanElement.getElementsByTagName("attribute");
               for (int j = 0; j < attrs.getLength(); j++)
               {
  -               Element attributeElement = (Element)attrs.item(j);
  +               Element attributeElement = (Element) attrs.item(j);
                  String attributeName = attributeElement.getAttribute("name");
                  if (attributeElement.hasChildNodes())
                  {
  @@ -239,7 +261,25 @@
                     }
                  }
               }
  -            
  +            /* Look for a config element and if it exists invoke the 
importXml(Element)
  +             operation to allow the MBean to support its own arbitrary 
configuration.
  +            */
  +            NodeList configs = mbeanElement.getElementsByTagName("config");
  +            if( configs.getLength() > 0 )
  +            {
  +               Element configElement = (Element) configs.item(0);
  +               Object[] args = { configElement };
  +               String[] signature = { "org.w3c.dom.Element" };
  +               try
  +               {
  +                  server.invoke(objectName, "importXml", args, signature);
  +               }
  +               catch(Exception e)
  +               {
  +                  logException(e);
  +               }
  +            }
  +
               // Register the mbean with the JBoss ServiceControl mbean
               registerService(objectName, info, mbeanElement);
            }
  @@ -434,7 +474,7 @@
       * @throws MalformedObjectNameException
       */
      private ObjectName parseObjectName(final Element element)
  -   throws ConfigurationException, MalformedObjectNameException
  +      throws ConfigurationException, MalformedObjectNameException
      {
         String name = element.getAttribute("name");
         if (name == null || name.trim().equals(""))
  @@ -465,12 +505,10 @@
      private static class ConstructorInfo
      {
         /** An empty parameters list. */
  -      public static final Object EMPTY_PARAMS[] =
  -      {};
  +      public static final Object EMPTY_PARAMS[] = {};
         
         /** An signature list. */
  -      public static final String EMPTY_SIGNATURE[] =
  -      {};
  +      public static final String EMPTY_SIGNATURE[] = {};
         
         /** The constructor signature. */
         public String[] signature = EMPTY_SIGNATURE;
  @@ -487,7 +525,7 @@
          * @throws ConfigurationException   Failed to create info object.
          */
         public static ConstructorInfo create(Element element)
  -      throws ConfigurationException
  +         throws ConfigurationException
         {
            ConstructorInfo info = new ConstructorInfo();
            
  @@ -524,62 +562,62 @@
                     {
                        signature = Short.TYPE.getName();
                        realValue = new Short( value );
  -                  } else
  -                     if( signature.equals( "int" ) )
  +                  }
  +                  else if( signature.equals( "int" ) )
  +                  {
  +                     signature = Integer.TYPE.getName();
  +                     realValue = new Integer( value );
  +                  }
  +                  else  if( signature.equals( "long" ) )
  +                  {
  +                     signature = Long.TYPE.getName();
  +                     realValue = new Long( value );
  +                  }
  +                  else if( signature.equals( "byte" ) )
  +                  {
  +                     signature = Byte.TYPE.getName();
  +                     realValue = new Byte( value );
  +                  }
  +                  else if( signature.equals( "char" ) )
  +                  {
  +                     signature = Character.TYPE.getName();
  +                     realValue = new Character( value.charAt( 0 ) );
  +                  }
  +                  else if( signature.equals( "float" ) )
  +                  {
  +                     signature = Float.TYPE.getName();
  +                     realValue = new Float( value );
  +                  }
  +                  else if( signature.equals( "double" ) )
  +                  {
  +                     signature = Double.TYPE.getName();
  +                     realValue = new Double( value );
  +                  }
  +                  else if( signature.equals( "boolean" ) )
  +                  {
  +                     signature = Boolean.TYPE.getName();
  +                     realValue = new Boolean( value );
  +                  }
  +                  else
  +                  {
  +                     try
                        {
  -                        signature = Integer.TYPE.getName();
  -                        realValue = new Integer( value );
  -                     } else
  -                        if( signature.equals( "long" ) )
  -                        {
  -                           signature = Long.TYPE.getName();
  -                           realValue = new Long( value );
  -                        } else
  -                           if( signature.equals( "byte" ) )
  -                           {
  -                              signature = Byte.TYPE.getName();
  -                              realValue = new Byte( value );
  -                           } else
  -                              if( signature.equals( "char" ) )
  -                              {
  -                                 signature = Character.TYPE.getName();
  -                                 realValue = new Character( value.charAt( 0 ) );
  -                              } else
  -                                 if( signature.equals( "float" ) )
  -                                 {
  -                                    signature = Float.TYPE.getName();
  -                                    realValue = new Float( value );
  -                                 } else
  -                                    if( signature.equals( "double" ) )
  -                                    {
  -                                       signature = Double.TYPE.getName();
  -                                       realValue = new Double( value );
  -                                    } else
  -                                       if( signature.equals( "boolean" ) )
  -                                       {
  -                                          signature = Boolean.TYPE.getName();
  -                                          realValue = new Boolean( value );
  -                                       }
  -                                       else
  -                                       {
  -                                          try
  -                                          {
  -                                             // Check if there is a constructor 
with a single String as
  -                                             // only parameter
  -                                             Class signatureClass =
  -                                             
Thread.currentThread().getContextClassLoader().loadClass( signature );
  -                                             Constructor signatureConstructor =
  -                                             signatureClass.getConstructor( new 
Class[]
  -                                             { String.class } );
  -                                             realValue = 
signatureConstructor.newInstance(
  -                                             new Object[]
  -                                             { value }
  -                                             );
  -                                          }
  -                                          catch( Exception e )
  -                                          {
  -                                          }
  -                                       }
  +                        // Check if there is a constructor with a single String as
  +                        // only parameter
  +                        Class signatureClass =
  +                        Thread.currentThread().getContextClassLoader().loadClass( 
signature );
  +                        Constructor signatureConstructor =
  +                        signatureClass.getConstructor( new Class[]
  +                        { String.class } );
  +                        realValue = signatureConstructor.newInstance(
  +                        new Object[]
  +                        { value }
  +                        );
  +                     }
  +                     catch( Exception e )
  +                     {
  +                     }
  +                  }
                  }
                  info.signature[j] = signature;
                  info.params[j] = realValue;
  @@ -640,10 +678,10 @@
                     // Create the MBean instance
                     ObjectInstance instance =
                     server.createMBean(code,
  -                  objectName,
  -                  loader,
  -                  constructor.params,
  -                  constructor.signature);
  +                     objectName,
  +                     loader,
  +                     constructor.params,
  +                     constructor.signature);
                     info = server.getMBeanInfo(instance.getObjectName());
                  } catch (Throwable ex)
                  {
  @@ -759,9 +797,8 @@
       * @throws IllegalAccessException
       */
      private void registerService(ObjectName objectName,
  -   MBeanInfo info,
  -   Element mbeanElement)
  -   throws ClassNotFoundException, InstantiationException, IllegalAccessException
  +      MBeanInfo info,  Element mbeanElement)
  +      throws ClassNotFoundException, InstantiationException, IllegalAccessException
      {
         // Check for a serviceFactory attribute
         String serviceFactory = mbeanElement.getAttribute("serviceFactory");
  @@ -769,10 +806,8 @@
         
         if (service != null)
         {
  -         Object[] args =
  -         { service };
  -         String[] signature =
  -         { "org.jboss.util.Service" };
  +         Object[] args = { service };
  +         String[] signature = { "org.jboss.util.Service" };
            try
            {
               server.invoke(serviceControl, "register", args, signature);
  @@ -796,9 +831,8 @@
       * @throws IllegalAccessException
       */
      private Service getServiceInstance(ObjectName objectName,
  -   MBeanInfo info,
  -   String serviceFactory)
  -   throws ClassNotFoundException, InstantiationException, IllegalAccessException
  +      MBeanInfo info,  String serviceFactory)
  +      throws ClassNotFoundException, InstantiationException, IllegalAccessException
      {
         Service service = null;
         ClassLoader loader = Thread.currentThread().getContextClassLoader();
  @@ -857,8 +891,7 @@
       */
      private class ServiceProxy implements InvocationHandler
      {
  -      private boolean[] hasOp =
  -      { false, false, false, false };
  +      private boolean[] hasOp = { false, false, false, false };
         private ObjectName objectName;
         
         /**
  @@ -870,7 +903,7 @@
          * @param opInfo
          */
         public ServiceProxy(ObjectName objectName,
  -      MBeanOperationInfo[] opInfo)
  +         MBeanOperationInfo[] opInfo)
         {
            this.objectName = objectName;
            int opCount = 0;
  @@ -898,8 +931,7 @@
            // Log a warning if the mbean does not implement
            // any Service methods
            if (opCount == 0)
  -            log.warning(objectName +
  -            " does not implement any Service methods");
  +            log.warning(objectName + " does not implement any Service methods");
         }
         
         /**
  @@ -924,9 +956,7 @@
            {
               try
               {
  -               String[] sig =
  -               {}
  -               ;
  +               String[] sig = {};
                  server.invoke(objectName, name, args, sig);
               } catch (JMRuntimeException e)
               {
  @@ -942,10 +972,3 @@
         }
      }
   }
  -
  -/* Log
  -6/13/2001 Andreas Schaefer Added type "short" for constructor argument and
  -                           any class having a constructor taking a "String"
  -                           as only parameter
  - */
  -
  
  
  

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

Reply via email to