Author: thomas.diesler(a)jboss.com
Date: 2009-02-28 09:56:34 -0500 (Sat, 28 Feb 2009)
New Revision: 4083
Modified:
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/test/java/org/jbpm/JbpmConfigurationTest.java
Log:
Add clearJbpmConfigurationStack to enable more explicit cleanup
Modified:
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java
===================================================================
---
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java 2009-02-28
12:06:41 UTC (rev 4082)
+++
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java 2009-02-28
14:56:34 UTC (rev 4083)
@@ -26,8 +26,8 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
-import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -248,7 +248,8 @@
* </tr>
* </table>
*/
-public class JbpmConfiguration implements Serializable {
+public class JbpmConfiguration implements Serializable
+{
private static final long serialVersionUID = 1L;
@@ -261,45 +262,55 @@
private JobExecutor jobExecutor;
private boolean isClosed;
- static class StackThreadLocal<E> extends ThreadLocal<List<E>> {
+ static class StackThreadLocal<E> extends ThreadLocal<List<E>>
+ {
@Override
- protected List<E> initialValue() {
+ protected List<E> initialValue()
+ {
return new ArrayList<E>();
}
}
- public JbpmConfiguration(ObjectFactory objectFactory) {
+ public JbpmConfiguration(ObjectFactory objectFactory)
+ {
this.objectFactory = objectFactory;
}
- public static JbpmConfiguration getInstance() {
+ public static JbpmConfiguration getInstance()
+ {
return getInstance(null);
}
- public static JbpmConfiguration getInstance(String resource) {
- if (resource == null) {
+ public static JbpmConfiguration getInstance(String resource)
+ {
+ if (resource == null)
+ {
resource = "jbpm.cfg.xml";
}
JbpmConfiguration instance;
- synchronized (instances) {
+ synchronized (instances)
+ {
// look for configuration in cache
instance = instances.get(resource);
- if (instance == null) {
+ if (instance == null)
+ {
// configuration does not exist or was evicted, construct it
- if (defaultObjectFactory != null) {
+ if (defaultObjectFactory != null)
+ {
log.debug("creating configuration from default object factory: " +
defaultObjectFactory);
instance = new JbpmConfiguration(defaultObjectFactory);
}
- else {
+ else
+ {
log.info("using configuration resource: " + resource);
InputStream jbpmCfgXmlStream =
ClassLoaderUtil.getJbpmConfigurationStream(resource);
/*
- * if a custom resource is specified, but not found in the classpath, log a
warning;
- * otherwise, users who want to load custom stuff will not receive any feedback
when their
- * resource cannot be found
+ * if a custom resource is specified, but not found in the classpath, log a
warning; otherwise, users who want to load custom stuff will not receive any
+ * feedback when their resource cannot be found
*/
- if (jbpmCfgXmlStream == null &&
!"jbpm.cfg.xml".equals(resource)) {
+ if (jbpmCfgXmlStream == null &&
!"jbpm.cfg.xml".equals(resource))
+ {
log.warn("configuration resource '" + resource + "'
could not be found");
}
ObjectFactory objectFactory = parseObjectFactory(jbpmCfgXmlStream);
@@ -312,18 +323,20 @@
return instance;
}
- public static boolean hasInstance(String resource) {
+ public static boolean hasInstance(String resource)
+ {
return instances.containsKey(resource != null ? resource :
"jbpm.cfg.xml");
}
- protected static ObjectFactory parseObjectFactory(InputStream inputStream) {
+ protected static ObjectFactory parseObjectFactory(InputStream inputStream)
+ {
log.debug("loading defaults in jbpm configuration");
ObjectFactoryParser objectFactoryParser = new ObjectFactoryParser();
ObjectFactoryImpl objectFactoryImpl = new ObjectFactoryImpl();
-
objectFactoryParser.parseElementsFromResource("org/jbpm/default.jbpm.cfg.xml",
- objectFactoryImpl);
+
objectFactoryParser.parseElementsFromResource("org/jbpm/default.jbpm.cfg.xml",
objectFactoryImpl);
- if (inputStream != null) {
+ if (inputStream != null)
+ {
log.debug("loading specific configuration...");
objectFactoryParser.parseElementsStream(inputStream, objectFactoryImpl);
}
@@ -331,26 +344,31 @@
return objectFactoryImpl;
}
- public static JbpmConfiguration parseXmlString(String xml) {
+ public static JbpmConfiguration parseXmlString(String xml)
+ {
log.debug("creating jbpm configuration from xml string");
InputStream inputStream = null;
- if (xml != null) {
+ if (xml != null)
+ {
inputStream = new ByteArrayInputStream(xml.getBytes());
}
ObjectFactory objectFactory = parseObjectFactory(inputStream);
return createJbpmConfiguration(objectFactory);
}
- protected static JbpmConfiguration createJbpmConfiguration(ObjectFactory objectFactory)
{
+ protected static JbpmConfiguration createJbpmConfiguration(ObjectFactory
objectFactory)
+ {
JbpmConfiguration jbpmConfiguration = new JbpmConfiguration(objectFactory);
// make the bean jbpm.configuration always available
- if (objectFactory instanceof ObjectFactoryImpl) {
- ObjectFactoryImpl objectFactoryImpl = (ObjectFactoryImpl) objectFactory;
+ if (objectFactory instanceof ObjectFactoryImpl)
+ {
+ ObjectFactoryImpl objectFactoryImpl = (ObjectFactoryImpl)objectFactory;
ObjectInfo jbpmConfigurationInfo = new ValueInfo("jbpmConfiguration",
jbpmConfiguration);
objectFactoryImpl.addObjectInfo(jbpmConfigurationInfo);
- if (getHideStaleObjectExceptions(objectFactory)) {
+ if (getHideStaleObjectExceptions(objectFactory))
+ {
StaleObjectLogConfigurer.hideStaleObjectExceptions();
}
}
@@ -358,184 +376,226 @@
return jbpmConfiguration;
}
- private static boolean getHideStaleObjectExceptions(ObjectFactory objectFactory) {
- if (!objectFactory.hasObject("jbpm.hide.stale.object.exceptions")) return
true;
+ private static boolean getHideStaleObjectExceptions(ObjectFactory objectFactory)
+ {
+ if (!objectFactory.hasObject("jbpm.hide.stale.object.exceptions"))
+ return true;
Object object =
objectFactory.createObject("jbpm.hide.stale.object.exceptions");
- return object instanceof Boolean ? (Boolean) object : true;
+ return object instanceof Boolean ? (Boolean)object : true;
}
- public static JbpmConfiguration parseInputStream(InputStream inputStream) {
+ public static JbpmConfiguration parseInputStream(InputStream inputStream)
+ {
log.debug("creating jbpm configuration from input stream");
ObjectFactory objectFactory = parseObjectFactory(inputStream);
return createJbpmConfiguration(objectFactory);
}
- public static JbpmConfiguration parseResource(String resource) {
+ public static JbpmConfiguration parseResource(String resource)
+ {
log.debug("creating jbpm configuration from resource: " + resource);
InputStream inputStream = null;
- if (resource != null) {
+ if (resource != null)
+ {
inputStream = ClassLoaderUtil.getJbpmConfigurationStream(resource);
}
ObjectFactory objectFactory = parseObjectFactory(inputStream);
return createJbpmConfiguration(objectFactory);
}
- public JbpmContext createJbpmContext() {
+ public JbpmContext createJbpmContext()
+ {
return createJbpmContext(JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
}
- public JbpmContext createJbpmContext(String name) {
+ public JbpmContext createJbpmContext(String name)
+ {
ensureOpen();
- JbpmContext jbpmContext = (JbpmContext) objectFactory.createObject(name);
+ JbpmContext jbpmContext = (JbpmContext)objectFactory.createObject(name);
jbpmContext.jbpmConfiguration = this;
jbpmContextCreated(jbpmContext);
return jbpmContext;
}
- private void ensureOpen() {
- if (isClosed) throw new JbpmException("configuration closed");
+ private void ensureOpen()
+ {
+ if (isClosed)
+ throw new JbpmException("configuration closed");
}
- public ServiceFactory getServiceFactory(String serviceName) {
+ public ServiceFactory getServiceFactory(String serviceName)
+ {
return getServiceFactory(serviceName, JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
}
- public ServiceFactory getServiceFactory(String serviceName, String jbpmContextName) {
+ public ServiceFactory getServiceFactory(String serviceName, String jbpmContextName)
+ {
ServiceFactory serviceFactory = null;
JbpmContext jbpmContext = createJbpmContext(jbpmContextName);
- try {
+ try
+ {
serviceFactory = jbpmContext.getServices().getServiceFactory(serviceName);
}
- finally {
+ finally
+ {
jbpmContext.close();
}
return serviceFactory;
}
- public static ClassLoader getProcessClassLoader(ProcessDefinition processDefinition) {
+ public static ClassLoader getProcessClassLoader(ProcessDefinition processDefinition)
+ {
ProcessClassLoaderFactory factory = null;
- if (Configs.hasObject("jbpm.processClassLoader")) {
- factory = (ProcessClassLoaderFactory)
Configs.getObject("jbpm.processClassLoader");
+ if (Configs.hasObject("jbpm.processClassLoader"))
+ {
+ factory =
(ProcessClassLoaderFactory)Configs.getObject("jbpm.processClassLoader");
}
- else {
+ else
+ {
factory = new DefaultProcessClassLoaderFactory();
}
return factory.getProcessClassLoader(processDefinition);
}
- /**
+ /*
* gives the jbpm domain model access to configuration information via the current
JbpmContext.
*/
- public static class Configs {
+ public static class Configs
+ {
- private Configs() {
+ private Configs()
+ {
// hide default constructor to prevent instantiation
}
- public static ObjectFactory getObjectFactory() {
+ public static ObjectFactory getObjectFactory()
+ {
ObjectFactory objectFactory = null;
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
- if (jbpmContext != null) {
+ if (jbpmContext != null)
+ {
objectFactory = jbpmContext.objectFactory;
}
- else {
+ else
+ {
objectFactory = getInstance().objectFactory;
}
return objectFactory;
}
- public static void setDefaultObjectFactory(ObjectFactory objectFactory) {
+ public static void setDefaultObjectFactory(ObjectFactory objectFactory)
+ {
defaultObjectFactory = objectFactory;
}
- public static boolean hasObject(String name) {
+ public static boolean hasObject(String name)
+ {
ObjectFactory objectFactory = getObjectFactory();
return objectFactory.hasObject(name);
}
- public static synchronized Object getObject(String name) {
+ public static synchronized Object getObject(String name)
+ {
ObjectFactory objectFactory = getObjectFactory();
return objectFactory.createObject(name);
}
- public static String getString(String name) {
- return (String) getObject(name);
+ public static String getString(String name)
+ {
+ return (String)getObject(name);
}
- public static long getLong(String name) {
- return ((Long) getObject(name)).longValue();
+ public static long getLong(String name)
+ {
+ return ((Long)getObject(name)).longValue();
}
- public static int getInt(String name) {
- return ((Integer) getObject(name)).intValue();
+ public static int getInt(String name)
+ {
+ return ((Integer)getObject(name)).intValue();
}
- public static boolean getBoolean(String name) {
- return ((Boolean) getObject(name)).booleanValue();
+ public static boolean getBoolean(String name)
+ {
+ return ((Boolean)getObject(name)).booleanValue();
}
}
- public void cleanSchema() {
+ public void cleanSchema()
+ {
cleanSchema(JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
}
- public void cleanSchema(String jbpmContextName) {
+ public void cleanSchema(String jbpmContextName)
+ {
getPersistenceServiceFactory(jbpmContextName).cleanSchema();
}
- public void createSchema() {
+ public void createSchema()
+ {
createSchema(JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
}
- public void createSchema(String jbpmContextName) {
+ public void createSchema(String jbpmContextName)
+ {
getPersistenceServiceFactory(jbpmContextName).createSchema();
}
- public void dropSchema() {
+ public void dropSchema()
+ {
dropSchema(JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
}
- public void dropSchema(String jbpmContextName) {
+ public void dropSchema(String jbpmContextName)
+ {
getPersistenceServiceFactory(jbpmContextName).dropSchema();
}
- private DbPersistenceServiceFactory getPersistenceServiceFactory(String
jbpmContextName) {
- return (DbPersistenceServiceFactory)
getServiceFactory(Services.SERVICENAME_PERSISTENCE,
- jbpmContextName);
+ private DbPersistenceServiceFactory getPersistenceServiceFactory(String
jbpmContextName)
+ {
+ return
(DbPersistenceServiceFactory)getServiceFactory(Services.SERVICENAME_PERSISTENCE,
jbpmContextName);
}
- public boolean isClosed() {
+ public boolean isClosed()
+ {
return isClosed;
}
- public void close() {
+ public void close()
+ {
close(JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
}
- public void close(String jbpmContextName) {
+ public void close(String jbpmContextName)
+ {
// prevent configuration from being closed more than once
- if (isClosed) return;
+ if (isClosed)
+ return;
// stop job executor
- if (jobExecutor != null) {
+ if (jobExecutor != null)
+ {
jobExecutor.stop();
jobExecutor = null;
}
// close service factories
JbpmContext jbpmContext = createJbpmContext(jbpmContextName);
- try {
- Map<String, ServiceFactory> serviceFactories = jbpmContext.getServices()
- .getServiceFactories();
- if (serviceFactories != null) {
- for (ServiceFactory serviceFactory : serviceFactories.values()) {
+ try
+ {
+ Map<String, ServiceFactory> serviceFactories =
jbpmContext.getServices().getServiceFactories();
+ if (serviceFactories != null)
+ {
+ for (ServiceFactory serviceFactory : serviceFactories.values())
+ {
serviceFactory.close();
}
}
}
- finally {
+ finally
+ {
jbpmContext.close();
}
@@ -546,9 +606,12 @@
jbpmContextStacks.remove();
// remove from configuration cache
- synchronized (instances) {
- for (java.util.Iterator<JbpmConfiguration> i = instances.values().iterator();
i.hasNext();) {
- if (this == i.next()) {
+ synchronized (instances)
+ {
+ for (java.util.Iterator<JbpmConfiguration> i = instances.values().iterator();
i.hasNext();)
+ {
+ if (this == i.next())
+ {
i.remove();
break;
}
@@ -557,89 +620,127 @@
}
@Override
- protected void finalize() throws Throwable {
+ protected void finalize() throws Throwable
+ {
close();
}
- static JbpmConfiguration getCurrentJbpmConfiguration() {
+ static JbpmConfiguration getCurrentJbpmConfiguration()
+ {
JbpmConfiguration currentJbpmConfiguration = null;
List<JbpmConfiguration> stack = getJbpmConfigurationStack();
- if (!stack.isEmpty()) {
+ if (!stack.isEmpty())
+ {
currentJbpmConfiguration = stack.get(stack.size() - 1);
}
return currentJbpmConfiguration;
}
- static List<JbpmConfiguration> getJbpmConfigurationStack() {
+ static List<JbpmConfiguration> getJbpmConfigurationStack()
+ {
return jbpmConfigurationStacks.get();
}
- synchronized void pushJbpmConfiguration() {
+ static void clearJbpmConfigurationStack()
+ {
+ List<JbpmConfiguration> configStack = new
ArrayList<JbpmConfiguration>(getJbpmConfigurationStack());
+ if (configStack != null)
+ {
+ for (JbpmConfiguration config : configStack)
+ {
+ List<JbpmContext> contextStack = new
ArrayList<JbpmContext>(config.getJbpmContextStack());
+ if (contextStack != null)
+ {
+ for (JbpmContext context : contextStack)
+ {
+ context.close();
+ }
+ }
+ contextStack.clear();
+ }
+ configStack.clear();
+ }
+ }
+
+ synchronized void pushJbpmConfiguration()
+ {
getJbpmConfigurationStack().add(this);
}
- synchronized void popJbpmConfiguration() {
+ synchronized void popJbpmConfiguration()
+ {
getJbpmConfigurationStack().remove(this);
}
- public JbpmContext getCurrentJbpmContext() {
+ public JbpmContext getCurrentJbpmContext()
+ {
ensureOpen();
JbpmContext currentJbpmContext = null;
List<JbpmContext> stack = getJbpmContextStack();
- if (!stack.isEmpty()) {
+ if (!stack.isEmpty())
+ {
currentJbpmContext = stack.get(stack.size() - 1);
}
return currentJbpmContext;
}
- List<JbpmContext> getJbpmContextStack() {
+ List<JbpmContext> getJbpmContextStack()
+ {
return jbpmContextStacks.get();
}
- void pushJbpmContext(JbpmContext jbpmContext) {
+ void pushJbpmContext(JbpmContext jbpmContext)
+ {
getJbpmContextStack().add(jbpmContext);
}
- void popJbpmContext(JbpmContext jbpmContext) {
+ void popJbpmContext(JbpmContext jbpmContext)
+ {
List<JbpmContext> stack = getJbpmContextStack();
int size = stack.size();
- if (size == 0) {
- log.warn("closed JbpmContext more than once... "
- + "check your try-finally clauses around JbpmContext blocks");
+ if (size == 0)
+ {
+ log.warn("closed JbpmContext more than once... " + "check your
try-finally clauses around JbpmContext blocks");
}
- else if (jbpmContext != stack.remove(size - 1)) {
+ else if (jbpmContext != stack.remove(size - 1))
+ {
stack.remove(jbpmContext); // prevent context from remaining in the stack
- log.warn("closed JbpmContext in some order that differs from creation...
"
- + "check your try-finally clauses around JbpmContext blocks");
+ log.warn("closed JbpmContext in some order that differs from creation...
" + "check your try-finally clauses around JbpmContext blocks");
}
}
- void jbpmContextCreated(JbpmContext jbpmContext) {
+ void jbpmContextCreated(JbpmContext jbpmContext)
+ {
pushJbpmConfiguration();
pushJbpmContext(jbpmContext);
}
- void jbpmContextClosed(JbpmContext jbpmContext) {
+ void jbpmContextClosed(JbpmContext jbpmContext)
+ {
popJbpmContext(jbpmContext);
popJbpmConfiguration();
}
- public void startJobExecutor() {
+ public void startJobExecutor()
+ {
getJobExecutor().start();
}
- public synchronized JobExecutor getJobExecutor() {
+ public synchronized JobExecutor getJobExecutor()
+ {
ensureOpen();
- if (jobExecutor == null) {
+ if (jobExecutor == null)
+ {
Object object = objectFactory.createObject("jbpm.job.executor");
- if (object instanceof JobExecutor) {
- jobExecutor = (JobExecutor) object;
+ if (object instanceof JobExecutor)
+ {
+ jobExecutor = (JobExecutor)object;
}
- else if (object != null) {
- throw new JbpmException("configuration object named
'jbpm.job.executor' is not a "
- + JobExecutor.class.getSimpleName());
+ else if (object != null)
+ {
+ throw new JbpmException("configuration object named
'jbpm.job.executor' is not a " + JobExecutor.class.getSimpleName());
}
}
return jobExecutor;
Modified:
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/test/java/org/jbpm/JbpmConfigurationTest.java
===================================================================
---
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/test/java/org/jbpm/JbpmConfigurationTest.java 2009-02-28
12:06:41 UTC (rev 4082)
+++
jbpm3/branches/jbpm-3.2.6.GA/modules/core/src/test/java/org/jbpm/JbpmConfigurationTest.java 2009-02-28
14:56:34 UTC (rev 4083)
@@ -28,17 +28,19 @@
import org.jbpm.configuration.ObjectFactoryParser;
import org.jbpm.util.XmlException;
-public class JbpmConfigurationTest extends AbstractJbpmTestCase {
+public class JbpmConfigurationTest extends AbstractJbpmTestCase
+{
- protected void setUp() throws Exception
+ protected void setUp() throws Exception
{
super.setUp();
+ JbpmConfiguration.clearJbpmConfigurationStack();
+ JbpmConfiguration.defaultObjectFactory = null;
JbpmConfiguration.instances.clear();
- JbpmConfiguration.defaultObjectFactory = null;
- JbpmConfiguration.jbpmConfigurationStacks.remove();
}
-
- public void testSingleton() {
+
+ public void testSingleton()
+ {
JbpmConfiguration.defaultObjectFactory = new ObjectFactoryImpl(null, null);
JbpmConfiguration instance = JbpmConfiguration.getInstance();
assertNotNull(instance);
@@ -47,36 +49,38 @@
assertSame(instance, JbpmConfiguration.getInstance());
}
- public void testDefaultContextCreation() {
+ public void testDefaultContextCreation()
+ {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
- "<jbpm-configuration>" +
- " <jbpm-context
name='"+JbpmContext.DEFAULT_JBPM_CONTEXT_NAME+"' />" +
- "</jbpm-configuration>"
- );
+ "<jbpm-configuration>" +
+ " <jbpm-context name='" + JbpmContext.DEFAULT_JBPM_CONTEXT_NAME
+ "' />" +
+ "</jbpm-configuration>");
assertNotNull(jbpmConfiguration);
assertNotNull(jbpmConfiguration.createJbpmContext());
}
- public void testNonExistingContext() {
- JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
- "<jbpm-configuration />"
- );
+ public void testNonExistingContext()
+ {
+ JbpmConfiguration jbpmConfiguration =
JbpmConfiguration.parseXmlString("<jbpm-configuration />");
assertNotNull(jbpmConfiguration);
- try {
+ try
+ {
jbpmConfiguration.createJbpmContext("non-existing-context");
fail("expected exception");
- } catch (ConfigurationException e) {
- //OK
}
+ catch (ConfigurationException e)
+ {
+ // OK
+ }
}
- public void testParseXmlStringConfiguration() {
+ public void testParseXmlStringConfiguration()
+ {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
- "<jbpm-configuration>" +
- " <jbpm-context name='a' />" +
- " <jbpm-context name='b' />" +
- "</jbpm-configuration>"
- );
+ "<jbpm-configuration>" +
+ " <jbpm-context name='a' />" +
+ " <jbpm-context name='b' />" +
+ "</jbpm-configuration>");
assertNotNull(jbpmConfiguration);
JbpmContext a = jbpmConfiguration.createJbpmContext("a");
assertNotNull(a);
@@ -85,12 +89,12 @@
assertNotSame(a, b);
}
- public void testNonSingletonContextCreation() {
+ public void testNonSingletonContextCreation()
+ {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
- "<jbpm-configuration>" +
- " <jbpm-context name='a' />" +
- "</jbpm-configuration>"
- );
+ "<jbpm-configuration>" +
+ " <jbpm-context name='a' />" +
+ "</jbpm-configuration>");
assertNotNull(jbpmConfiguration);
JbpmContext a = jbpmConfiguration.createJbpmContext("a");
assertNotNull(a);
@@ -99,111 +103,131 @@
assertNotSame(a, a2);
}
- public void testParseXmlFault() {
- try {
+ public void testParseXmlFault()
+ {
+ try
+ {
JbpmConfiguration.parseXmlString("< problematic // <</>
<x>M/L");
fail("expected exception");
- } catch (XmlException e) {
+ }
+ catch (XmlException e)
+ {
// OK
}
}
- public void testDomainModelConfigsWithoutJbpmContext() {
- // Without a current JbpmContext, the jbpm domain model objects that
- // need configuration information fetch it from the object factory of
- // the singleton instance. The singleton instance object factory is
- // by default initialized with the jbpm.cfg.xml resource unless, a
+ public void testDomainModelConfigsWithoutJbpmContext()
+ {
+ // Without a current JbpmContext, the jbpm domain model objects that
+ // need configuration information fetch it from the object factory of
+ // the singleton instance. The singleton instance object factory is
+ // by default initialized with the jbpm.cfg.xml resource unless, a
// custom default object factory is specified.
//
- // So to use jBPM without a JbpmContext, you can only use the resource with name
+ // So to use jBPM without a JbpmContext, you can only use the resource with name
// 'jbpm.cfg.xml' or the static method
JbpmConfiguration.Configs.setDefaultObjectFactory
// to specify the configuration information.
- JbpmConfiguration.Configs.setDefaultObjectFactory(
- ObjectFactoryParser.parseXmlString(
- "<jbpm-configuration>" +
- " <string name='myproperty'>myvalue</string>" +
- "</jbpm-configuration>"
- )
- );
+
JbpmConfiguration.Configs.setDefaultObjectFactory(ObjectFactoryParser.parseXmlString(
+ "<jbpm-configuration>" +
+ " <string name='myproperty'>myvalue</string>" +
+ "</jbpm-configuration>"));
assertEquals("myvalue",
JbpmConfiguration.Configs.getString("myproperty"));
}
- public static class CustomObjectFactory implements ObjectFactory {
+ public static class CustomObjectFactory implements ObjectFactory
+ {
private static final long serialVersionUID = 1L;
- public Object createObject(String name) {
+
+ public Object createObject(String name)
+ {
Object o = null;
- if ("myproperty".equals(name)) {
+ if ("myproperty".equals(name))
+ {
o = "mycustomfactoriedvalue";
}
return o;
}
- public boolean hasObject(String name) {
+
+ public boolean hasObject(String name)
+ {
return "myproperty".equals(name);
}
}
- public void testDomainModelConfigsWithCustomObjectFactory() {
- JbpmConfiguration.Configs.setDefaultObjectFactory(
- new CustomObjectFactory()
- );
+ public void testDomainModelConfigsWithCustomObjectFactory()
+ {
+ JbpmConfiguration.Configs.setDefaultObjectFactory(new CustomObjectFactory());
assertEquals("mycustomfactoriedvalue",
JbpmConfiguration.Configs.getString("myproperty"));
}
- public void testDomainModelConfigsWithJbpmContext() {
+ public void testDomainModelConfigsWithJbpmContext()
+ {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
- "<jbpm-configuration>" +
- " <jbpm-context name='default.jbpm.context' />" +
- " <string
name='myproperty'>myvalueinacontext</string>" +
- "</jbpm-configuration>"
- );
+ "<jbpm-configuration>" +
+ " <jbpm-context name='default.jbpm.context' />" +
+ " <string
name='myproperty'>myvalueinacontext</string>" +
+ "</jbpm-configuration>");
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try {
+ try
+ {
assertEquals("myvalueinacontext",
JbpmConfiguration.Configs.getString("myproperty"));
- } finally {
+ }
+ finally
+ {
jbpmContext.close();
}
}
- public void testDomainModelConfigsWithNestedJbpmContext() {
+ public void testDomainModelConfigsWithNestedJbpmContext()
+ {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
- "<jbpm-configuration>" +
- " <jbpm-context name='default.jbpm.context' />" +
- " <string
name='myproperty'>myvalueinacontext</string>" +
- "</jbpm-configuration>"
- );
+ "<jbpm-configuration>" +
+ " <jbpm-context name='default.jbpm.context' />" +
+ " <string
name='myproperty'>myvalueinacontext</string>" +
+ "</jbpm-configuration>");
+
JbpmConfiguration nestedJbpmConfiguration = JbpmConfiguration.parseXmlString(
- "<jbpm-configuration>" +
- " <jbpm-context name='default.jbpm.context' />" +
- " <string
name='myproperty'>myvalueinanestedcontext</string>" +
- "</jbpm-configuration>"
- );
-
+ "<jbpm-configuration>" +
+ " <jbpm-context name='default.jbpm.context' />" +
+ " <string
name='myproperty'>myvalueinanestedcontext</string>" +
+ "</jbpm-configuration>");
+
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try {
+ try
+ {
assertEquals("myvalueinacontext",
JbpmConfiguration.Configs.getString("myproperty"));
JbpmContext nestedJbpmContext = nestedJbpmConfiguration.createJbpmContext();
- try {
+ try
+ {
assertEquals("myvalueinanestedcontext",
JbpmConfiguration.Configs.getString("myproperty"));
- } finally {
+ }
+ finally
+ {
nestedJbpmContext.close();
}
-
+
assertEquals("myvalueinacontext",
JbpmConfiguration.Configs.getString("myproperty"));
- } finally {
+ }
+ finally
+ {
jbpmContext.close();
}
}
- public void testJbpmConfigurationClose() {
+ public void testJbpmConfigurationClose()
+ {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
SessionFactory sessionFactory;
- try {
+ try
+ {
sessionFactory = jbpmContext.getSessionFactory();
- } finally {
+ }
+ finally
+ {
jbpmContext.close();
}
jbpmConfiguration.close();