[jbpm-commits] JBoss JBPM SVN: r4689 - in jbpm3/trunk/modules/core/src: main/java/org/jbpm/instantiation and 4 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri May 1 05:12:16 EDT 2009


Author: alex.guizar at jboss.com
Date: 2009-05-01 05:12:16 -0400 (Fri, 01 May 2009)
New Revision: 4689

Added:
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/SharedProcessClassLoaderFactory.java
   jbpm3/trunk/modules/core/src/test/java/org/jbpm/instantiation/ConfigurableClassLoadersTest.java
Removed:
   jbpm3/trunk/modules/core/src/test/java/org/jbpm/instantiation/ConfigurableClassloadersTest.java
Modified:
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/DefaultProcessClassLoaderFactory.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/ProcessClassLoader.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/ProcessClassLoaderFactory.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/ClassLoaderUtil.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/XmlUtil.java
   jbpm3/trunk/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml
   jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessClassLoaderTest.java
Log:
[JBPM-2202] introduce ProcessClassLoaderFactory implementation that returns shared class loader per process definition
prevent ProcessClassLoader from keeping a reference to ProcessDefinition if the latter is persistent

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java	2009-05-01 09:04:22 UTC (rev 4688)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java	2009-05-01 09:12:16 UTC (rev 4689)
@@ -248,71 +248,64 @@
  * </tr>
  * </table>
  */
