[jboss-svn-commits] JBL Code SVN: r9618 - in labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions: jbpm and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Feb 19 16:02:17 EST 2007
Author: estebanschifman
Date: 2007-02-19 16:02:17 -0500 (Mon, 19 Feb 2007)
New Revision: 9618
Added:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/jbpm/
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/jbpm/CommandInterpreter.java
Removed:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/JbpmCommandInterpreter.java
Log:
Rename JbpmCommandInterpreter and move it to new actions.jbpm package
Deleted: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/JbpmCommandInterpreter.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/JbpmCommandInterpreter.java 2007-02-19 21:01:27 UTC (rev 9617)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/JbpmCommandInterpreter.java 2007-02-19 21:02:17 UTC (rev 9618)
@@ -1,325 +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.actions;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-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.util.JbpmCommandVehicle;
-import org.jbpm.JbpmConfiguration;
-import org.jbpm.JbpmContext;
-import org.jbpm.graph.def.ProcessDefinition;
-import org.jbpm.graph.exe.ProcessInstance;
-import org.jbpm.graph.exe.Token;
-
-/**
- *
- * jBPM command interpreter.
- *
- * <p/>This class is tightly coupled with JbpmCommmandVehicle.
- * <br/>It should be able to interpret all commands in the 'Operation' enum in JbpmCommandVehicle.
- * <br/>If new operations are added there, the process() method in this class should be changed accordingly.
- *
- * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
- *
- */
-public class JbpmCommandInterpreter
-{
-
-
- private JbpmCommandInterpreter() {}
- public JbpmCommandInterpreter(ConfigTree config) throws ConfigurationException
- {
- _config = config;
- checkMyParms();
- } // ________________________________
-
- public Message process(Message message)
- {
- _command = new JbpmCommandVehicle(message);
- Enum operator = _command.getOperator();
-
-
- if (operator.equals(JbpmCommandVehicle.Operation.signalToken))
- signalToken();
- else if (operator.equals(JbpmCommandVehicle.Operation.signalProcess))
- signalProcess();
- else if (operator.equals(JbpmCommandVehicle.Operation.getProcessInstanceVariables))
- getProcessInstanceVariabes();
- else if (operator.equals(JbpmCommandVehicle.Operation.setProcessInstanceVariables))
- setProcessInstanceVariables();
- else if (operator.equals(JbpmCommandVehicle.Operation.getTokenVariables))
- getTokenVariabes();
- else if (operator.equals(JbpmCommandVehicle.Operation.setTokenVariables))
- setTokenVariables();
- else if (operator.equals(JbpmCommandVehicle.Operation.newProcessInstance))
- newProcessInstance();
- else if (operator.equals(JbpmCommandVehicle.Operation.deployProcessDefinition))
- deployProcessDefinition();
- else
- {
- _logger.error("Unknown operator: "+operator.toString()+" - Returning message unchanged");
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_INVALID_OPCODE);
- }
-
- Message retMsg = _command.toCommandMessage();
-
- return retMsg;
- } // ________________________________
-
- public void deployProcessDefinition()
- {
- try
- {
- prepareJbpm();
- _jbpmCtx.getSession().beginTransaction();
- ProcessDefinition def = _command.getProcessDefinition();
- _jbpmCtx.deployProcessDefinition(def);
- _command.setProcessDefinitionName (def.getName());
- _command.setProcessVersion (def.getVersion());
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_OK);
- }
- catch (Exception e)
- {
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_EXCEPTION);
- _command.setException(e);
- }
- finally { cleanupJbpm(); }
- } //________________________________
- public void newProcessInstance()
- {
- try
- {
- prepareJbpm();
- _processInstance = _jbpmCtx.newProcessInstance(_command.getProcessDefinitionName());
- _jbpmCtx.getSession().beginTransaction();
- _jbpmCtx.save(_processInstance);
-
- _command.setProcessVersion(_processInstance.getProcessDefinition().getVersion());
- _command.setInstanceId (_processInstance.getId());
- _command.setTokenId (_processInstance.getRootToken().getId());
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_OK);
- }
- catch (Exception e)
- {
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_EXCEPTION);
- _command.setException(e);
- }
- finally { cleanupJbpm(); }
- } //________________________________
-
- public void signalProcess()
- {
- try
- {
- long id = _command.getInstanceId();
- prepareJbpm();
- _jbpmCtx.getSession().beginTransaction();
- _processInstance = _jbpmCtx.loadProcessInstanceForUpdate(id);
- _processInstance.signal();
- _jbpmCtx.save(_processInstance);
-
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_OK);
- }
- catch (Exception e)
- {
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_EXCEPTION);
- _command.setException(e);
- }
- finally { cleanupJbpm(); }
- } //________________________________
-
- public void signalToken()
- {
- try
- {
- long id = _command.getTokenId();
- prepareJbpm();
- _jbpmCtx.getSession().beginTransaction();
- Token token = _jbpmCtx.loadTokenForUpdate(id);
- token.signal();
- _jbpmCtx.save(token);
-
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_OK);
- }
- catch (Exception e)
- {
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_EXCEPTION);
- _command.setException(e);
- }
- finally { cleanupJbpm(); }
- } //________________________________
-
- public void getProcessInstanceVariabes()
- {
- try
- {
- long id = _command.getInstanceId();
- prepareJbpm();
- _processInstance = _jbpmCtx.loadProcessInstance(id);
- Map allVars = _processInstance.getContextInstance().getVariables();
- _command.setVariableValues(pickVarsFromMap(allVars));
-
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_OK);
- }
- catch (Exception e)
- {
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_EXCEPTION);
- _command.setException(e);
- }
- finally { cleanupJbpm(); }
- } //________________________________
-
- public void setProcessInstanceVariables()
- {
- try
- {
- Map<String,Object>newVals = _command.getVariableValues();
- if (null==newVals || newVals.size()<1)
- {
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_ERROR);
- _command.setErrorMessage("Null or empty variable Map");
- return;
- }
- long id = _command.getInstanceId();
- prepareJbpm();
- _jbpmCtx.getSession().beginTransaction();
- _processInstance = _jbpmCtx.loadProcessInstanceForUpdate(id);
- _processInstance.getContextInstance().addVariables(newVals);
- _jbpmCtx.save(_processInstance);
-
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_OK);
- }
- catch (Exception e)
- {
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_EXCEPTION);
- _command.setException(e);
- }
- finally { cleanupJbpm(); }
- } //________________________________
-
- public void getTokenVariabes()
- {
- try
- {
- long id = _command.getTokenId();
- prepareJbpm();
- _token = _jbpmCtx.loadToken(id);
- Map allVars = _token.getProcessInstance().getContextInstance().getVariables(_token);
- _command.setVariableValues(pickVarsFromMap(allVars));
-
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_OK);
- }
- catch (Exception e)
- {
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_EXCEPTION);
- _command.setException(e);
- }
- finally { cleanupJbpm(); }
- } //________________________________
-
- public void setTokenVariables()
- {
- try
- {
- Map<String,Object>newVals = _command.getVariableValues();
- if (null==newVals || newVals.size()<1)
- {
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_ERROR);
- _command.setErrorMessage("Null or empty variable Map");
- return;
- }
- long id = _command.getTokenId();
- prepareJbpm();
- _jbpmCtx.getSession().beginTransaction();
- _token = _jbpmCtx.loadToken(id);
- _token.getProcessInstance().getContextInstance().addVariables(newVals,_token);
- _jbpmCtx.save(_token);
-
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_OK);
- }
- catch (Exception e)
- {
- _command.setReturnCode(JbpmCommandVehicle.RETCODE_EXCEPTION);
- _command.setException(e);
- }
- finally { cleanupJbpm(); }
- } //________________________________
-
- /**
- * Get list of variables requested in command, from map in arg0.
- * <br/>List of requested variables is obtained from command invoking the getVariableNames() method.
- * <br/>If the list of variable names is NULL, all variables in the map will be returned.
- * <br/>If it's an empty List, an empty map will be returned (why would anybody ask for an empty list of vars ?)
- * @param variables
- * @return
- */
- @SuppressWarnings("unchecked")
- protected Map<String,Object>pickVarsFromMap(Map variables)
- {
- Set<String>names = _command.getVariableNames();
- if (null==names)
- return variables;
-
- Map<String,Object>retMap = new HashMap<String, Object>();
- for(String curr : names)
- retMap.put(curr, variables.get(curr));
-
- return retMap;
- } //________________________________
-
-
- protected void checkMyParms() throws ConfigurationException
- {
- } // _______________________________
-
- protected void prepareJbpm()
- {
- _jbpmConfig = null;
- _jbpmCtx = null;
- _jbpmConfig = JbpmConfiguration.getInstance();
- _jbpmCtx = _jbpmConfig.createJbpmContext();
- } //________________________________
- protected void cleanupJbpm()
- {
- if (null!=_jbpmCtx) _jbpmCtx.close();
- if (null!=_jbpmConfig) _jbpmConfig.close();
- _jbpmConfig = null;
- _jbpmCtx = null;
- _processInstance= null;
- _token = null;
- } //________________________________
-
- protected ConfigTree _config;
- protected JbpmCommandVehicle _command;
- protected JbpmConfiguration _jbpmConfig;
- protected JbpmContext _jbpmCtx;
- protected ProcessInstance _processInstance;
- protected Token _token;
-
- protected static Logger _logger = Logger.getLogger(JbpmCommandInterpreter.class);
-}
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/jbpm/CommandInterpreter.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/jbpm/CommandInterpreter.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/jbpm/CommandInterpreter.java 2007-02-19 21:02:17 UTC (rev 9618)
@@ -0,0 +1,325 @@
+/*
+ * 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.actions.jbpm;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+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.util.jbpm.CommandVehicle;
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmContext;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.graph.exe.Token;
+
+/**
+ *
+ * jBPM command interpreter.
+ *
+ * <p/>This class is tightly coupled with JbpmCommmandVehicle.
+ * <br/>It should be able to interpret all commands in the 'Operation' enum in JbpmCommandVehicle.
+ * <br/>If new operations are added there, the process() method in this class should be changed accordingly.
+ *
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ *
+ */
+public class CommandInterpreter
+{
+
+
+ private CommandInterpreter() {}
+ public CommandInterpreter(ConfigTree config) throws ConfigurationException
+ {
+ _config = config;
+ checkMyParms();
+ } // ________________________________
+
+ public Message process(Message message)
+ {
+ _command = new CommandVehicle(message);
+ Enum operator = _command.getOperator();
+
+
+ if (operator.equals(CommandVehicle.Operation.signalToken))
+ signalToken();
+ else if (operator.equals(CommandVehicle.Operation.signalProcess))
+ signalProcess();
+ else if (operator.equals(CommandVehicle.Operation.getProcessInstanceVariables))
+ getProcessInstanceVariabes();
+ else if (operator.equals(CommandVehicle.Operation.setProcessInstanceVariables))
+ setProcessInstanceVariables();
+ else if (operator.equals(CommandVehicle.Operation.getTokenVariables))
+ getTokenVariabes();
+ else if (operator.equals(CommandVehicle.Operation.setTokenVariables))
+ setTokenVariables();
+ else if (operator.equals(CommandVehicle.Operation.newProcessInstance))
+ newProcessInstance();
+ else if (operator.equals(CommandVehicle.Operation.deployProcessDefinition))
+ deployProcessDefinition();
+ else
+ {
+ _logger.error("Unknown operator: "+operator.toString()+" - Returning message unchanged");
+ _command.setReturnCode(CommandVehicle.RETCODE_INVALID_OPCODE);
+ }
+
+ Message retMsg = _command.toCommandMessage();
+
+ return retMsg;
+ } // ________________________________
+
+ public void deployProcessDefinition()
+ {
+ try
+ {
+ prepareJbpm();
+ _jbpmCtx.getSession().beginTransaction();
+ ProcessDefinition def = _command.getProcessDefinition();
+ _jbpmCtx.deployProcessDefinition(def);
+ _command.setProcessDefinitionName (def.getName());
+ _command.setProcessVersion (def.getVersion());
+ _command.setReturnCode(CommandVehicle.RETCODE_OK);
+ }
+ catch (Exception e)
+ {
+ _command.setReturnCode(CommandVehicle.RETCODE_EXCEPTION);
+ _command.setException(e);
+ }
+ finally { cleanupJbpm(); }
+ } //________________________________
+ public void newProcessInstance()
+ {
+ try
+ {
+ prepareJbpm();
+ _processInstance = _jbpmCtx.newProcessInstance(_command.getProcessDefinitionName());
+ _jbpmCtx.getSession().beginTransaction();
+ _jbpmCtx.save(_processInstance);
+
+ _command.setProcessVersion(_processInstance.getProcessDefinition().getVersion());
+ _command.setInstanceId (_processInstance.getId());
+ _command.setTokenId (_processInstance.getRootToken().getId());
+ _command.setReturnCode(CommandVehicle.RETCODE_OK);
+ }
+ catch (Exception e)
+ {
+ _command.setReturnCode(CommandVehicle.RETCODE_EXCEPTION);
+ _command.setException(e);
+ }
+ finally { cleanupJbpm(); }
+ } //________________________________
+
+ public void signalProcess()
+ {
+ try
+ {
+ long id = _command.getInstanceId();
+ prepareJbpm();
+ _jbpmCtx.getSession().beginTransaction();
+ _processInstance = _jbpmCtx.loadProcessInstanceForUpdate(id);
+ _processInstance.signal();
+ _jbpmCtx.save(_processInstance);
+
+ _command.setReturnCode(CommandVehicle.RETCODE_OK);
+ }
+ catch (Exception e)
+ {
+ _command.setReturnCode(CommandVehicle.RETCODE_EXCEPTION);
+ _command.setException(e);
+ }
+ finally { cleanupJbpm(); }
+ } //________________________________
+
+ public void signalToken()
+ {
+ try
+ {
+ long id = _command.getTokenId();
+ prepareJbpm();
+ _jbpmCtx.getSession().beginTransaction();
+ Token token = _jbpmCtx.loadTokenForUpdate(id);
+ token.signal();
+ _jbpmCtx.save(token);
+
+ _command.setReturnCode(CommandVehicle.RETCODE_OK);
+ }
+ catch (Exception e)
+ {
+ _command.setReturnCode(CommandVehicle.RETCODE_EXCEPTION);
+ _command.setException(e);
+ }
+ finally { cleanupJbpm(); }
+ } //________________________________
+
+ public void getProcessInstanceVariabes()
+ {
+ try
+ {
+ long id = _command.getInstanceId();
+ prepareJbpm();
+ _processInstance = _jbpmCtx.loadProcessInstance(id);
+ Map allVars = _processInstance.getContextInstance().getVariables();
+ _command.setVariableValues(pickVarsFromMap(allVars));
+
+ _command.setReturnCode(CommandVehicle.RETCODE_OK);
+ }
+ catch (Exception e)
+ {
+ _command.setReturnCode(CommandVehicle.RETCODE_EXCEPTION);
+ _command.setException(e);
+ }
+ finally { cleanupJbpm(); }
+ } //________________________________
+
+ public void setProcessInstanceVariables()
+ {
+ try
+ {
+ Map<String,Object>newVals = _command.getVariableValues();
+ if (null==newVals || newVals.size()<1)
+ {
+ _command.setReturnCode(CommandVehicle.RETCODE_ERROR);
+ _command.setErrorMessage("Null or empty variable Map");
+ return;
+ }
+ long id = _command.getInstanceId();
+ prepareJbpm();
+ _jbpmCtx.getSession().beginTransaction();
+ _processInstance = _jbpmCtx.loadProcessInstanceForUpdate(id);
+ _processInstance.getContextInstance().addVariables(newVals);
+ _jbpmCtx.save(_processInstance);
+
+ _command.setReturnCode(CommandVehicle.RETCODE_OK);
+ }
+ catch (Exception e)
+ {
+ _command.setReturnCode(CommandVehicle.RETCODE_EXCEPTION);
+ _command.setException(e);
+ }
+ finally { cleanupJbpm(); }
+ } //________________________________
+
+ public void getTokenVariabes()
+ {
+ try
+ {
+ long id = _command.getTokenId();
+ prepareJbpm();
+ _token = _jbpmCtx.loadToken(id);
+ Map allVars = _token.getProcessInstance().getContextInstance().getVariables(_token);
+ _command.setVariableValues(pickVarsFromMap(allVars));
+
+ _command.setReturnCode(CommandVehicle.RETCODE_OK);
+ }
+ catch (Exception e)
+ {
+ _command.setReturnCode(CommandVehicle.RETCODE_EXCEPTION);
+ _command.setException(e);
+ }
+ finally { cleanupJbpm(); }
+ } //________________________________
+
+ public void setTokenVariables()
+ {
+ try
+ {
+ Map<String,Object>newVals = _command.getVariableValues();
+ if (null==newVals || newVals.size()<1)
+ {
+ _command.setReturnCode(CommandVehicle.RETCODE_ERROR);
+ _command.setErrorMessage("Null or empty variable Map");
+ return;
+ }
+ long id = _command.getTokenId();
+ prepareJbpm();
+ _jbpmCtx.getSession().beginTransaction();
+ _token = _jbpmCtx.loadToken(id);
+ _token.getProcessInstance().getContextInstance().addVariables(newVals,_token);
+ _jbpmCtx.save(_token);
+
+ _command.setReturnCode(CommandVehicle.RETCODE_OK);
+ }
+ catch (Exception e)
+ {
+ _command.setReturnCode(CommandVehicle.RETCODE_EXCEPTION);
+ _command.setException(e);
+ }
+ finally { cleanupJbpm(); }
+ } //________________________________
+
+ /**
+ * Get list of variables requested in command, from map in arg0.
+ * <br/>List of requested variables is obtained from command invoking the getVariableNames() method.
+ * <br/>If the list of variable names is NULL, all variables in the map will be returned.
+ * <br/>If it's an empty List, an empty map will be returned (why would anybody ask for an empty list of vars ?)
+ * @param variables
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ protected Map<String,Object>pickVarsFromMap(Map variables)
+ {
+ Set<String>names = _command.getVariableNames();
+ if (null==names)
+ return variables;
+
+ Map<String,Object>retMap = new HashMap<String, Object>();
+ for(String curr : names)
+ retMap.put(curr, variables.get(curr));
+
+ return retMap;
+ } //________________________________
+
+
+ protected void checkMyParms() throws ConfigurationException
+ {
+ } // _______________________________
+
+ protected void prepareJbpm()
+ {
+ _jbpmConfig = null;
+ _jbpmCtx = null;
+ _jbpmConfig = JbpmConfiguration.getInstance();
+ _jbpmCtx = _jbpmConfig.createJbpmContext();
+ } //________________________________
+ protected void cleanupJbpm()
+ {
+ if (null!=_jbpmCtx) _jbpmCtx.close();
+ if (null!=_jbpmConfig) _jbpmConfig.close();
+ _jbpmConfig = null;
+ _jbpmCtx = null;
+ _processInstance= null;
+ _token = null;
+ } //________________________________
+
+ protected ConfigTree _config;
+ protected CommandVehicle _command;
+ protected JbpmConfiguration _jbpmConfig;
+ protected JbpmContext _jbpmCtx;
+ protected ProcessInstance _processInstance;
+ protected Token _token;
+
+ protected static Logger _logger = Logger.getLogger(CommandInterpreter.class);
+}
Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/jbpm/CommandInterpreter.java
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list