? mx4j
? lib/excalibur-converter-1.0.jar
Index: src/conf/kernel.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-phoenix/src/conf/kernel.xml,v
retrieving revision 1.20
diff -u -r1.20 kernel.xml
--- src/conf/kernel.xml	10 Aug 2002 20:12:07 -0000	1.20
+++ src/conf/kernel.xml	6 Sep 2002 10:13:43 -0000
@@ -33,9 +33,33 @@
         <component role="org.apache.avalon.phoenix.interfaces.SystemManager"
             class="@SYSTEM-MANAGER-CLASS@"
             logger="manager" >
-          <manager-adaptor-port>8082</manager-adaptor-port>
-          <enable-rmi-adaptor>false</enable-rmi-adaptor>
-          <stylesheets-dir>conf/xsl</stylesheets-dir>
+          <!--rmi-naming-factory>com.sun.jndi.rmi.registry.RegistryContextFactory</rmi-naming-factory-->
+
+          <mbean name="Http:name=XSLTProcessor" class="mx4j.adaptor.http.XSLTProcessor">
+              <attribute name="File" type="java.lang.String">conf/xsl</attribute>
+              <attribute name="UseCache" type="java.lang.Boolean">false</attribute>
+          </mbean>
+          <mbean name="Http:name=HttpAdaptor" class="mx4j.adaptor.http.HttpAdaptor">
+              <use name="ProcessorName">Http:name=XSLTProcessor</use>
+              <attribute name="Host" type="java.lang.String">localhost</attribute>
+              <attribute name="Port" type="java.lang.Integer">8082</attribute>
+              <attribute name="AuthenticationMethod" type="java.lang.String">basic</attribute>
+
+              <invoke name="addAuthorization">
+                  <parameter type="java.lang.String">root</parameter>
+                  <parameter type="java.lang.String">root</parameter>
+              </invoke>
+              <invoke name="start"/>
+          </mbean>
+
+          <mbean name="Naming:type=rmiregistry" class="mx4j.tools.naming.NamingService">
+              <invoke name="start"/>
+          </mbean>
+          <mbean name="Adaptor:protocol=JRMP" class="mx4j.adaptor.rmi.jrmp.JRMPAdaptor">
+              <attribute name="JNDIName" type="java.lang.String">jrmp</attribute>
+              <invoke name="start"/>
+          </mbean>
+
         </component>
 
         <!-- There are two kernels
Index: src/java/org/apache/avalon/phoenix/components/manager/MX4JSystemManager.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/MX4JSystemManager.java,v
retrieving revision 1.18
diff -u -r1.18 MX4JSystemManager.java
--- src/java/org/apache/avalon/phoenix/components/manager/MX4JSystemManager.java	16 Aug 2002 05:55:44 -0000	1.18
+++ src/java/org/apache/avalon/phoenix/components/manager/MX4JSystemManager.java	6 Sep 2002 10:13:44 -0000
@@ -12,14 +12,14 @@
 import javax.management.MBeanServer;
 import javax.management.MBeanServerFactory;
 import javax.management.ObjectName;
-import mx4j.adaptor.rmi.jrmp.JRMPAdaptorMBean;
-import mx4j.util.StandardMBeanProxy;
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.context.Context;
 import org.apache.avalon.framework.context.ContextException;
 import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.excalibur.converter.Converter;
+import org.apache.excalibur.converter.lib.SimpleMasterConverter;
 
 /**
  * This component is responsible for managing phoenix instance.
@@ -34,13 +34,10 @@
 {
     private static final String DEFAULT_NAMING_FACTORY =
         "com.sun.jndi.rmi.registry.RegistryContextFactory";
-    private static final int DEFAULT_HTTPADAPTER_PORT =
-        Integer.getInteger( "phoenix.adapter.http", 8082 ).intValue();
-    private int m_port;
-    private boolean m_rmi;
+
     private File m_homeDir;
-    private String m_stylesheetDir;
-    private String m_namingFactory;
+    private Configuration m_configuration;
+    private Converter m_converter;
 
     public void contextualize( Context context )
         throws ContextException
@@ -51,22 +48,18 @@
     public void configure( final Configuration configuration )
         throws ConfigurationException
     {
-        m_port = configuration.getChild( "manager-adaptor-port" ).
-            getValueAsInteger( DEFAULT_HTTPADAPTER_PORT );
-
-        getLogger().debug("MX4J HTTP listener port: " + m_port);
-
-        m_rmi = configuration.getChild( "enable-rmi-adaptor" ).getValueAsBoolean( false );
-
-        m_namingFactory =
-            configuration.getChild( "rmi-naming-factory" ).getValue( DEFAULT_NAMING_FACTORY );
-
-        final String stylesheets =
-            configuration.getChild( "stylesheets-dir" ).getValue( null );
-        if( null != stylesheets )
+        final String namingFactory =
+            configuration.getChild( "rmi-naming-factory" ).getValue( null);
+        if ( null != namingFactory )
         {
-            m_stylesheetDir = new File( m_homeDir, stylesheets ).getAbsolutePath();
+            System.setProperty( "java.naming.factory.initial", namingFactory );
         }
+        else if ( null == System.getProperty( "java.naming.factory.initial" ) )
+        {
+            System.setProperty( "java.naming.factory.initial", DEFAULT_NAMING_FACTORY  );
+        }
+
+        m_configuration = configuration;
     }
 
     public void initialize()
@@ -76,66 +69,64 @@
 
         final MBeanServer mBeanServer = getMBeanServer();
 
-        final ObjectName adaptorName = new ObjectName( "Http:name=HttpAdaptor" );
-        mBeanServer.createMBean( "mx4j.adaptor.http.HttpAdaptor", adaptorName, null );
-        mBeanServer.setAttribute( adaptorName, new Attribute( "Port", new Integer( m_port ) ) );
-
-
-        /**
-         // add user names
-         m_mBeanServer.invoke(adaptorName,
-         "addAuthorization",
-         new Object[] {"mx4j", "mx4j"},
-         new String[] {"java.lang.String", "java.lang.String"});
-
-         // use basic authentication
-         m_mBeanServer.setAttribute(adaptorName, new Attribute("AuthenticationMethod", "basic"));
-         */
+        m_converter = new SimpleMasterConverter();
 
