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

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Feb 26 09:29:20 EST 2009


Author: ainze
Date: 2009-02-26 09:29:20 -0500 (Thu, 26 Feb 2009)
New Revision: 4049

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/jpdl/src/main/resources/jbpm.jpdl.activities.xml
   jbpm4/branches/ainze/modules/jpdl/src/main/resources/jbpm.jpdl.hbm.xml
   jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringConfiguration.java
Log:
initial spring integration

Modified: jbpm4/branches/ainze/modules/jpdl/pom.xml
===================================================================
--- jbpm4/branches/ainze/modules/jpdl/pom.xml	2009-02-26 13:40:29 UTC (rev 4048)
+++ jbpm4/branches/ainze/modules/jpdl/pom.xml	2009-02-26 14:29:20 UTC (rev 4049)
@@ -63,6 +63,11 @@
       </exclusions>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+    	<groupId>commons-beanutils</groupId>
+    	<artifactId>commons-beanutils</artifactId>
+    	<version>1.8.0</version>
+	</dependency> 
   </dependencies>
 
   <!-- Plugins -->

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-02-26 14:29:20 UTC (rev 4049)
@@ -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-02-26 14:29:20 UTC (rev 4049)
@@ -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/jpdl/src/main/resources/jbpm.jpdl.activities.xml
===================================================================
--- jbpm4/branches/ainze/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml	2009-02-26 13:40:29 UTC (rev 4048)
+++ jbpm4/branches/ainze/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml	2009-02-26 14:29:20 UTC (rev 4049)
@@ -14,4 +14,5 @@
   <activity binding="org.jbpm.jpdl.internal.activity.ScriptBinding" />
   <activity binding="org.jbpm.jpdl.internal.activity.EsbBinding" />
   <activity binding="org.jbpm.jpdl.internal.activity.TaskBinding" />
+  <activity binding="org.jbpm.jpdl.internal.activity.SpringBeanBinding" />
 </activities>

Modified: jbpm4/branches/ainze/modules/jpdl/src/main/resources/jbpm.jpdl.hbm.xml
===================================================================
--- jbpm4/branches/ainze/modules/jpdl/src/main/resources/jbpm.jpdl.hbm.xml	2009-02-26 13:40:29 UTC (rev 4048)
+++ jbpm4/branches/ainze/modules/jpdl/src/main/resources/jbpm.jpdl.hbm.xml	2009-02-26 14:29:20 UTC (rev 4049)
@@ -85,6 +85,7 @@
     <subclass name="org.jbpm.jpdl.internal.activity.TaskActivity" discriminator-value="task">
       <property name="assignee" column="TEXT_" />
     </subclass>
+    <subclass name="org.jbpm.jpdl.internal.activity.SpringBeanActivity" discriminator-value="spring" />
   </class>
 
 </hibernate-mapping>
\ No newline at end of file

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-02-26 13:40:29 UTC (rev 4048)
+++ jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringConfiguration.java	2009-02-26 14:29:20 UTC (rev 4049)
@@ -21,78 +21,113 @@
  */
 package org.jbpm.pvm.internal.cfg;
 
-import java.util.HashSet;
-import java.util.Set;
+import java.io.IOException;
 
+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.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.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
-  
-  private static final long serialVersionUID = 1L;
-  
-  ApplicationContext applicationContext;
-  
-  public SpringEnvironment openEnvironment() {
-    return new SpringEnvironment(this);
-  }
+public class SpringConfiguration extends JbpmConfiguration implements
+		EnvironmentFactory, ProcessEngine, ApplicationContextAware {
 
-  public boolean has(String key) {
-    return applicationContext.isSingleton(key);
-  }
+	private static final long serialVersionUID = 1L;
 
-  public Object get(String key) {
-    if (has(key)) {
-      return applicationContext.getBean(key);
-    }
-    return null;
-  }
+	private ApplicationContext applicationContext;
 
-  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);
-  }
+	private SessionFactory sessionFactory;
 
-  public Set<String> keys() {
-    HashSet<String> keys = new HashSet<String>();
-    for (String key : applicationContext.getBeanDefinitionNames()) {
-      if (has(key)) {
-        keys.add(key);
-      }
-    }
-    return keys;
-  }
-  
-  public ApplicationContext getApplicationContext() {
-    return applicationContext;
-  }
+	/**
+	 * Instantiates a new spring configuration.
+	 */
+	public SpringConfiguration(String jbpmConfigurationLocation) {
+		super();
+		try {
+			super.setInputStream(new ClassPathResource(
+					jbpmConfigurationLocation).getInputStream());
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+		super.buildProcessEngine();
+	}
 
-  public void setApplicationContext(ApplicationContext applicationContext) {
-    this.applicationContext = applicationContext;
-  }
+	/**
+	 * {@inheritDoc)
+	 */
+	@Override
+	public Environment openEnvironment() {
+		SpringPvmEnvironment environment = new SpringPvmEnvironment(this, applicationContext);
+		environment.setSessionFactory(sessionFactory);
 
-  
-  public void close() {
-  }
+		// FIXME: All beneath should be a super call
 
-  public String getName() {
-    return null;
-  }
+		// set the classloader
+		ClassLoader classLoader = environmentFactoryCtxWireContext
+				.getClassLoader();
+		if (classLoader != null) {
+			environment.setClassLoader(classLoader);
+		}
 
-  public Object set(String key, Object value) {
-    return null;
-  }
+		// add the process-engine context
+		environment.addContext(environmentFactoryCtxWireContext);
+
+		// add the environment block context
+	    WireContext environmentContext = new WireContext(environmentCtxWireDefinition, Context.CONTEXTNAME_TRANSACTION, environment, true);
+	    // add the environment block context to the environment
+	    environment.addContext(environmentContext);
+
+		Environment.pushEnvironment(environment);
+		try {
+			// finish the creation of the environment wire context
+			environmentContext.create();
+
+		} catch (RuntimeException e) {
+			Environment.popEnvironment();
+			throw e;
+		}
+
+		// if all went well, return the created environment
+		return environment;
+	}
+
+	/**
+	 * {@inheritDoc)
+	 */
+	public void setApplicationContext(ApplicationContext applicationContext) {
+		this.applicationContext = applicationContext;
+	}
+
+	/**
+	 * Gets the application context.
+	 * 
+	 * @return the application context
+	 */
+	public ApplicationContext getApplicationContext() {
+		return applicationContext;
+	}
+
+	/**
+	 * Sets the session factory.
+	 * 
+	 * @param sessionFactory
+	 *            the new session factory
+	 */
+	public void setSessionFactory(SessionFactory sessionFactory) {
+		this.sessionFactory = sessionFactory;
+	}
 }

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-02-26 14:29:20 UTC (rev 4049)
@@ -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




More information about the jbpm-commits mailing list