You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2003/11/16 01:43:24 UTC
cvs commit: incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service ParserUtil.java
djencks 2003/11/15 16:43:24
Modified: modules/kernel/src/java/org/apache/geronimo/kernel/service
ParserUtil.java
Log:
Add several helper methods for mbean deployment
Revision Changes Path
1.5 +47 -6 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/ParserUtil.java
Index: ParserUtil.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/ParserUtil.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ParserUtil.java 11 Nov 2003 16:00:59 -0000 1.4
+++ ParserUtil.java 16 Nov 2003 00:43:24 -0000 1.5
@@ -61,6 +61,7 @@
import java.io.File;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
@@ -69,12 +70,13 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.kernel.deployment.DeploymentException;
/**
* @version $Revision$ $Date$
*/
public final class ParserUtil {
- private ParserUtil(){
+ private ParserUtil() {
}
@@ -114,7 +116,7 @@
// append the property
String propertyName = input.substring(prefixLoc + 2, suffixLoc);
String property = System.getProperty(propertyName);
- if(property == null) {
+ if (property == null) {
property = "";
}
buff.append(property);
@@ -321,7 +323,7 @@
public static Object getValue(Class type, String value, URI baseURI) {
value = parse(value);
- if(baseURI != null) {
+ if (baseURI != null) {
if (URI.class.equals(type)) {
return baseURI.resolve(value);
}
@@ -360,8 +362,7 @@
* @param type The class of the object to be edited.
* @return An editor for the given type or null if none was found.
*/
- public static PropertyEditor findEditor(final Class type)
- {
+ public static PropertyEditor findEditor(final Class type) {
if (type == null) {
throw new IllegalArgumentException("Type is null");
}
@@ -378,6 +379,46 @@
}
return editor;
+ }
+
+ public static Class[] translateArgs(String[] types, Object[] args, URI baseURI, ClassLoader classloader)
+ throws DeploymentException {
+ Class[] clazz = new Class[types.length];
+ for (int i = 0; i < types.length; i++) {
+ try {
+ clazz[i] = loadClass(types[i], classloader);
+ } catch (ClassNotFoundException e) {
+ throw new DeploymentException(e);
+ }
+
+ Object value = args[i];
+ if (value instanceof String) {
+ value = getValue(clazz[i], (String) value, baseURI);
+ args[i] = value;
+ }
+ }
+ return clazz;
+ }
+
+ public static Object instantiate(Class clazz, Object[] args, Class[] types)
+ throws InvocationTargetException,
+ InstantiationException,
+ IllegalAccessException,
+ NoSuchMethodException {
+ Constructor c = clazz.getConstructor(types);
+ return c.newInstance(args);
+ }
+
+ public static Object instantiate(String className, Object[] args, String[] types, URI baseURI, ClassLoader cl)
+ throws DeploymentException,
+ ClassNotFoundException,
+ NoSuchMethodException,
+ InvocationTargetException,
+ InstantiationException,
+ IllegalAccessException {
+ Class[] typeClazz = translateArgs(types, args, baseURI, cl);
+ Class clazz = cl.loadClass(className);
+ return instantiate(clazz, args, typeClazz);
}
}