-        final ObjectName processorName = new ObjectName( "Http:name=XSLTProcessor" );
-        mBeanServer.createMBean( "mx4j.adaptor.http.XSLTProcessor", processorName, null );
-        mBeanServer.setAttribute( adaptorName, new Attribute( "ProcessorName", processorName ) );
-
-        if( null != m_stylesheetDir )
+        final Configuration[] mBeanConfs = m_configuration.getChildren( "mbean" );
+        for ( int i = 0; i < mBeanConfs.length; i++ )
         {
-            final Attribute stylesheetDir = new Attribute( "File", m_stylesheetDir );
-            mBeanServer.setAttribute( processorName, stylesheetDir );
+            initializeMBean( mBeanServer, mBeanConfs[ i ] );
         }
+    }
 
-        final Attribute useCache =
-            new Attribute( "UseCache", Boolean.FALSE );
-        mBeanServer.setAttribute( processorName, useCache );
+    private void initializeMBean( final MBeanServer mBeanServer, final Configuration mBeanConf )
+        throws Exception
+    {
+        final ObjectName mBeanName = new ObjectName( mBeanConf.getAttribute( "name" ) );
+        mBeanServer.createMBean( mBeanConf.getAttribute( "class" ), mBeanName, null );
 
-        // starts the server
-        mBeanServer.invoke( adaptorName, "start", null, null );
+        final Configuration[] attributes = mBeanConf.getChildren( "attribute" );
+        for ( int i = 0; i < attributes.length; i++ )
+        {
+            final Configuration attribute = attributes[ i ];
+            final String name = attribute.getAttribute( "name" );
+            final String type = attribute.getAttribute( "type" );
+            Object value = attribute.getValue( null );
+            if ( null != value )
+            {
+                value = m_converter.convert( Class.forName( type ), value, null );
+            }
+            mBeanServer.setAttribute( mBeanName, new Attribute( name, value ) );
+        }
 
-        if( m_rmi )
+        final Configuration[] uses = mBeanConf.getChildren( "use" );
+        for ( int i = 0; i < uses.length; i++ )
         {
-            startRMIAdaptor( mBeanServer );
+            final Configuration use = uses[ i ];
+            final String name = use.getAttribute( "name" );
+            final String value = use.getValue();
+            mBeanServer.setAttribute( mBeanName, new Attribute( name, new ObjectName( value ) ) );
         }
-    }
 
-    private void startRMIAdaptor( MBeanServer server ) throws Exception
-    {
-        System.setProperty( "java.naming.factory.initial", m_namingFactory );
+        final Configuration[] invokes = mBeanConf.getChildren( "invoke" );
+        for ( int i = 0; i < invokes.length; i++ )
+        {
+            final Configuration invoke = invokes[ i ];
+            final Configuration[] paramConfs = invoke.getChildren( "parameter" );
 
-        // Create and start the naming service
-        ObjectName naming = new ObjectName( "Naming:type=rmiregistry" );
-        server.createMBean( "mx4j.tools.naming.NamingService", naming, null );
-        server.invoke( naming, "start", null, null );
-
-        // Create the JRMP adaptor
-        ObjectName adaptor = new ObjectName( "Adaptor:protocol=JRMP" );
-        server.createMBean( "mx4j.adaptor.rmi.jrmp.JRMPAdaptor", adaptor, null );
-        JRMPAdaptorMBean mbean =
-            (JRMPAdaptorMBean)StandardMBeanProxy.create( JRMPAdaptorMBean.class,
-                                                         server,
-                                                         adaptor );
-        // Set the JNDI name with which will be registered
-        String jndiName = "jrmp";
-        mbean.setJNDIName( jndiName );
-        // Register the JRMP adaptor in JNDI and start it
-        mbean.start();
+            final String operationName = invoke.getAttribute( "name" );
+            final String[] types = new String[ paramConfs.length ];
+            final Object[] values = new Object[ paramConfs.length ];
+            for ( int j = 0; j < paramConfs.length; j++ )
+            {
+                types[ j ] = paramConfs[ j ].getAttribute( "type" );
+                values[ j ] = paramConfs[ j ].getValue( null );
+                if ( null != values[ j ] )
+                {
+                    values[ j ] = m_converter.convert( Class.forName( types[ j ] ), values[ j ], null );
+                }
+            }
+            mBeanServer.invoke( mBeanName, operationName, values, types );
+        }
     }
 
     protected MBeanServer createMBeanServer()

