[jbpm-commits] JBoss JBPM SVN: r3821 - in jbpm3/trunk/modules/core/src: test/java/org/jbpm/instantiation and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Feb 9 23:07:11 EST 2009
Author: alex.guizar at jboss.com
Date: 2009-02-09 23:07:11 -0500 (Mon, 09 Feb 2009)
New Revision: 3821
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/ConstructorInstantiator.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/InstantiatorUtil.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/XmlInstantiator.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/instantiation/ConstructorInstantiatorTest.java
Log:
make ConstructorInstantiator accept null configuration
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4208220
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/ConstructorInstantiator.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/ConstructorInstantiator.java 2009-02-10 02:27:07 UTC (rev 3820)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/ConstructorInstantiator.java 2009-02-10 04:07:11 UTC (rev 3821)
@@ -24,7 +24,7 @@
public class ConstructorInstantiator implements Instantiator {
public <T> T instantiate(Class<T> type, String configuration) {
- return InstantiatorUtil.instantiate(type, configuration);
+ return InstantiatorUtil.instantiate(type, String.class, configuration);
}
}
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/InstantiatorUtil.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/InstantiatorUtil.java 2009-02-10 02:27:07 UTC (rev 3820)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/InstantiatorUtil.java 2009-02-10 04:07:11 UTC (rev 3821)
@@ -50,16 +50,16 @@
}
}
- public static <T> T instantiate(Class<T> type, Object configuration) {
+ public static <T, C> T instantiate(Class<T> type, Class<C> configType, C config) {
try {
- Constructor<T> constructor = type.getDeclaredConstructor(configuration.getClass());
+ Constructor<T> constructor = type.getDeclaredConstructor(configType);
constructor.setAccessible(true);
- return constructor.newInstance(configuration);
+ return constructor.newInstance(config);
}
catch (NoSuchMethodException e) {
throw new JbpmException(type
+ " does not have a "
- + configuration.getClass().getSimpleName()
+ + config.getClass().getSimpleName()
+ " constructor", e);
}
catch (InstantiationException e) {
@@ -69,20 +69,20 @@
throw new JbpmException(type + " is inaccessible", e);
}
catch (IllegalArgumentException e) {
- throw new JbpmException(type + " cannot be constructed with value " + configuration, e);
+ throw new JbpmException(type + " cannot be constructed with value " + config, e);
}
catch (InvocationTargetException e) {
throw new JbpmException("constructor for " + type + " threw exception", e.getCause());
}
}
- public static Element parseConfiguration(String configuration) {
+ public static Element parseConfiguration(String config) {
Element element = null;
try {
- element = DocumentHelper.parseText("<action>" + configuration + "</action>").getRootElement();
+ element = DocumentHelper.parseText("<action>" + config + "</action>").getRootElement();
}
catch (DocumentException e) {
- throw new JbpmException("failed to parse configuration: " + configuration, e);
+ throw new JbpmException("failed to parse configuration: " + config, e);
}
return element;
}
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/XmlInstantiator.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/XmlInstantiator.java 2009-02-10 02:27:07 UTC (rev 3820)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/XmlInstantiator.java 2009-02-10 04:07:11 UTC (rev 3821)
@@ -21,9 +21,12 @@
*/
package org.jbpm.instantiation;
+import org.dom4j.Element;
+
public class XmlInstantiator implements Instantiator {
public <T> T instantiate(Class<T> type, String configuration) {
- return InstantiatorUtil.instantiate(type, InstantiatorUtil.parseConfiguration(configuration));
+ return InstantiatorUtil.instantiate(type, Element.class,
+ InstantiatorUtil.parseConfiguration(configuration));
}
}
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/instantiation/ConstructorInstantiatorTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/instantiation/ConstructorInstantiatorTest.java 2009-02-10 02:27:07 UTC (rev 3820)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/instantiation/ConstructorInstantiatorTest.java 2009-02-10 04:07:11 UTC (rev 3821)
@@ -25,31 +25,30 @@
public class ConstructorInstantiatorTest extends AbstractJbpmTestCase {
- public ConstructorInstantiator constructorInstantiator = new ConstructorInstantiator();
-
+ ConstructorInstantiator constructorInstantiator = new ConstructorInstantiator();
+
public static class StringConstructorClass {
- String input = null;
- public StringConstructorClass( String input ) {
+ final String input;
+
+ public StringConstructorClass(String input) {
this.input = input;
}
}
public void testConstructorInstantiator() {
String configuration = "hello";
- StringConstructorClass o = (StringConstructorClass) constructorInstantiator.instantiate(StringConstructorClass.class, configuration);
- assertEquals("hello", o.input );
+ StringConstructorClass o = constructorInstantiator.instantiate(StringConstructorClass.class, configuration);
+ assertEquals(configuration, o.input);
}
-
+
/**
- * test that {@link ConstructorInstantiator} works also without configuration
- * (config=null) because this is used in some version of the jbpm ESB
- * integration, so this should be true for compatibility reasons!
- * See http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4208220
+ * test that {@link ConstructorInstantiator} works also without configuration (config==null)
+ * because this is used in some version of the ESB integration, so this should be true for
+ * compatibility reasons! See http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4208220
*/
public void testConstructorInstantiatorWithNullValue() {
- String configuration = null;
- StringConstructorClass o = (StringConstructorClass) constructorInstantiator.instantiate(StringConstructorClass.class, configuration);
- assertNull( o.input );
+ StringConstructorClass o = constructorInstantiator.instantiate(StringConstructorClass.class, null);
+ assertNull(o.input);
}
-
+
}
More information about the jbpm-commits
mailing list