[jboss-svn-commits] JBL Code SVN: r11197 - in labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal: preprocessors and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Apr 21 18:30:21 EDT 2007


Author: estebanschifman
Date: 2007-04-21 18:30:21 -0400 (Sat, 21 Apr 2007)
New Revision: 11197

Added:
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/DeployProcessDefinitionFacade.java
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/FacadeUtil.java
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/GetProcessInstanceFacade.java
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/GetTaskInstanceFacade.java
   labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/VariableMapping.java
Log:


Added: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/DeployProcessDefinitionFacade.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/DeployProcessDefinitionFacade.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/DeployProcessDefinitionFacade.java	2007-04-21 22:30:21 UTC (rev 11197)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.jboss.soa.esb.services.jbpm.internal.facades;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.jbpm.Constants;
+import org.jboss.soa.esb.services.jbpm.Constants.OpCode;
+import org.jboss.soa.esb.services.jbpm.actions.SingleCommandProcessor;
+import org.jboss.soa.esb.util.Util;
+import org.jbpm.graph.def.ProcessDefinition;
+
+/**
+ *
+ * Implementation of a message preprocessor that obtains the process definition 
+ * from the action configuration XML
+ * 
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a> 
+ */
+public class DeployProcessDefinitionFacade implements SingleCommandProcessor.MessageFacade
+{
+	public OpCode getOpCode() { return Constants.OpCode.DeployProcessDefinition; }
+
+	public DeployProcessDefinitionFacade(ConfigTree config) throws ConfigurationException
+	{
+		ConfigTree[] childs = config.getChildren(Constants.PROCESS_DEFINITION_XML_TAG);
+		if (null==childs || childs.length<1)
+			throw new ConfigurationException("Missing or invalid <"+Constants.PROCESS_DEFINITION_XML_TAG+"> element");
+		if (childs.length>1)
+			throw new ConfigurationException("Only one <"+Constants.PROCESS_DEFINITION_XML_TAG+"> element can be specified");
+
+		String version 	= childs[0].getAttribute("version");
+		String encoding = childs[0].getAttribute("encoding");
+		if (Util.isNullString(version) || Util.isNullString(encoding))
+			throw new ConfigurationException("Wrong 'version' or 'encoding' attribute in <"+Constants.PROCESS_DEFINITION_XML_TAG+">");
+		StringBuilder sb = new StringBuilder("<?xml version='").append(version)
+			.append("' encoding='").append(encoding).append("' ?>\n")
+		;
+
+		ConfigTree[] def = childs[0].getChildren("process-definition");
+		if (null==def || def.length<1)
+			throw new ConfigurationException("Missing or invalid <process-definition> element");
+		if (def.length>1)
+			throw new ConfigurationException("Only one <process-definition> element can be specified");
+
+		final String xmlString = sb.append(def[0].toString()).toString();
+		try
+		{
+			_processDef = ProcessDefinition.parseXmlString(xmlString);
+		}
+		catch (Exception e)
+		{
+			throw new ConfigurationException(e);
+		}
+	} // ________________________________
+	
+	public void preFormat(Message message) 
+	{
+		message.getBody().add(Constants.COMMAND_CODE,getOpCode().toString());
+		message.getBody().add(Constants.PROCESS_DEFINITION, _processDef);
+	} // ________________________________
+    
+	public Message postFormat(Message message) 
+	{
+		return message;
+	} // ________________________________
+    
+	ProcessDefinition _processDef;
+}


Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/DeployProcessDefinitionFacade.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/FacadeUtil.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/FacadeUtil.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/FacadeUtil.java	2007-04-21 22:30:21 UTC (rev 11197)
@@ -0,0 +1,101 @@
+package org.jboss.soa.esb.services.jbpm.internal.facades;
+
+import java.util.Map;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.jbpm.Constants;
+import org.jboss.soa.esb.services.jbpm.actions.SingleCommandProcessor;
+import org.jboss.soa.esb.util.Util;
+import org.jbpm.graph.exe.ProcessInstance;
+
+public class FacadeUtil 
+{
+	static Boolean getBooleanElement(ConfigTree tree, String tag) 
+		throws ConfigurationException
+	{
+		ConfigTree[] childs = tree.getChildren(tag);
+		if (null==childs || childs.length<1)
+			return null;
+		if (childs.length>1)
+			throw new ConfigurationException("Only one <"+tag
+					+"> element allowed in configuration");
+		try
+		{
+			return Boolean.parseBoolean(childs[0].getAttribute("value"));
+		}
+		catch (Exception e)
+		{
+			throw new ConfigurationException("<"+tag
+					+"> must have a 'value' attribute containing 'true' or 'false'");
+		}
+	} //________________________________
+
+	static VariableMapping getVariableMapping(ConfigTree tree, boolean acceptValue)
+		throws ConfigurationException
+	{
+		String tag = Constants.VARIABLES_TAG;
+		ConfigTree[] childs = tree.getChildren(tag);
+		if (null==childs || childs.length<1)
+			return null;
+		if (childs.length>1)
+			throw new ConfigurationException("Only one <"+tag
+					+"> element allowed in configuration");
+		
+		tag = Constants.ONE_VARIABLE_TAG;
+		childs	= childs[0].getChildren(tag);
+		if (null==childs || childs.length<1)
+			throw new ConfigurationException("At least one <"+tag
+					+"> child element required for <"+Constants.VARIABLES_TAG+">");
+		VariableMapping ret = new VariableMapping();
+		for (ConfigTree curr: childs)
+		{
+			String name		= curr.getAttribute("name");
+			String esbName	= curr.getAttribute(Constants.ESB_VARNAME_TAG);
+			String jbpmName	= curr.getAttribute(Constants.JBPM_VARNAME_TAG);
+			if (null!=name)
+			{
+				if (null!=esbName || null!=jbpmName)
+					throw new ConfigurationException("When 'name' is specified, neither '"
+							+Constants.JBPM_VARNAME_TAG+"' nor"
+							+Constants.ESB_VARNAME_TAG +"' are accepted");
+				esbName	= jbpmName	= name;
+			}
+			else
+			{
+				if (Util.isNullString(esbName) || Util.isNullString(jbpmName))
+					throw new ConfigurationException("Either 'name' or the pair '"
+							+Constants.JBPM_VARNAME_TAG+"' and"
+							+Constants.ESB_VARNAME_TAG +"' must be specified");
+			}
+			String value = curr.getAttribute("value");
+			if (! acceptValue && (null!=value))
+				throw new ConfigurationException("'value' attribute is incompatible with the '"
+							+tree.getAttribute(SingleCommandProcessor.COMMAND_ATTRIBUTE_TAG)
+							+"' command");
+
+			ret.setVariable(esbName, jbpmName, value);
+		}
+		return ret;
+	} //________________________________
+
+	@SuppressWarnings("unchecked")
+	static void jbpmVarsToMessage(Message message, VariableMapping mapping)
+	{
+		Body body = message.getBody();
+		ProcessInstance inst = (ProcessInstance)body.get(Constants.JBPM_RETURN_OBJECT);
+		if (null==inst)
+			return;
+		Map<String,Object> jbpmVars = inst.getContextInstance().getVariables();
+		for (Map.Entry<String, Object> curr: jbpmVars.entrySet())
+		{
+			String keyInMsg = (null==mapping) ? curr.getKey()
+					: mapping.getEsbName(curr.getKey());
+			body.add(keyInMsg, curr.getValue());
+		}
+	} // ________________________________
+    
+
+}


Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/FacadeUtil.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/GetProcessInstanceFacade.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/GetProcessInstanceFacade.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/GetProcessInstanceFacade.java	2007-04-21 22:30:21 UTC (rev 11197)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.jboss.soa.esb.services.jbpm.internal.facades;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.jbpm.Constants;
+import org.jboss.soa.esb.services.jbpm.Constants.OpCode;
+import org.jboss.soa.esb.services.jbpm.actions.SingleCommandProcessor;
+
+/**
+ *
+ * Implementation of a message preprocessor to obtain data from a process instance 
+ * from the action configuration XML
+ * 
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a> 
+ */
+public class GetProcessInstanceFacade implements SingleCommandProcessor.MessageFacade
+{
+	public OpCode getOpCode() { return Constants.OpCode.GetProcessInstanceCommand; }
+
+	public GetProcessInstanceFacade(ConfigTree config) throws ConfigurationException
+	{
+		_includeAllVars = FacadeUtil.getBooleanElement(config,Constants.INCLUDE_ALL_VARS_TAG);
+		_includeLogs	= FacadeUtil.getBooleanElement(config,Constants.INCLUDE_LOGS_TAG);
+		_variables		= FacadeUtil.getVariableMapping(config, false);
+	} // ________________________________
+	
+	public void preFormat(Message message) 
+	{
+		Body body = message.getBody();
+		if (null!=_includeLogs)
+			body.add(Constants.INCLUDE_LOGS		,_includeLogs);
+		
+		String key = Constants.INCLUDE_ALL_VARS_TAG;
+		// Currently, the jbpm GetProcessInstanceCommand does not accept a list of variables
+		// so, if configuration has a list of variables, we must bring'em all
+		if (null!=_variables)
+			body.add(key, true);
+		else if (null!=_includeAllVars)
+			body.add(key,_includeAllVars);
+	} // 
+    
+	public Message postFormat(Message response) 
+	{
+		if (null!=_variables)
+			FacadeUtil.jbpmVarsToMessage(response,_variables);
+		else if (null!=_includeAllVars && _includeAllVars)
+			FacadeUtil.jbpmVarsToMessage(response,null);
+		return response;
+	} // ________________________________
+	
+	Boolean 	_includeLogs;
+	Boolean 	_includeAllVars;
+	VariableMapping _variables;
+}


Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/GetProcessInstanceFacade.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/GetTaskInstanceFacade.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/GetTaskInstanceFacade.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/GetTaskInstanceFacade.java	2007-04-21 22:30:21 UTC (rev 11197)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.jboss.soa.esb.services.jbpm.internal.facades;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.jbpm.Constants;
+import org.jboss.soa.esb.services.jbpm.Constants.OpCode;
+import org.jboss.soa.esb.services.jbpm.actions.SingleCommandProcessor;
+
+/**
+ *
+ * Implementation of a message preprocessor to obtain data from a token instance 
+ * from the action configuration XML
+ * 
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a> 
+ */
+public class GetTaskInstanceFacade implements SingleCommandProcessor.MessageFacade
+{
+	public OpCode getOpCode() { return Constants.OpCode.GetTaskInstanceCommand; }
+
+	public GetTaskInstanceFacade(ConfigTree config) throws ConfigurationException
+	{
+		_includeAllVars = FacadeUtil.getBooleanElement(config,Constants.INCLUDE_ALL_VARS_TAG);
+		_includeLogs	= FacadeUtil.getBooleanElement(config,Constants.INCLUDE_LOGS_TAG);
+		_variables		= FacadeUtil.getVariableMapping(config, false);
+	} // ________________________________
+	
+	public void preFormat(Message message) 
+	{
+		Body body = message.getBody();
+		if (null!=_includeLogs)
+			body.add(Constants.INCLUDE_LOGS		,_includeLogs);
+		
+		String key = Constants.INCLUDE_ALL_VARS_TAG;
+		if (null!=_includeAllVars)
+			body.add(key,_includeAllVars);
+	} // 
+    
+	public Message postFormat(Message response) 
+	{
+		if (null!=_variables)
+			FacadeUtil.jbpmVarsToMessage(response,_variables);
+		else if (null!=_includeAllVars && _includeAllVars)
+			FacadeUtil.jbpmVarsToMessage(response,null);
+		return response;
+	} // ________________________________
+	
+	Boolean 	_includeLogs;
+	Boolean 	_includeAllVars;
+	VariableMapping _variables;
+}


Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/GetTaskInstanceFacade.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/VariableMapping.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/VariableMapping.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/VariableMapping.java	2007-04-21 22:30:21 UTC (rev 11197)
@@ -0,0 +1,61 @@
+package org.jboss.soa.esb.services.jbpm.internal.facades;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.soa.esb.util.Util;
+
+/**
+ * A container for variable names and values with access both by esb name and jbpm name.
+ * 
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a> 
+ *
+ */
+public class VariableMapping
+{
+	// internal key is always esb name
+	private Map<String,Object> _values 		= new HashMap<String, Object>();
+	// map jbpm names to esb names
+	private Map<String,String> _jbpmNames 	= new HashMap<String, String>();
+	// map esb names to jbpm names
+	private Map<String,String> _esbNames 	= new HashMap<String, String>();
+
+	public String setMapping(String esbName, String jbpmName)
+	{
+		if (Util.isNullString(esbName) && Util.isNullString(jbpmName))
+			throw new IllegalArgumentException("You must specify at least one valid variable name (esb or jBPM)");
+		if (Util.isNullString(jbpmName))
+			jbpmName = esbName;
+		if (Util.isNullString(esbName))
+			esbName = jbpmName;
+		String oldMapping = _esbNames.get(jbpmName);
+		if (null!=oldMapping && !oldMapping.equals(jbpmName))
+			throw new IllegalArgumentException
+			("Illegal mapping esb=<"+esbName+"> was mapped to jbpm=<"+oldMapping+ "> cannot remap to "+jbpmName);
+			
+		_esbNames	.put(esbName, jbpmName);
+		_jbpmNames	.put(jbpmName, esbName);
+		// Internally, esbName is the key to the variable values
+		return esbName;
+	}
+
+	public void setVariable(String esbName, String jbpmName, Object value)
+	{
+		_values		.put(setMapping(esbName, jbpmName), value);
+	}
+	
+	public String getEsbName	 (String key) { return _jbpmNames.get(key); }
+	public String getJbpmName	 (String key) { return _esbNames.get(key); }
+
+	public Object getEsbVariable (String key) { return _values.get(key); }
+	public Object getJbpmVariable(String key) { return _values.get(_jbpmNames.get(key)); }
+	
+	public Map<String,Object> esbVariables()  { return _values; }
+	public Map<String,Object> jbpmVariables() 
+	{ 
+		HashMap<String,Object> map = new HashMap<String, Object>();
+		for (Map.Entry<String, Object> curr: _values.entrySet())
+			map.put(_jbpmNames.get(curr.getKey()), curr.getValue());
+		return map;
+	}
+}


Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/preprocessors/VariableMapping.java
___________________________________________________________________
Name: svn:eol-style
   + native




More information about the jboss-svn-commits mailing list