User: mnf999
Date: 01/12/18 22:34:08
Modified: src/main/org/jboss/system ServiceCreator.java
Log:
Revision Changes Path
1.8 +132 -116 jboss/src/main/org/jboss/system/ServiceCreator.java
Index: ServiceCreator.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/system/ServiceCreator.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ServiceCreator.java 2001/12/09 03:36:01 1.7
+++ ServiceCreator.java 2001/12/19 06:34:08 1.8
@@ -1,9 +1,9 @@
/*
- * JBoss, the OpenSource J2EE webOS
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
+* JBoss, the OpenSource J2EE webOS
+*
+* Distributable under LGPL license.
+* See terms of license at gnu.org.
+*/
package org.jboss.system;
import java.lang.reflect.Constructor;
@@ -24,7 +24,7 @@
* @see Service
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
*
* <p><b>Revisions:</b>
* <p><b>2001/08/03 marcf </b>
@@ -38,46 +38,47 @@
/** Instance logger. */
private final Logger log = Logger.getLogger(getClass());
-
+
private MBeanServer server;
-
+
public ServiceCreator(final MBeanServer server) {
this.server = server;
}
-
+
/**
- * Parses the given configuration document and creates MBean
- * instances in the current MBean server.
- *
- * @param configuration The configuration document.
- *
- * @throws ConfigurationException The configuration document contains
- * invalid or missing syntax.
- * @throws Exception Failed for some other reason.
- */
- public ObjectInstance create(Element mbeanElement) throws Exception
+ * Parses the given configuration document and creates MBean
+ * instances in the current MBean server.
+ *
+ * @param configuration The configuration document.
+ *
+ * @throws ConfigurationException The configuration document contains
+ * invalid or missing syntax.
+ * @throws Exception Failed for some other reason.
+ */
+ public ObjectInstance install(Element mbeanElement) throws Exception
{
ObjectName name = parseObjectName(mbeanElement);
-
+
// marcf fixme add and remove the classlaoder from the controller
-
+
ObjectName loader = new ObjectName("ZClassLoaders:id="+name.hashCode());
-
+
MBeanClassLoader cl = new MBeanClassLoader(name);
-
+
if (!server.isRegistered(loader))
server.registerMBean(cl, loader);
-
+
// If class is given, instantiate it
String code = mbeanElement.getAttribute("code");
if (code == null)
{
throw new ConfigurationException("missing 'code' attribute");
}
-
+
// get the constructor params/sig to use
ConstructorInfo constructor =
- ConstructorInfo.create(mbeanElement);
+
+ ConstructorInfo.create(mbeanElement);
log.debug("About to create bean: "+name);
// Create the MBean instance
@@ -91,7 +92,7 @@
log.debug("Created bean: "+name);
return instance;
-
+
}
catch (Exception e)
{
@@ -104,66 +105,81 @@
throw e;
} // end of try-catch
+
+ }
+
+
+ public void remove(ObjectName name) throws Exception
+ {
+
+ // Remove the MBean from the MBeanServer
+ server.unregisterMBean(name);
+ // Remove the MBeanClassLoader used by the MBean
+ ObjectName loader = new ObjectName("ZClassLoaders:id=" + name.hashCode());
+ if (server.isRegistered(loader))
+ {
+ server.unregisterMBean(loader);
+ } // end of if ()
}
-
+
/**
- * Provides a wrapper around the information about which constructor
- * that MBeanServer should use to construct a MBean.
- * Please note that only basic datatypes (type is then the same as
- * you use to declare it "short", "int", "float" etc.) and any class
- * having a constructor taking a single "String" as only parameter.
- *
- * <p>XML syntax for contructor:
- * <pre>
- * <constructor>
- * <arg type="xxx" value="yyy"/>
- * ...
- * <arg type="xxx" value="yyy"/>
- * </constructor>
- * </pre>
- */
+ * Provides a wrapper around the information about which constructor
+ * that MBeanServer should use to construct a MBean.
+ * Please note that only basic datatypes (type is then the same as
+ * you use to declare it "short", "int", "float" etc.) and any class
+ * having a constructor taking a single "String" as only parameter.
+ *
+ * <p>XML syntax for contructor:
+ * <pre>
+ * <constructor>
+ * <arg type="xxx" value="yyy"/>
+ * ...
+ * <arg type="xxx" value="yyy"/>
+ * </constructor>
+ * </pre>
+ */
private static class ConstructorInfo
{
/** An empty parameters list. */
public static final Object EMPTY_PARAMS[] = {};
-
+
/** An signature list. */
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.
- */
+ * 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
+ 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");
+ ("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);
@@ -178,80 +194,80 @@
if( signature.equals( "short" ) ) {
signature = Short.TYPE.getName();
realValue = new Short( value );
+ } 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( "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 {
- // 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 ) {
- }
- }
+ 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 ) {
+ }
+ }
}
info.signature[j] = signature;
info.params[j] = realValue;
}
}
-
+
return info;
}
}
/**
- * Parse an object name from the given element attribute 'name'.
- *
- * @param element Element to parse name from.
- * @return Object name.
- *
- * @throws ConfigurationException Missing attribute 'name'
- * (thrown if 'name' is null or "").
- * @throws MalformedObjectNameException
- */
+ * Parse an object name from the given element attribute 'name'.
+ *
+ * @param element Element to parse name from.
+ * @return Object name.
+ *
+ * @throws ConfigurationException Missing attribute 'name'
+ * (thrown if 'name' is null or "").
+ * @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("")) {
throw new ConfigurationException
- ("MBean attribute 'name' must be given.");
+ ("MBean attribute 'name' must be given.");
}
-
+
return new ObjectName(name);
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development