[jbpm-commits] JBoss JBPM SVN: r4311 - in jbpm4/branches/ainze/modules: jpdl/src/main/java/org/jbpm/jpdl/internal/activity and 4 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Mar 23 17:35:10 EDT 2009


Author: ainze
Date: 2009-03-23 17:35:09 -0400 (Mon, 23 Mar 2009)
New Revision: 4311

Added:
   jbpm4/branches/ainze/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SpringBeanActivity.java
   jbpm4/branches/ainze/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SpringBeanBinding.java
   jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/SpringPvmEnvironment.java
Modified:
   jbpm4/branches/ainze/modules/jpdl/pom.xml
   jbpm4/branches/ainze/modules/pvm/pom.xml
   jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringConfiguration.java
   jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringCommandService.java
Log:
non-working commit

Modified: jbpm4/branches/ainze/modules/jpdl/pom.xml
===================================================================
--- jbpm4/branches/ainze/modules/jpdl/pom.xml	2009-03-23 14:47:40 UTC (rev 4310)
+++ jbpm4/branches/ainze/modules/jpdl/pom.xml	2009-03-23 21:35:09 UTC (rev 4311)
@@ -1,100 +1,105 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!-- ====================================================================== -->
-<!--                                                                        -->
-<!--  JBoss, the OpenSource J2EE webOS                                      -->
-<!--                                                                        -->
-<!--  Distributable under LGPL license.                                     -->
-<!--  See terms of license at http://www.gnu.org.                           -->
-<!--                                                                        -->
-<!-- ====================================================================== -->
-
-<!-- $Id: pom.xml 1790 2008-07-31 12:13:06Z tom.baeyens at jboss.com $ -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
-  <modelVersion>4.0.0</modelVersion>
-
-  <name>jBPM 4 - jPDL</name>
-  <groupId>org.jbpm.jbpm4</groupId>
-  <artifactId>jbpm-jpdl</artifactId>
-  <packaging>jar</packaging>
-
-  <!-- Parent -->
-  <parent>
-    <groupId>org.jbpm.jbpm4</groupId>
-    <artifactId>jbpm</artifactId>
-    <version>4.0.0-SNAPSHOT</version>
-    <relativePath>../../pom.xml</relativePath>
-  </parent>
-
-  <!-- Properties -->
-  <properties>
-  </properties>
-
-  <!-- Dependencies -->
-  <dependencies>
-
-    <!-- JBPM4 -->
-    <dependency>
-      <groupId>org.jbpm.jbpm4</groupId>
-      <artifactId>jbpm-pvm</artifactId>
-      <version>${version}</version>
-    </dependency>
-
-    <!-- 3rd Party -->
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.jbpm.jbpm4.dependencies.esb</groupId>
-      <artifactId>jbossesb-rosetta</artifactId>
-      <exclusions>
-        <exclusion>
-          <groupId>stax</groupId>
-          <artifactId>stax-api</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>stax</groupId>
-          <artifactId>stax</artifactId>
-        </exclusion>
-      </exclusions>
-      <scope>provided</scope>
-    </dependency>
-  </dependencies>
-
-  <!-- Plugins -->
-  <build>
-    <plugins>
-      <plugin>
-        <artifactId>maven-surefire-plugin</artifactId>
-        <configuration>
-          <excludes>
-            <exclude>org/jbpm/test/xml/DbGenTest.java</exclude>            
-          </excludes>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
-
-  <!-- Profiles -->
-  <profiles>
-    <profile>
-      <id>distro</id>
-      <build>
-        <plugins>
-          <plugin>
-            <artifactId>maven-surefire-plugin</artifactId>
-            <configuration>
-              <skipTests>false</skipTests>
-            </configuration>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-
-  </profiles>
-
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- ====================================================================== -->
+<!--                                                                        -->
+<!--  JBoss, the OpenSource J2EE webOS                                      -->
+<!--                                                                        -->
+<!--  Distributable under LGPL license.                                     -->
+<!--  See terms of license at http://www.gnu.org.                           -->
+<!--                                                                        -->
+<!-- ====================================================================== -->
+
+<!-- $Id: pom.xml 1790 2008-07-31 12:13:06Z tom.baeyens at jboss.com $ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <name>jBPM 4 - jPDL</name>
+  <groupId>org.jbpm.jbpm4</groupId>
+  <artifactId>jbpm-jpdl</artifactId>
+  <packaging>jar</packaging>
+
+  <!-- Parent -->
+  <parent>
+    <groupId>org.jbpm.jbpm4</groupId>
+    <artifactId>jbpm</artifactId>
+    <version>4.0.0-SNAPSHOT</version>
+    <relativePath>../../pom.xml</relativePath>
+  </parent>
+
+  <!-- Properties -->
+  <properties>
+  </properties>
+
+  <!-- Dependencies -->
+  <dependencies>
+
+    <!-- JBPM4 -->
+    <dependency>
+      <groupId>org.jbpm.jbpm4</groupId>
+      <artifactId>jbpm-pvm</artifactId>
+      <version>${version}</version>
+    </dependency>
+
+    <!-- 3rd Party -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jbpm.jbpm4.dependencies.esb</groupId>
+      <artifactId>jbossesb-rosetta</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>stax</groupId>
+          <artifactId>stax-api</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>stax</groupId>
+          <artifactId>stax</artifactId>
+        </exclusion>
+      </exclusions>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+    	<groupId>commons-beanutils</groupId>
+    	<artifactId>commons-beanutils</artifactId>
+    	<version>1.8.0</version>
+	</dependency> 
+  </dependencies>
+
+  <!-- Plugins -->
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <excludes>
+            <exclude>org/jbpm/test/xml/DbGenTest.java</exclude>            
+          </excludes>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <!-- Profiles -->
+  <profiles>
+    <profile>
+      <id>distro</id>
+      <build>
+        <plugins>
+          <plugin>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <skipTests>false</skipTests>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+
+  </profiles>
+
 </project>
