[jbpm-commits] JBoss JBPM SVN: r5956 - in jbpm4/trunk/modules: db/src/main/java/org/jbpm/db and 6 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Dec 11 12:20:27 EST 2009


Author: tom.baeyens at jboss.com
Date: 2009-12-11 12:20:24 -0500 (Fri, 11 Dec 2009)
New Revision: 5956

Added:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ConfigurationImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ConfigurationParser.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringProcessEngine.java
Removed:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/JbpmConfigurationParser.java
Modified:
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Configuration.java
   jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/Create.java
   jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/Upgrade.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ProcessEngineImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/EnvironmentInterceptorBinding.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ProcessEngineRefBinding.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/EnvironmentInterceptorDescriptor.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ProcessEngineDescriptor.java
   jbpm4/trunk/modules/pvm/src/main/resources/jbpm.tx.spring.cfg.xml
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/TxTests.java
Log:
split up ConfigurationImpl from ProcessEngineImpl to improve spring support

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Configuration.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Configuration.java	2009-12-11 15:02:25 UTC (rev 5955)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Configuration.java	2009-12-11 17:20:24 UTC (rev 5956)
@@ -24,8 +24,6 @@
 import java.io.File;
 import java.io.InputStream;
 import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
 
 import org.xml.sax.InputSource;
 
