[jboss-svn-commits] JBL Code SVN: r24708 - in labs/jbossrules/branches/mfossati: drools-compilers/src/main/java/org/drools/xml/processes and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jan 14 08:56:14 EST 2009
Author: mfossati
Date: 2009-01-14 08:56:14 -0500 (Wed, 14 Jan 2009)
New Revision: 24708
Added:
labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/AbstractProcessInstanceMarshaller.java
labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/ProcessMarshaller.java
labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/ProcessMarshallerRegistry.java
labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/RuleFlowProcessInstanceMarshaller.java
Modified:
labs/jbossrules/branches/mfossati/drools-compilers/src/main/java/org/drools/xml/XmlWorkflowProcessDumper.java
labs/jbossrules/branches/mfossati/drools-compilers/src/main/java/org/drools/xml/processes/ConnectionHandler.java
labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/InputMarshaller.java
labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/OutputMarshaller.java
labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/PersisterEnums.java
Log:
rebranch
Modified: labs/jbossrules/branches/mfossati/drools-compilers/src/main/java/org/drools/xml/XmlWorkflowProcessDumper.java
===================================================================
--- labs/jbossrules/branches/mfossati/drools-compilers/src/main/java/org/drools/xml/XmlWorkflowProcessDumper.java 2009-01-14 13:38:15 UTC (rev 24707)
+++ labs/jbossrules/branches/mfossati/drools-compilers/src/main/java/org/drools/xml/XmlWorkflowProcessDumper.java 2009-01-14 13:56:14 UTC (rev 24708)
@@ -78,7 +78,7 @@
xmlDump.append("</process>");
}
- private void visitHeader(WorkflowProcess process, StringBuffer xmlDump, boolean includeMeta) {
+ protected void visitHeader(WorkflowProcess process, StringBuffer xmlDump, boolean includeMeta) {
xmlDump.append(" <header>" + EOL);
visitImports(((org.drools.process.core.Process) process).getImports(), xmlDump);
visitGlobals(((org.drools.process.core.Process) process).getGlobals(), xmlDump);
Modified: labs/jbossrules/branches/mfossati/drools-compilers/src/main/java/org/drools/xml/processes/ConnectionHandler.java
===================================================================
--- labs/jbossrules/branches/mfossati/drools-compilers/src/main/java/org/drools/xml/processes/ConnectionHandler.java 2009-01-14 13:38:15 UTC (rev 24707)
+++ labs/jbossrules/branches/mfossati/drools-compilers/src/main/java/org/drools/xml/processes/ConnectionHandler.java 2009-01-14 13:56:14 UTC (rev 24708)
@@ -10,66 +10,71 @@
import org.drools.xml.BaseAbstractHandler;
import org.drools.xml.ExtensibleXmlParser;
import org.drools.xml.Handler;
+import org.w3c.dom.Element;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
public class ConnectionHandler extends BaseAbstractHandler implements Handler {
-
public ConnectionHandler() {
if ((this.validParents == null) && (this.validPeers == null)) {
- this.validParents = new HashSet<Class<?>>();
+ this.validParents = new HashSet();
this.validParents.add(NodeContainer.class);
- this.validPeers = new HashSet<Class<?>>();
+
+ this.validPeers = new HashSet();
this.validPeers.add(null);
this.validPeers.add(Connection.class);
+
this.allowNesting = false;
}
}
- public Object start(final String uri, final String localName,
- final Attributes attrs, final ExtensibleXmlParser parser)
- throws SAXException {
- parser.startElementBuilder(localName, attrs);
+ public Object start(final String uri,
+ final String localName,
+ final Attributes attrs,
+ final ExtensibleXmlParser parser) throws SAXException {
+ parser.startElementBuilder( localName, attrs );
+ String fromId = attrs.getValue( "from" );
+ emptyAttributeCheck( localName, "from", fromId, parser );
+ String toId = attrs.getValue( "to" );
+ emptyAttributeCheck( localName, "to", toId, parser );
+ String bendpoints = attrs.getValue( "bendpoints" );
- String fromId = attrs.getValue("from");
- emptyAttributeCheck(localName, "from", fromId, parser);
- String toId = attrs.getValue("to");
- emptyAttributeCheck(localName, "to", toId, parser);
- String bendpoints = attrs.getValue("bendpoints");
-
- String fromType = attrs.getValue("fromType");
+ String fromType = attrs.getValue( "fromType" );
if (fromType == null || fromType.trim().length() == 0) {
fromType = NodeImpl.CONNECTION_DEFAULT_TYPE;
}
- String toType = attrs.getValue("toType");
+ String toType = attrs.getValue( "toType" );
if (toType == null || toType.trim().length() == 0) {
toType = NodeImpl.CONNECTION_DEFAULT_TYPE;
}
NodeContainer nodeContainer = (NodeContainer) parser.getParent();
- Node fromNode = nodeContainer.getNode(new Long(fromId));
- Node toNode = nodeContainer.getNode(new Long(toId));
+ Node fromNode = nodeContainer.getNode( new Long(fromId) );
+ Node toNode = nodeContainer.getNode( new Long(toId) );
- if (fromNode == null) {
- throw new SAXParseException(
- "Node '" + fromId + "' cannot be found", parser.getLocator());
+ if ( fromNode == null ) {
+ throw new SAXParseException( "Node '" + fromId + "'cannot be found",
+ parser.getLocator() );
}
- if (toNode == null) {
- throw new SAXParseException("Node '" + toId + "' cannot be found", parser.getLocator());
+ if ( toNode == null ) {
+ throw new SAXParseException( "Node '" + toId + "' cannot be found",
+ parser.getLocator() );
}
- ConnectionImpl connection = new ConnectionImpl(fromNode, fromType, toNode, toType);
+ ConnectionImpl connection = new ConnectionImpl(fromNode, fromType,toNode, toType);
connection.setMetaData("bendpoints", bendpoints);
return connection;
}
- public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
+ public Object end(final String uri, final String localName,
+ final ExtensibleXmlParser parser) throws SAXException {
+ final Element element = parser.endElementBuilder();
return parser.getCurrent();
}
- public Class<?> generateNodeFor() {
+ public Class generateNodeFor() {
return Connection.class;
}
Added: labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/AbstractProcessInstanceMarshaller.java
===================================================================
--- labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/AbstractProcessInstanceMarshaller.java (rev 0)
+++ labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/AbstractProcessInstanceMarshaller.java 2009-01-14 13:56:14 UTC (rev 24708)
@@ -0,0 +1,297 @@
+package org.drools.marshalling;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.drools.process.core.context.swimlane.SwimlaneContext;
+import org.drools.process.core.context.variable.VariableScope;
+import org.drools.process.instance.context.swimlane.SwimlaneContextInstance;
+import org.drools.process.instance.context.variable.VariableScopeInstance;
+import org.drools.process.instance.impl.ProcessInstanceImpl;
+import org.drools.runtime.process.NodeInstance;
+import org.drools.runtime.process.NodeInstanceContainer;
+import org.drools.runtime.process.ProcessInstance;
+import org.drools.workflow.instance.WorkflowProcessInstance;
+import org.drools.workflow.instance.impl.NodeInstanceImpl;
+import org.drools.workflow.instance.impl.WorkflowProcessInstanceImpl;
+import org.drools.workflow.instance.node.CompositeContextNodeInstance;
+import org.drools.workflow.instance.node.ForEachNodeInstance;
+import org.drools.workflow.instance.node.HumanTaskNodeInstance;
+import org.drools.workflow.instance.node.JoinInstance;
+import org.drools.workflow.instance.node.MilestoneNodeInstance;
+import org.drools.workflow.instance.node.RuleSetNodeInstance;
+import org.drools.workflow.instance.node.SubProcessNodeInstance;
+import org.drools.workflow.instance.node.TimerNodeInstance;
+import org.drools.workflow.instance.node.WorkItemNodeInstance;
+
+
+/* Author: mfossati, salaboy */
+public abstract class AbstractProcessInstanceMarshaller implements ProcessMarshaller {
+
+ // Output methods
+
+ public void writeProcessInstance(MarshallerWriteContext context, ProcessInstance processInstance)
+ throws IOException {
+
+ WorkflowProcessInstanceImpl workFlow = (WorkflowProcessInstanceImpl) processInstance;
+ ObjectOutputStream stream = context.stream;
+ // saves the processInstance type first
+ stream.writeUTF(((ProcessInstanceImpl)processInstance).getProcess().getType());
+ stream.writeLong(workFlow.getId());
+ stream.writeUTF(workFlow.getProcessId());
+ stream.writeInt(workFlow.getState());
+ stream.writeLong(workFlow.getNodeInstanceCounter());
+
+ VariableScopeInstance variableScopeInstance = (VariableScopeInstance) workFlow
+ .getContextInstance(VariableScope.VARIABLE_SCOPE);
+ Map<String, Object> variables = variableScopeInstance.getVariables();
+ List<String> keys = new ArrayList<String>(variables.keySet());
+ Collections.sort(keys, new Comparator<String>() {
+ public int compare(String o1, String o2) {
+ return o1.compareTo(o2);
+ }
+ });
+ stream.writeInt(keys.size());
+ for (String key : keys) {
+ stream.writeUTF(key);
+ stream.writeObject(variables.get(key));
+ }
+
+ SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) workFlow
+ .getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);
+ if (swimlaneContextInstance != null) {
+ Map<String, String> swimlaneActors = swimlaneContextInstance.getSwimlaneActors();
+ stream.writeInt(swimlaneActors.size());
+ for (Map.Entry<String, String> entry : swimlaneActors.entrySet()) {
+ stream.writeUTF(entry.getKey());
+ stream.writeUTF(entry.getValue());
+ }
+ }
+ List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(workFlow.getNodeInstances());
+ Collections.sort(nodeInstances, new Comparator<NodeInstance>() {
+ public int compare(NodeInstance o1, NodeInstance o2) {
+ return (int) (o1.getId() - o2.getId());
+ }
+ });
+ for (NodeInstance nodeInstance : nodeInstances) {
+ stream.writeShort(PersisterEnums.NODE_INSTANCE);
+ writeNodeInstance(context, nodeInstance);
+ }
+ stream.writeShort(PersisterEnums.END);
+ }
+
+ public void writeNodeInstance(MarshallerWriteContext context, NodeInstance nodeInstance) throws IOException {
+ processCommonNodes(context, nodeInstance);
+ }
+
+ protected final void processCommonNodes(MarshallerWriteContext context, NodeInstance nodeInstance)
+ throws IOException {
+ ObjectOutputStream stream = context.stream;
+ stream.writeLong(nodeInstance.getId());
+ stream.writeLong(nodeInstance.getNodeId());
+ if (nodeInstance instanceof RuleSetNodeInstance) {
+ stream.writeShort(PersisterEnums.RULE_SET_NODE_INSTANCE);
+ } else if (nodeInstance instanceof HumanTaskNodeInstance) {
+ stream.writeShort(PersisterEnums.HUMAN_TASK_NODE_INSTANCE);
+ stream.writeLong(((HumanTaskNodeInstance) nodeInstance).getWorkItem().getId());
+ } else if (nodeInstance instanceof WorkItemNodeInstance) {
+ stream.writeShort(PersisterEnums.WORK_ITEM_NODE_INSTANCE);
+ stream.writeLong(((WorkItemNodeInstance) nodeInstance).getWorkItem().getId());
+ } else if (nodeInstance instanceof SubProcessNodeInstance) {
+ stream.writeShort(PersisterEnums.SUB_PROCESS_NODE_INSTANCE);
+ stream.writeLong(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId());
+ } else if (nodeInstance instanceof MilestoneNodeInstance) {
+ stream.writeShort(PersisterEnums.MILESTONE_NODE_INSTANCE);
+ List<Long> timerInstances = ((MilestoneNodeInstance) nodeInstance).getTimerInstances();
+ if (timerInstances != null) {
+ stream.writeInt(timerInstances.size());
+ for (Long id : timerInstances) {
+ stream.writeLong(id);
+ }
+ } else {
+ stream.writeInt(0);
+ }
+ } else if (nodeInstance instanceof TimerNodeInstance) {
+ stream.writeShort(PersisterEnums.TIMER_NODE_INSTANCE);
+ stream.writeLong(((TimerNodeInstance) nodeInstance).getTimerId());
+ } else if (nodeInstance instanceof JoinInstance) {
+ stream.writeShort(PersisterEnums.JOIN_NODE_INSTANCE);
+ Map<Long, Integer> triggers = ((JoinInstance) nodeInstance).getTriggers();
+ stream.writeInt(triggers.size());
+ List<Long> keys = new ArrayList<Long>(triggers.keySet());
+ Collections.sort(keys, new Comparator<Long>() {
+ public int compare(Long o1, Long o2) {
+ return o1.compareTo(o2);
+ }
+ });
+ for (Long key : keys) {
+ stream.writeLong(key);
+ stream.writeInt(triggers.get(key));
+ }
+ } else if (nodeInstance instanceof CompositeContextNodeInstance) {
+ stream.writeShort(PersisterEnums.COMPOSITE_NODE_INSTANCE);
+ CompositeContextNodeInstance compositeNodeInstance = (CompositeContextNodeInstance) nodeInstance;
+ VariableScopeInstance variableScopeInstance = (VariableScopeInstance) compositeNodeInstance
+ .getContextInstance(VariableScope.VARIABLE_SCOPE);
+ Map<String, Object> variables = variableScopeInstance.getVariables();
+ List<String> keys = new ArrayList<String>(variables.keySet());
+ Collections.sort(keys, new Comparator<String>() {
+ public int compare(String o1, String o2) {
+ return o1.compareTo(o2);
+ }
+ });
+ stream.writeInt(keys.size());
+ for (String key : keys) {
+ stream.writeUTF(key);
+ stream.writeObject(variables.get(key));
+ }
+ List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(compositeNodeInstance.getNodeInstances());
+ Collections.sort(nodeInstances, new Comparator<NodeInstance>() {
+ public int compare(NodeInstance o1, NodeInstance o2) {
+ return (int) (o1.getId() - o2.getId());
+ }
+ });
+ for (NodeInstance subNodeInstance : nodeInstances) {
+ stream.writeShort(PersisterEnums.NODE_INSTANCE);
+ writeNodeInstance(context, subNodeInstance);
+ }
+ stream.writeShort(PersisterEnums.END);
+ } else if (nodeInstance instanceof ForEachNodeInstance) {
+ stream.writeShort(PersisterEnums.FOR_EACH_NODE_INSTANCE);
+ ForEachNodeInstance forEachNodeInstance = (ForEachNodeInstance) nodeInstance;
+ List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(forEachNodeInstance.getNodeInstances());
+ Collections.sort(nodeInstances, new Comparator<NodeInstance>() {
+ public int compare(NodeInstance o1, NodeInstance o2) {
+ return (int) (o1.getId() - o2.getId());
+ }
+ });
+ for (NodeInstance subNodeInstance : nodeInstances) {
+ if (subNodeInstance instanceof CompositeContextNodeInstance) {
+ stream.writeShort(PersisterEnums.NODE_INSTANCE);
+ writeNodeInstance(context, subNodeInstance);
+ }
+ }
+ stream.writeShort(PersisterEnums.END);
+ } else {
+
+ // TODO timer manager
+ try {
+ outputSpecificNodes(context, nodeInstance);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ throw new IllegalArgumentException("Unknown node instance type: " + nodeInstance);
+ }
+ }
+ }
+
+ protected abstract void outputSpecificNodes(MarshallerWriteContext context, NodeInstance nodeInstance)
+ throws IOException;
+
+
+ // Input methods
+
+ public abstract ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException;
+
+
+ public NodeInstance readNodeInstance(MarshallerReaderContext context, NodeInstanceContainer nodeInstanceContainer,
+ WorkflowProcessInstance processInstance) throws IOException {
+ ObjectInputStream stream = context.stream;
+ NodeInstanceImpl nodeInstance = null;
+ long id = stream.readLong();
+ long nodeId = stream.readLong();
+ int nodeType = stream.readShort();
+ nodeInstance = inputSpecificNode(nodeInstance,nodeType,stream);
+ boolean found = (nodeInstance != null ? true : false);
+
+ if (!found) {
+ switch (nodeType) {
+ case PersisterEnums.RULE_SET_NODE_INSTANCE:
+ nodeInstance = new RuleSetNodeInstance();
+ break;
+ case PersisterEnums.HUMAN_TASK_NODE_INSTANCE:
+ nodeInstance = new HumanTaskNodeInstance();
+ ((HumanTaskNodeInstance) nodeInstance).internalSetWorkItemId(stream.readLong());
+ break;
+ case PersisterEnums.WORK_ITEM_NODE_INSTANCE:
+ nodeInstance = new WorkItemNodeInstance();
+ ((WorkItemNodeInstance) nodeInstance).internalSetWorkItemId(stream.readLong());
+ break;
+ case PersisterEnums.SUB_PROCESS_NODE_INSTANCE:
+ nodeInstance = new SubProcessNodeInstance();
+ ((SubProcessNodeInstance) nodeInstance).internalSetProcessInstanceId(stream.readLong());
+ break;
+ case PersisterEnums.MILESTONE_NODE_INSTANCE:
+ nodeInstance = new MilestoneNodeInstance();
+ int nbTimerInstances = stream.readInt();
+ if (nbTimerInstances > 0) {
+ List<Long> timerInstances = new ArrayList<Long>();
+ for (int i = 0; i < nbTimerInstances; i++) {
+ timerInstances.add(stream.readLong());
+ }
+ ((MilestoneNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
+ }
+ break;
+ case PersisterEnums.TIMER_NODE_INSTANCE:
+ nodeInstance = new TimerNodeInstance();
+ ((TimerNodeInstance) nodeInstance).internalSetTimerId(stream.readLong());
+ break;
+ case PersisterEnums.JOIN_NODE_INSTANCE:
+ nodeInstance = new JoinInstance();
+ int number = stream.readInt();
+ if (number > 0) {
+ Map<Long, Integer> triggers = new HashMap<Long, Integer>();
+ for (int i = 0; i < number; i++) {
+ long l = stream.readLong();
+ int count = stream.readInt();
+ triggers.put(l, count);
+ }
+ ((JoinInstance) nodeInstance).internalSetTriggers(triggers);
+ }
+ break;
+
+ case PersisterEnums.COMPOSITE_NODE_INSTANCE:
+ int nbVariables = stream.readInt();
+ if (nbVariables > 0) {
+ VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((CompositeContextNodeInstance) nodeInstance)
+ .getContextInstance(VariableScope.VARIABLE_SCOPE);
+ for (int i = 0; i < nbVariables; i++) {
+ String name = stream.readUTF();
+ try {
+ Object value = stream.readObject();
+ variableScopeInstance.setVariable(name, value);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException("Could not reload variable " + name);
+ }
+ }
+ }
+ while (stream.readShort() == PersisterEnums.NODE_INSTANCE) {
+ readNodeInstance(context, (CompositeContextNodeInstance) nodeInstance, processInstance);
+ }
+ break;
+ case PersisterEnums.FOR_EACH_NODE_INSTANCE:
+ while (stream.readShort() == PersisterEnums.NODE_INSTANCE) {
+ readNodeInstance(context, (ForEachNodeInstance) nodeInstance, processInstance);
+ }
+ break;
+ default:
+ throw new IllegalArgumentException("Unknown node type: " + nodeType);
+ }
+ }
+ nodeInstance.setNodeId(nodeId);
+ nodeInstance.setNodeInstanceContainer(nodeInstanceContainer);
+ nodeInstance.setProcessInstance(processInstance);
+ nodeInstance.setId(id);
+
+
+
+
+ return nodeInstance;
+ }
+}
Modified: labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/InputMarshaller.java
===================================================================
--- labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/InputMarshaller.java 2009-01-14 13:38:15 UTC (rev 24707)
+++ labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/InputMarshaller.java 2009-01-14 13:56:14 UTC (rev 24708)
@@ -3,10 +3,7 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Queue;
@@ -29,13 +26,9 @@
import org.drools.common.RuleFlowGroupImpl;
import org.drools.common.TruthMaintenanceSystem;
import org.drools.concurrent.ExecutorService;
-import org.drools.process.core.context.swimlane.SwimlaneContext;
-import org.drools.process.core.context.variable.VariableScope;
-import org.drools.process.instance.ProcessInstance;
import org.drools.process.instance.WorkItem;
import org.drools.process.instance.WorkItemManager;
-import org.drools.process.instance.context.swimlane.SwimlaneContextInstance;
-import org.drools.process.instance.context.variable.VariableScopeInstance;
+import org.drools.process.instance.impl.ProcessInstanceImpl;
import org.drools.process.instance.impl.WorkItemImpl;
import org.drools.process.instance.timer.TimerInstance;
import org.drools.process.instance.timer.TimerManager;
@@ -64,9 +57,6 @@
import org.drools.rule.GroupElement;
import org.drools.rule.Package;
import org.drools.rule.Rule;
-import org.drools.ruleflow.instance.RuleFlowProcessInstance;
-import org.drools.runtime.process.NodeInstance;
-import org.drools.runtime.process.NodeInstanceContainer;
import org.drools.spi.Activation;
import org.drools.spi.AgendaGroup;
import org.drools.spi.FactHandleFactory;
@@ -75,16 +65,6 @@
import org.drools.spi.RuleFlowGroup;
import org.drools.util.ObjectHashMap;
import org.drools.util.ObjectHashSet;
-import org.drools.workflow.instance.impl.NodeInstanceImpl;
-import org.drools.workflow.instance.node.CompositeContextNodeInstance;
-import org.drools.workflow.instance.node.ForEachNodeInstance;
-import org.drools.workflow.instance.node.HumanTaskNodeInstance;
-import org.drools.workflow.instance.node.JoinInstance;
-import org.drools.workflow.instance.node.MilestoneNodeInstance;
-import org.drools.workflow.instance.node.RuleSetNodeInstance;
-import org.drools.workflow.instance.node.SubProcessNodeInstance;
-import org.drools.workflow.instance.node.TimerNodeInstance;
-import org.drools.workflow.instance.node.WorkItemNodeInstance;
public class InputMarshaller {
/**
@@ -770,167 +750,175 @@
}
public static void readProcessInstances(MarshallerReaderContext context) throws IOException {
- ObjectInputStream stream = context.stream;
+ ObjectInputStream stream = context.stream;
+ ProcessMarshaller marshaller = getMarshaller(context);
while ( stream.readShort() == PersisterEnums.PROCESS_INSTANCE ) {
- readProcessInstance( context );
+ marshaller.readProcessInstance( context );
}
}
-
- public static ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException {
- ObjectInputStream stream = context.stream;
- InternalRuleBase ruleBase = context.ruleBase;
- InternalWorkingMemory wm = context.wm;
-
- RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
- processInstance.setId( stream.readLong() );
- String processId = stream.readUTF();
- processInstance.setProcessId( processId );
- if ( ruleBase != null ) {
- processInstance.setProcess( ruleBase.getProcess( processId ) );
- }
- processInstance.setState( stream.readInt() );
- long nodeInstanceCounter = stream.readLong();
- processInstance.setWorkingMemory( wm );
-
- int nbVariables = stream.readInt();
- if ( nbVariables > 0 ) {
- VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance( VariableScope.VARIABLE_SCOPE );
- for ( int i = 0; i < nbVariables; i++ ) {
- String name = stream.readUTF();
- try {
- Object value = stream.readObject();
- variableScopeInstance.setVariable( name,
- value );
- } catch ( ClassNotFoundException e ) {
- throw new IllegalArgumentException( "Could not reload variable " + name );
- }
- }
- }
-
- int nbSwimlanes = stream.readInt();
- if ( nbSwimlanes > 0 ) {
- SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance( SwimlaneContext.SWIMLANE_SCOPE );
- for ( int i = 0; i < nbSwimlanes; i++ ) {
- String name = stream.readUTF();
- String value = stream.readUTF();
- swimlaneContextInstance.setActorId( name,
- value );
- }
- }
-
- while ( stream.readShort() == PersisterEnums.NODE_INSTANCE ) {
- readNodeInstance( context,
- processInstance,
- processInstance );
- }
-
- processInstance.internalSetNodeInstanceCounter( nodeInstanceCounter );
- if ( wm != null ) {
- processInstance.reconnect();
- }
- return processInstance;
+
+ public static ProcessMarshaller getMarshaller (MarshallerReaderContext context) throws IOException {
+ ObjectInputStream stream = context.stream;
+ String processInstanceType= null;
+ processInstanceType = stream.readUTF();
+ return ProcessMarshallerRegistry.INSTANCE.getMarshaller(processInstanceType);
}
- public static NodeInstance readNodeInstance(MarshallerReaderContext context,
- NodeInstanceContainer nodeInstanceContainer,
- RuleFlowProcessInstance processInstance) throws IOException {
- ObjectInputStream stream = context.stream;
- NodeInstanceImpl nodeInstance = null;
- long id = stream.readLong();
- long nodeId = stream.readLong();
- int nodeType = stream.readShort();
- switch ( nodeType ) {
- case PersisterEnums.RULE_SET_NODE_INSTANCE :
- nodeInstance = new RuleSetNodeInstance();
- break;
- case PersisterEnums.HUMAN_TASK_NODE_INSTANCE :
- nodeInstance = new HumanTaskNodeInstance();
- ((HumanTaskNodeInstance) nodeInstance).internalSetWorkItemId( stream.readLong() );
- break;
- case PersisterEnums.WORK_ITEM_NODE_INSTANCE :
- nodeInstance = new WorkItemNodeInstance();
- ((WorkItemNodeInstance) nodeInstance).internalSetWorkItemId( stream.readLong() );
- break;
- case PersisterEnums.SUB_PROCESS_NODE_INSTANCE :
- nodeInstance = new SubProcessNodeInstance();
- ((SubProcessNodeInstance) nodeInstance).internalSetProcessInstanceId( stream.readLong() );
- break;
- case PersisterEnums.MILESTONE_NODE_INSTANCE :
- nodeInstance = new MilestoneNodeInstance();
- int nbTimerInstances = stream.readInt();
- if (nbTimerInstances > 0) {
- List<Long> timerInstances = new ArrayList<Long>();
- for (int i = 0; i < nbTimerInstances; i++) {
- timerInstances.add(stream.readLong());
- }
- ((MilestoneNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
- }
- break;
- case PersisterEnums.TIMER_NODE_INSTANCE :
- nodeInstance = new TimerNodeInstance();
- ((TimerNodeInstance) nodeInstance).internalSetTimerId( stream.readLong() );
- break;
- case PersisterEnums.JOIN_NODE_INSTANCE :
- nodeInstance = new JoinInstance();
- int number = stream.readInt();
- if ( number > 0 ) {
- Map<Long, Integer> triggers = new HashMap<Long, Integer>();
- for ( int i = 0; i < number; i++ ) {
- long l = stream.readLong();
- int count = stream.readInt();
- triggers.put( l,
- count );
- }
- ((JoinInstance) nodeInstance).internalSetTriggers( triggers );
- }
- break;
- case PersisterEnums.COMPOSITE_NODE_INSTANCE :
- nodeInstance = new CompositeContextNodeInstance();
- break;
- case PersisterEnums.FOR_EACH_NODE_INSTANCE :
- nodeInstance = new ForEachNodeInstance();
- break;
- default :
- throw new IllegalArgumentException( "Unknown node type: " + nodeType );
- }
- nodeInstance.setNodeId( nodeId );
- nodeInstance.setNodeInstanceContainer( nodeInstanceContainer );
- nodeInstance.setProcessInstance( processInstance );
- nodeInstance.setId( id );
- switch ( nodeType ) {
- case PersisterEnums.COMPOSITE_NODE_INSTANCE :
- int nbVariables = stream.readInt();
- if ( nbVariables > 0 ) {
- VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((CompositeContextNodeInstance) nodeInstance).getContextInstance( VariableScope.VARIABLE_SCOPE );
- for ( int i = 0; i < nbVariables; i++ ) {
- String name = stream.readUTF();
- try {
- Object value = stream.readObject();
- variableScopeInstance.setVariable( name,
- value );
- } catch ( ClassNotFoundException e ) {
- throw new IllegalArgumentException( "Could not reload variable " + name );
- }
- }
- }
- while ( stream.readShort() == PersisterEnums.NODE_INSTANCE ) {
- readNodeInstance( context,
- (CompositeContextNodeInstance) nodeInstance,
- processInstance );
- }
- break;
- case PersisterEnums.FOR_EACH_NODE_INSTANCE :
- while ( stream.readShort() == PersisterEnums.NODE_INSTANCE ) {
- readNodeInstance( context,
- (ForEachNodeInstance) nodeInstance,
- processInstance );
- }
- break;
- default :
- // do nothing
- }
- return nodeInstance;
- }
+// public static ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException {
+// ObjectInputStream stream = context.stream;
+// InternalRuleBase ruleBase = context.ruleBase;
+// InternalWorkingMemory wm = context.wm;
+//
+// RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
+// processInstance.setId( stream.readLong() );
+// String processId = stream.readUTF();
+// processInstance.setProcessId( processId );
+// if ( ruleBase != null ) {
+// processInstance.setProcess( ruleBase.getProcess( processId ) );
+// }
+// processInstance.setState( stream.readInt() );
+// long nodeInstanceCounter = stream.readLong();
+// processInstance.setWorkingMemory( wm );
+//
+// int nbVariables = stream.readInt();
+// if ( nbVariables > 0 ) {
+// VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance( VariableScope.VARIABLE_SCOPE );
+// for ( int i = 0; i < nbVariables; i++ ) {
+// String name = stream.readUTF();
+// try {
+// Object value = stream.readObject();
+// variableScopeInstance.setVariable( name,
+// value );
+// } catch ( ClassNotFoundException e ) {
+// throw new IllegalArgumentException( "Could not reload variable " + name );
+// }
+// }
+// }
+//
+// int nbSwimlanes = stream.readInt();
+// if ( nbSwimlanes > 0 ) {
+// SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance( SwimlaneContext.SWIMLANE_SCOPE );
+// for ( int i = 0; i < nbSwimlanes; i++ ) {
+// String name = stream.readUTF();
+// String value = stream.readUTF();
+// swimlaneContextInstance.setActorId( name,
+// value );
+// }
+// }
+//
+// while ( stream.readShort() == PersisterEnums.NODE_INSTANCE ) {
+// readNodeInstance( context,
+// processInstance,
+// processInstance );
+// }
+//
+// processInstance.internalSetNodeInstanceCounter( nodeInstanceCounter );
+// if ( wm != null ) {
+// processInstance.reconnect();
+// }
+// return processInstance;
+// }
+//
+// public static NodeInstance readNodeInstance(MarshallerReaderContext context,
+// NodeInstanceContainer nodeInstanceContainer,
+// RuleFlowProcessInstance processInstance) throws IOException {
+// ObjectInputStream stream = context.stream;
+// NodeInstanceImpl nodeInstance = null;
+// long id = stream.readLong();
+// long nodeId = stream.readLong();
+// int nodeType = stream.readShort();
+// switch ( nodeType ) {
+// case PersisterEnums.RULE_SET_NODE_INSTANCE :
+// nodeInstance = new RuleSetNodeInstance();
+// break;
+// case PersisterEnums.HUMAN_TASK_NODE_INSTANCE :
+// nodeInstance = new HumanTaskNodeInstance();
+// ((HumanTaskNodeInstance) nodeInstance).internalSetWorkItemId( stream.readLong() );
+// break;
+// case PersisterEnums.WORK_ITEM_NODE_INSTANCE :
+// nodeInstance = new WorkItemNodeInstance();
+// ((WorkItemNodeInstance) nodeInstance).internalSetWorkItemId( stream.readLong() );
+// break;
+// case PersisterEnums.SUB_PROCESS_NODE_INSTANCE :
+// nodeInstance = new SubProcessNodeInstance();
+// ((SubProcessNodeInstance) nodeInstance).internalSetProcessInstanceId( stream.readLong() );
+// break;
+// case PersisterEnums.MILESTONE_NODE_INSTANCE :
+// nodeInstance = new MilestoneNodeInstance();
+// int nbTimerInstances = stream.readInt();
+// if (nbTimerInstances > 0) {
+// List<Long> timerInstances = new ArrayList<Long>();
+// for (int i = 0; i < nbTimerInstances; i++) {
+// timerInstances.add(stream.readLong());
+// }
+// ((MilestoneNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
+// }
+// break;
+// case PersisterEnums.TIMER_NODE_INSTANCE :
+// nodeInstance = new TimerNodeInstance();
+// ((TimerNodeInstance) nodeInstance).internalSetTimerId( stream.readLong() );
+// break;
+// case PersisterEnums.JOIN_NODE_INSTANCE :
+// nodeInstance = new JoinInstance();
+// int number = stream.readInt();
+// if ( number > 0 ) {
+// Map<Long, Integer> triggers = new HashMap<Long, Integer>();
+// for ( int i = 0; i < number; i++ ) {
+// long l = stream.readLong();
+// int count = stream.readInt();
+// triggers.put( l,
+// count );
+// }
+// ((JoinInstance) nodeInstance).internalSetTriggers( triggers );
+// }
+// break;
+// case PersisterEnums.COMPOSITE_NODE_INSTANCE :
+// nodeInstance = new CompositeContextNodeInstance();
+// break;
+// case PersisterEnums.FOR_EACH_NODE_INSTANCE :
+// nodeInstance = new ForEachNodeInstance();
+// break;
+// default :
+// throw new IllegalArgumentException( "Unknown node type: " + nodeType );
+// }
+// nodeInstance.setNodeId( nodeId );
+// nodeInstance.setNodeInstanceContainer( nodeInstanceContainer );
+// nodeInstance.setProcessInstance( processInstance );
+// nodeInstance.setId( id );
+// switch ( nodeType ) {
+// case PersisterEnums.COMPOSITE_NODE_INSTANCE :
+// int nbVariables = stream.readInt();
+// if ( nbVariables > 0 ) {
+// VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((CompositeContextNodeInstance) nodeInstance).getContextInstance( VariableScope.VARIABLE_SCOPE );
+// for ( int i = 0; i < nbVariables; i++ ) {
+// String name = stream.readUTF();
+// try {
+// Object value = stream.readObject();
+// variableScopeInstance.setVariable( name,
+// value );
+// } catch ( ClassNotFoundException e ) {
+// throw new IllegalArgumentException( "Could not reload variable " + name );
+// }
+// }
+// }
+// while ( stream.readShort() == PersisterEnums.NODE_INSTANCE ) {
+// readNodeInstance( context,
+// (CompositeContextNodeInstance) nodeInstance,
+// processInstance );
+// }
+// break;
+// case PersisterEnums.FOR_EACH_NODE_INSTANCE :
+// while ( stream.readShort() == PersisterEnums.NODE_INSTANCE ) {
+// readNodeInstance( context,
+// (ForEachNodeInstance) nodeInstance,
+// processInstance );
+// }
+// break;
+// default :
+// // do nothing
+// }
+// return nodeInstance;
+// }
public static void readWorkItems(MarshallerReaderContext context) throws IOException {
InternalWorkingMemory wm = context.wm;
Modified: labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/OutputMarshaller.java
===================================================================
--- labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/OutputMarshaller.java 2009-01-14 13:38:15 UTC (rev 24707)
+++ labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/OutputMarshaller.java 2009-01-14 13:56:14 UTC (rev 24708)
@@ -27,11 +27,8 @@
import org.drools.common.ObjectStore;
import org.drools.common.RuleFlowGroupImpl;
import org.drools.common.WorkingMemoryAction;
-import org.drools.process.core.context.swimlane.SwimlaneContext;
-import org.drools.process.core.context.variable.VariableScope;
import org.drools.process.instance.WorkItemManager;
-import org.drools.process.instance.context.swimlane.SwimlaneContextInstance;
-import org.drools.process.instance.context.variable.VariableScopeInstance;
+import org.drools.process.instance.impl.ProcessInstanceImpl;
import org.drools.process.instance.timer.TimerInstance;
import org.drools.process.instance.timer.TimerManager;
import org.drools.reteoo.BetaNode;
@@ -49,7 +46,7 @@
import org.drools.rule.EntryPoint;
import org.drools.rule.Rule;
import org.drools.ruleflow.instance.RuleFlowProcessInstance;
-import org.drools.runtime.process.NodeInstance;
+import org.drools.runtime.process.ProcessInstance;
import org.drools.runtime.process.WorkItem;
import org.drools.spi.ActivationGroup;
import org.drools.spi.AgendaGroup;
@@ -57,15 +54,6 @@
import org.drools.spi.RuleFlowGroup;
import org.drools.util.ObjectHashMap;
import org.drools.util.ObjectHashSet;
-import org.drools.workflow.instance.node.CompositeContextNodeInstance;
-import org.drools.workflow.instance.node.ForEachNodeInstance;
-import org.drools.workflow.instance.node.HumanTaskNodeInstance;
-import org.drools.workflow.instance.node.JoinInstance;
-import org.drools.workflow.instance.node.MilestoneNodeInstance;
-import org.drools.workflow.instance.node.RuleSetNodeInstance;
-import org.drools.workflow.instance.node.SubProcessNodeInstance;
-import org.drools.workflow.instance.node.TimerNodeInstance;
-import org.drools.workflow.instance.node.WorkItemNodeInstance;
public class OutputMarshaller {
public static void writeSession(MarshallerWriteContext context) throws IOException {
@@ -739,164 +727,173 @@
for ( org.drools.runtime.process.ProcessInstance processInstance : processInstances ) {
stream.writeShort( PersisterEnums.PROCESS_INSTANCE );
writeProcessInstance( context,
- (RuleFlowProcessInstance) processInstance );
+ (ProcessInstanceImpl)processInstance );
}
stream.writeShort( PersisterEnums.END );
}
+
+ public static void writeProcessInstance(MarshallerWriteContext context,
+ ProcessInstance processInstance) throws IOException {
- public static void writeProcessInstance(MarshallerWriteContext context,
- RuleFlowProcessInstance processInstance) throws IOException {
- ObjectOutputStream stream = context.stream;
- stream.writeLong( processInstance.getId() );
- stream.writeUTF( processInstance.getProcessId() );
- stream.writeInt( processInstance.getState() );
- stream.writeLong( processInstance.getNodeInstanceCounter() );
+ ProcessMarshaller marshaller = ProcessMarshallerRegistry.INSTANCE
+ .getMarshaller(((ProcessInstanceImpl)processInstance).getProcess().getType());
+ marshaller.writeProcessInstance(context, processInstance);
- VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance( VariableScope.VARIABLE_SCOPE );
- Map<String, Object> variables = variableScopeInstance.getVariables();
- List<String> keys = new ArrayList<String>( variables.keySet() );
- Collections.sort( keys,
- new Comparator<String>() {
- public int compare(String o1,
- String o2) {
- return o1.compareTo( o2 );
- }
- } );
- stream.writeInt( keys.size() );
- for ( String key : keys ) {
- stream.writeUTF( key );
- stream.writeObject( variables.get( key ) );
- }
+ }
+//
+// public static void writeProcessInstance(MarshallerWriteContext context,
+// RuleFlowProcessInstance processInstance) throws IOException {
+// ObjectOutputStream stream = context.stream;
+// stream.writeLong( processInstance.getId() );
+// stream.writeUTF( processInstance.getProcessId() );
+// stream.writeInt( processInstance.getState() );
+// stream.writeLong( processInstance.getNodeInstanceCounter() );
+//
+// VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance( VariableScope.VARIABLE_SCOPE );
+// Map<String, Object> variables = variableScopeInstance.getVariables();
+// List<String> keys = new ArrayList<String>( variables.keySet() );
+// Collections.sort( keys,
+// new Comparator<String>() {
+// public int compare(String o1,
+// String o2) {
+// return o1.compareTo( o2 );
+// }
+// } );
+// stream.writeInt( keys.size() );
+// for ( String key : keys ) {
+// stream.writeUTF( key );
+// stream.writeObject( variables.get( key ) );
+// }
+//
+// SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance( SwimlaneContext.SWIMLANE_SCOPE );
+// Map<String, String> swimlaneActors = swimlaneContextInstance.getSwimlaneActors();
+// stream.writeInt( swimlaneActors.size() );
+// for ( Map.Entry<String, String> entry : swimlaneActors.entrySet() ) {
+// stream.writeUTF( entry.getKey() );
+// stream.writeUTF( entry.getValue() );
+// }
+//
+// List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>( processInstance.getNodeInstances() );
+// Collections.sort( nodeInstances,
+// new Comparator<NodeInstance>() {
+// public int compare(NodeInstance o1,
+// NodeInstance o2) {
+// return (int) (o1.getId() - o2.getId());
+// }
+// } );
+// for ( NodeInstance nodeInstance : nodeInstances ) {
+// stream.writeShort( PersisterEnums.NODE_INSTANCE );
+// writeNodeInstance( context,
+// nodeInstance );
+// }
+// stream.writeShort( PersisterEnums.END );
+// }
+//
+// public static void writeNodeInstance(MarshallerWriteContext context,
+// NodeInstance nodeInstance) throws IOException {
+// ObjectOutputStream stream = context.stream;
+// stream.writeLong( nodeInstance.getId() );
+// stream.writeLong( nodeInstance.getNodeId() );
+// if ( nodeInstance instanceof RuleSetNodeInstance ) {
+// stream.writeShort( PersisterEnums.RULE_SET_NODE_INSTANCE );
+// } else if ( nodeInstance instanceof HumanTaskNodeInstance ) {
+// stream.writeShort( PersisterEnums.HUMAN_TASK_NODE_INSTANCE );
+// stream.writeLong( ((HumanTaskNodeInstance) nodeInstance).getWorkItem().getId() );
+// } else if ( nodeInstance instanceof WorkItemNodeInstance ) {
+// stream.writeShort( PersisterEnums.WORK_ITEM_NODE_INSTANCE );
+// stream.writeLong( ((WorkItemNodeInstance) nodeInstance).getWorkItem().getId() );
+// } else if ( nodeInstance instanceof SubProcessNodeInstance ) {
+// stream.writeShort( PersisterEnums.SUB_PROCESS_NODE_INSTANCE );
+// stream.writeLong( ((SubProcessNodeInstance) nodeInstance).getProcessInstanceId() );
+// } else if ( nodeInstance instanceof MilestoneNodeInstance ) {
+// stream.writeShort( PersisterEnums.MILESTONE_NODE_INSTANCE );
+// List<Long> timerInstances =
+// ((MilestoneNodeInstance) nodeInstance).getTimerInstances();
+// if (timerInstances != null) {
+// stream.writeInt(timerInstances.size());
+// for (Long id: timerInstances) {
+// stream.writeLong(id);
+// }
+// } else {
+// stream.writeInt(0);
+// }
+// } else if ( nodeInstance instanceof TimerNodeInstance ) {
+// stream.writeShort( PersisterEnums.TIMER_NODE_INSTANCE );
+// stream.writeLong( ((TimerNodeInstance) nodeInstance).getTimerId() );
+// } else if ( nodeInstance instanceof JoinInstance ) {
+// stream.writeShort( PersisterEnums.JOIN_NODE_INSTANCE );
+// Map<Long, Integer> triggers = ((JoinInstance) nodeInstance).getTriggers();
+// stream.writeInt( triggers.size() );
+// List<Long> keys = new ArrayList<Long>( triggers.keySet() );
+// Collections.sort( keys,
+// new Comparator<Long>() {
+// public int compare(Long o1,
+// Long o2) {
+// return o1.compareTo( o2 );
+// }
+// } );
+// for ( Long key : keys ) {
+// stream.writeLong( key );
+// stream.writeInt( triggers.get( key ) );
+// }
+// } else if ( nodeInstance instanceof CompositeContextNodeInstance ) {
+// stream.writeShort( PersisterEnums.COMPOSITE_NODE_INSTANCE );
+// CompositeContextNodeInstance compositeNodeInstance = (CompositeContextNodeInstance) nodeInstance;
+// VariableScopeInstance variableScopeInstance = (VariableScopeInstance) compositeNodeInstance.getContextInstance( VariableScope.VARIABLE_SCOPE );
+// Map<String, Object> variables = variableScopeInstance.getVariables();
+// List<String> keys = new ArrayList<String>( variables.keySet() );
+// Collections.sort( keys,
+// new Comparator<String>() {
+// public int compare(String o1,
+// String o2) {
+// return o1.compareTo( o2 );
+// }
+// } );
+// stream.writeInt( keys.size() );
+// for ( String key : keys ) {
+// stream.writeUTF( key );
+// stream.writeObject( variables.get( key ) );
+// }
+// List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>( compositeNodeInstance.getNodeInstances() );
+// Collections.sort( nodeInstances,
+// new Comparator<NodeInstance>() {
+// public int compare(NodeInstance o1,
+// NodeInstance o2) {
+// return (int) (o1.getId() - o2.getId());
+// }
+// } );
+// for ( NodeInstance subNodeInstance : nodeInstances ) {
+// stream.writeShort( PersisterEnums.NODE_INSTANCE );
+// writeNodeInstance( context,
+// subNodeInstance );
+// }
+// stream.writeShort( PersisterEnums.END );
+// } else if ( nodeInstance instanceof ForEachNodeInstance ) {
+// stream.writeShort( PersisterEnums.FOR_EACH_NODE_INSTANCE );
+// ForEachNodeInstance forEachNodeInstance = (ForEachNodeInstance) nodeInstance;
+// List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>( forEachNodeInstance.getNodeInstances() );
+// Collections.sort( nodeInstances,
+// new Comparator<NodeInstance>() {
+// public int compare(NodeInstance o1,
+// NodeInstance o2) {
+// return (int) (o1.getId() - o2.getId());
+// }
+// } );
+// for ( NodeInstance subNodeInstance : nodeInstances ) {
+// if ( subNodeInstance instanceof CompositeContextNodeInstance ) {
+// stream.writeShort( PersisterEnums.NODE_INSTANCE );
+// writeNodeInstance( context,
+// subNodeInstance );
+// }
+// }
+// stream.writeShort( PersisterEnums.END );
+// } else {
+// // TODO ForEachNodeInstance
+// // TODO timer manager
+// throw new IllegalArgumentException( "Unknown node instance type: " + nodeInstance );
+// }
+// }
- SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance( SwimlaneContext.SWIMLANE_SCOPE );
- Map<String, String> swimlaneActors = swimlaneContextInstance.getSwimlaneActors();
- stream.writeInt( swimlaneActors.size() );
- for ( Map.Entry<String, String> entry : swimlaneActors.entrySet() ) {
- stream.writeUTF( entry.getKey() );
- stream.writeUTF( entry.getValue() );
- }
-
- List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>( processInstance.getNodeInstances() );
- Collections.sort( nodeInstances,
- new Comparator<NodeInstance>() {
- public int compare(NodeInstance o1,
- NodeInstance o2) {
- return (int) (o1.getId() - o2.getId());
- }
- } );
- for ( NodeInstance nodeInstance : nodeInstances ) {
- stream.writeShort( PersisterEnums.NODE_INSTANCE );
- writeNodeInstance( context,
- nodeInstance );
- }
- stream.writeShort( PersisterEnums.END );
- }
-
- public static void writeNodeInstance(MarshallerWriteContext context,
- NodeInstance nodeInstance) throws IOException {
- ObjectOutputStream stream = context.stream;
- stream.writeLong( nodeInstance.getId() );
- stream.writeLong( nodeInstance.getNodeId() );
- if ( nodeInstance instanceof RuleSetNodeInstance ) {
- stream.writeShort( PersisterEnums.RULE_SET_NODE_INSTANCE );
- } else if ( nodeInstance instanceof HumanTaskNodeInstance ) {
- stream.writeShort( PersisterEnums.HUMAN_TASK_NODE_INSTANCE );
- stream.writeLong( ((HumanTaskNodeInstance) nodeInstance).getWorkItem().getId() );
- } else if ( nodeInstance instanceof WorkItemNodeInstance ) {
- stream.writeShort( PersisterEnums.WORK_ITEM_NODE_INSTANCE );
- stream.writeLong( ((WorkItemNodeInstance) nodeInstance).getWorkItem().getId() );
- } else if ( nodeInstance instanceof SubProcessNodeInstance ) {
- stream.writeShort( PersisterEnums.SUB_PROCESS_NODE_INSTANCE );
- stream.writeLong( ((SubProcessNodeInstance) nodeInstance).getProcessInstanceId() );
- } else if ( nodeInstance instanceof MilestoneNodeInstance ) {
- stream.writeShort( PersisterEnums.MILESTONE_NODE_INSTANCE );
- List<Long> timerInstances =
- ((MilestoneNodeInstance) nodeInstance).getTimerInstances();
- if (timerInstances != null) {
- stream.writeInt(timerInstances.size());
- for (Long id: timerInstances) {
- stream.writeLong(id);
- }
- } else {
- stream.writeInt(0);
- }
- } else if ( nodeInstance instanceof TimerNodeInstance ) {
- stream.writeShort( PersisterEnums.TIMER_NODE_INSTANCE );
- stream.writeLong( ((TimerNodeInstance) nodeInstance).getTimerId() );
- } else if ( nodeInstance instanceof JoinInstance ) {
- stream.writeShort( PersisterEnums.JOIN_NODE_INSTANCE );
- Map<Long, Integer> triggers = ((JoinInstance) nodeInstance).getTriggers();
- stream.writeInt( triggers.size() );
- List<Long> keys = new ArrayList<Long>( triggers.keySet() );
- Collections.sort( keys,
- new Comparator<Long>() {
- public int compare(Long o1,
- Long o2) {
- return o1.compareTo( o2 );
- }
- } );
- for ( Long key : keys ) {
- stream.writeLong( key );
- stream.writeInt( triggers.get( key ) );
- }
- } else if ( nodeInstance instanceof CompositeContextNodeInstance ) {
- stream.writeShort( PersisterEnums.COMPOSITE_NODE_INSTANCE );
- CompositeContextNodeInstance compositeNodeInstance = (CompositeContextNodeInstance) nodeInstance;
- VariableScopeInstance variableScopeInstance = (VariableScopeInstance) compositeNodeInstance.getContextInstance( VariableScope.VARIABLE_SCOPE );
- Map<String, Object> variables = variableScopeInstance.getVariables();
- List<String> keys = new ArrayList<String>( variables.keySet() );
- Collections.sort( keys,
- new Comparator<String>() {
- public int compare(String o1,
- String o2) {
- return o1.compareTo( o2 );
- }
- } );
- stream.writeInt( keys.size() );
- for ( String key : keys ) {
- stream.writeUTF( key );
- stream.writeObject( variables.get( key ) );
- }
- List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>( compositeNodeInstance.getNodeInstances() );
- Collections.sort( nodeInstances,
- new Comparator<NodeInstance>() {
- public int compare(NodeInstance o1,
- NodeInstance o2) {
- return (int) (o1.getId() - o2.getId());
- }
- } );
- for ( NodeInstance subNodeInstance : nodeInstances ) {
- stream.writeShort( PersisterEnums.NODE_INSTANCE );
- writeNodeInstance( context,
- subNodeInstance );
- }
- stream.writeShort( PersisterEnums.END );
- } else if ( nodeInstance instanceof ForEachNodeInstance ) {
- stream.writeShort( PersisterEnums.FOR_EACH_NODE_INSTANCE );
- ForEachNodeInstance forEachNodeInstance = (ForEachNodeInstance) nodeInstance;
- List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>( forEachNodeInstance.getNodeInstances() );
- Collections.sort( nodeInstances,
- new Comparator<NodeInstance>() {
- public int compare(NodeInstance o1,
- NodeInstance o2) {
- return (int) (o1.getId() - o2.getId());
- }
- } );
- for ( NodeInstance subNodeInstance : nodeInstances ) {
- if ( subNodeInstance instanceof CompositeContextNodeInstance ) {
- stream.writeShort( PersisterEnums.NODE_INSTANCE );
- writeNodeInstance( context,
- subNodeInstance );
- }
- }
- stream.writeShort( PersisterEnums.END );
- } else {
- // TODO ForEachNodeInstance
- // TODO timer manager
- throw new IllegalArgumentException( "Unknown node instance type: " + nodeInstance );
- }
- }
-
public static void writeWorkItems(MarshallerWriteContext context) throws IOException {
ObjectOutputStream stream = context.stream;
Modified: labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/PersisterEnums.java
===================================================================
--- labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/PersisterEnums.java 2009-01-14 13:38:15 UTC (rev 24707)
+++ labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/PersisterEnums.java 2009-01-14 13:56:14 UTC (rev 24708)
@@ -39,5 +39,5 @@
public static final short HUMAN_TASK_NODE_INSTANCE = 27;
public static final short FOR_EACH_NODE_INSTANCE = 28;
public static final short TIMER = 29;
-
+ public static final short STEP_NODE_INSTANCE = 30;
}
Added: labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/ProcessMarshaller.java
===================================================================
--- labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/ProcessMarshaller.java (rev 0)
+++ labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/ProcessMarshaller.java 2009-01-14 13:56:14 UTC (rev 24708)
@@ -0,0 +1,31 @@
+package org.drools.marshalling;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+
+import org.drools.runtime.process.NodeInstance;
+import org.drools.runtime.process.ProcessInstance;
+import org.drools.workflow.instance.impl.NodeInstanceImpl;
+
+/**
+* A ProcessMarshaller must contain all the write/read logic for nodes of a specific ProcessInstance.
+* It colaborates with OutputMarshaller and InputMarshaller, that delegates in ProcessMarshaller to
+* stream in/out runtime information.
+*
+* @see OutPutMarshaller
+* @see InputMarshaller
+* @see ProcessMarshallerRegistry
+*
+* @author mfossati, salaboy
+*/
+
+public interface ProcessMarshaller {
+
+ public void writeProcessInstance(MarshallerWriteContext context, ProcessInstance processInstance) throws IOException;
+
+ public void writeNodeInstance(MarshallerWriteContext context, NodeInstance nodeInstance) throws IOException;
+
+ public ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException;
+
+ public NodeInstanceImpl inputSpecificNode (NodeInstanceImpl nodeInstance,int nodeType,ObjectInputStream stream) throws IOException;
+}
Added: labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/ProcessMarshallerRegistry.java
===================================================================
--- labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/ProcessMarshallerRegistry.java (rev 0)
+++ labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/ProcessMarshallerRegistry.java 2009-01-14 13:56:14 UTC (rev 24708)
@@ -0,0 +1,38 @@
+package org.drools.marshalling;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.process.instance.impl.ProcessInstanceImpl;
+import org.drools.ruleflow.core.RuleFlowProcess;
+import org.drools.ruleflow.instance.RuleFlowProcessInstance;
+
+/**
+* Registry for Process/ProcessMarshaller
+*/
+public class ProcessMarshallerRegistry {
+
+ public static ProcessMarshallerRegistry INSTANCE = new ProcessMarshallerRegistry();
+
+ private Map<String , ProcessMarshaller> registry;
+
+ private ProcessMarshallerRegistry() {
+ this.registry = new HashMap<String, ProcessMarshaller >();
+
+ // default logic that used to be in OutPutMarshaller:
+ register( RuleFlowProcess.RULEFLOW_TYPE,
+ RuleFlowProcessInstanceMarshaller.INSTANCE );
+ }
+
+ public void register(String cls,
+ ProcessMarshaller marchaller) {
+ this.registry.put(cls, marchaller);
+ }
+
+ @SuppressWarnings("unchecked")
+ public ProcessMarshaller getMarshaller(String type) {
+ return this.registry.get(type);
+ }
+
+
+}
Added: labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/RuleFlowProcessInstanceMarshaller.java
===================================================================
--- labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/RuleFlowProcessInstanceMarshaller.java (rev 0)
+++ labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/RuleFlowProcessInstanceMarshaller.java 2009-01-14 13:56:14 UTC (rev 24708)
@@ -0,0 +1,99 @@
+package org.drools.marshalling;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+
+import org.drools.common.InternalRuleBase;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.process.core.context.swimlane.SwimlaneContext;
+import org.drools.process.core.context.variable.VariableScope;
+import org.drools.process.instance.context.swimlane.SwimlaneContextInstance;
+import org.drools.process.instance.context.variable.VariableScopeInstance;
+import org.drools.ruleflow.instance.RuleFlowProcessInstance;
+import org.drools.runtime.process.NodeInstance;
+import org.drools.runtime.process.ProcessInstance;
+import org.drools.workflow.instance.impl.NodeInstanceImpl;
+
+/**
+* Marshaller class for RuleFlowProcessInstances
+*
+* @author mfossati
+*/
+
+public class RuleFlowProcessInstanceMarshaller extends
+ AbstractProcessInstanceMarshaller {
+
+ public static RuleFlowProcessInstanceMarshaller INSTANCE = new RuleFlowProcessInstanceMarshaller();
+
+ private RuleFlowProcessInstanceMarshaller() {
+ }
+
+ @Override
+ protected void outputSpecificNodes(MarshallerWriteContext context,
+ NodeInstance nodeInstance) throws IOException {
+ // nothing to do, so every instance is handled by processCommonsNode in
+ // superclass
+
+ }
+
+ public ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException {
+ ObjectInputStream stream = context.stream;
+ InternalRuleBase ruleBase = context.ruleBase;
+ InternalWorkingMemory wm = context.wm;
+
+ RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
+ processInstance.setId( stream.readLong() );
+ String processId = stream.readUTF();
+ processInstance.setProcessId( processId );
+ if ( ruleBase != null ) {
+ processInstance.setProcess( ruleBase.getProcess( processId ) );
+ }
+ processInstance.setState( stream.readInt() );
+ long nodeInstanceCounter = stream.readLong();
+ processInstance.setWorkingMemory( wm );
+
+ int nbVariables = stream.readInt();
+ if ( nbVariables > 0 ) {
+ VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance( VariableScope.VARIABLE_SCOPE );
+ for ( int i = 0; i < nbVariables; i++ ) {
+ String name = stream.readUTF();
+ try {
+ Object value = stream.readObject();
+ variableScopeInstance.setVariable( name,
+ value );
+ } catch ( ClassNotFoundException e ) {
+ throw new IllegalArgumentException( "Could not reload variable " + name );
+ }
+ }
+ }
+
+ int nbSwimlanes = stream.readInt();
+ if ( nbSwimlanes > 0 ) {
+ SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance( SwimlaneContext.SWIMLANE_SCOPE );
+ for ( int i = 0; i < nbSwimlanes; i++ ) {
+ String name = stream.readUTF();
+ String value = stream.readUTF();
+ swimlaneContextInstance.setActorId( name,
+ value );
+ }
+ }
+
+ while ( stream.readShort() == PersisterEnums.NODE_INSTANCE ) {
+ readNodeInstance( context,
+ processInstance,
+ processInstance );
+ }
+
+ processInstance.internalSetNodeInstanceCounter( nodeInstanceCounter );
+ if ( wm != null ) {
+ processInstance.reconnect();
+ }
+ return processInstance;
+ }
+
+ public NodeInstanceImpl inputSpecificNode(NodeInstanceImpl nodeInstance, int nodeType, ObjectInputStream stream)
+ throws IOException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
More information about the jboss-svn-commits
mailing list