[jboss-svn-commits] JBL Code SVN: r16705 - in labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src: main/java/org/jboss/soa/esb/services/jbpm/actionhandlers and 5 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Nov 20 11:21:22 EST 2007
Author: kurt.stam at jboss.com
Date: 2007-11-20 11:21:21 -0500 (Tue, 20 Nov 2007)
New Revision: 16705
Added:
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CancelProcessInstanceFacade.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/DeployProcessDefinitionFacade.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/FacadeUtil.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/MessageFacade.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/MessageHelper.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/NewProcessInstanceFacade.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/SignalFacade.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/VariableMapping.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/cmd/
Removed:
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/mapping/
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/util/
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/mapping/
Modified:
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandler.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/BpmProcessor.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandExecutor.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/BpmProcessorUnitTest.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/cmd/VariableMappingUnitTest.java
Log:
JBESB-1301 Moving code into their right package
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandler.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandler.java 2007-11-20 16:14:49 UTC (rev 16704)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandler.java 2007-11-20 16:21:21 UTC (rev 16705)
@@ -40,7 +40,7 @@
import org.jboss.soa.esb.message.format.MessageFactory;
import org.jboss.soa.esb.message.mapping.ObjectMapper;
import org.jboss.soa.esb.services.jbpm.Constants;
-import org.jboss.soa.esb.services.jbpm.mapping.MessageHelper;
+import org.jboss.soa.esb.services.jbpm.cmd.MessageHelper;
import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.def.Node;
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/BpmProcessor.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/BpmProcessor.java 2007-11-20 16:14:49 UTC (rev 16704)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/BpmProcessor.java 2007-11-20 16:21:21 UTC (rev 16705)
@@ -31,7 +31,7 @@
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.services.jbpm.Constants;
import org.jboss.soa.esb.services.jbpm.cmd.CommandExecutor;
-import org.jboss.soa.esb.services.jbpm.mapping.MessageFacade;
+import org.jboss.soa.esb.services.jbpm.cmd.MessageFacade;
import org.jbpm.JbpmException;
/**
Copied: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CancelProcessInstanceFacade.java (from rev 16704, labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/mapping/CancelProcessInstanceFacade.java)
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CancelProcessInstanceFacade.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CancelProcessInstanceFacade.java 2007-11-20 16:21:21 UTC (rev 16705)
@@ -0,0 +1,49 @@
+/*
+ * 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.cmd;
+
+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;
+
+/**
+ *
+ * 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 CancelProcessInstanceFacade extends MessageFacade
+{
+ public OpCode getOpCode() { return Constants.OpCode.CancelProcessInstanceCommand; }
+
+ public CancelProcessInstanceFacade(ConfigTree config) throws ConfigurationException
+ {
+ }
+
+ public void setJBPMContextParameters(Message message)
+ {
+ }
+}
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandExecutor.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandExecutor.java 2007-11-20 16:14:49 UTC (rev 16704)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandExecutor.java 2007-11-20 16:21:21 UTC (rev 16705)
@@ -30,7 +30,6 @@
import org.jboss.soa.esb.message.mapping.ObjectMapper;
import org.jboss.soa.esb.message.mapping.ObjectMappingException;
import org.jboss.soa.esb.services.jbpm.Constants;
-import org.jboss.soa.esb.services.jbpm.mapping.MessageHelper;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.JbpmException;
Copied: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/DeployProcessDefinitionFacade.java (from rev 16704, labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/mapping/DeployProcessDefinitionFacade.java)
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/DeployProcessDefinitionFacade.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/DeployProcessDefinitionFacade.java 2007-11-20 16:21:21 UTC (rev 16705)
@@ -0,0 +1,115 @@
+/*
+ * 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.cmd;
+
+import java.io.InputStream;
+
+import org.apache.log4j.Logger;
+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.BpmProcessor;
+import org.jboss.soa.esb.util.ClassUtil;
+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 extends MessageFacade
+{
+ public OpCode getOpCode() { return Constants.OpCode.DeployProcessDefinition; }
+
+ public DeployProcessDefinitionFacade(ConfigTree config) throws ConfigurationException
+ {
+ _fileName=config.getAttribute(Constants.PROCESS_DEFINITION_FILE_TAG);
+ ConfigTree[] childs = config.getChildren(Constants.PROCESS_DEFINITION_XML_TAG);
+
+ if (null!=_fileName)
+ {
+ if (childs.length>0)
+ throw new ConfigurationException
+ ("You can specify either '"+Constants.PROCESS_DEFINITION_FILE_TAG+"' attribute OR "
+ +Constants.PROCESS_DEFINITION_XML_TAG+"> element, but not both");
+
+ InputStream stream = ClassUtil.getResourceAsStream(_fileName, BpmProcessor.class);
+ _validProcessDef = ProcessDefinition.parseXmlInputStream(stream);
+ return;
+ }
+
+ if (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
+ {
+ _validProcessDef = ProcessDefinition.parseXmlString(xmlString);
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ public void setJBPMContextParameters(Message message)
+ {
+ if (null!= _fileName)
+ try
+ {
+ InputStream stream = ClassUtil.getResourceAsStream(_fileName, BpmProcessor.class);
+ _validProcessDef = ProcessDefinition.parseXmlInputStream(stream);
+ }
+ catch (Exception e)
+ {
+ _logger.info("Keeping previous process definition");
+ _logger.error("Invalid process definition file <"+_fileName+">",e);
+ }
+ message.getBody().add(Constants.PROCESS_DEFINITION, _validProcessDef);
+ }
+
+ protected String _fileName;
+ protected ProcessDefinition _validProcessDef;
+ private static final Logger _logger = Logger.getLogger(DeployProcessDefinitionFacade.class);
+}
Copied: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/FacadeUtil.java (from rev 16704, labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/mapping/FacadeUtil.java)
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/FacadeUtil.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/FacadeUtil.java 2007-11-20 16:21:21 UTC (rev 16705)
@@ -0,0 +1,136 @@
+/*
+ * 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.cmd;
+
+import java.util.HashMap;
+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.message.mapping.ObjectMapper;
+import org.jboss.soa.esb.message.mapping.ObjectMappingException;
+import org.jboss.soa.esb.services.jbpm.Constants;
+
+public class FacadeUtil
+{
+ static Boolean booleanFromConfig(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 variablesFromConfig(ConfigTree tree, boolean acceptValue)
+ throws ConfigurationException
+ {
+ VariableMapping ret = new VariableMapping();
+ ConfigTree[] objectList = tree.getChildren(Constants.OBJECT_PATH_TAG);
+ if (objectList != null) {
+ for (ConfigTree curr : objectList) {
+ String esbName = curr.getAttribute(Constants.ESB_VARNAME_TAG);
+ String jbpmName = curr.getAttribute(Constants.JBPM_VARNAME_TAG);
+ String value = curr.getAttribute("value");
+ ret.setVariable(esbName, jbpmName, value);
+ }
+ }
+ return ret;
+ }
+
+ static String[] actorsFromConfig(ConfigTree tree, boolean acceptValue)
+ throws ConfigurationException
+ {
+ String tag = Constants.ACTORS_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_ACTOR_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+">");
+ String[] ret = new String[childs.length];
+ int i1=0;
+ for (ConfigTree curr: childs)
+ {
+ String name = curr.getAttribute("name");
+ if (null==name)
+ {
+ throw new ConfigurationException
+ ("You must specify the 'name' attribute for all <"
+ +tag+"> element");
+ }
+ ret[i1++] = name;
+ }
+ return ret;
+ }
+
+
+ static void populateVariableValues (Message message, VariableMapping mapping)
+ {
+ if (null==mapping || mapping.size()<1)
+ return;
+
+ Body body = message.getBody();
+ HashMap<String,Object> map = new HashMap<String, Object>();
+ for (Map.Entry<String, Object> curr: mapping.esbVariables().entrySet())
+ {
+ String esbName = curr.getKey();
+ String jbpmName = mapping.getJbpmName(esbName);
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ Object value = null;
+ try {
+ value = objectMapper.getObjectFromMessage(message, esbName);
+ } catch (ObjectMappingException ome) {
+ throw new IllegalArgumentException(ome.getMessage(), ome);
+ }
+ // if object not found in body, use default value (from config)
+ if (null==value)
+ value = curr.getValue();
+ // only put it in the map if it's not null
+ if (null!=value)
+ map.put(jbpmName, value);
+ }
+ body.add(Constants.VARIABLE_VALUES, map);
+ }
+
+}
Copied: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/MessageFacade.java (from rev 16704, labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/mapping/MessageFacade.java)
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/MessageFacade.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/MessageFacade.java 2007-11-20 16:21:21 UTC (rev 16705)
@@ -0,0 +1,60 @@
+/**
+ *
+ */
+package org.jboss.soa.esb.services.jbpm.cmd;
+
+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.actions.BpmProcessor;
+
+/**
+ * @author kstam
+ *
+ */
+public abstract class MessageFacade
+{
+ /**
+ * Obtain the operation code that this preprocessor will force into the command message
+ * @return Constants.OpCode
+ */
+ public abstract Constants.OpCode getOpCode();
+ /**
+ * Some message values are fixed at action configuration time (from the jboss-esb.xml).
+ * <br/>This method is responsible of stuffing these static values into every Message
+ * before passing it to the generic CommandInterpreter process(Message) method
+ * <br/>Some of the Message content will thus come from configuration XML, and some will
+ * be the users' responsibility (e.g. processId, tokenId, etc)
+ * <br/>Variable name mapping between esb and jBPM is also handled by this interface
+ * @param message Message - Into which the static values will be added
+ */
+ public abstract void setJBPMContextParameters(Message request);
+
+
+ public static MessageFacade getFacade(ConfigTree config)
+ throws ConfigurationException, UnsupportedOperationException
+ {
+ Constants.OpCode opCode = null;
+ String sAux = config.getRequiredAttribute(BpmProcessor.COMMAND_ATTRIBUTE_TAG);
+ try { opCode = Constants.OpCode.valueOf(sAux); }
+ catch (IllegalArgumentException e)
+ {
+ throw new ConfigurationException("Attribute '"+BpmProcessor.COMMAND_ATTRIBUTE_TAG+"' has an invalid value"
+ +"- see CommandVehicle.Operation enum for possible values");
+ }
+
+ if (Constants.OpCode.CancelProcessInstanceCommand.equals(opCode))
+ return new CancelProcessInstanceFacade(config);
+ if (Constants.OpCode.NewProcessInstanceCommand.equals(opCode))
+ return new NewProcessInstanceFacade(config, false);
+ if (Constants.OpCode.SignalCommand.equals(opCode))
+ return new SignalFacade(config);
+ if (Constants.OpCode.StartProcessInstanceCommand.equals(opCode))
+ return new NewProcessInstanceFacade(config, true);
+ if (Constants.OpCode.DeployProcessDefinition.equals(opCode))
+ return new DeployProcessDefinitionFacade(config);
+
+ throw new UnsupportedOperationException(opCode.toString()+" not implemented");
+ }
+}
Copied: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/MessageHelper.java (from rev 16704, labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/mapping/MessageHelper.java)
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/MessageHelper.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/MessageHelper.java 2007-11-20 16:21:21 UTC (rev 16705)
@@ -0,0 +1,148 @@
+package org.jboss.soa.esb.services.jbpm.cmd;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+/**
+ * Convient Helper to set or set parameters on an EsbMessage.
+ * @author kstam
+ *
+ */
+public class MessageHelper
+{
+ private static Logger _logger = Logger.getLogger(MessageHelper.class);
+
+ public static String argumentException(String str)
+ {
+ return new String("Missing or invalid <"+str+"> object in Message body");
+ }
+
+ public static Message commandMessageTemplate()
+ {
+ Message template = MessageFactory.getInstance().getMessage();
+ URI uri = null;
+ try { uri = new URI(UUID.randomUUID().toString()); }
+ catch (URISyntaxException e)
+ {
+ _logger.fatal("Problem with UUID.randomUUID() - This should not happen");
+ return null;
+ }
+ template.getHeader().getCall().setMessageID(uri);
+
+ return template;
+ }
+
+ public static void setLongValue(Message message, String key, Long value)
+ {
+ setObjectValue(message, key, value);
+ }
+ public static void setIntValue(Message message, String key, Integer value)
+ {
+ setObjectValue(message, key, value);
+ }
+ public static void setBooleanValue(Message message, String key, Boolean value)
+ {
+ setObjectValue(message, key, value);
+ }
+ public static void setObjectValue(Message message, String key, Object value)
+ {
+ message.getBody().add(key, value);
+ }
+
+ public static void setStringValue(Message msg,String key,Object obj)
+ {
+ setStringValue(msg, key, obj.toString());
+ }
+
+ public static void setStringValue(Message msg,String key,String str)
+ {
+ setObjectValue(msg, key, str);
+ }
+
+ public static void setStringListValue(Message msg,String key,String[] list)
+ {
+ boolean addComma = false;
+ StringBuilder sb = new StringBuilder();
+ for (String curr : list)
+ {
+ sb.append((addComma)?",":"").append(curr);
+ addComma = true;
+ }
+ setObjectValue(msg,key, sb.toString());
+ }
+
+ public static void setVariablesMap(Message msg,String key,Map<String,Object> value)
+ {
+ msg.getBody().add(key, value);
+ }
+
+ public static Integer getIntValue(Message msg,String key)
+ {
+ Object obj = msg.getBody().get(key);
+ if (obj instanceof Integer) return (Integer)obj;
+ if (obj instanceof String) return Integer.parseInt((String)obj);
+ _logger.error(argumentException(key));
+ return null;
+ }
+
+ public static Long getLongValue(Message msg,String key)
+ {
+ Object obj = msg.getBody().get(key);
+ if (null==obj) return null;
+ if (obj instanceof Long) return (Long)obj;
+ if (obj instanceof String) return Long.parseLong((String)obj);
+ if (obj instanceof Integer) return new Long(obj.toString());
+ _logger.error(argumentException(key));
+ return null;
+ }
+
+ public static Boolean getBooleanValue(Message msg,String key)
+ {
+ return getBooleanValue(msg, key, null);
+ }
+
+ public static Boolean getBooleanValue(Message msg,String key, Boolean dflt)
+ {
+ Object obj = msg.getBody().get(key);
+ if (null==obj) return dflt;
+ if (obj instanceof Boolean) return (Boolean)obj;
+ if (obj instanceof String) return Boolean.parseBoolean((String)obj);
+ _logger.error(argumentException(key));
+ return null;
+ }
+
+ public static String getStringValue(Message msg,String key)
+ {
+ return getStringValue(msg, key, null);
+ }
+
+ public static String getStringValue(Message msg,String key, String dflt)
+ {
+ Object obj = msg.getBody().get(key);
+ if (null==obj) return dflt;
+ if (obj instanceof String) return (String)obj;
+ _logger.error(argumentException(key));
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static Map<String,Object>getVariablesMap(Message msg,String key)
+ {
+ Object obj = msg.getBody().get(key);
+ if (null==obj) return null;
+ if (obj instanceof Map) return (Map<String,Object>)obj;
+ _logger.error(argumentException(key));
+ return null;
+ }
+
+ public static Object getObjectValue(Message msg,String key)
+ {
+ return msg.getBody().get(key);
+ }
+
+}
Copied: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/NewProcessInstanceFacade.java (from rev 16704, labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/mapping/NewProcessInstanceFacade.java)
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/NewProcessInstanceFacade.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/NewProcessInstanceFacade.java 2007-11-20 16:21:21 UTC (rev 16705)
@@ -0,0 +1,91 @@
+/*
+ * 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.cmd;
+
+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;
+
+/**
+ *
+ * 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 NewProcessInstanceFacade extends MessageFacade
+{
+ public OpCode getOpCode()
+ {
+ return (_start)
+ ?Constants.OpCode.StartProcessInstanceCommand
+ :Constants.OpCode.NewProcessInstanceCommand;
+ }
+
+ public NewProcessInstanceFacade(ConfigTree config, boolean start) throws ConfigurationException
+ {
+ _start = start;
+ _actor = config.getAttribute(Constants.ONE_ACTOR_TAG);
+ _processName= config.getAttribute(Constants.PROCESS_DEFINITION_NAME_TAG);
+ _keyPath = config.getAttribute(Constants.KEY_TAG);
+ String aux = config.getAttribute(Constants.PROCESS_DEFINITION_ID_TAG);
+ if (null!=aux)
+ try {_processId = Long.parseLong(aux); }
+ catch(NumberFormatException e)
+ {
+ throw new ConfigurationException("Invalid value for '"+Constants.PROCESS_DEFINITION_ID_TAG+"'");
+ }
+ _variables = FacadeUtil.variablesFromConfig(config, true);
+
+ if (_start)
+ _transitionName = config.getAttribute(Constants.TRANSITION_NAME_TAG);
+ }
+
+ public void setJBPMContextParameters(Message message)
+ {
+ Body body = message.getBody();
+ if (null!=_keyPath)
+ body.add(Constants.KEYPATH, _keyPath);
+ if (null!=_actor)
+ body.add(Constants.ACTOR_ID ,_actor);
+ if (null!=_processName)
+ body.add(Constants.PROCESS_DEFINITION_NAME ,_processName);
+ if (null!=_processId)
+ body.add(Constants.PROCESS_DEFINITION_ID ,_processId);
+ if (null!=_transitionName)
+ body.add(Constants.TRANSITION_NAME, _transitionName);
+
+ FacadeUtil.populateVariableValues(message,_variables);
+ }
+
+ boolean _start;
+ String _keyPath;
+ String _actor;
+ String _processName;
+ String _transitionName;
+ Long _processId;
+ VariableMapping _variables;
+}
Copied: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/SignalFacade.java (from rev 16704, labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/mapping/SignalFacade.java)
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/SignalFacade.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/SignalFacade.java 2007-11-20 16:21:21 UTC (rev 16705)
@@ -0,0 +1,59 @@
+/*
+ * 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.cmd;
+
+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;
+
+/**
+ *
+ * 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 SignalFacade extends MessageFacade
+{
+ public OpCode getOpCode() { return Constants.OpCode.SignalCommand; }
+
+ public SignalFacade(ConfigTree config) throws ConfigurationException
+ {
+ _transition = config.getAttribute(Constants.TRANSITION_NAME_TAG);
+ _variables = FacadeUtil.variablesFromConfig(config, false);
+ }
+
+ public void setJBPMContextParameters(Message message)
+ {
+ Body body = message.getBody();
+ if (null!=_transition)
+ body.add(Constants.TRANSITION_NAME, _transition);
+ FacadeUtil.populateVariableValues(message, _variables);
+ }
+
+ String _transition;
+ VariableMapping _variables;
+}
Copied: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/VariableMapping.java (from rev 16704, labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/mapping/VariableMapping.java)
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/VariableMapping.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/VariableMapping.java 2007-11-20 16:21:21 UTC (rev 16705)
@@ -0,0 +1,66 @@
+package org.jboss.soa.esb.services.jbpm.cmd;
+
+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 int size() { return _values.size(); }
+
+ private 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 bpm)");
+ if (Util.isNullString(jbpmName))
+ jbpmName = getName(esbName);
+ if (Util.isNullString(esbName))
+ esbName = getName(jbpmName);
+ String oldMapping = _esbNames.get(jbpmName);
+ if (null!=oldMapping && !oldMapping.equals(jbpmName))
+ throw new IllegalArgumentException
+ ("Illegal mapping esb=<"+esbName+"> was mapped to bpm=<"+oldMapping+ "> cannot remap to "+jbpmName);
+
+ _esbNames .put(esbName, jbpmName);
+ _jbpmNames .put(jbpmName, esbName);
+ // Internally, esbName is the key to the variable values
+ return esbName;
+ }
+
+ protected String getName(String path)
+ {
+ String name = path;
+ int index = path.lastIndexOf(".");
+ if (index > 0) {
+ name = path.substring(index+1);
+ }
+ return name;
+ }
+
+ 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; }
+}
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/BpmProcessorUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/BpmProcessorUnitTest.java 2007-11-20 16:14:49 UTC (rev 16704)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actions/BpmProcessorUnitTest.java 2007-11-20 16:21:21 UTC (rev 16705)
@@ -30,7 +30,7 @@
import org.apache.log4j.Logger;
import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.services.jbpm.mapping.MessageHelper;
+import org.jboss.soa.esb.services.jbpm.cmd.MessageHelper;
import org.jbpm.JbpmConfiguration;
import org.junit.AfterClass;
import org.junit.Test;
Copied: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/cmd (from rev 16704, labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/mapping)
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/cmd/VariableMappingUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/mapping/VariableMappingUnitTest.java 2007-11-20 16:14:49 UTC (rev 16704)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/cmd/VariableMappingUnitTest.java 2007-11-20 16:21:21 UTC (rev 16705)
@@ -19,13 +19,13 @@
* 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.mapping;
+package org.jboss.soa.esb.services.jbpm.cmd;
import static org.junit.Assert.assertEquals;
import junit.framework.JUnit4TestAdapter;
-import org.jboss.soa.esb.services.jbpm.mapping.VariableMapping;
+import org.jboss.soa.esb.services.jbpm.cmd.VariableMapping;
import org.junit.Test;
More information about the jboss-svn-commits
mailing list