User: user57  
  Date: 01/04/19 22:19:38

  Modified:    src/main/org/jboss/configuration ConfigurationService.java
  Added:       src/main/org/jboss/configuration ConfigurationException.java
  Log:
   o Added support for MBean creation via non-default constructor.
     To specify the constructor, provide a nested <constructor> element
     that contains nested <arg> elements (which mimik the mlet syntax).
  
   o Added ConfigurationException, currently only thrown when there is
     more than one <constructor> element per <mbean>, but could possibly
     be thrown in other places in the future.
  
  Revision  Changes    Path
  1.23      +99 -17    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.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- ConfigurationService.java 2001/04/20 04:09:58     1.22
  +++ ConfigurationService.java 2001/04/20 05:19:38     1.23
  @@ -24,24 +24,28 @@
   import org.xml.sax.*;
   import javax.xml.parsers.*;
   
  -
   import org.jboss.logging.Log;
   import org.jboss.util.Service;
   import org.jboss.util.ServiceFactory;
   import org.jboss.util.ServiceMBeanSupport;
   import org.jboss.util.XmlHelper;
   
  -/** The ConfigurationService MBean is loaded when JBoss starts up by the
  -JMX MLet. The ConfigurationService in turn loads the jboss.jcml configuration
  -when loadConfiguration() is invoked. This instantiates JBoss specific mbean
  -services that wish to be controlled by the JBoss ServiceControl/Service
  -lifecycle service.
  +/** 
  + * The ConfigurationService MBean is loaded when JBoss starts up by the
  + * JMX MLet.
  + *
  + * <p>The ConfigurationService in turn loads the jboss.jcml configuration 
  + *    when {@link #loadConfiguration} is invoked. This instantiates JBoss 
  + *    specific mbean services that wish to be controlled by the JBoss 
  + *    {@link ServiceControl}/{@link Service} lifecycle service.
    *
  - *   @see org.jboss.util.Service
  - *   @see org.jboss.util.ServiceControl
  - *   @author Rickard �berg ([EMAIL PROTECTED])
  - *   @author [EMAIL PROTECTED]
  - *   @version $Revision: 1.22 $
  + * @see org.jboss.util.Service
  + * @see org.jboss.util.ServiceControl
  + *
  + * @author  Rickard �berg ([EMAIL PROTECTED])
  + * @author  [EMAIL PROTECTED]
  + * @author  Jason Dillon <a 
href="mailto:[EMAIL PROTECTED]">&lt;[EMAIL PROTECTED]&gt;</a>
  + * @version $Revision: 1.23 $
    */
   public class ConfigurationService
      extends ServiceMBeanSupport
  @@ -115,7 +119,7 @@
                     // It's ok, skip to next one
                     continue;
                   }
  -
  +                
                   // Set attributes
                   NodeList attrs = mbeanElement.getElementsByTagName("attribute");
                   for (int j = 0; j < attrs.getLength(); j++)
  @@ -248,8 +252,8 @@
            try {
                out = new PrintWriter(new FileOutputStream(confFile.getFile()));
             } catch (java.io.FileNotFoundException e) {
  -             log.error("Configuration file "+confFile.getFile()+" must be available 
and writable.");
  -             log.exception(e);
  +           log.error("Configuration file "+confFile.getFile()+" must be available 
and writable.");
  +           log.exception(e);
             }
             out.print(xml);
             out.close();
  @@ -298,6 +302,73 @@
       }
   
       // Protected -----------------------------------------------------
  +
  +    /**
  +     * Provides a wrapper around the information about which constructor 
  +     * that MBeanServer should use to construct a MBean.
  +     *
  +     * <p>XML syntax for contructor:
  +     *   <pre>
  +     *      <constructor>
  +     *         <arg type="xxx" value="yyy"/>
  +     *         ...
  +     *         <arg type="xxx" value="yyy"/>
  +     *      </constructor>
  +     *   </pre>
  +     */
  +    protected static class ConstructorInfo
  +    {
  +       public static final Object EMPTY_PARAMS[] = {};
  +       public static final String EMPTY_SIGNATURE[] = {};
  +
  +       /** The constructor signature. */
  +       public String[] signature = EMPTY_SIGNATURE;
  +
  +       /** The constructor parameters. */
  +       public Object[] params = EMPTY_PARAMS;
  +       
  +       /**
  +        * Create a ConstructorInfo object for the given configuration.
  +        *
  +        * @param element   The element to build info for.
  +        * @return          A constructor information object.
  +        *
  +        * @throws ConfigurationException   Failed to create info object.
  +        */
  +       public static ConstructorInfo create(Element element)
  +          throws ConfigurationException
  +       {
  +          ConstructorInfo info = new ConstructorInfo();
  +
  +          NodeList list = element.getElementsByTagName("constructor");
  +          if (list.getLength() > 1) {
  +             throw new ConfigurationException
  +                ("only one <constructor> element may be defined");
  +          }
  +          else if (list.getLength() == 1) {
  +             element = (Element)list.item(0);
  +             
  +             // get all of the "arg" elements
  +             list = element.getElementsByTagName("arg");
  +             int length = list.getLength();
  +             info.params = new Object[length];
  +             info.signature = new String[length];
  +             
  +             // decode the values into params & signature
  +             for (int j=0; j<length; j++) {
  +                Element arg = (Element)list.item(j);
  +                //
  +                // NOTE: should coerce value to the correct type??
  +                //
  +                info.signature[j] = arg.getAttribute("type");
  +                info.params[j] = arg.getAttribute("value");
  +             }
  +          }
  +          
  +          return info;
  +       }
  +    }
  +
       protected void create(Document configuration)
           throws Exception
       {
  @@ -328,9 +399,20 @@
                     {
                        try
                        {
  -                        // Create MBean
  -                        ObjectInstance instance = server.createMBean(code, 
objectName,
  -                            new ObjectName(server.getDefaultDomain(), "service", 
"MLet"));
  +                        // get the constructor params/sig to use
  +                        ConstructorInfo constructor = 
  +                           ConstructorInfo.create(mbeanElement);
  +
  +                        // Could probably cache this value
  +                        ObjectName loader = new 
ObjectName(server.getDefaultDomain(), "service", "MLet");
  +
  +                        // Create the MBean instance
  +                        ObjectInstance instance = 
  +                           server.createMBean(code, 
  +                                              objectName, 
  +                                              loader, 
  +                                              constructor.params, 
  +                                              constructor.signature);
                           
                           info = server.getMBeanInfo(instance.getObjectName());
                        } catch (Throwable ex)
  
  
  
  1.1                  
jboss/src/main/org/jboss/configuration/ConfigurationException.java
  
  Index: ConfigurationException.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.configuration;
  
  /**
   * Throw to indicate a non-fatal configuration related problem.
   *
   * @see ConfigurationService
   *
   * @author  Jason Dillon <a 
href="mailto:[EMAIL PROTECTED]">&lt;[EMAIL PROTECTED]&gt;</a>
   * @version <pre>$Revision: 1.1 $</pre>
   */
  public class ConfigurationException
     extends Exception
  {
     /** The root cause of this exception */
     protected Throwable cause;
     
     /**
      * Construct a <tt>ConfigurationException</tt>.
      *
      * @param message    The exception detail message.
      */
     public ConfigurationException(final String message) {
        super(message);
     }
     
     /**
      * Construct a <tt>ConfigurationException</tt>.
      *
      * @param message    The exception detail message.
      * @param cause      The detail cause of the exception.
      */
     public ConfigurationException(final String message, 
                                   final Throwable cause) 
     {
        super(message);
        this.cause = cause;
     }
  
     /**
      * Get the cause of the exception.
      *
      * @return  The cause of the exception or null if there is none.
      */
     public Throwable getCause() { 
        return cause; 
     }
     
     /**
      * Return a string representation of the exception.
      *
      * @return  A string representation.
      */
     public String toString() {
        return cause == null ? 
           super.toString() : 
           super.toString() + ", Cause: " + cause;
     }
  }
  
  
  

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

Reply via email to