@@ -35,53 +33,19 @@
  * @author Tom Baeyens
  */
 public class Configuration {
-  
-  static Map<String, String> implementationClassNames = null;
 
+  /** singletone instance */
+  private static ProcessEngine singleton;
+  
   transient Configuration impl;
   
-  /** 
-   * Cached processEngine instance used by the 
-   * convience 'getProcessEngine()' operation. 
-   */
-  private static ProcessEngine cachedProcessEngine;
- 
   /** default constructor */
   public Configuration() {
-    this((String)null);
+    impl = instantiate("org.jbpm.pvm.internal.cfg.ConfigurationImpl");
   }
 
-  /** creates a configuration of a specific implementation type.
-   * no values are supported for type yet.  only <code>null</code>.
-   */
-  public Configuration(String type) {
-    String implementationClassName = getImplementationClassName(type);
-    if (implementationClassName==null) {
-      throw new JbpmException("type is null");
-    }
-    impl = instantiate(implementationClassName);
+  protected Configuration(Object o) {
   }
-  
-  /** empty constructor to be used by concrete implementations of Configuration */ 
-  protected Configuration(Configuration base){
-  }
-  
-  private synchronized String getImplementationClassName(String type) {
-    if (implementationClassNames==null) {
-      implementationClassNames = new HashMap<String, String>();
-      // null represents the default configuration (== the JbpmConfiguration)
-      implementationClassNames.put(null, "org.jbpm.pvm.internal.cfg.ProcessEngineImpl");
-      implementationClassNames.put("spring-test", "org.jbpm.pvm.internal.cfg.SpringConfiguration");
-      // TODO 
-      // implementationClasses.put("mc", "org.jbpm.pvm.internal.cfg.McConfiguration");
-      // implementationClasses.put("programatic", "org.jbpm.pvm.internal.cfg.ProgramaticConfiguration");
-    }
-    String implementationClassName = implementationClassNames.get(type);
-    if (implementationClassName==null) {
-      implementationClassName = type;
-    }
-    return implementationClassName;
-  }
 
   protected Configuration instantiate(String className) {
     Configuration implementation;
@@ -147,22 +111,16 @@
     return impl.setHibernateSessionFactory(hibernateSessionFactory);
   }
   
-  /**
-   * Convenience method to retrieve the default {@link ProcessEngine}. To
-   * construct this {@link ProcessEngine}, the classpath resource 'jbpm.cfg.xml'
-   * will be used.
-   * 
-   * Subsequent calls will return the same {@link ProcessEngine} instance.
-   */
+  /** get the singleton ProcessEngine that is created from the default 
+   * configuration file 'jbpm.cfg.xml'. */
   public static ProcessEngine getProcessEngine() {
-    if (cachedProcessEngine == null) {
+    if (singleton == null) {
       synchronized (Configuration.class) {
-        if (cachedProcessEngine == null) {
-          cachedProcessEngine = new Configuration().setResource("jbpm.cfg.xml").buildProcessEngine();          
+        if (singleton == null) {
+          singleton = new Configuration().setResource("jbpm.cfg.xml").buildProcessEngine();          
         }
       }
     }
-    return Configuration.cachedProcessEngine;
+    return Configuration.singleton;
   }
-  
 }

Modified: jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/Create.java
===================================================================
--- jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/Create.java	2009-12-11 15:02:25 UTC (rev 5955)
+++ jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/Create.java	2009-12-11 17:20:24 UTC (rev 5956)
@@ -26,7 +26,7 @@
 import org.jbpm.api.cmd.Command;
 import org.jbpm.api.cmd.Environment;
 import org.jbpm.internal.log.Log;
-import org.jbpm.pvm.internal.cfg.ProcessEngineImpl;
+import org.jbpm.pvm.internal.cfg.ConfigurationImpl;
 import org.jbpm.pvm.internal.id.PropertyImpl;
 
 /**
@@ -50,7 +50,7 @@
     
     database = args[0];
     
-    ProcessEngine processEngine = new ProcessEngineImpl()
+    ProcessEngine processEngine = new ConfigurationImpl()
         .skipDbCheck()
         .buildProcessEngine();
     

Modified: jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/Upgrade.java
===================================================================
--- jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/Upgrade.java	2009-12-11 15:02:25 UTC (rev 5955)
+++ jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/Upgrade.java	2009-12-11 17:20:24 UTC (rev 5956)
@@ -31,6 +31,7 @@
 import org.jbpm.api.cmd.Command;
 import org.jbpm.api.cmd.Environment;
 import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.cfg.ConfigurationImpl;
 import org.jbpm.pvm.internal.cfg.ProcessEngineImpl;
 import org.jbpm.pvm.internal.id.PropertyImpl;
 import org.jbpm.pvm.internal.repository.DeploymentImpl;
@@ -57,7 +58,7 @@
     
     database = args[0];
     
-    ProcessEngine processEngine = new ProcessEngineImpl()
+    ProcessEngine processEngine = new ConfigurationImpl()
       .skipDbCheck()
       .buildProcessEngine();
   

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ConfigurationImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ConfigurationImpl.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ConfigurationImpl.java	2009-12-11 17:20:24 UTC (rev 5956)
@@ -0,0 +1,182 @@
+/*
+ * 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.pvm.internal.cfg;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jbpm.api.Configuration;
+import org.jbpm.api.ProcessEngine;
+import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.env.Context;
+import org.jbpm.pvm.internal.stream.FileStreamInput;
+import org.jbpm.pvm.internal.stream.InputStreamInput;
+import org.jbpm.pvm.internal.stream.ResourceStreamInput;
+import org.jbpm.pvm.internal.stream.StreamInput;
+import org.jbpm.pvm.internal.stream.StringStreamInput;
+import org.jbpm.pvm.internal.stream.UrlStreamInput;
+import org.jbpm.pvm.internal.wire.WireContext;
+import org.jbpm.pvm.internal.wire.WireDefinition;
+import org.jbpm.pvm.internal.wire.descriptor.ProvidedObjectDescriptor;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ConfigurationImpl extends Configuration {
+  
+  public static final String DEFAULT_CONFIG_RESOURCENAME = "jbpm.cfg.xml";
+
+  private static Log log = Log.getLog(ConfigurationImpl.class.getName());
+
+  transient protected boolean isConfigured = false;
+  transient String jndiName;
+  transient boolean checkDb = true;
+  transient boolean isSpringEnabled = false;
+  transient boolean isInstantiatedFromSpring = false;
+  transient WireContext processEngineWireContext = new WireContext(new WireDefinition(), Context.CONTEXTNAME_PROCESS_ENGINE, true);
+  transient WireDefinition transactionWireDefinition = new WireDefinition();
+  transient ProcessEngine producedProcessEngine;
+  
+  public ConfigurationImpl() {
+    super(null);
+  }
+  
+  @Override
+  public ProcessEngine buildProcessEngine() {
+    if (!isConfigured) {
+      setResource(DEFAULT_CONFIG_RESOURCENAME);
+    }
+    if (jndiName!=null) {
+      try {
+        InitialContext initialContext = new InitialContext();
+        ProcessEngineImpl existing = (ProcessEngineImpl) initialContext.lookup(jndiName);
+        if (existing!=null) {
+          log.debug("found existing process engine under "+jndiName);
+          return existing;
+        }
+      } catch (NamingException e) {
+        log.debug("jndi name "+jndiName+" is not bound");
+      }
+    }
+
+    if (isSpringEnabled) {
+      return new SpringProcessEngine(this);
+    }
+    return new ProcessEngineImpl(this);
+  }
+
+  public ConfigurationImpl setHibernateSessionFactory(Object hibernateSessionFactory) {
+    processEngineWireContext
+        .getWireDefinition()
+        .addDescriptor(new ProvidedObjectDescriptor(hibernateSessionFactory, true));
+    return this;
+  }
+
+  public ConfigurationImpl setInputStream(InputStream inputStream) {
+    parse(new InputStreamInput(inputStream));
+    return this;
+  }
+
+  public ConfigurationImpl setResource(String resource) {
+    parse(new ResourceStreamInput(resource, getClassLoader()));
+    return this;
+  }
+
+  public ConfigurationImpl setUrl(URL url) {
+    parse(new UrlStreamInput(url));
+    return this;
+  }
+
+  public ConfigurationImpl setFile(File file) {
+    parse(new FileStreamInput(file));
+    return this;
+  }
+
+  public ConfigurationImpl setXmlString(String xmlString) {
+    parse(new StringStreamInput(xmlString));
+    return this;
+  }
+
+  protected void parse(StreamInput streamSource) {
+    isConfigured = true;
+    ConfigurationParser.getInstance()
+      .createParse()
+      .contextStackPush(this)
+      .setStreamSource(streamSource)
+      .execute()
+      .checkErrors("jbpm configuration " + streamSource);
+  }
+  
+  // fluent setters ///////////////////////////////////////////////////////////
+
+  public ConfigurationImpl skipDbCheck() {
+    checkDb = false;
+    return this;
+  }
+
+  public ConfigurationImpl jndiName(String jndiName) {
+    this.jndiName = jndiName;
+    return this;
+  }
+
+  public ConfigurationImpl springInitiated() {
+    this.isSpringEnabled = true;
+    this.isInstantiatedFromSpring = true;
+    return this;
+  }
+
+  public ConfigurationImpl springEnabled() {
+    this.isSpringEnabled = true;
+    return this;
+  }
+
+  public ConfigurationImpl jndi(String jndiName) {
+    this.jndiName = jndiName;
+    return this;
+  }
+
+  // getters and setters //////////////////////////////////////////////////////
+
+  public WireContext getProcessEngineWireContext() {
+    return processEngineWireContext;
+  }
+  public WireDefinition getTransactionWireDefinition() {
+    return transactionWireDefinition;
+  }
+  public String getJndiName() {
+    return jndiName;
+  }
+  public boolean isCheckDb() {
+    return checkDb;
+  }
+  public ProcessEngine getProducedProcessEngine() {
+    return producedProcessEngine;
+  }
+  public boolean isInstantiatedFromSpring() {
+    return isInstantiatedFromSpring;
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ConfigurationImpl.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ConfigurationParser.java (from rev 5944, jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/JbpmConfigurationParser.java)
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ConfigurationParser.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ConfigurationParser.java	2009-12-11 17:20:24 UTC (rev 5956)
@@ -0,0 +1,134 @@
+/*
+ * 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.pvm.internal.cfg;
+
+import org.jbpm.pvm.internal.util.XmlUtil;
+import org.jbpm.pvm.internal.wire.WireDefinition;
+import org.jbpm.pvm.internal.wire.xml.WireParser;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/** parses the <code>jbpm-configuration</code>, which is assumed the document element
+ * and can contain the {@link EnvironmentFactoryXmlParser process-engine}
+ * context and the {@link EnvironmentXmlParser environment} context.
+ * 
+ * See {@link Parser} for usage instructions.
+ *   
+ * @author Tom Baeyens
+ */
+public class ConfigurationParser extends Parser {
+
+  private static final long serialVersionUID = 1L;
+  
+  // private static Log log = Log.getLog(JbpmConfigurationParser.class.getName());
+
+  Parser processEngineContextParser = new WireParser();
+  Parser transactionContextParser = new WireParser();
+
+  protected static ConfigurationParser INSTANCE = new ConfigurationParser();
+  
+  public static ConfigurationParser getInstance() {
+    return INSTANCE;
+  }
+
+  public Object parseDocument(Document document, Parse parse) {
+    Element documentElement = document.getDocumentElement();
+    
+    // if the default environment factory was already set in the parse
+    ConfigurationImpl configuration = parse.contextStackFind(ConfigurationImpl.class);
+
+    // this code will be called for the original jbpm.cfg.xml document as 
+    // well as for the imported documents.  only one of those can specify
+    // a spring-cfg.  for sure no 2 config files can specify different jndi-names
+    String spring = XmlUtil.attribute(documentElement, "spring");
+    if ("enabled".equals(spring)) {
+      configuration.springEnabled();
+    }
+
+    // this code will be called for the original jbpm.cfg.xml document as 
+    // well as for the imported documents.  only one of those can specify
+    // a jndi-name.  for sure no 2 config files can specify different jndi-names
+    String jndiName = XmlUtil.attribute(documentElement, "jndi-name");
+    if (jndiName!=null) {
+      if ( (configuration.getJndiName()!=null)
+           && (!jndiName.equals(configuration.getJndiName()))
+         ) {
+        parse.addProblem("duplicate jndi name specification: "+jndiName+" != "+configuration.getJndiName());
+      } else {
+        configuration.jndi(jndiName);
+      }
+    }
+
+    for (Element importElement : XmlUtil.elements(documentElement, "import")) {
+      if (importElement.hasAttribute("resource")) {
+        String resource = importElement.getAttribute("resource");
+        Parse importParse = createParse()
+          .setResource(resource)
+          .contextStackPush(configuration)
+          .execute();
+        
+        parse.addProblems(importParse.getProblems());
+      }
+    }
+
+    Element processEngineElement = XmlUtil.element(documentElement, "process-engine-context");
+    if (processEngineElement != null) {
+      WireDefinition processEngineContextDefinition = configuration.getProcessEngineWireContext().getWireDefinition();
+      parse.contextStackPush(processEngineContextDefinition);
+      try {
+        processEngineContextParser.parseDocumentElement(processEngineElement, parse);
+      } finally {
+        parse.contextStackPop();
+      }
+    }
+
+    Element txCtxElement = XmlUtil.element(documentElement, "transaction-context");
+    if (txCtxElement != null) {
+      WireDefinition transactionContextDefinition = configuration.getTransactionWireDefinition();
+      parse.contextStackPush(transactionContextDefinition);
+      try {
+        transactionContextParser.parseDocumentElement(txCtxElement, parse);
+      } finally {
+        parse.contextStackPop();
+      }
+    }
+
+    parse.setDocumentObject(configuration);
+    
+    return configuration;
+  }
+
+  public Parser getProcessEngineContextParser() {
+    return processEngineContextParser;
+  }
+  public void setProcessEngineContextParser(Parser applicationWireXmlParser) {
+    this.processEngineContextParser = applicationWireXmlParser;
+  }
+  public Parser getTransactionContextParser() {
+    return transactionContextParser;
+  }
+  public void setTransactionContextParser(Parser blockWireXmlParser) {
+    this.transactionContextParser = blockWireXmlParser;
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ConfigurationParser.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ProcessEngineImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ProcessEngineImpl.java	2009-12-11 15:02:25 UTC (rev 5955)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ProcessEngineImpl.java	2009-12-11 17:20:24 UTC (rev 5956)
@@ -21,10 +21,7 @@
  */
 package org.jbpm.pvm.internal.cfg;
 
-import java.io.File;
-import java.io.InputStream;
 import java.io.Serializable;
-import java.net.URL;
 import java.sql.Connection;
 import java.util.ArrayList;
 import java.util.List;
@@ -33,7 +30,6 @@
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
-import org.jbpm.api.Configuration;
 import org.jbpm.api.ExecutionService;
 import org.jbpm.api.HistoryService;
 import org.jbpm.api.IdentityService;
@@ -49,19 +45,11 @@
 import org.jbpm.pvm.internal.env.Context;
 import org.jbpm.pvm.internal.env.EnvironmentFactory;
 import org.jbpm.pvm.internal.env.EnvironmentImpl;
-import org.jbpm.pvm.internal.env.JbpmConfigurationParser;
 import org.jbpm.pvm.internal.env.PvmEnvironment;
 import org.jbpm.pvm.internal.env.UserProvidedEnvironmentObject;
 import org.jbpm.pvm.internal.jobexecutor.JobExecutor;
-import org.jbpm.pvm.internal.stream.FileStreamInput;
-import org.jbpm.pvm.internal.stream.InputStreamInput;
-import org.jbpm.pvm.internal.stream.ResourceStreamInput;
-import org.jbpm.pvm.internal.stream.StreamInput;
-import org.jbpm.pvm.internal.stream.StringStreamInput;
-import org.jbpm.pvm.internal.stream.UrlStreamInput;
 import org.jbpm.pvm.internal.wire.WireContext;
 import org.jbpm.pvm.internal.wire.WireDefinition;
-import org.jbpm.pvm.internal.wire.descriptor.ProvidedObjectDescriptor;
 
 /**
  * an environment factory that also is the process-engine context.
@@ -93,46 +81,27 @@
  * 
  * @author Tom Baeyens
  */
-public class ProcessEngineImpl extends Configuration implements Context, ProcessEngine, EnvironmentFactory, Serializable {
+public class ProcessEngineImpl implements Context, ProcessEngine, EnvironmentFactory, Serializable {
 
   private static final long serialVersionUID = 1L;
   private static final Log log = Log.getLog(ProcessEngineImpl.class.getName());
   
   public static final String JBPM_LIBRARY_VERSION = "4.3-SNAPSHOT";
 
-  transient protected String jndiName;
-  transient protected boolean checkDb = true;
-  transient protected boolean isConfigured = false;
-  transient protected WireContext processEngineWireContext = new WireContext(new WireDefinition(), Context.CONTEXTNAME_PROCESS_ENGINE, true);
-  transient protected WireDefinition transactionWireDefinition = new WireDefinition();
+  transient protected WireContext processEngineWireContext;
+  transient protected WireDefinition transactionWireDefinition;
   
   transient protected ThreadLocal<List<UserProvidedEnvironmentObject>> userProvidedEnvironmentObjectsThreadLocal = new ThreadLocal<List<UserProvidedEnvironmentObject>>();
   transient protected ThreadLocal<String> authenticatedUserIdThreadLocal = new ThreadLocal<String>();
   
   transient protected CommandService userCommandService = null;
   
-  public ProcessEngineImpl() {
-    super((Configuration)null);
-  }
+  public ProcessEngineImpl(ConfigurationImpl configuration) {
+    configuration.producedProcessEngine = this;
 
-  public ProcessEngine buildProcessEngine() {
-    if (!isConfigured) {
-      setResource("jbpm.cfg.xml");
-    }
+    this.processEngineWireContext = configuration.getProcessEngineWireContext();
+    this.transactionWireDefinition = configuration.getTransactionWireDefinition();
     
-    if (jndiName!=null) {
-      try {
-        InitialContext initialContext = new InitialContext();
-        ProcessEngineImpl existing = (ProcessEngineImpl) initialContext.lookup(jndiName);
-        if (existing!=null) {
-          log.debug("found existing process engine under "+jndiName);
-          return existing;
-        }
-      } catch (NamingException e) {
-        log.debug("jndi name "+jndiName+" is not bound");
-      }
-    }
-    
     if (log.isTraceEnabled()) {
       log.trace("created ProcessEngine "+System.identityHashCode(this));
       if ( (processEngineWireContext!=null)
@@ -157,6 +126,7 @@
     processEngineWireContext.create();
     userCommandService = (CommandService) processEngineWireContext.get(CommandService.NAME_TX_REQUIRED_COMMAND_SERVICE);
 
+    String jndiName = configuration.getJndiName();
     if (jndiName!=null) {
       try {
         log.debug("publishing jBPM ProcessEngine in jndi at "+jndiName);
@@ -166,66 +136,12 @@
         throw new JbpmException("JNDI binding problem", e);
       }
     }
-    
-    checkDb();
 
-    return this;
-  }
-
-  protected void checkDb() {
-    if (checkDb) {
+    if (configuration.isCheckDb()) {
       userCommandService.execute(new CheckDbCmd());
     }
   }
 
-  public Configuration setHibernateSessionFactory(Object hibernateSessionFactory) {
-    processEngineWireContext
-        .getWireDefinition()
-        .addDescriptor(new ProvidedObjectDescriptor(hibernateSessionFactory, true));
-    return this;
-  }
-
-  public Configuration setInputStream(InputStream inputStream) {
-    parse(new InputStreamInput(inputStream));
-    return this;
-  }
-
-  public Configuration setResource(String resource) {
-    parse(new ResourceStreamInput(resource, getClassLoader()));
-    return this;
-  }
-
-  public Configuration setUrl(URL url) {
-    parse(new UrlStreamInput(url));
-    return this;
-  }
-
-  public Configuration setFile(File file) {
-    parse(new FileStreamInput(file));
-    return this;
-  }
-
-  public Configuration setXmlString(String xmlString) {
-    parse(new StringStreamInput(xmlString));
-    return this;
-  }
-
-
-  public static EnvironmentFactory parseXmlString(String xmlString) {
-    ProcessEngineImpl processEngineImpl = new ProcessEngineImpl();
-    processEngineImpl.setXmlString(xmlString);
-    return processEngineImpl;
-  }
-
-  protected void parse(StreamInput streamSource) {
-    isConfigured = true;
-    JbpmConfigurationParser.getInstance()
-      .createParse()
-      .contextStackPush(this)
-      .setStreamSource(streamSource)
-      .execute()
-      .checkErrors("jbpm configuration " + streamSource);
-  }
   
   public ExecutionService getExecutionService() {
     return get(ExecutionService.class);
@@ -373,16 +289,12 @@
   public <T> T execute(Command<T> command) {
     return userCommandService.execute(command);
   }
-  
-  public ProcessEngineImpl skipDbCheck() {
-    checkDb = false;
-    return this;
-  }
 
-  public String getJndiName() {
-    return jndiName;
+  // left in for legacy test code
+  public static EnvironmentFactory parseXmlString(String jbpmConfigurationXml) {
+    return (EnvironmentFactory) new ConfigurationImpl()
+        .setXmlString(jbpmConfigurationXml)
+        .skipDbCheck()
+        .buildProcessEngine();
   }
-  public void setJndiName(String jndiName) {
-    this.jndiName = jndiName;
-  }
 }

Copied: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringProcessEngine.java (from rev 5944, jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringConfiguration.java)
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringProcessEngine.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringProcessEngine.java	2009-12-11 17:20:24 UTC (rev 5956)
@@ -0,0 +1,114 @@
+/*
+ * 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.pvm.internal.cfg;
+
+import org.jbpm.api.ProcessEngine;
+import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.env.EnvironmentFactory;
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
+import org.jbpm.pvm.internal.env.PvmEnvironment;
+import org.jbpm.pvm.internal.env.SpringContext;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * this environment factory will see only the singleton beans.
+ * 
+ * The created {@link SpringEnvironment}s will see the prototype beans and it
+ * will cache them.
+ * 
+ * @author Andries Inze
+ */
+public class SpringProcessEngine extends ProcessEngineImpl implements EnvironmentFactory, ProcessEngine, ApplicationContextAware {
+
+  private static final Log log = Log.getLog(SpringProcessEngine.class.getName());
+  
+  private static final long serialVersionUID = 1L;
+
+  private ApplicationContext applicationContext;
+
+  public static ProcessEngine create() {
+    return create(ConfigurationImpl.DEFAULT_CONFIG_RESOURCENAME);
+  }
+  public static ProcessEngine create(String jbpmCfg) {
+    return new ConfigurationImpl()
+        .springInitiated()
+        .setResource(jbpmCfg)
+        .buildProcessEngine();
+  }
+
+  public SpringProcessEngine(ConfigurationImpl configuration) {
+    super(configuration);
+
+    if (!configuration.isInstantiatedFromSpring()) {
+      String springCfg = (String) configuration.getProcessEngineWireContext().get("spring.cfg");
+      if (springCfg==null) {
+        springCfg = "applicationContext.xml";
+      }
+      applicationContext = new ClassPathXmlApplicationContext(springCfg);
+    }
+  }
+
+  public EnvironmentImpl openEnvironment() {
+    PvmEnvironment environment = new PvmEnvironment(this);
+
+    if (log.isTraceEnabled())
+      log.trace("opening jbpm-spring" + environment);
+
+    environment.setContext(new SpringContext(applicationContext));
+
+    installAuthenticatedUserId(environment);
+    installProcessEngineContext(environment);
+    installTransactionContext(environment);
+
+    return environment;
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public <T> T get(Class<T> type) {
+    String[] names = applicationContext.getBeanNamesForType(type);
+    if (names.length == 1) {
+      return (T) applicationContext.getBean(names[0]);
+    }
+
+    return super.get(type);
+  }
+
+  @Override
+  public Object get(String key) {
+    if (applicationContext.containsBean(key)) {
+      return applicationContext.getBean(key);
+    }
+
+    return super.get(key);
+  }
+
+  public void setApplicationContext(ApplicationContext applicationContext) {
+    this.applicationContext = applicationContext;
+  }
+
+  public ApplicationContext getApplicationContext() {
+    return applicationContext;
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringProcessEngine.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + LF

Deleted: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/JbpmConfigurationParser.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/JbpmConfigurationParser.java	2009-12-11 15:02:25 UTC (rev 5955)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/JbpmConfigurationParser.java	2009-12-11 17:20:24 UTC (rev 5956)
@@ -1,130 +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.pvm.internal.env;
-
-import org.jbpm.pvm.internal.cfg.ProcessEngineImpl;
-import org.jbpm.pvm.internal.util.XmlUtil;
-import org.jbpm.pvm.internal.wire.WireDefinition;
-import org.jbpm.pvm.internal.wire.xml.WireParser;
-import org.jbpm.pvm.internal.xml.Parse;
-import org.jbpm.pvm.internal.xml.Parser;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-/** parses the <code>jbpm-configuration</code>, which is assumed the document element
- * and can contain the {@link EnvironmentFactoryXmlParser process-engine}
- * context and the {@link EnvironmentXmlParser environment} context.
- * 
- * See {@link Parser} for usage instructions.
- *   
- * @author Tom Baeyens
- */
-public class JbpmConfigurationParser extends Parser {
-
-  private static final long serialVersionUID = 1L;
-  
-  // private static Log log = Log.getLog(JbpmConfigurationParser.class.getName());
-
-  Parser processEngineContextParser = new WireParser();
-  Parser transactionContextParser = new WireParser();
-
-  protected static JbpmConfigurationParser INSTANCE = new JbpmConfigurationParser();
-  
-  public static JbpmConfigurationParser getInstance() {
-    return INSTANCE;
-  }
-
-  public Object parseDocument(Document document, Parse parse) {
-    Element documentElement = document.getDocumentElement();
-    
-    // if the default environment factory was already set in the parse
-    ProcessEngineImpl processEngine = (ProcessEngineImpl) parse.contextStackFind(ProcessEngineImpl.class);
-    if (processEngine==null) {
-      processEngine = new ProcessEngineImpl();
-    }
-    
-    // this code will be called for the original jbpm.cfg.xml document as 
-    // well as for the imported documents.  only one of those should specify
-    // a jndi-name.  for sure no 2 config files can specify different jndi-names
-    String jndiName = XmlUtil.attribute(documentElement, "jndi-name");
-    if (jndiName!=null) {
-      if ( (processEngine.getJndiName()!=null)
-           && (!jndiName.equals(processEngine.getJndiName()))
-         ) {
-        parse.addProblem("duplicate jndi name specification: "+jndiName+" != "+processEngine.getJndiName());
-      } else {
-        processEngine.setJndiName(jndiName);
-      }
-    }
-    
-    for (Element importElement : XmlUtil.elements(documentElement, "import")) {
-      if (importElement.hasAttribute("resource")) {
-        String resource = importElement.getAttribute("resource");
-        Parse importParse = createParse()
-          .setResource(resource)
-          .contextStackPush(processEngine)
-          .execute();
-        
-        parse.addProblems(importParse.getProblems());
-      }
-    }
-
-    Element processEngineElement = XmlUtil.element(documentElement, "process-engine-context");
-    if (processEngineElement != null) {
-      WireDefinition processEngineContextDefinition = processEngine.getProcessEngineWireContext().getWireDefinition();
-      parse.contextStackPush(processEngineContextDefinition);
-      try {
-        processEngineContextParser.parseDocumentElement(processEngineElement, parse);
-      } finally {
-        parse.contextStackPop();
-      }
-    }
-
-    Element txCtxElement = XmlUtil.element(documentElement, "transaction-context");
-    if (txCtxElement != null) {
-      WireDefinition transactionContextDefinition = processEngine.getTransactionWireDefinition();
-      parse.contextStackPush(transactionContextDefinition);
-      try {
-        transactionContextParser.parseDocumentElement(txCtxElement, parse);
-      } finally {
-        parse.contextStackPop();
-      }
-    }
-
-    parse.setDocumentObject(processEngine);
-    
-    return processEngine;
-  }
-
-  public Parser getProcessEngineContextParser() {
-    return processEngineContextParser;
-  }
-  public void setProcessEngineContextParser(Parser applicationWireXmlParser) {
-    this.processEngineContextParser = applicationWireXmlParser;
-  }
-  public Parser getTransactionContextParser() {
-    return transactionContextParser;
-  }
-  public void setTransactionContextParser(Parser blockWireXmlParser) {
-    this.transactionContextParser = blockWireXmlParser;
-  }
-}

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/EnvironmentInterceptorBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/EnvironmentInterceptorBinding.java	2009-12-11 15:02:25 UTC (rev 5955)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/EnvironmentInterceptorBinding.java	2009-12-11 17:20:24 UTC (rev 5956)
@@ -21,6 +21,7 @@
  */
 package org.jbpm.pvm.internal.wire.binding;
 
+import org.jbpm.pvm.internal.cfg.ConfigurationImpl;
 import org.jbpm.pvm.internal.cfg.ProcessEngineImpl;
 import org.jbpm.pvm.internal.env.EnvironmentFactory;
 import org.jbpm.pvm.internal.svc.Policy;
@@ -41,8 +42,8 @@
   public Object parse(Element element, Parse parse, Parser parser) {
     EnvironmentInterceptorDescriptor environmentInterceptorDescriptor = new EnvironmentInterceptorDescriptor();
 
-    EnvironmentFactory environmentFactory = (EnvironmentFactory) parse.contextStackFind(ProcessEngineImpl.class);
-    environmentInterceptorDescriptor.setEnvironmentFactory(environmentFactory);
+    ConfigurationImpl configuration = (ConfigurationImpl) parse.contextStackFind(ConfigurationImpl.class);
+    environmentInterceptorDescriptor.setConfiguration(configuration);
     
     if ( element.hasAttribute("policy")
          && ("requiresNew".equals(element.getAttribute("policy")))

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ProcessEngineRefBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ProcessEngineRefBinding.java	2009-12-11 15:02:25 UTC (rev 5955)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ProcessEngineRefBinding.java	2009-12-11 17:20:24 UTC (rev 5956)
@@ -21,7 +21,7 @@
  */
 package org.jbpm.pvm.internal.wire.binding;
 
-import org.jbpm.api.ProcessEngine;
+import org.jbpm.pvm.internal.cfg.ConfigurationImpl;
 import org.jbpm.pvm.internal.env.EnvironmentFactory;
 import org.jbpm.pvm.internal.wire.descriptor.ProcessEngineDescriptor;
 import org.jbpm.pvm.internal.xml.Parse;
@@ -42,7 +42,7 @@
   }
 
   public Object parse(Element element, Parse parse, Parser parser) {
-    ProcessEngine processEngine = (ProcessEngine) parse.contextStackFind(ProcessEngine.class);
-    return new ProcessEngineDescriptor(processEngine);
+    ConfigurationImpl configuration = (ConfigurationImpl) parse.contextStackFind(ConfigurationImpl.class);
+    return new ProcessEngineDescriptor(configuration);
   }
 }
\ No newline at end of file

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/EnvironmentInterceptorDescriptor.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/EnvironmentInterceptorDescriptor.java	2009-12-11 15:02:25 UTC (rev 5955)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/EnvironmentInterceptorDescriptor.java	2009-12-11 17:20:24 UTC (rev 5956)
@@ -21,6 +21,7 @@
  */
 package org.jbpm.pvm.internal.wire.descriptor;
 
+import org.jbpm.pvm.internal.cfg.ConfigurationImpl;
 import org.jbpm.pvm.internal.env.EnvironmentFactory;
 import org.jbpm.pvm.internal.svc.EnvironmentInterceptor;
 import org.jbpm.pvm.internal.svc.Policy;
@@ -33,10 +34,11 @@
 
   private static final long serialVersionUID = 1L;
   
-  protected EnvironmentFactory environmentFactory;
+  protected ConfigurationImpl configuration;
   protected Policy policy;
   
   public Object construct(WireContext wireContext) {
+    EnvironmentFactory environmentFactory = (EnvironmentFactory) configuration.getProducedProcessEngine();
     EnvironmentInterceptor environmentInterceptor = new EnvironmentInterceptor();
     environmentInterceptor.setEnvironmentFactory(environmentFactory);
     if (policy!=null) {
@@ -45,11 +47,10 @@
     return environmentInterceptor;
   }
 
-  public void setEnvironmentFactory(EnvironmentFactory environmentFactory) {
-    this.environmentFactory = environmentFactory;
-  }
-  
   public void setPolicy(Policy policy) {
     this.policy = policy;
   }
+  public void setConfiguration(ConfigurationImpl configuration) {
+    this.configuration = configuration;
+  }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ProcessEngineDescriptor.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ProcessEngineDescriptor.java	2009-12-11 15:02:25 UTC (rev 5955)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ProcessEngineDescriptor.java	2009-12-11 17:20:24 UTC (rev 5956)
@@ -1,6 +1,6 @@
 package org.jbpm.pvm.internal.wire.descriptor;
 
-import org.jbpm.api.ProcessEngine;
+import org.jbpm.pvm.internal.cfg.ConfigurationImpl;
 import org.jbpm.pvm.internal.env.EnvironmentFactory;
 import org.jbpm.pvm.internal.wire.WireContext;
 
@@ -13,13 +13,13 @@
 
   private static final long serialVersionUID = 1L;
   
-  protected ProcessEngine processEngine;
+  protected ConfigurationImpl configuration;
 
-  public ProcessEngineDescriptor(ProcessEngine processEngine) {
-    this.processEngine = processEngine;
+  public ProcessEngineDescriptor(ConfigurationImpl configuration) {
+    this.configuration = configuration;
   }
 
   public Object construct(WireContext wireContext) {
-    return processEngine;
+    return configuration.getProducedProcessEngine();
   }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.tx.spring.cfg.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.tx.spring.cfg.xml	2009-12-11 15:02:25 UTC (rev 5955)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.tx.spring.cfg.xml	2009-12-11 17:20:24 UTC (rev 5956)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
-<jbpm-configuration>
+<jbpm-configuration spring="enabled">
 
   <process-engine-context>
   

Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/TxTests.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/TxTests.java	2009-12-11 15:02:25 UTC (rev 5955)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/TxTests.java	2009-12-11 17:20:24 UTC (rev 5956)
@@ -21,14 +21,12 @@
  */
 package org.jbpm.pvm.internal.tx;
 
-import org.jbpm.api.Configuration;
-import org.jbpm.pvm.internal.cfg.ProcessEngineImpl;
-import org.jbpm.pvm.internal.env.EnvironmentFactory;
-import org.jbpm.pvm.internal.env.EnvironmentImpl;
-
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.jbpm.pvm.internal.cfg.ConfigurationImpl;
+import org.jbpm.pvm.internal.env.EnvironmentFactory;
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
 
 /**
  * @author Tom Baeyens
@@ -36,9 +34,10 @@
 public class TxTests {
   
   public static EnvironmentImpl openEnvironment(String xmlString) {
-    ProcessEngineImpl processEngineImpl = (ProcessEngineImpl) new Configuration().setXmlString(xmlString);
-    processEngineImpl.skipDbCheck();
-    EnvironmentFactory environmentFactory = (EnvironmentFactory) processEngineImpl.buildProcessEngine();
+    EnvironmentFactory environmentFactory = (EnvironmentFactory) new ConfigurationImpl()
+        .setXmlString(xmlString)
+        .skipDbCheck()
+        .buildProcessEngine();
     return environmentFactory.openEnvironment();
   }
 



More information about the jbpm-commits mailing list