\ No newline at end of file

Added: jbpm4/branches/ainze/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SpringBeanActivity.java
===================================================================
--- jbpm4/branches/ainze/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SpringBeanActivity.java	                        (rev 0)
+++ jbpm4/branches/ainze/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SpringBeanActivity.java	2009-03-23 21:35:09 UTC (rev 4311)
@@ -0,0 +1,133 @@
+/*
+ * 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.jpdl.internal.activity;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.beanutils.MethodUtils;
+import org.jbpm.JbpmException;
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.env.Environment;
+import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.env.SpringPvmEnvironment;
+import org.jbpm.pvm.internal.wire.Descriptor;
+import org.jbpm.pvm.internal.wire.WireContext;
+import org.jbpm.pvm.internal.wire.descriptor.ListDescriptor;
+
+/**
+ * @author Andries Inze
+ */
+public class SpringBeanActivity extends JpdlActivity {
+
+	@SuppressWarnings("unused")
+	private static final Log LOG = Log.getLog(SpringBeanActivity.class
+			.getName());
+
+	private static final long serialVersionUID = 1L;
+
+	private String beanName;
+	private String methodName;
+	private ListDescriptor parametersListDescriptor;
+	private String resultVariableName;
+
+	public void execute(ActivityExecution execution) {
+		Environment environment = Environment.getCurrent();
+		
+		if (!(environment instanceof SpringPvmEnvironment)) {
+			throw new JbpmException("No spring environment is defined, " +
+					"which is needed for the " + SpringBeanBinding.TAG);
+		}
+		
+		if (environment == null) {
+			throw new JbpmException("no environment for jpdl activity "
+					+ SpringBeanBinding.TAG);
+		}
+		
+		if (beanName == null || beanName.equals("")) {
+			throw new JbpmException("No beanName was specified!");
+		}
+		
+		SpringPvmEnvironment springEnvironment = (SpringPvmEnvironment) environment;
+		Object o = springEnvironment.get(beanName);
+		
+		if (o == null) {
+			throw new JbpmException("No bean could be found in the applicationContext with name " + beanName); 
+		}
+		
+		
+		List<Object> parameters = new ArrayList<Object>();
+	    if (parametersListDescriptor!=null) {
+	        for (Descriptor valueDescriptor : parametersListDescriptor
+					.getValueDescriptors()) {
+				String parameterName = valueDescriptor.getName();
+				Object value = WireContext.create(valueDescriptor);
+				parameters.add(value);
+			}
+	    }
+		
+	    Object result;
+		try {
+			result = MethodUtils.invokeMethod(o, methodName, parameters.toArray());
+		} catch (NoSuchMethodException e) {
+			throw new JbpmException("No method found with beanName: " + beanName + ", methodName=" + methodName + " and parameters=" + parameters);
+		} catch (IllegalAccessException e) {
+			throw new JbpmException("Illegal access with beanName: " + beanName + ", methodName=" + methodName + " and parameters=" + parameters);
+		} catch (InvocationTargetException e) {
+			throw new JbpmException("InvocationTargetException with beanName: " + beanName + ", methodName=" + methodName + " and parameters=" + parameters);
+		}
+		
+		execution.setVariable(resultVariableName, result);
+		
+		execution.historyAutomatic();
+	}
+
+	public void setResultVariableName(String resultVariableName) {
+		this.resultVariableName = resultVariableName;
+	}
+
+	/**
+	 * @param beanName
+	 *            the beanName to set
+	 */
+	public void setBeanName(String beanName) {
+		this.beanName = beanName;
+	}
+
+	/**
+	 * @param methodName
+	 *            the methodName to set
+	 */
+	public void setMethodName(String methodName) {
+		this.methodName = methodName;
+	}
+
+	/**
+	 * @param parametersListDescriptor
+	 *            the parametersListDescriptor to set
+	 */
+	public void setParametersListDescriptor(
+			ListDescriptor parametersListDescriptor) {
+		this.parametersListDescriptor = parametersListDescriptor;
+	}
+}