-public class JbpmConfiguration implements Serializable
-{
+public class JbpmConfiguration implements Serializable {
 
   private static final long serialVersionUID = 1L;
 
   static ObjectFactory defaultObjectFactory;
   static final Map<String, JbpmConfiguration> instances = new HashMap<String, JbpmConfiguration>();
-  static final ThreadLocal<List<JbpmConfiguration>> jbpmConfigurationStacks = new StackThreadLocal<JbpmConfiguration>();
+  static final ThreadLocal<List<JbpmConfiguration>> jbpmConfigurationStacks =
+      new StackThreadLocal<JbpmConfiguration>();
 
   private final ObjectFactory objectFactory;
-  private final ThreadLocal<List<JbpmContext>> jbpmContextStacks = new StackThreadLocal<JbpmContext>();
+  private final ThreadLocal<List<JbpmContext>> jbpmContextStacks =
+      new StackThreadLocal<JbpmContext>();
   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(log.isDebugEnabled()){
-        	  log.debug("creating configuration from default object factory: " + defaultObjectFactory);
+        if (defaultObjectFactory != null) {
+          if (log.isDebugEnabled()) {
+            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);
+          InputStream jbpmCfgXmlStream = ClassLoaderUtil.getStream(resource, false);
           /*
-           * 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);
@@ -325,20 +318,18 @@
     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);
     }
@@ -346,31 +337,26 @@
     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();
       }
     }
@@ -378,228 +364,184 @@
     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)
-  {
-    if(log.isDebugEnabled()){
-    	log.debug("creating jbpm configuration from resource: " + resource);
+  public static JbpmConfiguration parseResource(String resource) {
+    if (log.isDebugEnabled()) {
+      log.debug("creating jbpm configuration from resource: " + resource);
     }
     InputStream inputStream = null;
-    if (resource != null)
-    {
-      inputStream = ClassLoaderUtil.getJbpmConfigurationStream(resource);
+    if (resource != null) {
+      inputStream = ClassLoaderUtil.getStream(resource, false);
     }
     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)
-  {
-    ServiceFactory serviceFactory = null;
+  public ServiceFactory getServiceFactory(String serviceName, String jbpmContextName) {
     JbpmContext jbpmContext = createJbpmContext(jbpmContextName);
-    try
-    {
-      serviceFactory = jbpmContext.getServices().getServiceFactory(serviceName);
+    try {
+      return jbpmContext.getServices().getServiceFactory(serviceName);
     }
-    finally
-    {
+    finally {
       jbpmContext.close();
     }
-    return serviceFactory;
   }
 
-  public static ClassLoader getProcessClassLoader(ProcessDefinition processDefinition)
-  {
-    ProcessClassLoaderFactory factory = null;
-    if (Configs.hasObject("jbpm.processClassLoader"))
-    {
-      factory = (ProcessClassLoaderFactory)Configs.getObject("jbpm.processClassLoader");
+  public static ClassLoader getProcessClassLoader(ProcessDefinition processDefinition) {
+    ProcessClassLoaderFactory factory;
+    if (Configs.hasObject("process.class.loader.factory")) {
+      factory = (ProcessClassLoaderFactory) Configs.getObject("process.class.loader.factory");
     }
-    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();
     }
 
@@ -610,12 +552,9 @@
     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;
         }
@@ -623,34 +562,26 @@
     }
   }
 
-  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();
   }
 
-  static void clearJbpmConfigurationStack()
-  {
+  static void clearJbpmConfigurationStack() {
     List<JbpmConfiguration> configStack = getJbpmConfigurationStack();
-    if (configStack != null)
-    {
-      for (JbpmConfiguration config : new ArrayList<JbpmConfiguration>(configStack))
-      {
+    if (configStack != null) {
+      for (JbpmConfiguration config : new ArrayList<JbpmConfiguration>(configStack)) {
         List<JbpmContext> contextStack = config.getJbpmContextStack();
-        if (contextStack != null)
-        {
-          for (JbpmContext context : new ArrayList<JbpmContext>(contextStack))
-          {
+        if (contextStack != null) {
+          for (JbpmContext context : new ArrayList<JbpmContext>(contextStack)) {
             context.close();
           }
         }
@@ -660,85 +591,72 @@
     }
   }
 
-  synchronized void pushJbpmConfiguration()
-  {
+  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/trunk/modules/core/src/main/java/org/jbpm/instantiation/DefaultProcessClassLoaderFactory.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/DefaultProcessClassLoaderFactory.java	2009-05-01 09:04:22 UTC (rev 4688)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/DefaultProcessClassLoaderFactory.java	2009-05-01 09:12:16 UTC (rev 4689)
@@ -1,7 +1,5 @@
 package org.jbpm.instantiation;
 
-import java.io.Serializable;
-
 import org.jbpm.graph.def.ProcessDefinition;
 import org.jbpm.util.ClassLoaderUtil;
 
@@ -10,7 +8,7 @@
  * 
  * @author bernd.ruecker at camunda.com
  */
-public class DefaultProcessClassLoaderFactory implements ProcessClassLoaderFactory, Serializable {
+public class DefaultProcessClassLoaderFactory implements ProcessClassLoaderFactory {
   
   private static final long serialVersionUID = 1L;
 

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/ProcessClassLoader.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/ProcessClassLoader.java	2009-05-01 09:04:22 UTC (rev 4688)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/ProcessClassLoader.java	2009-05-01 09:12:16 UTC (rev 4689)
@@ -29,35 +29,53 @@
 import java.net.URLConnection;
 import java.net.URLStreamHandler;
 
+import org.jbpm.JbpmContext;
 import org.jbpm.JbpmException;
 import org.jbpm.file.def.FileDefinition;
 import org.jbpm.graph.def.ProcessDefinition;
 
 public class ProcessClassLoader extends ClassLoader {
 
-  private ProcessDefinition processDefinition = null;
+  private ProcessDefinition processDefinition;
+  private long processDefinitionId;
 
   public ProcessClassLoader(ClassLoader parent, ProcessDefinition processDefinition) {
     super(parent);
-    this.processDefinition = processDefinition;
+    // check whether the given process definition is transient
+    long id = processDefinition.getId();
+    if (id != 0) {
+      // persistent, keep id only
+      processDefinitionId = id;
+    }
+    else {
+      // transient, keep full object
+      this.processDefinition = processDefinition;
+    }
   }
 
+  protected ProcessDefinition getProcessDefinition() {
+    return processDefinition != null ? processDefinition : JbpmContext.getCurrentJbpmContext()
+        .getGraphSession()
+        .loadProcessDefinition(processDefinitionId);
+  }
+
   public URL findResource(String name) {
-    URL url = null;
+    ProcessDefinition processDefinition = getProcessDefinition();
     FileDefinition fileDefinition = processDefinition.getFileDefinition();
     if (fileDefinition != null) {
-      // if the name of the resources starts with a /
-      if (name.startsWith("/")) {
-        // then we start searching from the root of the process archive
+      // we know that the leading slashes are removed in the names of the
+      // file definitions, therefore we skip the leading slashes
+      int off = 0;
+      for (int len = name.length(); off < len && name.charAt(off) == '/'; off++)
+        /* just increase offset */;
 
-        // we know that the leading slashes are removed in the names of the
-        // file definitions, therefore we skip the leading slashes
-        while (name.startsWith("/")) {
-          name = name.substring(1);
-        }
+      // if the name of the resources is absolute (starts with one or more slashes)
+      if (off > 0) {
+        // then start searching from the root of the process archive
+        name = name.substring(off);
       }
       else {
-        // otherwise, (if the resource is relative), we look in the classes
+        // otherwise (if the resource is relative), look in the classes
         // directory in the process archive
         name = "classes/" + name;
       }
@@ -68,7 +86,7 @@
       }
       if (bytes != null) {
         try {
-          url = new URL(null, "processresource://"
+          return new URL(null, "processresource://"
               + processDefinition.getName()
               + "/classes/"
               + name, new BytesUrlStreamHandler(bytes));
@@ -78,7 +96,7 @@
         }
       }
     }
-    return url;
+    return null;
   }
 
   public static class BytesUrlStreamHandler extends URLStreamHandler {
@@ -110,7 +128,7 @@
   }
 
   public Class<?> findClass(String className) throws ClassNotFoundException {
-    FileDefinition fileDefinition = processDefinition.getFileDefinition();
+    FileDefinition fileDefinition = getProcessDefinition().getFileDefinition();
     if (fileDefinition != null) {
       String fileName = "classes/" + className.replace('.', '/') + ".class";
       byte[] classBytes = fileDefinition.getBytes(fileName);

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/ProcessClassLoaderFactory.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/ProcessClassLoaderFactory.java	2009-05-01 09:04:22 UTC (rev 4688)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/ProcessClassLoaderFactory.java	2009-05-01 09:12:16 UTC (rev 4689)
@@ -1,21 +1,31 @@
 package org.jbpm.instantiation;
 
+import java.io.Serializable;
+
+import org.jbpm.JbpmConfiguration;
 import org.jbpm.graph.def.ProcessDefinition;
 
 /**
- * Factory to retrieve the Process{@link ClassLoader} which is then used
- * to load delegation classes used by the process.
+ * <p>
+ * Factory to retrieve the Process {@link ClassLoader} which is then used to load delegation classes
+ * used by the process.
+ * </p>
+ * <p>
+ * Default is the build in {@link ProcessClassLoader}, which tries to load the classes from the jBPM
+ * database first.
+ * </p>
+ * <p>
+ * Can be configured by setting the property <code>jbpm.process.class.loader</code> in the
+ * configuration file to the class name of the custom class loader.
+ * </p>
+ * <p>
+ * Implementations should be serializable, as the {@link JbpmConfiguration} that references them is.
+ * </p>
  * 
- * Default is the build in {@link ProcessClassLoader}, which 
- * tries to load the classes from the jbpm database first.
- * 
- * Can be configured by setting the property <b>'jbpm.processClassLoader'</b>
- * in the jbpm.cfg.xml to the class name of the custom class loader.
- * 
  * @author bernd.ruecker at camunda.com
  */
-public interface ProcessClassLoaderFactory {
+public interface ProcessClassLoaderFactory extends Serializable {
 
   public ClassLoader getProcessClassLoader(ProcessDefinition processDefinition);
-  
+
 }
\ No newline at end of file

Added: jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/SharedProcessClassLoaderFactory.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/SharedProcessClassLoaderFactory.java	                        (rev 0)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/SharedProcessClassLoaderFactory.java	2009-05-01 09:12:16 UTC (rev 4689)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.instantiation;
+
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.util.ClassLoaderUtil;
+
+/**
+ * Refined process class loader factory that maintains a cache of the class loaders it returns. The
+ * cache does not prevent class loaders from being discarded by the garbage collector.
+ * 
+ * @author Alejandro Guizar
+ */
+public class SharedProcessClassLoaderFactory implements ProcessClassLoaderFactory {
+
+  private transient Map<Long, WeakReference<ProcessClassLoader>> classLoaderRefs =
+      new HashMap<Long, WeakReference<ProcessClassLoader>>();
+
+  private static final long serialVersionUID = 1L;
+
+  public ClassLoader getProcessClassLoader(ProcessDefinition processDefinition) {
+    // determine the key to lookup a cached class loader
+    long id = processDefinition.getId();
+    // observe that the given process definition may be transient
+    Long key = id != 0 ? id : processDefinition.hashCode();
+
+    synchronized (classLoaderRefs) {
+      // lookup the class loader reference
+      WeakReference<ProcessClassLoader> classLoaderRef = classLoaderRefs.get(key);
+      ProcessClassLoader classLoader;
+      // the reference may not exist or may have been cleared already
+      if (classLoaderRef == null || (classLoader = classLoaderRef.get()) == null) {
+        // (re-)create the class loader and the reference
+        classLoader = new ProcessClassLoader(ClassLoaderUtil.getClassLoader(), processDefinition);
+        classLoaderRef = new WeakReference<ProcessClassLoader>(classLoader);
+        // cache the reference
+        classLoaderRefs.put(key, classLoaderRef);
+      }
+      return classLoader;
+    }
+  }
+
+}

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/ClassLoaderUtil.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/ClassLoaderUtil.java	2009-05-01 09:04:22 UTC (rev 4688)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/ClassLoaderUtil.java	2009-05-01 09:12:16 UTC (rev 4689)
@@ -31,131 +31,101 @@
 /**
  * provides centralized classloader lookup.
  */
-public class ClassLoaderUtil
-{
+public class ClassLoaderUtil {
 
-  private ClassLoaderUtil()
-  {
+  private ClassLoaderUtil() {
     // hide default constructor to prevent instantiation
   }
 
   /**
-   * Bad usage of ClassLoader.loadClass() under JDK 6
-   * https://jira.jboss.org/jira/browse/JBPM-1976
+   * Bad usage of ClassLoader.loadClass() under JDK 6.
    * 
-   * @deprecated Use ClassLoaderUtil.classForName
+   * @deprecated Use {@linkplain #classForName(String) classForName()} instead
+   * @see <a href="https://jira.jboss.org/jira/browse/JBPM-1976">JBPM-1976</a>
    */
-  public static Class<?> loadClass(String className)
-  {
-    try
-    {
+  public static Class<?> loadClass(String className) {
+    try {
       return getClassLoader().loadClass(className);
     }
-    catch (ClassNotFoundException e)
-    {
+    catch (ClassNotFoundException e) {
       throw new JbpmException("class not found '" + className + "'", e);
     }
   }
 
-  public static Class<?> classForName(String className)
-  {
-    try
-    {
-      return Class.forName(className, false, getClassLoader());
+  public static Class<?> classForName(String className) {
+    try {
+      return Class.forName(className, true, getClassLoader());
     }
-    catch (ClassNotFoundException e)
-    {
+    catch (ClassNotFoundException e) {
       throw new JbpmException("class not found '" + className + "'", e);
     }
   }
 
+  public static Class<?> classForName(String className, boolean useConfiguredLoader) {
+    if (useConfiguredLoader) return classForName(className);
+
+    // try context class loader first, so that applications can override provided classes
+    try {
+      return Class.forName(className, true, Thread.currentThread().getContextClassLoader());
+    }
+    catch (ClassNotFoundException e) {
+      // try the class loader of the current class
+      try {
+        return Class.forName(className);
+      }
+      catch (ClassNotFoundException e2) {
+        // give up
+        throw new JbpmException("class not found '" + className + "'", e);
+      }
+    }
+  }
+
   /**
-   * returns the {@link ClassLoader} which is used in jbpm. Can be configured in jbpm.cfg.xml by the
-   * property <code>jbpm.classLoader</code>.
+   * Returns the {@link ClassLoader} employed by jBPM to load classes referenced in the
+   * configuration. The class loader can be changed in <code>jbpm.cfg.xml</code> by setting the
+   * string property <code>jbpm.class.loader</code>. The possible values are:
    * <ul>
-   * <li><code>jbpm</code> (default) uses the {@link ClassLoaderUtil#getClassLoader()}. This
-   * was the only behavior available before <a
-   * href="https://jira.jboss.org/jira/browse/JBPM-1148">JBPM-1148</a>.</li>
-   * <li><code>context</code> uses the {@link Thread#getContextClassLoader()}.</li>
-   * <li><code>custom</code> means that a ClassLoader class has to be provided in the property
-   * <code>jbpm.classLoader.className</code></li>
+   * <li><code>jbpm</code> (default) indicates the class loader of the jBPM classes. Before <a
+   * href="https://jira.jboss.org/jira/browse/JBPM-1148">JBPM-1148</a> no other behavior was
+   * available</li>
+   * <li><code>context</code> indicates the {@linkplain Thread#getContextClassLoader() context class
+   * loader}</li>
+   * <li>any other value is interpreted as a reference to a class loader bean described in the
+   * configuration</li>
    * </ul>
    */
-  public static ClassLoader getClassLoader()
-  {
-    if (JbpmConfiguration.Configs.hasObject("jbpm.classLoader"))
-    {
-      String jbpmClassloader = JbpmConfiguration.Configs.getString("jbpm.classLoader");
+  public static ClassLoader getClassLoader() {
+    if (JbpmConfiguration.Configs.hasObject("jbpm.class.loader")) {
+      String jbpmClassLoader = JbpmConfiguration.Configs.getString("jbpm.class.loader");
 
-      if (jbpmClassloader.equals("jbpm"))
-      {
+      if (jbpmClassLoader.equals("jbpm")) {
+        // use class loader that loaded the jbpm classes
         return ClassLoaderUtil.class.getClassLoader();
       }
-      else if (jbpmClassloader.equals("context"))
-      {
+
+      if (jbpmClassLoader.equals("context")) {
+        // use the context class loader
         return Thread.currentThread().getContextClassLoader();
       }
-      else if (jbpmClassloader.equals("custom"))
-      {
-        String classloaderClassname = null;
-        try
-        {
-          if (!JbpmConfiguration.Configs.hasObject("jbpm.customClassLoader.className"))
-          {
-            throw new JbpmException(
-                "'jbpm.classLoader' property set to 'custom' but 'jbpm.customClassLoader.className' is absent!");
-          }
-          classloaderClassname = JbpmConfiguration.Configs
-              .getString("jbpm.customClassLoader.className");
-          if (classloaderClassname == null)
-          {
-            throw new JbpmException(
-                "'jbpm.classloader' property set to 'custom' but 'jbpm.customClassLoader.className' is null!");
-          }
 
-          Class<?> clazz = Class.forName(classloaderClassname, false, ClassLoaderUtil.class.getClassLoader());
-          if (clazz == null) {
-            clazz = Class.forName(classloaderClassname, false, Thread.currentThread().getContextClassLoader());
-          }
-
-          return (ClassLoader) clazz.newInstance();
-        }
-        catch (InstantiationException e)
-        {
-          throw new JbpmException("Error instantiating custom classloader "
-              + classloaderClassname, e);
-        }
-        catch (IllegalAccessException e)
-        {
-          throw new JbpmException("Error accessing custom classloader " + classloaderClassname,
-              e);
-        }
-        catch (ClassNotFoundException e)
-        {
-          throw new JbpmException("Custom classloader " + classloaderClassname + " not found ",
-              e);
-        }
+      // interpret value as a reference to a class loader bean
+      Object bean = JbpmConfiguration.Configs.getObject(jbpmClassLoader);
+      if (!(bean instanceof ClassLoader)) {
+        throw new JbpmException("bean '" + jbpmClassLoader + "' is not a class loader");
       }
-      else
-      {
-        throw new JbpmException("'jbpm.classloader' property set to '"
-            + jbpmClassloader
-            + "' but only the values 'jbpm'/'context'/'custom' are supported!");
-      }
+      return (ClassLoader) bean;
     }
-    else
-    {
-      // default behavior like before https://jira.jboss.org/jira/browse/JBPM-1148
+    else {
+      // behave like before JBPM-1148
       return ClassLoaderUtil.class.getClassLoader();
     }
   }
 
-  public static InputStream getStream(String resource)
-  {
+  public static InputStream getStream(String resource) {
     return getClassLoader().getResourceAsStream(resource);
   }
 
-  /*
+  /**
    * Load jbpm configuration related resources as stream (normally jbpm.cfg.xml). This method first
    * tries to load the resource from the {@link ClassLoaderUtil} class loader, if not found it tries
    * the context class loader. If this doesn't return any ressource the call is delegated to the
@@ -163,28 +133,27 @@
    * loader which has to be used for loading the jbpm.cfg.xml cannot be configured in the
    * jbpm.cfg.xml itself.
    */
-  public static InputStream getJbpmConfigurationStream(String resource)
-  {
-    InputStream jbpmCfgStream = ClassLoaderUtil.class.getClassLoader()
-        .getResourceAsStream(resource);
-    if (jbpmCfgStream == null)
-    {
-      jbpmCfgStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
+  public static InputStream getStream(String resource, boolean useConfiguredLoader) {
+    if (useConfiguredLoader) return getStream(resource);
+
+    // try context class loader first, so that applications can override provided classes
+    InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(
+        resource);
+    if (stream == null) {
+      // try the class loader of the current class
+      stream = ClassLoaderUtil.class.getClassLoader().getResourceAsStream(resource);
     }
-    return jbpmCfgStream;
+    return stream;
   }
 
-  public static Properties getProperties(String resource)
-  {
+  public static Properties getProperties(String resource) {
     Properties properties = new Properties();
-    try
-    {
+    try {
       InputStream inStream = getStream(resource);
       properties.load(inStream);
       inStream.close();
     }
-    catch (IOException e)
-    {
+    catch (IOException e) {
       throw new JbpmException("couldn't load properties file '" + resource + "'", e);
     }
     return properties;

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/XmlUtil.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/XmlUtil.java	2009-05-01 09:04:22 UTC (rev 4688)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/XmlUtil.java	2009-05-01 09:12:16 UTC (rev 4689)
@@ -68,7 +68,7 @@
     // configuration (see https://jira.jboss.org/jira/browse/JBPM-1148)
     InputStream inputStream = null;
     if (isJbpmConfiguration)
-      inputStream = ClassLoaderUtil.getJbpmConfigurationStream(resource);
+      inputStream = ClassLoaderUtil.getStream(resource, false);
     else
       inputStream = ClassLoaderUtil.getStream(resource);
 

Modified: jbpm3/trunk/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml
===================================================================
--- jbpm3/trunk/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml	2009-05-01 09:04:22 UTC (rev 4688)
+++ jbpm3/trunk/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml	2009-05-01 09:12:16 UTC (rev 4689)
@@ -31,11 +31,8 @@
   <string name="resource.mail.templates" value="jbpm.mail.templates.xml" />
 
   <!-- class loading -->
-  <!--
-  <string name="jbpm.classLoader" value="jbpm" />
-  <string name="jbpm.customClassLoader.className" value="org.example.ClassLoader" /> 
-  <bean name="jbpm.processClassLoader" class="org.jbpm.instantiation.DefaultProcessClassLoaderFactory" singleton="true" />
-  -->
+  <string name="jbpm.class.loader" value="context" />
+  <bean name="process.class.loader.factory" class="org.jbpm.instantiation.SharedProcessClassLoaderFactory" singleton="true" />
 
   <!-- make sure the block size matches the length in ByteArray.hbm.xml -->
   <int    name="jbpm.byte.block.size" value="1024" singleton="true" />

Copied: jbpm3/trunk/modules/core/src/test/java/org/jbpm/instantiation/ConfigurableClassLoadersTest.java (from rev 4393, jbpm3/trunk/modules/core/src/test/java/org/jbpm/instantiation/ConfigurableClassloadersTest.java)
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/instantiation/ConfigurableClassLoadersTest.java	                        (rev 0)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/instantiation/ConfigurableClassLoadersTest.java	2009-05-01 09:12:16 UTC (rev 4689)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.instantiation;
+
+import org.jbpm.AbstractJbpmTestCase;
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmContext;
+import org.jbpm.JbpmException;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.util.ClassLoaderUtil;
+
+/**
+ * {@link ProcessClassLoaderFactory} and class loader can be configured via
+ * {@link JbpmConfiguration} / jbpm.cfg.xml. Test if that works. Introduced with
+ * https://jira.jboss.org/jira/browse/JBPM-1148
+ * 
+ * @author bernd.ruecker at camunda.com
+ */
+public class ConfigurableClassLoadersTest extends AbstractJbpmTestCase {
+
+  private ProcessDefinition processDefinition = new ProcessDefinition();
+
+  public void testDefaultProcessClassLoaderFactory() {
+    ClassLoader processClassLoader = JbpmConfiguration.getProcessClassLoader(processDefinition);
+    assertSame(ProcessClassLoader.class, processClassLoader.getClass());
+  }
+
+  public void testCustomProcessClassLoaderFactory() {
+    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString("<jbpm-configuration>"
+        + "  <bean name='process.class.loader.factory' class='"
+        + CustomProcessClassLoaderFactory.class.getName()
+        + "' singleton='true' />"
+        + "</jbpm-configuration>");
+    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+
+    ClassLoader processClassLoader = JbpmConfiguration.getProcessClassLoader(processDefinition);
+    assertSame(CustomClassLoader.class, processClassLoader.getClass());
+
+    jbpmContext.close();
+    jbpmConfiguration.close();
+  }
+
+  public static class CustomProcessClassLoaderFactory implements ProcessClassLoaderFactory {
+    private static final long serialVersionUID = 1L;
+    public ClassLoader getProcessClassLoader(ProcessDefinition processDefinition) {
+      return new CustomClassLoader();
+    }
+  }
+
+  public void testDefaultClassLoader() {
+    ClassLoader classLoader = ClassLoaderUtil.getClassLoader();
+    assertSame(ClassLoaderUtil.class.getClassLoader(), classLoader);
+  }
+
+  public void testJbpmClassLoader() {
+    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString("<jbpm-configuration>"
+        + "  <string name='jbpm.class.loader' value='jbpm' /> "
+        + "</jbpm-configuration>");
+    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+
+    ClassLoader classLoader = ClassLoaderUtil.getClassLoader();
+    assertSame(ClassLoaderUtil.class.getClassLoader(), classLoader);
+
+    jbpmContext.close();
+    jbpmConfiguration.close();
+  }
+
+  public void testContextClassLoader() {
+    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString("<jbpm-configuration>"
+        + "  <string name='jbpm.class.loader' value='context' /> "
+        + "</jbpm-configuration>");
+    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+
+    ClassLoader classLoader = ClassLoaderUtil.getClassLoader();
+    assertSame(Thread.currentThread().getContextClassLoader(), classLoader);
+
+    jbpmContext.close();
+    jbpmConfiguration.close();
+  }
+
+  public void testNonExistentClassLoader() {
+    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString("<jbpm-configuration>"
+        + "  <string name='jbpm.class.loader' value='absent' /> "
+        + "</jbpm-configuration>");
+    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+
+    try {
+      ClassLoaderUtil.getClassLoader();
+      fail("expected " + JbpmException.class.getName());
+    }
+    catch (JbpmException ex) {
+      // fine, exception was expected
+    }
+
+    jbpmContext.close();
+    jbpmConfiguration.close();
+  }
+
+  public void testCustomClassLoader() {
+    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString("<jbpm-configuration>"
+        + "  <string name='jbpm.class.loader' value='custom.class.loader' />"
+        + "  <bean name='custom.class.loader' class='"
+        + CustomClassLoader.class.getName()
+        + "' /> "
+        + "</jbpm-configuration>");
+    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+
+    ClassLoader classLoader = ClassLoaderUtil.getClassLoader();
+    assertSame(CustomClassLoader.class, classLoader.getClass());
+
+    jbpmContext.close();
+    jbpmConfiguration.close();
+  }
+
+  public static class CustomClassLoader extends ClassLoader {
+    public CustomClassLoader() {
+      super(Thread.currentThread().getContextClassLoader());
+    }
+  }
+
+}

Deleted: jbpm3/trunk/modules/core/src/test/java/org/jbpm/instantiation/ConfigurableClassloadersTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/instantiation/ConfigurableClassloadersTest.java	2009-05-01 09:04:22 UTC (rev 4688)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/instantiation/ConfigurableClassloadersTest.java	2009-05-01 09:12:16 UTC (rev 4689)
@@ -1,135 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jbpm.instantiation;
-
-import org.jbpm.AbstractJbpmTestCase;
-import org.jbpm.JbpmConfiguration;
-import org.jbpm.JbpmContext;
-import org.jbpm.graph.def.ProcessDefinition;
-
-/**
- * {@link ProcessClassLoaderFactory} and class loader can be configured 
- * via {@link JbpmConfiguration} / jbpm.cfg.xml. Test if that works.
- * 
- * Introduced with https://jira.jboss.org/jira/browse/JBPM-1148
- * 
- * @author bernd.ruecker at camunda.com
- */
-public class ConfigurableClassloadersTest extends AbstractJbpmTestCase {
-  
-  public void testDefaultBehavior() {
-    JbpmConfiguration.getInstance();
-    ClassLoader processClassLoader = JbpmConfiguration.getProcessClassLoader(null);
-    
-    assertNotNull(processClassLoader);
-    assertEquals(ProcessClassLoader.class, processClassLoader.getClass());
-  }
-
-  public static class MyClassLoader extends ClassLoader {
-    public MyClassLoader() {      
-    }
-    public MyClassLoader(ClassLoader parent) {
-      super(parent);
-    }    
-  }
-  
-  public static class TestProcessClassLoaderFactory implements ProcessClassLoaderFactory {
-    public ClassLoader getProcessClassLoader(ProcessDefinition processDefinition) {
-      return new MyClassLoader(Thread.currentThread().getContextClassLoader());
-    }   
-  }
-
-  public void testOwnProcessFactory() {
-    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
-            "<jbpm-configuration>" +
-            "  <jbpm-context>" +
-            "  </jbpm-context>" +
-            "  <string name='jbpm.classLoader' value='jbpm' /> " +
-            "  <bean name='jbpm.processClassLoader' class='org.jbpm.instantiation.ConfigurableClassloadersTest$TestProcessClassLoaderFactory' singelton='true' />" +
-            "</jbpm-configuration>"
-    );
-    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-    
-    ClassLoader processClassLoader = JbpmConfiguration.getProcessClassLoader(null);    
-    assertNotNull(processClassLoader);
-    assertEquals(MyClassLoader.class, processClassLoader.getClass());
-    
-    jbpmContext.close();
-    jbpmConfiguration.close();
-  }
-  
-  public void testContextClassloaderFactory() {
-    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
-            "<jbpm-configuration>" +
-            "  <jbpm-context>" +
-            "  </jbpm-context>" +
-            "  <string name='jbpm.classLoader' value='context' /> " +
-            "</jbpm-configuration>"
-    );
-    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-
-    assertNotNull(jbpmContext);
-    
-    jbpmContext.close();
-    jbpmConfiguration.close();
-  }
-
-  public void testCustomClassloaderFactoryWithoutClassname() {
-    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
-            "<jbpm-configuration>" +
-            "  <jbpm-context>" +
-            "  </jbpm-context>" +
-            "  <string name='jbpm.classLoader' value='custom' /> " +
-            "</jbpm-configuration>"
-    );
-    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-    try {
-      ClassLoader processClassLoader = JbpmConfiguration.getProcessClassLoader(null);    
-      fail("we should get an exception because custom class loader class not specified");
-    }
-    catch (Exception ex) {}
-    
-    jbpmContext.close();
-    jbpmConfiguration.close();
-  }
-  
-  public void testCustomClassloaderFactory() {
-    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
-            "<jbpm-configuration>" +
-            "  <jbpm-context>" +
-            "  </jbpm-context>" +
-            "  <string name='jbpm.classLoader' value='custom' /> " +
-            "  <string name='jbpm.customClassLoader.className' value='org.jbpm.instantiation.ConfigurableClassloadersTest$MyClassLoader' />" +
-            "</jbpm-configuration>"
-    );
-    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-    
-    ClassLoader processClassLoader = JbpmConfiguration.getProcessClassLoader(null);    
-    assertNotNull(processClassLoader);
-    // not configured, must be default
-    assertEquals(ProcessClassLoader.class, processClassLoader.getClass());
-    
-    jbpmContext.close();
-    jbpmConfiguration.close();
-  }
-  
-}

Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessClassLoaderTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessClassLoaderTest.java	2009-05-01 09:04:22 UTC (rev 4688)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessClassLoaderTest.java	2009-05-01 09:12:16 UTC (rev 4689)
@@ -7,14 +7,14 @@
 import org.jbpm.graph.def.ProcessDefinition;
 import org.jbpm.graph.exe.ExecutionContext;
 import org.jbpm.graph.exe.ProcessInstance;
-import org.jbpm.instantiation.ConfigurableClassloadersTest;
+import org.jbpm.instantiation.ConfigurableClassLoadersTest;
 import org.jbpm.instantiation.ProcessClassLoader;
 import org.jbpm.util.ClassLoaderUtil;
 
 /**
  * Test case for ProcessClassLoader hierarchy and setting the ContextClassLoader correctly.
  * 
- * Relates to {@link ConfigurableClassloadersTest}.
+ * Relates to {@link ConfigurableClassLoadersTest}.
  * 
  * @author Tom Baeyens, bernd.ruecker at camunda.com
  *




More information about the jbpm-commits mailing list