[jboss-svn-commits] JBL Code SVN: r9577 - labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Feb 18 03:15:36 EST 2007
Author: estebanschifman
Date: 2007-02-18 03:15:35 -0500 (Sun, 18 Feb 2007)
New Revision: 9577
Added:
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/AbstractCommandVehicle.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/JbpmCommandVehicle.java
Log:
Helper classes to implement the Command pattern in the scope of the ESB
Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/AbstractCommandVehicle.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/AbstractCommandVehicle.java (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/AbstractCommandVehicle.java 2007-02-18 08:15:35 UTC (rev 9577)
@@ -0,0 +1,105 @@
+/*
+ * 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.util;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.util.JbpmCommandVehicle.Operation;
+/**
+ * Auxiliary class that deals with implementation details of event messages handled by ESB aware applications.
+ * <p/>The '_command' enumeration is inteded to contain all accepted command codes, and should be provided
+ * by all classes that extend AbstractCommandMessage
+ * <br/>Values that this class is able to render are (arbitrarily) stored in a Map<String,Object>
+ * contained in the message body as a named Object with key getCommandValuesTag()
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ *
+ */
+public abstract class AbstractCommandVehicle implements Serializable
+{
+ /**
+ * Provide a name for the named object to look for in the ESB Message body.
+ * @return String : intended to be used as the key in Message.getBody().get(arg)
+ */
+ public abstract String getCommandValuesTag();
+
+ /**
+ * The key for the command operation code in the command values map
+ * @return String : intended to be used as the key in _values.get(arg)
+ */
+ public abstract String getCommandOpcodeKey();
+
+ protected Map<String,Object>_values = new HashMap<String,Object>();
+
+ protected Enum _operator;
+ public Enum getOperator() { return _operator; }
+
+ protected AbstractCommandVehicle(Enum command)
+ {
+ _operator = command;
+ }
+
+ /**
+ * Populate this event's associated values contained in the ESB message
+ * <br/>Values that this class is able to render are expected to be in a Map<String,Object>
+ * contained in the message body as a named Object (key=getCommandValuesTag())
+ * @param message : Message - the vehicle of this command
+ */
+ @SuppressWarnings("unchecked")
+ protected AbstractCommandVehicle(Message message)
+ {
+ Object obj = message.getBody().get(getCommandValuesTag());
+ if (! (obj instanceof Map))
+ throw new IllegalArgumentException("Message command values must be stored as a Map<String,Object>");
+ _values.putAll((Map)obj);
+ _operator = Operation.valueOf((String)_values.get(getCommandOpcodeKey()));
+ _values.remove(getCommandValuesTag());
+ } //________________________________
+
+ /**
+ * Instantiate a new message, and put values where they belong
+ * @return Message - a fresh Message, with the command values in the appropriate spot
+ */
+ public Message toCommandMessage()
+ {
+ Message message = MessageFactory.getInstance().getMessage();
+ _values.put(getCommandOpcodeKey(), _operator.toString());
+ message.getBody().add(getCommandValuesTag(), _values);
+
+ return message;
+ } //________________________________
+
+ protected Object setValue(String key, Object value)
+ {
+ if (null==key)
+ throw new IllegalArgumentException("Key must not be null");
+ Object oldVal = _values.get(key);
+ if (null==value)
+ _values.remove(key);
+ else
+ oldVal = _values.put(key, value);
+ return oldVal;
+ } //________________________________
+}
Property changes on: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/AbstractCommandVehicle.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/JbpmCommandVehicle.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/JbpmCommandVehicle.java (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/JbpmCommandVehicle.java 2007-02-18 08:15:35 UTC (rev 9577)
@@ -0,0 +1,111 @@
+/*
+ * 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.util;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.soa.esb.message.Message;
+
+/**
+ *
+ * Base class to use when a jBPM command should go through the wire to a jBPM aware ESB action class.
+ *
+ * <p/>When more commands are added to the 'Command' enumeration, corresponding action class
+ * (org.jboss.soa.esb.actions.JbpmCommandInterpreter) should be modified accordingly in order to
+ * execute new commands
+ *
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ *
+ */
+public class JbpmCommandVehicle extends AbstractCommandVehicle
+{
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public String getCommandValuesTag() { return "jBPMCommandValues"; }
+ @Override
+ public String getCommandOpcodeKey() { return "jBPMOpCode";}
+
+ public static final String PROCESS_DEFINITION_NAME ="processDefName";
+ public static final String PROCESS_DEFINITION_VERSION ="processVersion";
+ public static final String PROCESS_INSTANCE_ID ="instanceId";
+ public static final String TOKEN_ID ="tokenId";
+ public static final String TRANSITION_NAME ="transitionName";
+ public static final String VARIABLE_NAMES_LIST ="variableNamesList";
+ public static final String VARIABLE_VALUES ="variableValuesMap";
+ public static final String EXCEPTION ="jbpmException";
+ public static final String ERROR_MESSAGE ="errorMsg";
+
+ public static final String RETURN_CODE ="returnCode";
+
+ public static final String RETCODE_OK ="OK";
+ public static final String RETCODE_INVALID_OPCODE ="invalidOpCode";
+ public static final String RETCODE_EXCEPTION ="exceptionThrown";
+ public static final String RETCODE_ERROR ="error";
+
+
+ public enum Operation
+ {
+ newProcessInstance
+ ,signalProcess
+ ,signalToken
+ ,getProcessInstanceVariables
+ ,setProcessInstanceVariables
+ ,getTokenVariables
+ ,setTokenVariables
+ }
+
+ public JbpmCommandVehicle(Enum command) { super(command); }
+ public JbpmCommandVehicle(Message message){ super(message); }
+
+ public Object getReturnCode () { return _values.get(RETURN_CODE); }
+ public String getProcessDefinitionName () { return (String) _values.get(PROCESS_DEFINITION_NAME); }
+ public int getProcessVersion () { return (Integer) _values.get(PROCESS_DEFINITION_VERSION); }
+ public long getInstanceId () { return (Long) _values.get(PROCESS_INSTANCE_ID); }
+ public long getTokenId () { return (Long) _values.get(TOKEN_ID); }
+ public String getTransitionName () { return (String) _values.get(TRANSITION_NAME); }
+ @SuppressWarnings("unchecked")
+ public Set<String> getVariableNames () { return (Set<String>)_values.get(VARIABLE_NAMES_LIST); }
+ @SuppressWarnings("unchecked")
+ public Map<String,Object>getVariableValues()
+ {
+ return (Map)_values.get(VARIABLE_VALUES);
+ }
+ public Exception getException () { return (Exception)_values.get(EXCEPTION); }
+ public String getErrorMessage () { return (String) _values.get(ERROR_MESSAGE); }
+
+ public void setReturnCode (Object obj){ super.setValue(RETURN_CODE ,obj); }
+ public void setProcessDefinitionName(String obj){ super.setValue(PROCESS_DEFINITION_NAME ,obj); }
+ public void setProcessVersion (int obj){ super.setValue(PROCESS_DEFINITION_VERSION,obj); }
+ public void setInstanceId (long obj){ super.setValue(PROCESS_INSTANCE_ID ,obj); }
+ public void setTokenId (long obj){ super.setValue(TOKEN_ID ,obj); }
+ public void setTransitionName (String obj){ super.setValue(TRANSITION_NAME ,obj); }
+ public void setVariableNames (Set<String> obj){ super.setValue(VARIABLE_NAMES_LIST,obj); }
+ public void setVariableValues(Map<String,Object>obj)
+ {
+ super.setValue(VARIABLE_VALUES,obj);
+ }
+ public void setException (Exception obj) { super.setValue(EXCEPTION, obj); }
+ public void setErrorMessage (String obj) { super.setValue(ERROR_MESSAGE, obj); }
+
+}
Property changes on: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/JbpmCommandVehicle.java
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list