Property changes on: jbpm4/branches/ainze/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SpringBeanActivity.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jbpm4/branches/ainze/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SpringBeanBinding.java
===================================================================
--- jbpm4/branches/ainze/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SpringBeanBinding.java	                        (rev 0)
+++ jbpm4/branches/ainze/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SpringBeanBinding.java	2009-03-23 21:35:09 UTC (rev 4311)
@@ -0,0 +1,120 @@
+/*
+ * 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.jpdl.internal.activity;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jbpm.pvm.internal.util.XmlUtil;
+import org.jbpm.pvm.internal.wire.Descriptor;
+import org.jbpm.pvm.internal.wire.descriptor.ListDescriptor;
+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.Element;
+
+/**
+ * @author Andries Inze
+ */
+public class SpringBeanBinding extends JpdlActivityBinding {
+
+	public static final String TAG = "spring";
+
+	public SpringBeanBinding() {
+		super(TAG);
+	}
+
+	protected SpringBeanBinding(String tagName) {
+		super(tagName);
+	}
+
+	public Object parse(Element element, Parse parse, Parser parser) {
+		SpringBeanActivity springActivity = createSpringBeanActivity();
+
+		Element beanElement = XmlUtil.element(element, "bean", true, parse);
+		if (beanElement != null) {
+			String bean = XmlUtil.getContentText(beanElement);
+			springActivity.setBeanName(bean);
+		}
+		
+		Element methodElement = XmlUtil.element(element, "method", true, parse);
+		if (beanElement != null) {
+			String method = XmlUtil.getContentText(methodElement);
+			springActivity.setMethodName(method);
+		}
+		
+	    Element parametersElement = XmlUtil.element(element, "parameters");
+	    List<Element> paramElements = XmlUtil.elements(parametersElement);
+	    if (!paramElements.isEmpty()) {
+	      List<Descriptor> parametersDescriptor = new ArrayList<Descriptor>();
+	      for (Element paramElement: paramElements) {
+	        WireParser wireParser = WireParser.getInstance();
+	        Descriptor paramDescriptor = (Descriptor) wireParser.parseElement(paramElement, parse, WireParser.CATEGORY_DESCRIPTOR);
+	        parametersDescriptor.add(paramDescriptor);
+	      }
+
+	      ListDescriptor parametersListDescriptor = new ListDescriptor();
+	      parametersListDescriptor.setValueDescriptors(parametersDescriptor);
+	      springActivity.setParametersListDescriptor(parametersListDescriptor);
+	    }
+
+		// HqlActivity hqlActivity = createHqlActivity();
+		//    
+		// Element queryElement = XmlUtil.element(element, "query", true,
+		// parse);
+		// if (queryElement!=null) {
+		// String query = XmlUtil.getContentText(queryElement);
+		// hqlActivity.setQuery(query);
+		// }
+		//    
+		// if (XmlUtil.attributeBoolean(element, "unique", false, parse,
+		// Boolean.FALSE)) {
+		// hqlActivity.setResultUnique(true);
+		// }
+		//    
+		// String variableName = XmlUtil.attribute(element, "var", true, parse);
+		// hqlActivity.setResultVariableName(variableName);
+		//    
+		// Element parametersElement = XmlUtil.element(element, "parameters");
+		// List<Element> paramElements = XmlUtil.elements(parametersElement);
+		// if (!paramElements.isEmpty()) {
+		// List<Descriptor> parametersDescriptor = new ArrayList<Descriptor>();
+		// for (Element paramElement: paramElements) {
+		// WireParser wireParser = WireParser.getInstance();
+		// Descriptor paramDescriptor = (Descriptor)
+		// wireParser.parseElement(paramElement, parse,
+		// WireParser.CATEGORY_DESCRIPTOR);
+		// parametersDescriptor.add(paramDescriptor);
+		// }
+		//
+		// ListDescriptor parametersListDescriptor = new ListDescriptor();
+		// parametersListDescriptor.setValueDescriptors(parametersDescriptor);
+		// hqlActivity.setParametersDescriptor(parametersListDescriptor);
+		// }
+		//      
+		return springActivity;
+	}
+
+	protected SpringBeanActivity createSpringBeanActivity() {
+		return new SpringBeanActivity();
+	}
+}


