[jboss-svn-commits] JBL Code SVN: r11196 - in labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm: actions and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Apr 21 18:27:26 EDT 2007
Author: estebanschifman
Date: 2007-04-21 18:27:26 -0400 (Sat, 21 Apr 2007)
New Revision: 11196
Added:
labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/CommandExecutorFactory.java
labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/MessageFacadeFactory.java
labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultCommandExecutorFactoryImpl.java
labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultMessageFacadeFactoryImpl.java
labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/internal/
Removed:
labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/MessagePreprocessorFactory.java
labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultPreprocessorFactoryImpl.java
labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DeployProcessDef.java
Modified:
labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/Constants.java
labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/CommandInterpreter.java
labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/SingleCommandProcessor.java
Log:
Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/Constants.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/Constants.java 2007-04-21 21:43:19 UTC (rev 11195)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/Constants.java 2007-04-21 22:27:26 UTC (rev 11196)
@@ -21,13 +21,7 @@
*/
package org.jboss.soa.esb.services.jbpm;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.log4j.Logger;
-import org.jboss.soa.esb.services.jbpm.actions.CommandInterpreter;
-import org.jboss.soa.esb.util.ClassUtil;
-
/**
*
* @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
@@ -35,8 +29,6 @@
*/
public class Constants {
- private static Logger _logger = Logger.getLogger(Constants.class);
-
// Names to be used as keys both in the ESB message and in the Jbpm context (process & token)
public static final String COMMAND_CODE ="jbpmCommandCode";
@@ -74,7 +66,12 @@
public static final String PROCESS_DEFINITION_XML_TAG ="ProcessDefinitionXml";
public static final String PROCESS_DEFINITION_NAME_TAG ="ProcessDefinitionName";
public static final String TRANSITION_NAME_TAG ="TransitionName";
- public static final String VARIABLES_TAG ="variables";
+ public static final String INCLUDE_ALL_VARS_TAG ="IncludeAllVariables";
+ public static final String INCLUDE_LOGS_TAG ="IncludeLogs";
+ public static final String VARIABLES_TAG ="Variables";
+ public static final String ONE_VARIABLE_TAG ="variable";
+ public static final String ESB_VARNAME_TAG ="esbName";
+ public static final String JBPM_VARNAME_TAG ="jbpmName";
public enum OpCode
{
@@ -101,45 +98,5 @@
,TaskInstanceEndCommand
,VariablesCommand
;
- public Class getClazz() throws ClassNotFoundException
- {
- return _mapName2class.get(toString());
- }
}
- private static Map<String,Class> _mapName2class = new HashMap<String, Class>();
- private static Map<Class ,String> _mapClass2name = new HashMap<Class, String>();
-
- public static String getCommandCode(Class clazz)
- {
- String cmd = _mapClass2name.get(clazz);
- if (null==cmd)
- throw new IllegalArgumentException("No command code mapped to <"+clazz+">");
- return cmd;
- }
-
- static
- {
- String name = null, qName= null;
- // at present, we assume all command implementors are in the org.jbpm.commmand pkg
- // if this changes, you'll have to replace the for loop with individual put(name,Class)
- for(OpCode curr : OpCode.values())
- {
- name = curr.toString();
- if (curr.equals(OpCode.DeployProcessDefinition))
- qName= CommandInterpreter.DeployProcessDefCommand.class.getName();
- else
- qName= "org.jbpm.command."+name;
- try
- {
- Class clazz = ClassUtil.forName(qName, Constants.class);
- _mapName2class.put(name,clazz);
- _mapClass2name.put(clazz,name);
- }
- catch (ClassNotFoundException e)
- {
- _logger.fatal("",e);
- }
- }
- }
-
}
Added: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/CommandExecutorFactory.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/CommandExecutorFactory.java (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/CommandExecutorFactory.java 2007-04-21 22:27:26 UTC (rev 11196)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ */
+package org.jboss.soa.esb.services.jbpm.actions;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.jbpm.actions.impl.DefaultCommandExecutorFactoryImpl;
+
+/**
+ * Factory to obtain appropriate Performer for the jBPM CommandInterpreter
+ *
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ *
+ */
+public abstract class CommandExecutorFactory
+{
+
+ public abstract CommandInterpreter.CommandExecutor
+ getPerformer(Message message) throws Exception;
+
+
+ protected static final Object s_oSynch = new Integer(0);
+
+ private static CommandExecutorFactory _factory;
+ public static CommandExecutorFactory getInstance()
+ {
+ if (null==_factory)
+ synchronized(s_oSynch)
+ {
+ if (null==_factory)
+ _factory=new DefaultCommandExecutorFactoryImpl();
+ };
+ return _factory;
+ } //________________________________
+}
Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/CommandExecutorFactory.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/CommandInterpreter.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/CommandInterpreter.java 2007-04-21 21:43:19 UTC (rev 11195)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/CommandInterpreter.java 2007-04-21 22:27:26 UTC (rev 11196)
@@ -21,9 +21,6 @@
*/
package org.jboss.soa.esb.services.jbpm.actions;
-import java.io.Serializable;
-import java.util.Map;
-
import org.apache.log4j.Logger;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.actions.ActionLifecycle;
@@ -39,28 +36,10 @@
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.services.jbpm.Constants;
import org.jboss.soa.esb.services.jbpm.util.Helper;
-import org.jboss.soa.esb.util.Util;
import org.jbpm.JbpmConfiguration;
-import org.jbpm.JbpmContext;
-import org.jbpm.command.CancelProcessInstanceCommand;
-import org.jbpm.command.CancelTokenCommand;
-import org.jbpm.command.CancelWorkOnTaskCommand;
import org.jbpm.command.Command;
import org.jbpm.command.CommandService;
-import org.jbpm.command.GetProcessInstanceCommand;
-import org.jbpm.command.GetTaskInstanceCommand;
-import org.jbpm.command.GetTaskListCommand;
-import org.jbpm.command.NewProcessInstanceCommand;
-import org.jbpm.command.SignalCommand;
-import org.jbpm.command.StartProcessInstanceCommand;
-import org.jbpm.command.StartWorkOnTaskCommand;
-import org.jbpm.command.TaskInstanceEndCommand;
-import org.jbpm.command.VariablesCommand;
import org.jbpm.command.impl.CommandServiceImpl;
-import org.jbpm.graph.def.ProcessDefinition;
-import org.jbpm.graph.exe.ProcessInstance;
-import org.jbpm.graph.exe.Token;
-import org.jbpm.taskmgmt.exe.TaskInstance;
/**
*
@@ -88,11 +67,28 @@
checkMyParms();
} // ________________________________
+ public Message process(Message message)
+ throws MalformedEPRException, CourierException, ActionProcessingException
+ {
+ Message response = null;
+ try
+ {
+ response = CommandExecutorFactory.getInstance().getPerformer(message).execute(message);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new ActionProcessingException(e);
+ }
+
+ return replyMessage(message,response);
+ } //________________________________
+
/**
* @param message - Containing payload and replyToEpr where to send the reply.
* @throws Exception
*/
- protected Message defaultReply(Message message)
+ public static Message defaultReply(Message message)
throws MalformedEPRException,CourierException
{
EPR reply = message.getHeader().getCall().getReplyTo();
@@ -106,7 +102,7 @@
return message;
} // ________________________________
- protected Message replyMessage(Message input, Message output)
+ public static Message replyMessage(Message input, Message output)
throws CourierException, MalformedEPRException
{
EPR toEpr = input.getHeader().getCall().getTo();
@@ -121,67 +117,8 @@
return (null==replyTo)? output : defaultReply(output);
} //________________________________
- private static final String DO_NOT_USE_CREATE_SCHEMA ="DONOTUSE_createSchema";
- public Message process(Message message)
- throws MalformedEPRException, CourierException, ActionProcessingException
+ public static Message doTheJob(Command command)
{
- Message response = null;
- try
- {
- String strCommand = (String)message.getBody().get(Constants.COMMAND_CODE);
- Constants.OpCode opCode =(DO_NOT_USE_CREATE_SCHEMA.equals(strCommand))
- ? null
- : Constants.OpCode.valueOf(strCommand);
- if (DO_NOT_USE_CREATE_SCHEMA.equals(strCommand))
- response = createSchema(message);
- else if (Constants.OpCode.DeployProcessDefinition.equals(opCode))
- response = deployProcessDefinition(message);
- else if (Constants.OpCode.DeployProcessDefinition.equals(opCode))
- response = deployProcessDefinition(message);
- else if (Constants.OpCode.CancelProcessInstanceCommand.equals(opCode))
- response = cancelProcessInstance(message);
- else if (Constants.OpCode.CancelTokenCommand.equals(opCode))
- response = cancelToken(message);
- else if (Constants.OpCode.CancelWorkOnTaskCommand.equals(opCode))
- response = cancelWorkOnTask(message);
- else if (Constants.OpCode.GetProcessInstanceCommand.equals(opCode))
- response = getProcessInstance(message);
- else if (Constants.OpCode.GetTaskInstanceCommand.equals(opCode))
- response = getTaskInstance(message);
- else if (Constants.OpCode.GetTaskListCommand.equals(opCode))
- response = getTaskList(message);
- else if (Constants.OpCode.NewProcessInstanceCommand.equals(opCode))
- response = newProcessInstance(message, false);
- else if (Constants.OpCode.SignalCommand.equals(opCode))
- response = signal(message);
- else if (Constants.OpCode.StartProcessInstanceCommand.equals(opCode))
- response = newProcessInstance(message, true);
- else if (Constants.OpCode.StartWorkOnTaskCommand.equals(opCode))
- response = startWorkOnTask(message);
- else if (Constants.OpCode.TaskInstanceEndCommand.equals(opCode))
- response = taskInstanceEnd(message);
- else if (Constants.OpCode.VariablesCommand.equals(opCode))
- response = variables(message);
-
- if (null==response)
- {
- // this should NEVER happen
- Exception e = new Exception("Something VERY WRONG with this class");
- _logger.fatal(e);
- throw e;
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw new ActionProcessingException(e);
- }
-
- return replyMessage(message,response);
- } //________________________________
-
- public Message doTheJob(Command command)
- {
Message response = Helper.commandMessageTemplate();
Body body = response.getBody();
@@ -202,300 +139,6 @@
} //________________________________
/**
- * Do NOT NOT NOT use the following command - only for debug purposess
- */
- private static Boolean s_schemaAlreadyCreated = false;
- private Message createSchema(Message request) throws Exception
- {
- return doTheJob(new CreateSchemaCommand());
- } //________________________________
-
- /**
- * Until there is an appropriate Command for this in the jBPM api, use the local implementation
- * @param request Message - containing either a process definition, or it's XML representation
- * @return
- * @throws Exception
- */
- public Message deployProcessDefinition(Message request) throws Exception
- {
- ProcessDefinition def = null;
-
- Object obj = Helper.getObjectValue(request, Constants.PROCESS_DEFINITION);
- if (null!=obj)
- def = (ProcessDefinition) obj;
- else
- {
- obj = Helper.getObjectValue(request,Constants.PROCESS_DEFINITION_XML);
- def = ProcessDefinition.parseXmlString((String)obj);
- }
- Message response = doTheJob(new DeployProcessDefCommand(def));
- Helper.setObjectValue(response, Constants.PROCESS_DEFINITION_NAME, def.getName());
- Helper.setObjectValue(response, Constants.PROCESS_DEFINITION_VERSION, def.getVersion());
- return response;
- } // _______________________________
-
- public Message cancelProcessInstance(Message request) throws Exception
- {
- long processId = Helper.getLongValue(request,Constants.PROCESS_INSTANCE_ID);
- return doTheJob(new CancelProcessInstanceCommand(processId));
- } // _______________________________
-
- public Message cancelToken(Message request) throws Exception
- {
- long tokenId = Helper.getLongValue(request,Constants.TOKEN_ID);
- return doTheJob(new CancelTokenCommand(tokenId));
- } // _______________________________
-
- public Message cancelWorkOnTask(Message request) throws Exception
- {
- long taskId = Helper.getLongValue(request,Constants.TASK_INSTANCE_ID);
- return doTheJob(new CancelWorkOnTaskCommand(taskId));
- } // _______________________________
-
- public Message getProcessInstance(Message request) throws Exception
- {
- GetProcessInstanceCommand command = new GetProcessInstanceCommand();
- Long id = Helper.getLongValue(request,Constants.PROCESS_INSTANCE_ID);
- if (null!=id)
- command.setProcessInstanceId(id);
- else
- {
- id = Helper.getLongValue(request, Constants.TOKEN_ID);
- if (null!=id)
- command.setTokenId(id);
- else
- {
- id = Helper.getLongValue(request, Constants.TASK_INSTANCE_ID);
- if (null!=id)
- command.setTaskInstanceId(id);
- else
- throw new Exception
- ("Either <"+Constants.PROCESS_INSTANCE_ID
- +"> or <"+Constants.TOKEN_ID
- +"> or <"+Constants.TASK_INSTANCE_ID
- +"> object must be specified in Message body to know what to retrieve");
-
- }
-
- }
- Boolean includeVars = Helper.getBooleanValue(request, Constants.INCLUDE_VARIABLES);
- if (null!=includeVars)
- command.setIncludeAllVariables(includeVars);
- Boolean includeLogs = Helper.getBooleanValue(request, Constants.INCLUDE_LOGS);
- if (null!=includeLogs)
- command.setIncludeLogs(includeLogs);
- return doTheJob(command);
- } // _______________________________
-
- public Message getTaskInstance(Message request) throws Exception
- {
- long taskId = Helper.getLongValue(request,Constants.TASK_INSTANCE_ID);
- GetTaskInstanceCommand command = new GetTaskInstanceCommand(taskId);
- String[] vars = Helper.getStringListValue(request,Constants.VARIABLE_NAMES_LIST);
- if (null!=vars)
- {
- if (vars.length < 1)
- command.setIncludeAllVariables(false);
- else
- command.setVariablesToInclude(vars);
- }
- else
- {
- Boolean includeVars = Helper.getBooleanValue(request, Constants.INCLUDE_VARIABLES);
- if (null!=includeVars)
- command.setIncludeAllVariables(includeVars);
- }
- Boolean includeLogs = Helper.getBooleanValue(request, Constants.INCLUDE_LOGS);
- if (null!=includeLogs)
- command.setIncludeLogs(includeLogs);
-
- Message response = doTheJob(command);
- TaskInstance tInst = (TaskInstance)Helper.getObjectValue(response, Constants.JBPM_RETURN_OBJECT);
- if (null!=tInst)
- {
- Helper.setLongValue(response, Constants.PROCESS_INSTANCE_ID ,tInst.getProcessInstance().getId());
- Helper.setLongValue(response, Constants.TOKEN_ID ,tInst.getToken().getId());
- Helper.setLongValue(response, Constants.TASK_INSTANCE_ID ,tInst.getId());
- }
-
- return response;
- } // _______________________________
-
- public Message getTaskList(Message request) throws Exception
- {
- String[] actors = Helper.getStringListValue(request,Constants.ACTOR_LIST);
- if (null==actors || actors.length<1)
- throw new Exception(Helper.argumentException(Constants.ACTOR_LIST));
-
- GetTaskListCommand command = new GetTaskListCommand(actors);
-
- String[] vars = Helper.getStringListValue(request,Constants.VARIABLE_NAMES_LIST);
- if (null!=vars)
- {
- if (vars.length < 1)
- command.setIncludeAllVariables(false);
- else
- command.setVariablesToInclude(vars);
- }
- else
- {
- Boolean includeVars = Helper.getBooleanValue(request, Constants.INCLUDE_VARIABLES);
- if (null!=includeVars)
- command.setIncludeAllVariables(includeVars);
- }
-
- return doTheJob(command);
- } // _______________________________
-
- public Message newProcessInstance(Message request, boolean start) throws Exception
- {
- String processName = Helper.getStringValue(request,Constants.PROCESS_DEFINITION_NAME);
- if (Util.isNullString(processName))
- throw new Exception(Helper.argumentException(Constants.PROCESS_DEFINITION_NAME));
- NewProcessInstanceCommand command = null;
- if (start)
- {
- StartProcessInstanceCommand startCmd = new StartProcessInstanceCommand();
- String transition = Helper.getStringValue(request, Constants.TRANSITION_NAME);
- if (null!=transition)
- startCmd.setStartTransitionName(transition);
- command = startCmd;
- }
- else
- command = new NewProcessInstanceCommand();
-
- command.setProcessName(processName);
-
- String actorId = Helper.getStringValue(request, Constants.ACTOR_ID);
- if (null!=actorId)
- command.setActorId(actorId);
- Boolean createStartTask = Helper.getBooleanValue(request, Constants.CREATE_START_TASK);
- if (null!=createStartTask)
- command.setCreateStartTask(createStartTask);
- Map<String, Serializable> variables = Helper.getVariablesMap(request, Constants.VARIABLE_VALUES);
- if (null!=variables)
- command.setVariables(variables);
-
- Message response = doTheJob(command);
-
- String retCode = Helper.getStringValue(response, Constants.RETURN_CODE);
- if (Constants.RETCODE_OK.equals(retCode))
- {
- Object obj = Helper.getObjectValue(response, Constants.JBPM_RETURN_OBJECT);
- if (obj instanceof TaskInstance)
- {
- TaskInstance tInst = (TaskInstance)obj;
- Helper.setLongValue(response, Constants.PROCESS_INSTANCE_ID ,tInst.getProcessInstance().getId());
- Helper.setLongValue(response, Constants.TOKEN_ID ,tInst.getToken().getId());
- Helper.setLongValue(response, Constants.TASK_INSTANCE_ID ,tInst.getId());
- }
- else if (obj instanceof ProcessInstance)
- {
- ProcessInstance pInst = (ProcessInstance)obj;
- Helper.setLongValue(response, Constants.PROCESS_INSTANCE_ID, pInst.getId());
- Helper.setLongValue(response, Constants.TOKEN_ID ,pInst.getRootToken().getId());
- }
- }
- return response;
- } // _______________________________
-
- public Message signal(Message request) throws Exception
- {
- SignalCommand command = new SignalCommand();
- String transition = Helper.getStringValue(request, Constants.TRANSITION_NAME);
- if (null!=transition)
- command.setTransitionName(transition);
-
- // try token id first
- Long tokenId = Helper.getLongValue(request,Constants.TOKEN_ID);
- if (null== tokenId)
- {
- // now try with the process id (use root token)
- Long processId = Helper.getLongValue(request,Constants.PROCESS_INSTANCE_ID);
- if (null== processId)
- throw new Exception("Either <"+Constants.TOKEN_ID+"> or <"+Constants.PROCESS_INSTANCE_ID
- +"> object must be specified in Message body to know who to signal");
- ProcessInstance inst = (ProcessInstance)getJbpmCommandService().execute(new GetProcessInstanceCommand(processId));
- tokenId = inst.getRootToken().getId();
- }
- command.setTokenId(tokenId);
-
- Message response = doTheJob(command);
- Token token = (Token)Helper.getObjectValue(response, Constants.JBPM_RETURN_OBJECT);
- if (null!=token)
- {
- Helper.setLongValue(response, Constants.TOKEN_ID ,token.getId());
- Helper.setLongValue(response, Constants.PROCESS_INSTANCE_ID, token.getProcessInstance().getId());
- Helper.setBooleanValue(response, Constants.PROCESS_HAS_ENDED, token.hasEnded());
- }
- return response;
- } // _______________________________
-
- public Message startWorkOnTask(Message request) throws Exception
- {
- StartWorkOnTaskCommand command = new StartWorkOnTaskCommand();
- Long taskId = Helper.getLongValue(request, Constants.TASK_INSTANCE_ID);
- if (null!=taskId)
- command.setTaskInstanceId(taskId);
- Boolean overwrite = Helper.getBooleanValue(request, Constants.OVERWRITE_SWIMLANE);
- if (null!=overwrite)
- command.setOverwriteSwimlane(overwrite);
- return doTheJob(command);
- } // _______________________________
-
- public Message taskInstanceEnd(Message request) throws Exception
- {
- TaskInstanceEndCommand command = new TaskInstanceEndCommand();
- Long taskId = Helper.getLongValue(request,Constants.TASK_INSTANCE_ID);
- if (null!=taskId)
- command.setTaskInstanceId(taskId);
- Map<String, Serializable> variables = Helper.getVariablesMap(request, Constants.VARIABLE_VALUES);
- if (null!=variables)
- command.setVariables(variables);
-
- String transition = Helper.getStringValue(request, Constants.TRANSITION_NAME);
- if (null!=transition)
- command.setTransitionName(transition);
-
- Message response = doTheJob(command);
- TaskInstance tInst = (TaskInstance)Helper.getObjectValue(response, Constants.JBPM_RETURN_OBJECT);
- if (null!=tInst)
- {
- Helper.setLongValue(response, Constants.PROCESS_INSTANCE_ID ,tInst.getProcessInstance().getId());
- Helper.setLongValue(response, Constants.TOKEN_ID ,tInst.getToken().getId());
- Helper.setLongValue(response, Constants.TASK_INSTANCE_ID ,tInst.getId());
- }
- return response;
- } // _______________________________
-
- public Message variables(Message request) throws Exception
- {
- VariablesCommand command = new VariablesCommand();
- Long id = Helper.getLongValue(request, Constants.TOKEN_ID);
- if (null!=id)
- command.setTokenId(id);
- else
- {
- id = Helper.getLongValue(request, Constants.TASK_INSTANCE_ID);
- if (null!=id)
- command.setTaskInstanceId(id);
- else
- throw new Exception
- ("Either <"+Constants.TOKEN_ID
- +"> or <"+Constants.TASK_INSTANCE_ID
- +"> object must be specified in Message body to know what to retrieve");
-
- }
-
- Map<String, Serializable> variables = Helper.getVariablesMap(request, Constants.VARIABLE_VALUES);
- if (null!=variables)
- command.setVariables(variables);
-
-
- return doTheJob(command);
- } // _______________________________
-
- /**
* Should this class need any extra configuration, this is the placeholder where to check
* if configuration is OK.
* @throws ConfigurationException
@@ -509,7 +152,7 @@
* <br/>If it can't be cached, we only need to change this method.
* @return CommandService
*/
- protected static CommandService getJbpmCommandService()
+ public static CommandService getJbpmCommandService()
{
if (null== s_jbpmService)
synchronized (s_oSynch)
@@ -561,38 +204,9 @@
private static JbpmConfiguration s_jbpmConfig;
private static CommandService s_jbpmService;
- public static class DeployProcessDefCommand implements Command
+ protected CommandExecutor _performer;
+ public interface CommandExecutor
{
- private static final long serialVersionUID = 1L;
- ProcessDefinition _def;
-
- public DeployProcessDefCommand(ProcessDefinition def)
- {
- _def = def;
- }
-
- public Object execute(JbpmContext jbpmCtx) throws Exception
- {
- jbpmCtx.deployProcessDefinition(_def);
- return null;
- }
-
+ public Message execute (Message message) throws Exception;
}
- private static class CreateSchemaCommand implements Command
- {
- private static final long serialVersionUID = 1L;
- public Object execute(JbpmContext jbpmCtx) throws Exception
- {
- if (! s_schemaAlreadyCreated)
- synchronized (s_oSynch)
- {
- if (! s_schemaAlreadyCreated)
- {
- jbpmCtx.getJbpmConfiguration().createSchema();
- s_schemaAlreadyCreated = true;
- }
- }
- return null;
- }
- }
}
Added: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/MessageFacadeFactory.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/MessageFacadeFactory.java (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/MessageFacadeFactory.java 2007-04-21 22:27:26 UTC (rev 11196)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ */
+package org.jboss.soa.esb.services.jbpm.actions;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.services.jbpm.actions.impl.DefaultMessageFacadeFactoryImpl;
+
+/**
+ * Factory to obtain appropriate MessageManipulator for jBPM SingleCommandProcessors
+ *
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ *
+ */
+public abstract class MessageFacadeFactory
+{
+
+ public abstract SingleCommandProcessor.MessageFacade
+ getPreProcessor(ConfigTree config) throws ConfigurationException;
+
+
+ protected static final Object s_oSynch = new Integer(0);
+
+ private static MessageFacadeFactory _factory;
+ public static MessageFacadeFactory getInstance()
+ {
+ if (null==_factory)
+ synchronized(s_oSynch)
+ {
+ if (null==_factory)
+ _factory=new DefaultMessageFacadeFactoryImpl();
+ };
+ return _factory;
+ } //________________________________
+}
Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/MessageFacadeFactory.java
___________________________________________________________________
Name: svn:eol-style
+ native
Deleted: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/MessagePreprocessorFactory.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/MessagePreprocessorFactory.java 2007-04-21 21:43:19 UTC (rev 11195)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/MessagePreprocessorFactory.java 2007-04-21 22:27:26 UTC (rev 11196)
@@ -1,52 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * 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,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * (C) 2005-2006,
- */
-package org.jboss.soa.esb.services.jbpm.actions;
-
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.services.jbpm.actions.impl.DefaultPreprocessorFactoryImpl;
-
-/**
- * Factory to obtain appropriate MessagePreprocessor for jBPM SingleCommandProcessors
- *
- * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
- *
- */
-public abstract class MessagePreprocessorFactory
-{
-
- public abstract SingleCommandProcessor.MessagePreprocessor
- getPreProcessor(ConfigTree config) throws ConfigurationException;
-
-
- protected static final Object s_oSynch = new Integer(0);
-
- private static MessagePreprocessorFactory _factory;
- public static MessagePreprocessorFactory getInstance()
- {
- if (null==_factory)
- synchronized(s_oSynch)
- {
- if (null==_factory)
- _factory=new DefaultPreprocessorFactoryImpl();
- };
- return _factory;
- } //________________________________
-}
Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/SingleCommandProcessor.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/SingleCommandProcessor.java 2007-04-21 21:43:19 UTC (rev 11195)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/SingleCommandProcessor.java 2007-04-21 22:27:26 UTC (rev 11196)
@@ -47,25 +47,40 @@
{
super(config);
}
- public Constants.OpCode getOpCode() { return _prepro.getOpCode(); }
+ public Constants.OpCode getOpCode() { return _stuffer.getOpCode(); }
@Override
protected void checkMyParms() throws ConfigurationException
{
- _prepro = MessagePreprocessorFactory.getInstance().getPreProcessor(_config);
+ _stuffer = MessageFacadeFactory.getInstance().getPreProcessor(_config);
} // _______________________________
@Override
public Message process(Message message)
throws MalformedEPRException, CourierException, ActionProcessingException
{
- _prepro.preFormat(message);
- return super.process(message);
+ _stuffer.preFormat(message);
+ Message response = super.process(message);
+ return _stuffer.postFormat(response);
} // _______________________________
- protected MessagePreprocessor _prepro;
- public interface MessagePreprocessor
+ protected MessageFacade _stuffer;
+ public interface MessageFacade
{
+ /**
+ * Obtain the operation code that this preprocessor will force into the command message
+ * @return Constants.OpCode
+ */
public Constants.OpCode getOpCode();
- public void preFormat(Message message);
+ /**
+ * 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 void preFormat(Message request);
+ public Message postFormat(Message response);
}
}
Added: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultCommandExecutorFactoryImpl.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultCommandExecutorFactoryImpl.java (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultCommandExecutorFactoryImpl.java 2007-04-21 22:27:26 UTC (rev 11196)
@@ -0,0 +1,465 @@
+/*
+ * 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.actions.impl;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.jbpm.Constants;
+import org.jboss.soa.esb.services.jbpm.actions.CommandInterpreter;
+import org.jboss.soa.esb.services.jbpm.actions.CommandExecutorFactory;
+import org.jboss.soa.esb.services.jbpm.actions.CommandInterpreter.CommandExecutor;
+import org.jboss.soa.esb.services.jbpm.util.Helper;
+import org.jboss.soa.esb.util.Util;
+import org.jbpm.JbpmContext;
+import org.jbpm.command.CancelProcessInstanceCommand;
+import org.jbpm.command.CancelTokenCommand;
+import org.jbpm.command.CancelWorkOnTaskCommand;
+import org.jbpm.command.Command;
+import org.jbpm.command.GetProcessInstanceCommand;
+import org.jbpm.command.GetTaskInstanceCommand;
+import org.jbpm.command.GetTaskListCommand;
+import org.jbpm.command.NewProcessInstanceCommand;
+import org.jbpm.command.SignalCommand;
+import org.jbpm.command.StartProcessInstanceCommand;
+import org.jbpm.command.StartWorkOnTaskCommand;
+import org.jbpm.command.TaskInstanceEndCommand;
+import org.jbpm.command.VariablesCommand;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.graph.exe.Token;
+import org.jbpm.taskmgmt.exe.TaskInstance;
+
+/**
+ * Default implementation of a performer factory for the CommandInterpreter
+ *
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ *
+ */
+public class DefaultCommandExecutorFactoryImpl extends CommandExecutorFactory
+{
+
+ private static final String DO_NOT_USE_CREATE_SCHEMA ="DONOTUSE_createSchema";
+
+ @Override
+ public CommandExecutor getPerformer(Message message) throws Exception
+ {
+ String strCommand = (String)message.getBody().get(Constants.COMMAND_CODE);
+ if (DO_NOT_USE_CREATE_SCHEMA.equals(strCommand))
+ return CREATE_SCHEMA_PERFORMER;
+
+ Constants.OpCode opCode = Constants.OpCode.valueOf(strCommand);
+ CommandExecutor ret = _values.get(opCode);
+ if (null==ret)
+ throw new Exception(opCode.toString()+" not implemented via jBossESB message");
+ return ret;
+ }
+
+ protected Logger _logger = Logger.getLogger(this.getClass());
+
+ /**
+ * Do NOT NOT NOT use the following performer - only for test/debug purposess
+ */
+ private static Boolean s_schemaAlreadyCreated = false;
+ private static CommandExecutor CREATE_SCHEMA_PERFORMER = new CommandExecutor()
+ {
+ public Message execute(Message request) throws Exception
+ {
+ Message response = CommandInterpreter.doTheJob(
+ new Command()
+ {
+ private static final long serialVersionUID = 1L;
+ public Object execute(JbpmContext jbpmCtx) throws Exception
+ {
+ if (! s_schemaAlreadyCreated)
+ synchronized (s_oSynch)
+ {
+ if (! s_schemaAlreadyCreated)
+ {
+ jbpmCtx.getJbpmConfiguration().createSchema();
+ s_schemaAlreadyCreated = true;
+ }
+ }
+ return null;
+ }
+ });
+ // No values other than the completion code are returned by this command
+ return response;
+ };
+ };
+
+ protected static final CommandExecutor DEPLOY_PROCESS_DEF_PERFORMER = new CommandExecutor()
+ {
+ public Message execute(Message request) throws Exception
+ {
+ Object obj = Helper.getObjectValue(request, Constants.PROCESS_DEFINITION);
+ if (null==obj)
+ {
+ obj = ProcessDefinition.parseXmlString
+ ((String)Helper.getObjectValue(request,Constants.PROCESS_DEFINITION_XML));
+ }
+ final ProcessDefinition def = (ProcessDefinition)obj;
+ Message response = CommandInterpreter.doTheJob(
+ new Command()
+ {
+ private static final long serialVersionUID = 1L;
+ ProcessDefinition _def = def;
+ public Object execute(JbpmContext jbpmCtx) throws Exception
+ {
+ jbpmCtx.deployProcessDefinition(_def);
+ return null;
+ }
+ });
+ Helper.setObjectValue(response, Constants.PROCESS_DEFINITION_NAME, def.getName());
+ Helper.setObjectValue(response, Constants.PROCESS_DEFINITION_VERSION, def.getVersion());
+ return response;
+ }
+ };
+
+ protected static final CommandExecutor CANCEL_PROCESS_INSTANCE_PERFORMER = new CommandExecutor()
+ {
+ public Message execute(Message request) throws Exception
+ {
+ long processId = Helper.getLongValue(request,Constants.PROCESS_INSTANCE_ID);
+ return CommandInterpreter.doTheJob(new CancelProcessInstanceCommand(processId));
+ } // _______________________________
+ };
+
+ protected static final CommandExecutor CANCEL_TOKEN_PERFORMER = new CommandExecutor()
+ {
+ public Message execute(Message request) throws Exception
+ {
+ long tokenId = Helper.getLongValue(request,Constants.TOKEN_ID);
+ return CommandInterpreter.doTheJob(new CancelTokenCommand(tokenId));
+ } // _______________________________
+ };
+
+ protected static final CommandExecutor CANCEL_WORK_ON_TASK_PERFORMER = new CommandExecutor()
+ {
+ public Message execute(Message request) throws Exception
+ {
+ long taskId = Helper.getLongValue(request,Constants.TASK_INSTANCE_ID);
+ return CommandInterpreter.doTheJob(new CancelWorkOnTaskCommand(taskId));
+ } // _______________________________
+ };
+
+ protected static final CommandExecutor GET_PROCESS_INSTANCE_PERFORMER=new CommandExecutor()
+ {
+ public Message execute(Message request) throws Exception
+ {
+ GetProcessInstanceCommand command = new GetProcessInstanceCommand();
+ Long id = Helper.getLongValue(request,Constants.PROCESS_INSTANCE_ID);
+ if (null!=id)
+ command.setProcessInstanceId(id);
+ else
+ {
+ id = Helper.getLongValue(request, Constants.TOKEN_ID);
+ if (null!=id)
+ command.setTokenId(id);
+ else
+ {
+ id = Helper.getLongValue(request, Constants.TASK_INSTANCE_ID);
+ if (null!=id)
+ command.setTaskInstanceId(id);
+ else
+ throw new Exception
+ ("Either <"+Constants.PROCESS_INSTANCE_ID
+ +"> or <"+Constants.TOKEN_ID
+ +"> or <"+Constants.TASK_INSTANCE_ID
+ +"> object must be specified in Message body to know what to retrieve");
+
+ }
+
+ }
+ Boolean includeVars = Helper.getBooleanValue(request, Constants.INCLUDE_VARIABLES);
+ if (null!=includeVars)
+ command.setIncludeAllVariables(includeVars);
+ Boolean includeLogs = Helper.getBooleanValue(request, Constants.INCLUDE_LOGS);
+ if (null!=includeLogs)
+ command.setIncludeLogs(includeLogs);
+ return CommandInterpreter.doTheJob(command);
+ } // _______________________________
+ };
+
+ protected static final CommandExecutor GET_TASK_INSTANCE_PERFORMER=new CommandExecutor()
+ {
+ public Message execute(Message request) throws Exception
+ {
+ long taskId = Helper.getLongValue(request,Constants.TASK_INSTANCE_ID);
+ GetTaskInstanceCommand command = new GetTaskInstanceCommand(taskId);
+ String[] vars = Helper.getStringListValue(request,Constants.VARIABLE_NAMES_LIST);
+ if (null!=vars)
+ {
+ if (vars.length < 1)
+ command.setIncludeAllVariables(false);
+ else
+ command.setVariablesToInclude(vars);
+ }
+ else
+ {
+ Boolean includeVars = Helper.getBooleanValue(request, Constants.INCLUDE_VARIABLES);
+ if (null!=includeVars)
+ command.setIncludeAllVariables(includeVars);
+ }
+ Boolean includeLogs = Helper.getBooleanValue(request, Constants.INCLUDE_LOGS);
+ if (null!=includeLogs)
+ command.setIncludeLogs(includeLogs);
+
+ Message response = CommandInterpreter.doTheJob(command);
+ TaskInstance tInst = (TaskInstance)Helper.getObjectValue(response, Constants.JBPM_RETURN_OBJECT);
+ if (null!=tInst)
+ {
+ Helper.setLongValue(response, Constants.PROCESS_INSTANCE_ID ,tInst.getProcessInstance().getId());
+ Helper.setLongValue(response, Constants.TOKEN_ID ,tInst.getToken().getId());
+ Helper.setLongValue(response, Constants.TASK_INSTANCE_ID ,tInst.getId());
+ }
+
+ return response;
+ } // _______________________________
+ };
+
+ protected static final CommandExecutor GET_TASK_LIST_PERFORMER=new CommandExecutor()
+ {
+ public Message execute(Message request) throws Exception
+ {
+ String[] actors = Helper.getStringListValue(request,Constants.ACTOR_LIST);
+ if (null==actors || actors.length<1)
+ throw new Exception(Helper.argumentException(Constants.ACTOR_LIST));
+
+ GetTaskListCommand command = new GetTaskListCommand(actors);
+
+ String[] vars = Helper.getStringListValue(request,Constants.VARIABLE_NAMES_LIST);
+ if (null!=vars)
+ {
+ if (vars.length < 1)
+ command.setIncludeAllVariables(false);
+ else
+ command.setVariablesToInclude(vars);
+ }
+ else
+ {
+ Boolean includeVars = Helper.getBooleanValue(request, Constants.INCLUDE_VARIABLES);
+ if (null!=includeVars)
+ command.setIncludeAllVariables(includeVars);
+ }
+
+ return CommandInterpreter.doTheJob(command);
+ } // _______________________________
+ };
+
+ protected static final CommandExecutor SIGNAL_PERFORMER=new CommandExecutor()
+ {
+ public Message execute(Message request) throws Exception
+ {
+ SignalCommand command = new SignalCommand();
+ String transition = Helper.getStringValue(request, Constants.TRANSITION_NAME);
+ if (null!=transition)
+ command.setTransitionName(transition);
+
+ // try token id first
+ Long tokenId = Helper.getLongValue(request,Constants.TOKEN_ID);
+ if (null== tokenId)
+ {
+ // now try with the process id (use root token)
+ Long processId = Helper.getLongValue(request,Constants.PROCESS_INSTANCE_ID);
+ if (null== processId)
+ throw new Exception("Either <"+Constants.TOKEN_ID+"> or <"+Constants.PROCESS_INSTANCE_ID
+ +"> object must be specified in Message body to know who to signal");
+ ProcessInstance inst = (ProcessInstance)CommandInterpreter.getJbpmCommandService()
+ .execute(new GetProcessInstanceCommand(processId));
+ tokenId = inst.getRootToken().getId();
+ }
+ command.setTokenId(tokenId);
+
+ Message response = CommandInterpreter.doTheJob(command);
+ Token token = (Token)Helper.getObjectValue(response, Constants.JBPM_RETURN_OBJECT);
+ if (null!=token)
+ {
+ Helper.setLongValue(response, Constants.TOKEN_ID ,token.getId());
+ Helper.setLongValue(response, Constants.PROCESS_INSTANCE_ID, token.getProcessInstance().getId());
+ Helper.setBooleanValue(response, Constants.PROCESS_HAS_ENDED, token.hasEnded());
+ }
+ return response;
+ } // _______________________________
+ };
+
+ protected static final CommandExecutor START_WORK_ON_TASK_PERFORMER=new CommandExecutor()
+ {
+ public Message execute(Message request) throws Exception
+ {
+ StartWorkOnTaskCommand command = new StartWorkOnTaskCommand();
+ Long taskId = Helper.getLongValue(request, Constants.TASK_INSTANCE_ID);
+ if (null!=taskId)
+ command.setTaskInstanceId(taskId);
+ Boolean overwrite = Helper.getBooleanValue(request, Constants.OVERWRITE_SWIMLANE);
+ if (null!=overwrite)
+ command.setOverwriteSwimlane(overwrite);
+ return CommandInterpreter.doTheJob(command);
+ } // _______________________________
+ };
+
+ protected static final CommandExecutor TASK_INSTANCE_END_PERFORMER=new CommandExecutor()
+ {
+ public Message execute(Message request) throws Exception
+ {
+ TaskInstanceEndCommand command = new TaskInstanceEndCommand();
+ Long taskId = Helper.getLongValue(request,Constants.TASK_INSTANCE_ID);
+ if (null!=taskId)
+ command.setTaskInstanceId(taskId);
+ Map<String, Serializable> variables = Helper.getVariablesMap(request, Constants.VARIABLE_VALUES);
+ if (null!=variables)
+ command.setVariables(variables);
+
+ String transition = Helper.getStringValue(request, Constants.TRANSITION_NAME);
+ if (null!=transition)
+ command.setTransitionName(transition);
+
+ Message response = CommandInterpreter.doTheJob(command);
+ TaskInstance tInst = (TaskInstance)Helper.getObjectValue(response, Constants.JBPM_RETURN_OBJECT);
+ if (null!=tInst)
+ {
+ Helper.setLongValue(response, Constants.PROCESS_INSTANCE_ID ,tInst.getProcessInstance().getId());
+ Helper.setLongValue(response, Constants.TOKEN_ID ,tInst.getToken().getId());
+ Helper.setLongValue(response, Constants.TASK_INSTANCE_ID ,tInst.getId());
+ }
+ return response;
+ } // _______________________________
+ };
+
+ protected static final CommandExecutor VARIABLES_PERFORMER=new CommandExecutor()
+ {
+ public Message execute(Message request) throws Exception
+ {
+ VariablesCommand command = new VariablesCommand();
+ Long id = Helper.getLongValue(request, Constants.TOKEN_ID);
+ if (null!=id)
+ command.setTokenId(id);
+ else
+ {
+ id = Helper.getLongValue(request, Constants.TASK_INSTANCE_ID);
+ if (null!=id)
+ command.setTaskInstanceId(id);
+ else
+ throw new Exception
+ ("Either <"+Constants.TOKEN_ID
+ +"> or <"+Constants.TASK_INSTANCE_ID
+ +"> object must be specified in Message body to know what to retrieve");
+
+ }
+
+ Map<String, Serializable> variables = Helper.getVariablesMap(request, Constants.VARIABLE_VALUES);
+ if (null!=variables)
+ command.setVariables(variables);
+
+
+ return CommandInterpreter.doTheJob(command);
+ } // _______________________________
+ };
+
+
+ protected static Map<Constants.OpCode,CommandExecutor> _values = new HashMap<Constants.OpCode,CommandExecutor>();
+ static
+ {
+ _values.put(Constants.OpCode.DeployProcessDefinition ,DEPLOY_PROCESS_DEF_PERFORMER);
+ _values.put(Constants.OpCode.CancelProcessInstanceCommand,CANCEL_PROCESS_INSTANCE_PERFORMER);
+ _values.put(Constants.OpCode.CancelTokenCommand ,CANCEL_TOKEN_PERFORMER);
+ _values.put(Constants.OpCode.CancelWorkOnTaskCommand ,CANCEL_WORK_ON_TASK_PERFORMER);
+ _values.put(Constants.OpCode.GetProcessInstanceCommand ,GET_PROCESS_INSTANCE_PERFORMER);
+ _values.put(Constants.OpCode.GetTaskInstanceCommand ,GET_TASK_INSTANCE_PERFORMER);
+// _values.put(Constants.OpCode.GetTaskListCommand ,???);
+ _values.put(Constants.OpCode.NewProcessInstanceCommand
+ ,new DefaultCommandExecutorFactoryImpl.NewProcessInstancePerformer(false));
+ _values.put(Constants.OpCode.SignalCommand ,SIGNAL_PERFORMER);
+ _values.put(Constants.OpCode.StartProcessInstanceCommand
+ ,new DefaultCommandExecutorFactoryImpl.NewProcessInstancePerformer(true));
+ _values.put(Constants.OpCode.StartWorkOnTaskCommand ,START_WORK_ON_TASK_PERFORMER);
+ _values.put(Constants.OpCode.TaskInstanceEndCommand ,TASK_INSTANCE_END_PERFORMER);
+ _values.put(Constants.OpCode.VariablesCommand ,VARIABLES_PERFORMER);
+ }
+
+ // this class will be used both for NewProcessInstance and for StartProcessInstance
+ protected static final class NewProcessInstancePerformer implements CommandInterpreter.CommandExecutor
+ {
+ private boolean _start;
+ public NewProcessInstancePerformer(boolean start) { _start = start; }
+ public Message execute(Message request) throws Exception
+ {
+ return perform(request,_start);
+ }
+
+ private Message perform(Message request, boolean start) throws Exception
+ {
+ String processName = Helper.getStringValue(request,Constants.PROCESS_DEFINITION_NAME);
+ if (Util.isNullString(processName))
+ throw new Exception(Helper.argumentException(Constants.PROCESS_DEFINITION_NAME));
+ NewProcessInstanceCommand command = null;
+ if (start)
+ {
+ StartProcessInstanceCommand startCmd = new StartProcessInstanceCommand();
+ String transition = Helper.getStringValue(request, Constants.TRANSITION_NAME);
+ if (null!=transition)
+ startCmd.setStartTransitionName(transition);
+ command = startCmd;
+ }
+ else
+ command = new NewProcessInstanceCommand();
+
+ command.setProcessName(processName);
+
+ String actorId = Helper.getStringValue(request, Constants.ACTOR_ID);
+ if (null!=actorId)
+ command.setActorId(actorId);
+ Boolean createStartTask = Helper.getBooleanValue(request, Constants.CREATE_START_TASK);
+ if (null!=createStartTask)
+ command.setCreateStartTask(createStartTask);
+ Map<String, Serializable> variables = Helper.getVariablesMap(request, Constants.VARIABLE_VALUES);
+ if (null!=variables)
+ command.setVariables(variables);
+
+ Message response = CommandInterpreter.doTheJob(command);
+
+ String retCode = Helper.getStringValue(response, Constants.RETURN_CODE);
+ if (Constants.RETCODE_OK.equals(retCode))
+ {
+ Object obj = Helper.getObjectValue(response, Constants.JBPM_RETURN_OBJECT);
+ if (obj instanceof TaskInstance)
+ {
+ TaskInstance tInst = (TaskInstance)obj;
+ Helper.setLongValue(response, Constants.PROCESS_INSTANCE_ID ,tInst.getProcessInstance().getId());
+ Helper.setLongValue(response, Constants.TOKEN_ID ,tInst.getToken().getId());
+ Helper.setLongValue(response, Constants.TASK_INSTANCE_ID ,tInst.getId());
+ }
+ else if (obj instanceof ProcessInstance)
+ {
+ ProcessInstance pInst = (ProcessInstance)obj;
+ Helper.setLongValue(response, Constants.PROCESS_INSTANCE_ID, pInst.getId());
+ Helper.setLongValue(response, Constants.TOKEN_ID ,pInst.getRootToken().getId());
+ }
+ }
+ return response;
+ } // _______________________________
+ }
+}
Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultCommandExecutorFactoryImpl.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultMessageFacadeFactoryImpl.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultMessageFacadeFactoryImpl.java (rev 0)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultMessageFacadeFactoryImpl.java 2007-04-21 22:27:26 UTC (rev 11196)
@@ -0,0 +1,92 @@
+/*
+ * 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.actions.impl;
+
+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.MessageFacadeFactory;
+import org.jboss.soa.esb.services.jbpm.actions.SingleCommandProcessor;
+import org.jboss.soa.esb.services.jbpm.actions.SingleCommandProcessor.MessageFacade;
+import org.jboss.soa.esb.services.jbpm.internal.facades.DeployProcessDefinitionFacade;
+import org.jboss.soa.esb.services.jbpm.internal.facades.GetProcessInstanceFacade;
+import org.jboss.soa.esb.services.jbpm.internal.facades.GetTaskInstanceFacade;
+
+/**
+ * Default implementation of a message preprocessor factory
+ *
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ *
+ */
+public class DefaultMessageFacadeFactoryImpl extends MessageFacadeFactory
+{
+ // This is a dummy message preprocessor that does nothing but implement the interface
+ static class PassThrough implements MessageFacade
+ {
+ private OpCode _opCode;
+ PassThrough(OpCode opCode) { _opCode = opCode; }
+ public OpCode getOpCode() { return _opCode; }
+ public void preFormat(Message message) { }
+ public Message postFormat(Message response) { return response; }
+ };
+
+ @Override
+ public SingleCommandProcessor.MessageFacade getPreProcessor(ConfigTree config)
+ throws ConfigurationException
+ {
+ Constants.OpCode opCode = null;
+ String sAux = config.getRequiredAttribute(SingleCommandProcessor.COMMAND_ATTRIBUTE_TAG);
+ try { opCode = Constants.OpCode.valueOf(sAux); }
+ catch (IllegalArgumentException e)
+ {
+ throw new ConfigurationException("Attribute '"+SingleCommandProcessor.COMMAND_ATTRIBUTE_TAG+"' has an invalid value"
+ +"- see CommandVehicle.Operation enum for possible values");
+ }
+
+ if (Constants.OpCode.DeployProcessDefinition .equals(opCode))
+ return new DeployProcessDefinitionFacade(config);
+ if (Constants.OpCode.GetProcessInstanceCommand .equals(opCode))
+ return new GetProcessInstanceFacade(config);
+ if (Constants.OpCode.GetTaskInstanceCommand .equals(opCode))
+ return new GetTaskInstanceFacade(config);
+ if (Constants.OpCode.GetTaskListCommand .equals(opCode))
+ return null;
+ if (Constants.OpCode.NewProcessInstanceCommand .equals(opCode))
+ return null;
+ if (Constants.OpCode.SignalCommand .equals(opCode))
+ return null;
+ if (Constants.OpCode.StartProcessInstanceCommand .equals(opCode))
+ return null;
+ if (Constants.OpCode.StartWorkOnTaskCommand .equals(opCode))
+ return null;
+ if (Constants.OpCode.TaskInstanceEndCommand .equals(opCode))
+ return null;
+ if (Constants.OpCode.VariablesCommand .equals(opCode))
+ return null;
+
+ throw new ConfigurationException(opCode.toString()+" not implemented");
+ } // _______________________________
+
+}
Property changes on: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultMessageFacadeFactoryImpl.java
___________________________________________________________________
Name: svn:eol-style
+ native
Deleted: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultPreprocessorFactoryImpl.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultPreprocessorFactoryImpl.java 2007-04-21 21:43:19 UTC (rev 11195)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DefaultPreprocessorFactoryImpl.java 2007-04-21 22:27:26 UTC (rev 11196)
@@ -1,77 +0,0 @@
-/*
- * 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.actions.impl;
-
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.services.jbpm.Constants;
-import org.jboss.soa.esb.services.jbpm.actions.MessagePreprocessorFactory;
-import org.jboss.soa.esb.services.jbpm.actions.SingleCommandProcessor;
-
-/**
- * Default implementation of a message preprocessor factory
- *
- * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
- *
- */
-public class DefaultPreprocessorFactoryImpl extends MessagePreprocessorFactory
-{
-
- @Override
- public SingleCommandProcessor.MessagePreprocessor getPreProcessor(ConfigTree config)
- throws ConfigurationException
- {
- Constants.OpCode opCode = null;
- String sAux = config.getRequiredAttribute(SingleCommandProcessor.COMMAND_ATTRIBUTE_TAG);
- try { opCode = Constants.OpCode.valueOf(sAux); }
- catch (IllegalArgumentException e)
- {
- throw new ConfigurationException("Attribute '"+SingleCommandProcessor.COMMAND_ATTRIBUTE_TAG+"' has an invalid value"
- +"- see CommandVehicle.Operation enum for possible values");
- }
-
- if (Constants.OpCode.DeployProcessDefinition .equals(opCode))
- return new DeployProcessDef(config);
- if (Constants.OpCode.GetProcessInstanceCommand .equals(opCode))
- return null;
- if (Constants.OpCode.GetTaskInstanceCommand .equals(opCode))
- return null;
- if (Constants.OpCode.GetTaskListCommand .equals(opCode))
- return null;
- if (Constants.OpCode.NewProcessInstanceCommand .equals(opCode))
- return null;
- if (Constants.OpCode.SignalCommand .equals(opCode))
- return null;
- if (Constants.OpCode.StartProcessInstanceCommand .equals(opCode))
- return null;
- if (Constants.OpCode.StartWorkOnTaskCommand .equals(opCode))
- return null;
- if (Constants.OpCode.TaskInstanceEndCommand .equals(opCode))
- return null;
- if (Constants.OpCode.VariablesCommand .equals(opCode))
- return null;
-
- throw new ConfigurationException(opCode.toString()+" not implemented");
- } // _______________________________
-
-}
Deleted: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DeployProcessDef.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DeployProcessDef.java 2007-04-21 21:43:19 UTC (rev 11195)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actions/impl/DeployProcessDef.java 2007-04-21 22:27:26 UTC (rev 11196)
@@ -1,83 +0,0 @@
-/*
- * 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.actions.impl;
-
-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 DeployProcessDef implements SingleCommandProcessor .MessagePreprocessor
-{
- public OpCode getOpCode() { return Constants.OpCode.DeployProcessDefinition; }
-
- public DeployProcessDef(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);
- } // ________________________________
-
- ProcessDefinition _processDef;
-
-}
More information about the jboss-svn-commits
mailing list