[jboss-svn-commits] JBL Code SVN: r24976 - in labs/jbossrules/branches/mfossati: drools-osworkflow/src/main/java/org/drools/osworkflow/persistence/marshaller and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jan 28 11:18:29 EST 2009
Author: mfossati
Date: 2009-01-28 11:18:28 -0500 (Wed, 28 Jan 2009)
New Revision: 24976
Added:
labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/ProcessInstanceMarshaller.java
labs/jbossrules/branches/mfossati/drools-osworkflow/src/main/java/org/drools/osworkflow/persistence/marshaller/OSWorkFlowPersisterEnums.java
labs/jbossrules/branches/mfossati/drools-osworkflow/src/main/java/org/drools/osworkflow/persistence/marshaller/OSWorkflowProcessInstanceMarshaller.java
Removed:
labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/ProcessMarshaller.java
labs/jbossrules/branches/mfossati/drools-osworkflow/src/main/java/org/drools/osworkflow/persistence/marshaller/OSWorkflowMarshaller.java
Modified:
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/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
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
labs/jbossrules/branches/mfossati/drools-osworkflow/src/test/java/org/drools/osworkflow/test/persistence/AbstractJPAPersistenceTestCase.java
labs/jbossrules/branches/mfossati/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/ProcessInstanceInfo.java
Log:
Refactor over marshalling process. Cleaned up code.
Modified: 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 2009-01-28 16:16:15 UTC (rev 24975)
+++ labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/AbstractProcessInstanceMarshaller.java 2009-01-28 16:18:28 UTC (rev 24976)
@@ -10,11 +10,14 @@
import java.util.List;
import java.util.Map;
+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.process.instance.impl.ProcessInstanceImpl;
+import org.drools.ruleflow.instance.RuleFlowProcessInstance;
import org.drools.runtime.process.NodeInstance;
import org.drools.runtime.process.NodeInstanceContainer;
import org.drools.runtime.process.ProcessInstance;
@@ -31,19 +34,20 @@
import org.drools.workflow.instance.node.TimerNodeInstance;
import org.drools.workflow.instance.node.WorkItemNodeInstance;
-
/* Author: mfossati, salaboy */
-public abstract class AbstractProcessInstanceMarshaller implements ProcessMarshaller {
+public abstract class AbstractProcessInstanceMarshaller implements
+ ProcessInstanceMarshaller {
// Output methods
-
- public void writeProcessInstance(MarshallerWriteContext context, ProcessInstance processInstance)
- throws IOException {
+ 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.writeUTF(((ProcessInstanceImpl) processInstance).getProcess()
+ .getType());
stream.writeLong(workFlow.getId());
stream.writeUTF(workFlow.getProcessId());
stream.writeInt(workFlow.getState());
@@ -67,14 +71,16 @@
SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) workFlow
.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);
if (swimlaneContextInstance != null) {
- Map<String, String> swimlaneActors = swimlaneContextInstance.getSwimlaneActors();
+ 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());
+ 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());
@@ -87,29 +93,35 @@
stream.writeShort(PersisterEnums.END);
}
- public void writeNodeInstance(MarshallerWriteContext context, NodeInstance nodeInstance) throws IOException {
- processCommonNodes(context, nodeInstance);
+ public void writeNodeInstance(MarshallerWriteContext context,
+ NodeInstance nodeInstance) throws IOException {
+ ObjectOutputStream stream = context.stream;
+ stream.writeLong(nodeInstance.getId());
+ stream.writeLong(nodeInstance.getNodeId());
+ writeNodeInstanceContent(stream, nodeInstance, context);
}
- protected final void processCommonNodes(MarshallerWriteContext context, NodeInstance nodeInstance)
+ protected void writeNodeInstanceContent(ObjectOutputStream stream,
+ NodeInstance nodeInstance, MarshallerWriteContext context)
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());
+ stream.writeLong(((HumanTaskNodeInstance) nodeInstance)
+ .getWorkItem().getId());
} else if (nodeInstance instanceof WorkItemNodeInstance) {
stream.writeShort(PersisterEnums.WORK_ITEM_NODE_INSTANCE);
- stream.writeLong(((WorkItemNodeInstance) nodeInstance).getWorkItem().getId());
+ stream.writeLong(((WorkItemNodeInstance) nodeInstance)
+ .getWorkItem().getId());
} else if (nodeInstance instanceof SubProcessNodeInstance) {
stream.writeShort(PersisterEnums.SUB_PROCESS_NODE_INSTANCE);
- stream.writeLong(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId());
+ stream.writeLong(((SubProcessNodeInstance) nodeInstance)
+ .getProcessInstanceId());
} else if (nodeInstance instanceof MilestoneNodeInstance) {
stream.writeShort(PersisterEnums.MILESTONE_NODE_INSTANCE);
- List<Long> timerInstances = ((MilestoneNodeInstance) nodeInstance).getTimerInstances();
+ List<Long> timerInstances = ((MilestoneNodeInstance) nodeInstance)
+ .getTimerInstances();
if (timerInstances != null) {
stream.writeInt(timerInstances.size());
for (Long id : timerInstances) {
@@ -123,7 +135,8 @@
stream.writeLong(((TimerNodeInstance) nodeInstance).getTimerId());
} else if (nodeInstance instanceof JoinInstance) {
stream.writeShort(PersisterEnums.JOIN_NODE_INSTANCE);
- Map<Long, Integer> triggers = ((JoinInstance) nodeInstance).getTriggers();
+ 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>() {
@@ -140,7 +153,8 @@
CompositeContextNodeInstance compositeNodeInstance = (CompositeContextNodeInstance) nodeInstance;
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) compositeNodeInstance
.getContextInstance(VariableScope.VARIABLE_SCOPE);
- Map<String, Object> variables = variableScopeInstance.getVariables();
+ 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) {
@@ -152,7 +166,8 @@
stream.writeUTF(key);
stream.writeObject(variables.get(key));
}
- List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(compositeNodeInstance.getNodeInstances());
+ 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());
@@ -166,7 +181,8 @@
} else if (nodeInstance instanceof ForEachNodeInstance) {
stream.writeShort(PersisterEnums.FOR_EACH_NODE_INSTANCE);
ForEachNodeInstance forEachNodeInstance = (ForEachNodeInstance) nodeInstance;
- List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(forEachNodeInstance.getNodeInstances());
+ 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());
@@ -180,118 +196,173 @@
}
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 ProcessInstance readProcessInstance(MarshallerReaderContext context)
+ throws IOException {
+ ObjectInputStream stream = context.stream;
+ InternalRuleBase ruleBase = context.ruleBase;
+ InternalWorkingMemory wm = context.wm;
- // Input methods
-
- public abstract ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException;
-
+ 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);
- public NodeInstance readNodeInstance(MarshallerReaderContext context, NodeInstanceContainer nodeInstanceContainer,
+ 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 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);
+ NodeInstanceImpl nodeInstance = readNodeInstanceContent(nodeType,
+ stream, context, processInstance);
+
+ nodeInstance.setNodeId(nodeId);
+ nodeInstance.setNodeInstanceContainer(nodeInstanceContainer);
+ nodeInstance.setProcessInstance(processInstance);
+ nodeInstance.setId(id);
+
+ return nodeInstance;
+ }
+
+ protected NodeInstanceImpl readNodeInstanceContent(int nodeType,
+ ObjectInputStream stream, MarshallerReaderContext context,
+ WorkflowProcessInstance processInstance) throws IOException {
+ NodeInstanceImpl nodeInstance = null;
+ 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());
}
- 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);
+ ((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);
}
- 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);
- }
+ ((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);
-
-
-
-
+ 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);
+ }
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-28 16:16:15 UTC (rev 24975)
+++ labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/InputMarshaller.java 2009-01-28 16:18:28 UTC (rev 24976)
@@ -751,13 +751,13 @@
public static void readProcessInstances(MarshallerReaderContext context) throws IOException {
ObjectInputStream stream = context.stream;
- ProcessMarshaller marshaller = getMarshaller(context);
+ ProcessInstanceMarshaller marshaller = getMarshaller(context);
while ( stream.readShort() == PersisterEnums.PROCESS_INSTANCE ) {
marshaller.readProcessInstance( context );
}
}
- public static ProcessMarshaller getMarshaller (MarshallerReaderContext context) throws IOException {
+ public static ProcessInstanceMarshaller getMarshaller (MarshallerReaderContext context) throws IOException {
ObjectInputStream stream = context.stream;
String processInstanceType= null;
processInstanceType = stream.readUTF();
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-28 16:16:15 UTC (rev 24975)
+++ labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/OutputMarshaller.java 2009-01-28 16:18:28 UTC (rev 24976)
@@ -735,7 +735,7 @@
public static void writeProcessInstance(MarshallerWriteContext context,
ProcessInstance processInstance) throws IOException {
- ProcessMarshaller marshaller = ProcessMarshallerRegistry.INSTANCE
+ ProcessInstanceMarshaller marshaller = ProcessMarshallerRegistry.INSTANCE
.getMarshaller(((ProcessInstanceImpl)processInstance).getProcess().getType());
marshaller.writeProcessInstance(context, processInstance);
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-28 16:16:15 UTC (rev 24975)
+++ labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/PersisterEnums.java 2009-01-28 16:18:28 UTC (rev 24976)
@@ -39,5 +39,4 @@
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;
}
Copied: labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/ProcessInstanceMarshaller.java (from rev 24708, 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/ProcessInstanceMarshaller.java (rev 0)
+++ labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/ProcessInstanceMarshaller.java 2009-01-28 16:18:28 UTC (rev 24976)
@@ -0,0 +1,39 @@
+package org.drools.marshalling;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+
+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;
+
+/**
+ * A ProcessInstanceMarshaller must contain all the write/read logic for nodes
+ * of a specific ProcessInstance. It colaborates with OutputMarshaller and
+ * InputMarshaller, that delegates in a ProcessInstanceMarshaller to stream in/out runtime
+ * information.
+ *
+ * @see OutPutMarshaller
+ * @see InputMarshaller
+ * @see ProcessMarshallerRegistry
+ *
+ * @author mfossati, salaboy
+ */
+
+public interface ProcessInstanceMarshaller {
+
+ 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 NodeInstance readNodeInstance(MarshallerReaderContext context,
+ NodeInstanceContainer nodeInstanceContainer,
+ WorkflowProcessInstance processInstance) throws IOException;
+}
Property changes on: labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/ProcessInstanceMarshaller.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: 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 2009-01-28 16:16:15 UTC (rev 24975)
+++ labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/ProcessMarshaller.java 2009-01-28 16:18:28 UTC (rev 24976)
@@ -1,31 +0,0 @@
-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;
-}
Modified: 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 2009-01-28 16:16:15 UTC (rev 24975)
+++ labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/ProcessMarshallerRegistry.java 2009-01-28 16:18:28 UTC (rev 24976)
@@ -14,10 +14,10 @@
public static ProcessMarshallerRegistry INSTANCE = new ProcessMarshallerRegistry();
- private Map<String , ProcessMarshaller> registry;
+ private Map<String , ProcessInstanceMarshaller> registry;
private ProcessMarshallerRegistry() {
- this.registry = new HashMap<String, ProcessMarshaller >();
+ this.registry = new HashMap<String, ProcessInstanceMarshaller >();
// default logic that used to be in OutPutMarshaller:
register( RuleFlowProcess.RULEFLOW_TYPE,
@@ -25,12 +25,12 @@
}
public void register(String cls,
- ProcessMarshaller marchaller) {
+ ProcessInstanceMarshaller marchaller) {
this.registry.put(cls, marchaller);
}
@SuppressWarnings("unchecked")
- public ProcessMarshaller getMarshaller(String type) {
+ public ProcessInstanceMarshaller getMarshaller(String type) {
return this.registry.get(type);
}
Modified: 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 2009-01-28 16:16:15 UTC (rev 24975)
+++ labs/jbossrules/branches/mfossati/drools-core/src/main/java/org/drools/marshalling/RuleFlowProcessInstanceMarshaller.java 2009-01-28 16:18:28 UTC (rev 24976)
@@ -28,14 +28,6 @@
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;
@@ -90,10 +82,4 @@
}
return processInstance;
}
-
- public NodeInstanceImpl inputSpecificNode(NodeInstanceImpl nodeInstance, int nodeType, ObjectInputStream stream)
- throws IOException {
- // TODO Auto-generated method stub
- return null;
- }
}
Added: labs/jbossrules/branches/mfossati/drools-osworkflow/src/main/java/org/drools/osworkflow/persistence/marshaller/OSWorkFlowPersisterEnums.java
===================================================================
--- labs/jbossrules/branches/mfossati/drools-osworkflow/src/main/java/org/drools/osworkflow/persistence/marshaller/OSWorkFlowPersisterEnums.java (rev 0)
+++ labs/jbossrules/branches/mfossati/drools-osworkflow/src/main/java/org/drools/osworkflow/persistence/marshaller/OSWorkFlowPersisterEnums.java 2009-01-28 16:18:28 UTC (rev 24976)
@@ -0,0 +1,7 @@
+package org.drools.osworkflow.persistence.marshaller;
+
+public class OSWorkFlowPersisterEnums {
+
+ public static final short STEP_NODE_INSTANCE = 1000;
+
+}
Deleted: labs/jbossrules/branches/mfossati/drools-osworkflow/src/main/java/org/drools/osworkflow/persistence/marshaller/OSWorkflowMarshaller.java
===================================================================
--- labs/jbossrules/branches/mfossati/drools-osworkflow/src/main/java/org/drools/osworkflow/persistence/marshaller/OSWorkflowMarshaller.java 2009-01-28 16:16:15 UTC (rev 24975)
+++ labs/jbossrules/branches/mfossati/drools-osworkflow/src/main/java/org/drools/osworkflow/persistence/marshaller/OSWorkflowMarshaller.java 2009-01-28 16:18:28 UTC (rev 24976)
@@ -1,123 +0,0 @@
-package org.drools.osworkflow.persistence.marshaller;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-import org.drools.common.InternalRuleBase;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.marshalling.AbstractProcessInstanceMarshaller;
-import org.drools.marshalling.MarshallerReaderContext;
-import org.drools.marshalling.MarshallerWriteContext;
-import org.drools.marshalling.PersisterEnums;
-import org.drools.osworkflow.instance.OSWorkflowProcessInstance;
-import org.drools.osworkflow.instance.node.StepNodeInstance;
-import org.drools.process.core.context.variable.VariableScope;
-import org.drools.process.instance.context.variable.VariableScopeInstance;
-import org.drools.runtime.process.NodeInstance;
-import org.drools.runtime.process.ProcessInstance;
-import org.drools.workflow.instance.impl.NodeInstanceImpl;
-
-public class OSWorkflowMarshaller extends AbstractProcessInstanceMarshaller {
-
- public static OSWorkflowMarshaller INSTANCE = new OSWorkflowMarshaller();
-
- private OSWorkflowMarshaller() {
-
- }
-
-
-
- @Override
- protected void outputSpecificNodes(MarshallerWriteContext context,
- NodeInstance nodeInstance) throws IOException {
- // Handles StepNodeInstances
- ObjectOutputStream stream = context.stream;
- if (nodeInstance instanceof StepNodeInstance) {
- stream.writeShort(PersisterEnums.STEP_NODE_INSTANCE);
- stream.writeLong(((StepNodeInstance) nodeInstance).getNodeId());
- String status = ((StepNodeInstance) nodeInstance).getStatus();
- if (status == null || "".equals(status)) {
- stream.writeBoolean(false);
- } else {
- stream.writeBoolean(true);
- stream.writeUTF(((StepNodeInstance) nodeInstance).getStatus());
- }
- String owner = ((StepNodeInstance) nodeInstance).getOwner();
- if (owner == null || "".equals(owner)) {
- stream.writeBoolean(false);
- } else {
- stream.writeBoolean(true);
- stream.writeUTF(((StepNodeInstance) nodeInstance).getOwner());
- }
-
- }
-
- }
-
- @Override
- public ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException {
- ObjectInputStream stream = context.stream;
- InternalRuleBase ruleBase = context.ruleBase;
- InternalWorkingMemory wm = context.wm;
-
- OSWorkflowProcessInstance processInstance = new OSWorkflowProcessInstance();
- 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 );
- }
- }
- }
-
-
-
- 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 {
- if (nodeType == PersisterEnums.STEP_NODE_INSTANCE) {
- nodeInstance = new StepNodeInstance();
- ((StepNodeInstance)nodeInstance).setNodeId(stream.readLong());
- if (stream.readBoolean()) {
- ((StepNodeInstance)nodeInstance).setStatus(stream.readUTF());
- }
- if (stream.readBoolean()) {
- ((StepNodeInstance)nodeInstance).setOwner(stream.readUTF());
- }
-
-
- return nodeInstance;
- }
- return null;
- }
-
-}
Copied: labs/jbossrules/branches/mfossati/drools-osworkflow/src/main/java/org/drools/osworkflow/persistence/marshaller/OSWorkflowProcessInstanceMarshaller.java (from rev 24681, labs/jbossrules/branches/mfossati/drools-osworkflow/src/main/java/org/drools/osworkflow/persistence/marshaller/OSWorkflowMarshaller.java)
===================================================================
--- labs/jbossrules/branches/mfossati/drools-osworkflow/src/main/java/org/drools/osworkflow/persistence/marshaller/OSWorkflowProcessInstanceMarshaller.java (rev 0)
+++ labs/jbossrules/branches/mfossati/drools-osworkflow/src/main/java/org/drools/osworkflow/persistence/marshaller/OSWorkflowProcessInstanceMarshaller.java 2009-01-28 16:18:28 UTC (rev 24976)
@@ -0,0 +1,121 @@
+package org.drools.osworkflow.persistence.marshaller;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.drools.common.InternalRuleBase;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.marshalling.AbstractProcessInstanceMarshaller;
+import org.drools.marshalling.MarshallerReaderContext;
+import org.drools.marshalling.MarshallerWriteContext;
+import org.drools.marshalling.PersisterEnums;
+import org.drools.osworkflow.instance.OSWorkflowProcessInstance;
+import org.drools.osworkflow.instance.node.StepNodeInstance;
+import org.drools.process.core.context.variable.VariableScope;
+import org.drools.process.instance.context.variable.VariableScopeInstance;
+import org.drools.runtime.process.NodeInstance;
+import org.drools.runtime.process.ProcessInstance;
+import org.drools.workflow.instance.WorkflowProcessInstance;
+import org.drools.workflow.instance.impl.NodeInstanceImpl;
+
+public class OSWorkflowProcessInstanceMarshaller extends
+ AbstractProcessInstanceMarshaller {
+
+ public static OSWorkflowProcessInstanceMarshaller INSTANCE = new OSWorkflowProcessInstanceMarshaller();
+
+ private OSWorkflowProcessInstanceMarshaller() {
+
+ }
+
+ @Override
+ public ProcessInstance readProcessInstance(MarshallerReaderContext context)
+ throws IOException {
+ ObjectInputStream stream = context.stream;
+ InternalRuleBase ruleBase = context.ruleBase;
+ InternalWorkingMemory wm = context.wm;
+
+ OSWorkflowProcessInstance processInstance = new OSWorkflowProcessInstance();
+ 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);
+ }
+ }
+ }
+
+ while (stream.readShort() == PersisterEnums.NODE_INSTANCE) {
+ readNodeInstance(context, processInstance, processInstance);
+ }
+
+ processInstance.internalSetNodeInstanceCounter(nodeInstanceCounter);
+ if (wm != null) {
+ processInstance.reconnect();
+ }
+ return processInstance;
+ }
+
+ protected NodeInstanceImpl readNodeInstanceContent(int nodeType,
+ ObjectInputStream stream, MarshallerReaderContext context,
+ WorkflowProcessInstance processInstance) throws IOException {
+ NodeInstanceImpl nodeInstance = null;
+ if (nodeType == OSWorkFlowPersisterEnums.STEP_NODE_INSTANCE) {
+ nodeInstance = new StepNodeInstance();
+ ((StepNodeInstance) nodeInstance).setNodeId(stream.readLong());
+ if (stream.readBoolean()) {
+ ((StepNodeInstance) nodeInstance).setStatus(stream.readUTF());
+ }
+ if (stream.readBoolean()) {
+ ((StepNodeInstance) nodeInstance).setOwner(stream.readUTF());
+ }
+
+ return nodeInstance;
+ } else
+ return super.readNodeInstanceContent(nodeType, stream, context,
+ processInstance);
+ }
+
+ protected void writeNodeInstanceContent(ObjectOutputStream stream,
+ NodeInstance nodeInstance, MarshallerWriteContext context)
+ throws IOException {
+ if (nodeInstance instanceof StepNodeInstance) {
+ stream.writeShort(OSWorkFlowPersisterEnums.STEP_NODE_INSTANCE);
+ stream.writeLong(((StepNodeInstance) nodeInstance).getNodeId());
+ String status = ((StepNodeInstance) nodeInstance).getStatus();
+ if (status == null || "".equals(status)) {
+ stream.writeBoolean(false);
+ } else {
+ stream.writeBoolean(true);
+ stream.writeUTF(((StepNodeInstance) nodeInstance).getStatus());
+ }
+ String owner = ((StepNodeInstance) nodeInstance).getOwner();
+ if (owner == null || "".equals(owner)) {
+ stream.writeBoolean(false);
+ } else {
+ stream.writeBoolean(true);
+ stream.writeUTF(((StepNodeInstance) nodeInstance).getOwner());
+ }
+
+ } else
+ super.writeNodeInstanceContent(stream, nodeInstance, context);
+ }
+
+}
Property changes on: labs/jbossrules/branches/mfossati/drools-osworkflow/src/main/java/org/drools/osworkflow/persistence/marshaller/OSWorkflowProcessInstanceMarshaller.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: labs/jbossrules/branches/mfossati/drools-osworkflow/src/test/java/org/drools/osworkflow/test/persistence/AbstractJPAPersistenceTestCase.java
===================================================================
--- labs/jbossrules/branches/mfossati/drools-osworkflow/src/test/java/org/drools/osworkflow/test/persistence/AbstractJPAPersistenceTestCase.java 2009-01-28 16:16:15 UTC (rev 24975)
+++ labs/jbossrules/branches/mfossati/drools-osworkflow/src/test/java/org/drools/osworkflow/test/persistence/AbstractJPAPersistenceTestCase.java 2009-01-28 16:18:28 UTC (rev 24976)
@@ -16,7 +16,7 @@
import org.drools.marshalling.ProcessMarshallerRegistry;
import org.drools.osworkflow.core.OSWorkflowProcess;
import org.drools.osworkflow.instance.OSWorkflowProcessInstance;
-import org.drools.osworkflow.persistence.marshaller.OSWorkflowMarshaller;
+import org.drools.osworkflow.persistence.marshaller.OSWorkflowProcessInstanceMarshaller;
import org.drools.rule.Package;
public abstract class AbstractJPAPersistenceTestCase extends TestCase {
@@ -47,7 +47,7 @@
properties.put("workItemManagerFactory", "org.drools.persistence.processinstance.JPAWorkItemManagerFactory");
properties.put("processSignalManagerFactory", "org.drools.persistence.processinstance.JPASignalManagerFactory");
//TODO configure this with IOC
- ProcessMarshallerRegistry.INSTANCE.register(OSWorkflowProcess.OSWORKFLOW_TYPE, OSWorkflowMarshaller.INSTANCE);
+ ProcessMarshallerRegistry.INSTANCE.register(OSWorkflowProcess.OSWORKFLOW_TYPE, OSWorkflowProcessInstanceMarshaller.INSTANCE);
return properties;
}
Modified: labs/jbossrules/branches/mfossati/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/ProcessInstanceInfo.java
===================================================================
--- labs/jbossrules/branches/mfossati/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/ProcessInstanceInfo.java 2009-01-28 16:16:15 UTC (rev 24975)
+++ labs/jbossrules/branches/mfossati/drools-process-enterprise/src/main/java/org/drools/persistence/processinstance/ProcessInstanceInfo.java 2009-01-28 16:18:28 UTC (rev 24976)
@@ -20,8 +20,7 @@
import org.drools.marshalling.MarshallerReaderContext;
import org.drools.marshalling.MarshallerWriteContext;
import org.drools.marshalling.OutputMarshaller;
-import org.drools.marshalling.ProcessMarshaller;
-import org.drools.ruleflow.instance.RuleFlowProcessInstance;
+import org.drools.marshalling.ProcessInstanceMarshaller;
import org.drools.runtime.process.ProcessInstance;
import org.hibernate.annotations.CollectionOfElements;
@@ -83,7 +82,7 @@
try {
ByteArrayInputStream bais = new ByteArrayInputStream(processInstanceByteArray);
MarshallerReaderContext context = new MarshallerReaderContext(bais, null, null, null);
- ProcessMarshaller marshaller = InputMarshaller.getMarshaller(context);
+ ProcessInstanceMarshaller marshaller = InputMarshaller.getMarshaller(context);
processInstance = marshaller.readProcessInstance(context);
context.close();
} catch (IOException e) {
More information about the jboss-svn-commits
mailing list