Property changes on: jbpm4/branches/ainze/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SpringBeanBinding.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: jbpm4/branches/ainze/modules/pvm/pom.xml
===================================================================
--- jbpm4/branches/ainze/modules/pvm/pom.xml	2009-03-23 14:47:40 UTC (rev 4310)
+++ jbpm4/branches/ainze/modules/pvm/pom.xml	2009-03-23 21:35:09 UTC (rev 4311)
@@ -49,6 +49,10 @@
       <artifactId>jbpm-test-base</artifactId>
     </dependency>
 
+	<dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+    </dependency>
     <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>

Modified: jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringConfiguration.java
===================================================================
--- jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringConfiguration.java	2009-03-23 14:47:40 UTC (rev 4310)
+++ jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringConfiguration.java	2009-03-23 21:35:09 UTC (rev 4311)
@@ -21,85 +21,120 @@
  */
 package org.jbpm.pvm.internal.cfg;
 
-import java.util.HashSet;
+import java.io.IOException;
 import java.util.List;
-import java.util.Set;
 
+import org.hibernate.SessionFactory;
+import org.jbpm.ProcessEngine;
+import org.jbpm.env.Context;
 import org.jbpm.env.Environment;
 import org.jbpm.env.EnvironmentFactory;
 import org.jbpm.env.WireObject;
+import org.jbpm.pvm.internal.env.SpringPvmEnvironment;
 import org.jbpm.pvm.internal.spring.SpringEnvironment;
-import org.jbpm.pvm.internal.util.ReflectUtil;
+import org.jbpm.pvm.internal.wire.WireContext;
+import org.jbpm.pvm.internal.wire.WireDefinition;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
+import org.springframework.core.io.ClassPathResource;
 
-/** this environment factory will see only the singleton beans.
+/**
+ * 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 Tom Baeyens
+ * The created {@link SpringEnvironment}s will see the prototype beans and it
+ * will cache them.
+ * 
+ * @author Andries Inze
  */
-public class SpringConfiguration implements EnvironmentFactory, ApplicationContextAware {
-  
-  // TODO pull up the common behaviour between this class and the SpringEnvironmentContext
-  
+public class SpringConfiguration extends JbpmConfiguration implements EnvironmentFactory, ProcessEngine, ApplicationContextAware {
+
   private static final long serialVersionUID = 1L;
-  
-  ApplicationContext applicationContext;
-  
-  public SpringEnvironment openEnvironment() {
-    return new SpringEnvironment(this);
-  }
 
-  public boolean has(String key) {
-    return applicationContext.isSingleton(key);
-  }
+  private ApplicationContext applicationContext;
 
-  public Object get(String key) {
-    if (has(key)) {
-      return applicationContext.getBean(key);
+  private SessionFactory sessionFactory;
+
+  /**
+   * Instantiates a new spring configuration.
+   */
+  public SpringConfiguration(String jbpmConfigurationLocation) {
+    super();
+    try {
+      super.setInputStream(new ClassPathResource(jbpmConfigurationLocation).getInputStream());
+    } catch (IOException e) {
+      throw new RuntimeException(e);
     }
-    return null;
+    super.buildProcessEngine();
   }
 
-  public <T> T get(Class<T> type) {
-    String name = ReflectUtil.getUnqualifiedClassName(type);
-    name = name.substring(0, 1).toLowerCase() + name.substring(1);
-    return (T) get(name);
-  }
+  /**
+   * {@inheritDoc)
 
-  public Set<String> keys() {
-    HashSet<String> keys = new HashSet<String>();
-    for (String key : applicationContext.getBeanDefinitionNames()) {
-      if (has(key)) {
-        keys.add(key);
-      }
+   */
+  @Override
+  public Environment openEnvironment(List<WireObject> txWireObjects) {
+    SpringPvmEnvironment environment = new SpringPvmEnvironment(this, applicationContext);
+    environment.setSessionFactory(sessionFactory);
+
+    // FIXME: All beneath should be a super call
+
+    // set the classloader
+    ClassLoader classLoader = environmentFactoryCtxWireContext.getClassLoader();
+    if (classLoader != null) {
+      environment.setClassLoader(classLoader);
     }
-    return keys;
+
+    // add the process-engine context
+    environment.addContext(environmentFactoryCtxWireContext);
+
+    // add the transaction context
+    WireDefinition usedWireDefinition = transactionCtxWireDefinition;
+    if (txWireObjects != null) {
+      usedWireDefinition = new WireDefinition(transactionCtxWireDefinition, txWireObjects);
+    }
+
+    WireContext transactionContext = new WireContext(usedWireDefinition, Context.CONTEXTNAME_TRANSACTION, environment, true);
+    // add the environment block context to the environment
+    environment.addContext(transactionContext);
+
+    Environment.pushEnvironment(environment);
+    try {
+      // finish the creation of the environment wire context
+      transactionContext.create();
+
+    } catch (RuntimeException e) {
+      Environment.popEnvironment();
+      throw e;
+    }
+
+    // if all went well, return the created environment
+    return environment;
   }
-  
-  public ApplicationContext getApplicationContext() {
-    return applicationContext;
-  }
 
+  /**
+   * {@inheritDoc)
+
+   */
   public void setApplicationContext(ApplicationContext applicationContext) {
     this.applicationContext = applicationContext;
   }
 
-  
-  public void close() {
+  /**
+   * Gets the application context.
+   * 
+   * @return the application context
+   */
+  public ApplicationContext getApplicationContext() {
+    return applicationContext;
   }
 
-  public String getName() {
-    return null;
+  /**
+   * Sets the session factory.
+   * 
+   * @param sessionFactory
+   *          the new session factory
+   */
+  public void setSessionFactory(SessionFactory sessionFactory) {
+    this.sessionFactory = sessionFactory;
   }
-
-  public Object set(String key, Object value) {
-    return null;
-  }
-
-  public Environment openEnvironment(List<WireObject> txWireObjects) {
-    return null;
-  }
 }

Added: jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/SpringPvmEnvironment.java
===================================================================
--- jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/SpringPvmEnvironment.java	                        (rev 0)
+++ jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/SpringPvmEnvironment.java	2009-03-23 21:35:09 UTC (rev 4311)
@@ -0,0 +1,64 @@
+package org.jbpm.pvm.internal.env;
+
+import org.hibernate.SessionFactory;
+import org.jbpm.pvm.internal.cfg.JbpmConfiguration;
+import org.springframework.context.ApplicationContext;
+
+/**
+ * The Spring environment resolves beans from the Spring applicationContext.
+ * 
+ * 
+ * @author Andries Inze
+ */
+public class SpringPvmEnvironment extends PvmEnvironment {
+
+	/** Needed for serialization. */
+	private static final long serialVersionUID = 6616989989982030327L;
+	
+	private SessionFactory sessionFactory;
+	
+	private ApplicationContext applicationContext;
+	
+	public SpringPvmEnvironment(JbpmConfiguration jbpmConfiguration, ApplicationContext applicationContext) {
+		super(jbpmConfiguration);
+		this.applicationContext = applicationContext;
+	}
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public <T> T get(Class<T> type) {
+		if (sessionFactory != null && type.equals(SessionFactory.class)) {
+			return (T) sessionFactory;
+		}
+		return super.get(type);
+	}
+	
+	
+
+	/**
+	 * {@inheritDoc)
+	 */
+	@Override
+	public Object get(String name) {
+		if (applicationContext.containsBean(name)) {
+			return applicationContext.getBean(name);
+		}
+		return super.get(name);
+	}
+
+	/**
+	 * Sets the session factory.
+	 * 
+	 * @param sessionFactory the new session factory
+	 */
+	public void setSessionFactory(SessionFactory sessionFactory) {
+		this.sessionFactory = sessionFactory;
+	}
+
+	/**
+	 * @param applicationContext the applicationContext to set
+	 */
+	public void setApplicationContext(ApplicationContext applicationContext) {
+		this.applicationContext = applicationContext;
+	}
+}
\ No newline at end of file


Property changes on: jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/SpringPvmEnvironment.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringCommandService.java
===================================================================
--- jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringCommandService.java	2009-03-23 14:47:40 UTC (rev 4310)
+++ jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringCommandService.java	2009-03-23 21:35:09 UTC (rev 4311)
@@ -21,38 +21,46 @@
  */
 package org.jbpm.pvm.internal.spring;
 
-import org.hibernate.Session;
+import org.apache.commons.lang.StringUtils;
 import org.jbpm.cmd.Command;
 import org.jbpm.cmd.CommandService;
-import org.jbpm.env.Environment;
 import org.jbpm.env.EnvironmentFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
 import org.springframework.orm.hibernate3.HibernateTransactionManager;
-import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
 import org.springframework.transaction.support.TransactionTemplate;
 
-
 /**
- * @author Tom Baeyens
+ * CommandService which uses the Spring TransactionTemplate
+ * to wrap any command into a transaction.
+ * 
+ * @author Andries Inze
  */
-public class SpringCommandService implements CommandService {
-  
-  TransactionTemplate transactionTemplate;
-  EnvironmentFactory environmentFactory;
-  
-  public void setEnvironmentFactory(EnvironmentFactory environmentFactory) {
-    this.environmentFactory = environmentFactory;
-  }
+public class SpringCommandService implements CommandService,
+		ApplicationContextAware {
 
-  public void setTransactionManager(HibernateTransactionManager transactionManager) {
-    this.transactionTemplate = new TransactionTemplate(transactionManager);
-  }
-  
-  public <T> T execute(Command<T> command) {
-    return (T) transactionTemplate.execute(
-        new CommandTransactionCallback(command, environmentFactory)
-    );
-  }
-  
-  
+	private TransactionTemplate transactionTemplate;
+	private String configurationBeanName;
+	private ApplicationContext applicationContext;
 
+	@SuppressWarnings("unchecked")
+	public <T> T execute(Command<T> command) {
+		return (T) transactionTemplate.execute(new CommandTransactionCallback(
+				command, (EnvironmentFactory) applicationContext
+						.getBean(StringUtils.defaultIfEmpty(
+								configurationBeanName, "configuration"))));
+	}
+
+	public void setTransactionManager(
+			HibernateTransactionManager transactionManager) {
+		this.transactionTemplate = new TransactionTemplate(transactionManager);
+	}
+
+	public void setApplicationContext(ApplicationContext applicationContext) {
+		this.applicationContext = applicationContext;
+	}
+
+	public void setConfigurationBeanName(String configurationBeanName) {
+		this.configurationBeanName = configurationBeanName;
+	}
 }




More information about the jbpm-commits mailing list