[jboss-svn-commits] JBL Code SVN: r28542 - in labs/jbossrules/trunk/drools-process/drools-jpdl/src: main/java/org/drools/jpdl/core/node and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jul 28 12:38:03 EDT 2009


Author: salaboy21
Date: 2009-07-28 12:38:02 -0400 (Tue, 28 Jul 2009)
New Revision: 28542

Added:
   labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/core/node/SuperState.java
   labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2superState/
   labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2superState/gpd.xml
   labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2superState/processdefinition.xml
Modified:
   labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/EpdlWriter.java
   labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/JpdlParser.java
   labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/java/org/drools/ParseSimpleProcessTest.java
Log:
Support for jPDL SuperState nodes into a Composite node

Modified: labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/EpdlWriter.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/EpdlWriter.java	2009-07-28 16:09:20 UTC (rev 28541)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/EpdlWriter.java	2009-07-28 16:38:02 UTC (rev 28542)
@@ -44,114 +44,118 @@
         Node[] nodes = process.getNodes();
         int id = 0;
         
-        String generatedConnections = "";
+        
         System.out.println("<process xmlns=\"http://drools.org/drools-5.0/process\""+
                 " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\" "+
                 "xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\" " +
                 "type=\"RuleFlow\" name=\"flow\" id=\""+process.getName()+"\" package-name=\"org.drools.examples\" >");
         System.out.println("<header>");
         System.out.println("</header>");
+        //Print nodes and Connections
+        printNodesAndConnections(nodes);
+        
+
+        System.out.println("</process>");
+    }
+
+    private static void printNodesAndConnections(Node[] nodes) {
+        String generatedConnections = "";
         System.out.println("<nodes>");
-        for(Node node : nodes){
+        for (Node node : nodes) {
             //System.out.println("Node Type: "+node.getClass()+" - Name"+node.getName());
-            if(node instanceof org.drools.jpdl.core.node.StartState){
-                System.out.println("<start id=\""+node.getId()+"\" name=\""+node.getName()+"\" />");
-            }
-            else if(node instanceof org.drools.jpdl.core.node.Fork){
-                System.out.println("<split id=\""+node.getId()+"\" name=\""+node.getName()+"\" type=\"1\" />");
-            }
-            else if(node instanceof org.drools.jpdl.core.node.Join){
-                System.out.println("<join id=\""+node.getId()+"\" name=\""+node.getName()+"\" type=\"1\" />");
-            }
-            else if(node instanceof org.drools.jpdl.core.node.State){
-                generatedConnections= suggestJoinNode(node);
-                
-                    
-                
-                System.out.println("<state id=\""+node.getId()+"\" name=\""+node.getName()+"\" >");
+            if (node instanceof org.drools.jpdl.core.node.StartState) {
+                System.out.println("<start id=\"" + node.getId() + "\" name=\"" + node.getName() + "\" />");
+            } else if (node instanceof org.drools.jpdl.core.node.Fork) {
+                System.out.println("<split id=\"" + node.getId() + "\" name=\"" + node.getName() + "\" type=\"1\" />");
+            } else if (node instanceof org.drools.jpdl.core.node.Join) {
+                System.out.println("<join id=\"" + node.getId() + "\" name=\"" + node.getName() + "\" type=\"1\" />");
+            } else if (node instanceof org.drools.jpdl.core.node.SuperState) {
+                generatedConnections += suggestSplitNode(node);
+                generatedConnections += suggestJoinNode(node);
+                System.out.println("<composite id=\""+ node.getId() +"\" name=\""+ node.getName() +"\">");
+                    List<org.drools.jpdl.core.node.JpdlNode> nodesList = ((org.drools.jpdl.core.node.SuperState)node).getNodes();
+                    printNodesAndConnections(nodesList.toArray(new Node[nodes.length]));
+                System.out.println("</composite>");
+
+            } else if (node instanceof org.drools.jpdl.core.node.State) {
+                generatedConnections += suggestJoinNode(node);
+                System.out.println("<state id=\"" + node.getId() + "\" name=\"" + node.getName() + "\" >");
                 System.out.println("    <constraints>");
                 Set<String> keys = node.getOutgoingConnections().keySet();
-                for(String key: keys){
-                    for (Connection connection: node.getOutgoingConnections(key)) {
-                        System.out.println("        <constraint toNodeId=\""+connection.getTo().getId()+"\" name=\"signalTo"+connection.getTo().getName()+"\" />");
+                for (String key : keys) {
+                    for (Connection connection : node.getOutgoingConnections(key)) {
+                        System.out.println("        <constraint toNodeId=\"" + connection.getTo().getId() + "\" name=\"signalTo" + connection.getTo().getName() + "\" />");
                     }
                 }
                 System.out.println("    </constraints>");
                 System.out.println("</state>");
-
-            }
-            else if(node instanceof org.drools.jpdl.core.node.Decision){
-                System.out.println("<split id=\""+node.getId()+"\" name=\""+node.getName()+"\" type=\"2\" >");
-                 System.out.println("    <constraints>");
+            } else if (node instanceof org.drools.jpdl.core.node.Decision) {
+                System.out.println("<split id=\"" + node.getId() + "\" name=\"" + node.getName() + "\" type=\"2\" >");
+                System.out.println("    <constraints>");
                 Set<String> keys = node.getOutgoingConnections().keySet();
-                for(String key: keys){
-
-                    for (Connection connection: node.getOutgoingConnections(key)) {
-                        System.out.println("        <constraint toNodeId=\""+connection.getTo().getId()+"\" name=\"signalTo"+connection.getTo().getName()+
-                                            "\" toType=\"DROOLS_DEFAULT\" type=\"rule\" dialect=\"java\" >");
+                for (String key : keys) {
+                    for (Connection connection : node.getOutgoingConnections(key)) {
+                        System.out.println("        <constraint toNodeId=\"" + connection.getTo().getId() + "\" name=\"signalTo" + connection.getTo().getName() + "\" toType=\"DROOLS_DEFAULT\" type=\"rule\" dialect=\"java\" >");
                         //System.out.println("            "+"There is no way to get the conditions in each leavingTransition (depracated since 3.2 - http://docs.jboss.com/jbpm/v3.2/userguide/html_single/#condition.element)");
                         //System.out.println("            "+"There is no way to access the decision expresion or the decision delegation class through the APIs");
                         System.out.println("        </constraint>");
-
                     }
                 }
                 System.out.println("    </constraints>");
                 System.out.println("</split>");
-            }
-            else if(node instanceof org.drools.jpdl.core.node.EndState){
+            } else if (node instanceof org.drools.jpdl.core.node.EndState) {
                 generatedConnections += suggestJoinNode(node);
-                
-
-                System.out.println("<end id=\""+node.getId()+"\" name=\""+node.getName()+"\" />");
-
-            }
-            else if(node instanceof org.drools.jpdl.core.node.JpdlNode){
+                System.out.println("<end id=\"" + node.getId() + "\" name=\"" + node.getName() + "\" />");
+            } else if (node instanceof org.drools.jpdl.core.node.JpdlNode) {
                 generatedConnections += suggestSplitNode(node);
                 generatedConnections += suggestJoinNode(node);
-
-                System.out.println("<actionNode id=\""+node.getId()+"\" name=\""+node.getName()+"\">");
+                System.out.println("<actionNode id=\"" + node.getId() + "\" name=\"" + node.getName() + "\">");
                 System.out.println("    <action type=\"expression\" dialect=\"java\" >");
-                Action action = ((org.drools.jpdl.core.node.JpdlNode)node).getAction();
-                if(action != null){
+                Action action = ((org.drools.jpdl.core.node.JpdlNode) node).getAction();
+                if (action != null) {
                     Delegation delegation = action.getActionDelegation();
-                    if(delegation != null){
-                       // System.out.println("Introspect = "+delegation.getClassName());
-                       // System.out.println("replaced"+delegation.getClassName().replace(".","/"));
-                       // Resource resource = ResourceFactory.newInputStreamResource(EpdlWriter.class.getResourceAsStream(delegation.getClassName().replace(".","/")));
-                       // System.out.println(""+resource);
-                       //  System.out.println("Paste the content of the execute() method of the class"+delegation.getClassName());
+                    if (delegation != null) {
+                        // System.out.println("Introspect = "+delegation.getClassName());
+                        // System.out.println("replaced"+delegation.getClassName().replace(".","/"));
+                        // Resource resource = ResourceFactory.newInputStreamResource(EpdlWriter.class.getResourceAsStream(delegation.getClassName().replace(".","/")));
+                        // System.out.println(""+resource);
+                        //  System.out.println("Paste the content of the execute() method of the class"+delegation.getClassName());
                     }
                 }
                 System.out.println("    </action>");
                 System.out.println("</actionNode>");
             }
-            
         }
         System.out.println("</nodes>");
-
         System.out.println("<connections>");
-        for(Node node : nodes){
-
+        for (Node node : nodes) {
             Map<String, List<Connection>> outConnections = node.getOutgoingConnections();
             Set<String> keys = outConnections.keySet();
-            for(String key : keys){
+            if(keys.size() == 0){
+                break;
+            }
+            for (String key : keys) {
                 List<Connection> connections = outConnections.get(key);
-                for(Connection connection : connections){
-                    System.out.println("    <connection from=\""+node.getId()+"\" to=\""+connection.getTo().getId()+"\" />");
+                for (Connection connection : connections) {
+                    System.out.println("    <connection from=\"" + node.getId() + "\" to=\"" + connection.getTo().getId() + "\" />");
                 }
             }
-
         }
-        System.out.println("<!-- Generated Connection for suggested nodes -->");
-        System.out.println(generatedConnections);
-        System.out.println("<!-- END - Generated Connection for suggested nodes -->");
+        if(!generatedConnections.equals("")){
+            System.out.println("<!-- Generated Connection for suggested nodes -->");
+            System.out.println(generatedConnections);
+            System.out.println("<!-- END - Generated Connection for suggested nodes -->");
+        }
         System.out.println("</connections>");
-        System.out.println("</process>");
     }
 
     private static String suggestJoinNode(Node node) {
         String resultGeneratedConnection = "";
         Set<String> incomingConnectionsTypes = node.getIncomingConnections().keySet();
+        //Probably we are inside a composite node or in a disconected node (??)
+        if(incomingConnectionsTypes.size()== 0){
+            return "";
+        }
         String firstKey = incomingConnectionsTypes.iterator().next();
         boolean suggestJoinNode = false;
         if (incomingConnectionsTypes.size() > 1) {
@@ -160,6 +164,7 @@
             suggestJoinNode = true;
         }
         if (suggestJoinNode) {
+
             System.out.println("<!-- This is a suggested Join Node -->");
             System.out.println("<join id=\"" + (suggestedNodeId) + "\" name=\"Join XOR - "+suggestedNodeId+"\" type=\"2\" />");
             
@@ -191,7 +196,11 @@
     private static String suggestSplitNode(Node node) {
         String resultGeneratedConnection = "";
         Set<String> outgoingConnectionsTypes = node.getOutgoingConnections().keySet();
-         String firstKey = outgoingConnectionsTypes.iterator().next();
+         //Probably we are inside a composite node or in a disconected node (??)
+        if(outgoingConnectionsTypes.size()== 0){
+            return "";
+        }
+        String firstKey = outgoingConnectionsTypes.iterator().next();
         boolean suggestSplitNode = false;
         if (outgoingConnectionsTypes.size() > 1) {
             suggestSplitNode = true;

Modified: labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/JpdlParser.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/JpdlParser.java	2009-07-28 16:09:20 UTC (rev 28541)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/JpdlParser.java	2009-07-28 16:38:02 UTC (rev 28542)
@@ -19,6 +19,7 @@
 import org.drools.jpdl.core.node.ProcessState;
 import org.drools.jpdl.core.node.StartState;
 import org.drools.jpdl.core.node.State;
+import org.drools.jpdl.core.node.SuperState;
 import org.drools.jpdl.core.node.TaskNode;
 import org.drools.process.core.ParameterDefinition;
 import org.drools.process.core.context.swimlane.Swimlane;
@@ -33,159 +34,50 @@
 import org.jbpm.taskmgmt.def.Task;
 
 public class JpdlParser {
-    
+
     private static final Set<ParameterDefinition> EMAIL_PARAMETER_DEFINITIONS = new HashSet<ParameterDefinition>();
     private static final Pattern MAIL_TEMPLATE_PATTERN = Pattern.compile("<template>(.*)</template>", Pattern.DOTALL);
     private static final Pattern MAIL_ACTORS_PATTERN = Pattern.compile("<actors>(.*)</actors>", Pattern.DOTALL);
     private static final Pattern MAIL_TO_PATTERN = Pattern.compile("<to>(.*)</to>", Pattern.DOTALL);
     private static final Pattern MAIL_SUBJECT_PATTERN = Pattern.compile("<subject>(.*)</subject>", Pattern.DOTALL);
     private static final Pattern MAIL_TEXT_PATTERN = Pattern.compile("<text>(.*)</text>", Pattern.DOTALL);
-    
+    private int nodeId = 0;
+
     static {
         EMAIL_PARAMETER_DEFINITIONS.add(new ParameterDefinitionImpl("From", new StringDataType()));
         EMAIL_PARAMETER_DEFINITIONS.add(new ParameterDefinitionImpl("To", new StringDataType()));
         EMAIL_PARAMETER_DEFINITIONS.add(new ParameterDefinitionImpl("Subject", new StringDataType()));
         EMAIL_PARAMETER_DEFINITIONS.add(new ParameterDefinitionImpl("Text", new StringDataType()));
     }
-    
     private ProcessValidationError[] errors;
-    
+
     public JpdlProcess loadJpdlProcess(String name) {
         org.jbpm.graph.def.ProcessDefinition processDefinition =
-            org.jbpm.graph.def.ProcessDefinition.parseXmlResource(name);
+                org.jbpm.graph.def.ProcessDefinition.parseXmlResource(name);
         return loadJpdlProcess(processDefinition);
     }
-    
+
     public JpdlProcess loadJpdlProcess(org.jbpm.graph.def.ProcessDefinition processDefinition) {
         JpdlProcess process = new JpdlProcess();
         process.setId(processDefinition.getName());
         process.setName(processDefinition.getName());
         process.setPackageName("org.drools");
-        SwimlaneContext swimlaneContext = (SwimlaneContext)
-        	process.getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
+        SwimlaneContext swimlaneContext = (SwimlaneContext) process.getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
         process.setDefaultContext(swimlaneContext);
         org.jbpm.graph.def.Node startState = processDefinition.getStartState();
         String startStateName = startState == null ? null : startState.getName();
-        
+
         List<org.jbpm.graph.def.Node> nodes = processDefinition.getNodes();
-        int nodeId = 0;
+
         Map<org.jbpm.graph.def.Node, Node> mapping = new HashMap<org.jbpm.graph.def.Node, Node>();
-        for (org.jbpm.graph.def.Node jPDLnode: nodes) {
-            JpdlNode node = null;
-            if (jPDLnode instanceof org.jbpm.graph.node.StartState) {
-                StartState newNode = new StartState();
-                Task task = processDefinition.getTaskMgmtDefinition().getStartTask();
-                if (task != null) {
-                	newNode.setTask(task);
-                	org.jbpm.taskmgmt.def.Swimlane jPDLswimlane = task.getSwimlane();
-            	    if (jPDLswimlane != null) {
-            	        String swimlaneName = jPDLswimlane.getName();
-            	        if (swimlaneContext.getSwimlane(swimlaneName) == null) {
-            	            Swimlane swimlane = new Swimlane();
-            	            swimlane.setName(swimlaneName);
-            	            swimlane.setActorId(jPDLswimlane.getActorIdExpression());
-            	            // TODO support other types of actor expressions as well
-            	            swimlaneContext.addSwimlane(swimlane);
-            	        }
-            	    }
-                }
-                node = newNode;
-            } else if (jPDLnode instanceof org.jbpm.graph.node.EndState) {
-                node = new EndState();
-            } else if (org.jbpm.graph.def.Node.class.equals(jPDLnode.getClass())) {
-                JpdlNode newNode = new JpdlNode();
-                setDefaultNodeProperties(jPDLnode, newNode);
-                node = newNode;
-            } else if (jPDLnode instanceof org.jbpm.graph.node.Fork) {
-                org.jbpm.graph.node.Fork jPDLfork =
-                    (org.jbpm.graph.node.Fork) jPDLnode; 
-                Fork newNode = new Fork();
-                newNode.setScript(jPDLfork.getScript());
-                node = newNode;
-            } else if (jPDLnode instanceof org.jbpm.graph.node.Join) {
-                org.jbpm.graph.node.Join jPDLjoin =
-                    (org.jbpm.graph.node.Join) jPDLnode; 
-                Join newNode = new Join();
-                newNode.setDiscriminator(jPDLjoin.isDiscriminator());
-                newNode.setTokenNames(jPDLjoin.getTokenNames());
-                newNode.setScript(jPDLjoin.getScript());
-                newNode.setNOutOfM(jPDLjoin.getNOutOfM());
-                node = newNode;
-            } else if (jPDLnode instanceof org.jbpm.graph.node.MailNode) {
-                String config = jPDLnode.getAction().getActionDelegation().getConfiguration();
-                
-                MailNode newNode = new MailNode();
-                Matcher matcher = MAIL_TEMPLATE_PATTERN.matcher(config);
-                if (matcher.find()) {
-                    newNode.setTemplate(matcher.group(1));
-                }
-                matcher = MAIL_ACTORS_PATTERN.matcher(config);
-                if (matcher.find()) {
-                    newNode.setActors(matcher.group(1));
-                }
-                matcher = MAIL_TO_PATTERN.matcher(config);
-                if (matcher.find()) {
-                    newNode.setToEmail(matcher.group(1));
-                }
-                matcher = MAIL_SUBJECT_PATTERN.matcher(config);
-                if (matcher.find()) {
-                    newNode.setSubject(matcher.group(1));
-                }
-                matcher = MAIL_TEXT_PATTERN.matcher(config);
-                if (matcher.find()) {
-                    newNode.setText(matcher.group(1));
-                }
-                node = newNode;
-            } else if (jPDLnode instanceof org.jbpm.graph.node.Decision) {
-            	org.jbpm.graph.node.Decision jPDLdecision =
-                    (org.jbpm.graph.node.Decision) jPDLnode; 
-            	Decision newNode = new Decision();
-            	newNode.setDecisionConditions(jPDLdecision.getDecisionConditions());
-            	// TODO: unable to access decisionDelegation
-            	// TODO: unable to access decisionExpression
-            	node = newNode;
-            } else if (jPDLnode instanceof org.jbpm.graph.node.ProcessState) {
-            	org.jbpm.graph.node.ProcessState jPDLprocessState =
-                    (org.jbpm.graph.node.ProcessState) jPDLnode; 
-            	ProcessState newNode = new ProcessState();
-            	ProcessDefinition subProcessDefinition = 
-            		jPDLprocessState.getSubProcessDefinition();
-            	if (subProcessDefinition != null) {
-            		newNode.setSubProcessName(subProcessDefinition.getName());
-            		// TODO: parse sub process definition as well
-            	}
-            	// TODO: unable to access subProcessName
-            	// TODO: unable to access variableAccesses
-            	node = newNode;
-            } else if (jPDLnode instanceof org.jbpm.graph.node.TaskNode) {
-            	org.jbpm.graph.node.TaskNode jPDLtaskNode =
-                    (org.jbpm.graph.node.TaskNode) jPDLnode; 
-            	TaskNode newNode = new TaskNode();
-            	Set<Task> tasks = jPDLtaskNode.getTasks();
-            	newNode.setTasks(tasks);
-            	newNode.setSignal(jPDLtaskNode.getSignal());
-            	newNode.setCreateTasks(jPDLtaskNode.getCreateTasks());
-            	newNode.setEndTasks(jPDLtaskNode.isEndTasks());
-            	for (Task task: tasks) {
-            	    org.jbpm.taskmgmt.def.Swimlane jPDLswimlane = task.getSwimlane();
-            	    if (jPDLswimlane != null) {
-            	        String swimlaneName = jPDLswimlane.getName();
-            	        if (swimlaneContext.getSwimlane(swimlaneName) == null) {
-            	            Swimlane swimlane = new Swimlane();
-            	            swimlane.setName(swimlaneName);
-            	            swimlane.setActorId(jPDLswimlane.getActorIdExpression());
-            	            // TODO support other types of actor expressions as well
-            	            swimlaneContext.addSwimlane(swimlane);
-            	        }
-            	    }
-            	}
-            	node = newNode;
-            } else if (jPDLnode instanceof org.jbpm.graph.node.State) {
-            	node = new State();
-            }
+
+        for (org.jbpm.graph.def.Node jPDLnode : nodes) {
+            JpdlNode node = classifyNode(processDefinition, jPDLnode, swimlaneContext);
+            //@TODO: see how to include this following code into the classifyNode method
+
             if (node == null) {
                 throw new IllegalArgumentException(
-                    "Unknown node type: " + jPDLnode.getClass().getName() + " " + jPDLnode);
+                        "Unknown node type: " + jPDLnode.getClass().getName() + " " + jPDLnode);
             }
             setDefaultNodeProperties(jPDLnode, (JpdlNode) node);
             node.setId(++nodeId);
@@ -195,12 +87,153 @@
                 process.setStartState(node);
             }
         }
-        
-        for (Map.Entry<org.jbpm.graph.def.Node, Node> entry: mapping.entrySet()) {
-            List<org.jbpm.graph.def.Transition> leavingTransitions =
-                (List<org.jbpm.graph.def.Transition>) entry.getKey().getLeavingTransitions();
+
+        generateConnections(mapping);
+
+        errors = JpdlProcessValidator.getInstance().validateProcess(process);
+        return process;
+    }
+
+    private JpdlNode classifyNode(org.jbpm.graph.def.ProcessDefinition processDefinition, org.jbpm.graph.def.Node jPDLnode, SwimlaneContext swimlaneContext) {
+        JpdlNode node = null;
+        if (jPDLnode instanceof org.jbpm.graph.node.StartState) {
+            StartState newNode = new StartState();
+            Task task = processDefinition.getTaskMgmtDefinition().getStartTask();
+            if (task != null) {
+                newNode.setTask(task);
+                org.jbpm.taskmgmt.def.Swimlane jPDLswimlane = task.getSwimlane();
+                if (jPDLswimlane != null) {
+                    String swimlaneName = jPDLswimlane.getName();
+                    if (swimlaneContext.getSwimlane(swimlaneName) == null) {
+                        Swimlane swimlane = new Swimlane();
+                        swimlane.setName(swimlaneName);
+                        swimlane.setActorId(jPDLswimlane.getActorIdExpression());
+                        // TODO support other types of actor expressions as well
+                        swimlaneContext.addSwimlane(swimlane);
+                    }
+                }
+            }
+            node = newNode;
+        } else if (jPDLnode instanceof org.jbpm.graph.node.EndState) {
+            node = new EndState();
+        } else if (org.jbpm.graph.def.Node.class.equals(jPDLnode.getClass())) {
+            JpdlNode newNode = new JpdlNode();
+            setDefaultNodeProperties(jPDLnode, newNode);
+            node = newNode;
+        } else if (jPDLnode instanceof org.jbpm.graph.node.Fork) {
+            org.jbpm.graph.node.Fork jPDLfork =
+                    (org.jbpm.graph.node.Fork) jPDLnode;
+            Fork newNode = new Fork();
+            newNode.setScript(jPDLfork.getScript());
+            node = newNode;
+        } else if (jPDLnode instanceof org.jbpm.graph.node.Join) {
+            org.jbpm.graph.node.Join jPDLjoin =
+                    (org.jbpm.graph.node.Join) jPDLnode;
+            Join newNode = new Join();
+            newNode.setDiscriminator(jPDLjoin.isDiscriminator());
+            newNode.setTokenNames(jPDLjoin.getTokenNames());
+            newNode.setScript(jPDLjoin.getScript());
+            newNode.setNOutOfM(jPDLjoin.getNOutOfM());
+            node = newNode;
+        } else if (jPDLnode instanceof org.jbpm.graph.node.MailNode) {
+            String config = jPDLnode.getAction().getActionDelegation().getConfiguration();
+
+            MailNode newNode = new MailNode();
+            Matcher matcher = MAIL_TEMPLATE_PATTERN.matcher(config);
+            if (matcher.find()) {
+                newNode.setTemplate(matcher.group(1));
+            }
+            matcher = MAIL_ACTORS_PATTERN.matcher(config);
+            if (matcher.find()) {
+                newNode.setActors(matcher.group(1));
+            }
+            matcher = MAIL_TO_PATTERN.matcher(config);
+            if (matcher.find()) {
+                newNode.setToEmail(matcher.group(1));
+            }
+            matcher = MAIL_SUBJECT_PATTERN.matcher(config);
+            if (matcher.find()) {
+                newNode.setSubject(matcher.group(1));
+            }
+            matcher = MAIL_TEXT_PATTERN.matcher(config);
+            if (matcher.find()) {
+                newNode.setText(matcher.group(1));
+            }
+            node = newNode;
+        } else if (jPDLnode instanceof org.jbpm.graph.node.Decision) {
+            org.jbpm.graph.node.Decision jPDLdecision =
+                    (org.jbpm.graph.node.Decision) jPDLnode;
+            Decision newNode = new Decision();
+            newNode.setDecisionConditions(jPDLdecision.getDecisionConditions());
+            // TODO: unable to access decisionDelegation
+            // TODO: unable to access decisionExpression
+            node = newNode;
+        } else if (jPDLnode instanceof org.jbpm.graph.node.ProcessState) {
+            org.jbpm.graph.node.ProcessState jPDLprocessState =
+                    (org.jbpm.graph.node.ProcessState) jPDLnode;
+            ProcessState newNode = new ProcessState();
+            ProcessDefinition subProcessDefinition =
+                    jPDLprocessState.getSubProcessDefinition();
+            if (subProcessDefinition != null) {
+                newNode.setSubProcessName(subProcessDefinition.getName());
+                // TODO: parse sub process definition as well
+            }
+            // TODO: unable to access subProcessName
+            // TODO: unable to access variableAccesses
+            node = newNode;
+        } else if (jPDLnode instanceof org.jbpm.graph.def.SuperState) {
+            org.jbpm.graph.def.SuperState jPDLsuperState =
+                    (org.jbpm.graph.def.SuperState) jPDLnode;
+            SuperState newNode = new SuperState();
+            List<org.jbpm.graph.def.Node> nodes = jPDLsuperState.getNodes();
+            Map<org.jbpm.graph.def.Node, Node> mapping = new HashMap<org.jbpm.graph.def.Node, Node>();
+            for (org.jbpm.graph.def.Node nodeInsideSuperState : nodes) {
+                JpdlNode nodeToAdd = classifyNode(processDefinition, nodeInsideSuperState, swimlaneContext);
+                if (nodeToAdd == null) {
+                    throw new IllegalArgumentException(
+                            "Unknown node type: " + jPDLnode.getClass().getName() + " " + jPDLnode);
+                }
+                setDefaultNodeProperties(nodeInsideSuperState, (JpdlNode) nodeToAdd);
+                nodeToAdd.setId(++nodeId);
+                mapping.put(nodeInsideSuperState, nodeToAdd);
+                newNode.addNode(nodeToAdd);
+            }
+            generateConnections(mapping);
+            node = newNode;
+        } else if (jPDLnode instanceof org.jbpm.graph.node.TaskNode) {
+            org.jbpm.graph.node.TaskNode jPDLtaskNode =
+                    (org.jbpm.graph.node.TaskNode) jPDLnode;
+            TaskNode newNode = new TaskNode();
+            Set<Task> tasks = jPDLtaskNode.getTasks();
+            newNode.setTasks(tasks);
+            newNode.setSignal(jPDLtaskNode.getSignal());
+            newNode.setCreateTasks(jPDLtaskNode.getCreateTasks());
+            newNode.setEndTasks(jPDLtaskNode.isEndTasks());
+            for (Task task : tasks) {
+                org.jbpm.taskmgmt.def.Swimlane jPDLswimlane = task.getSwimlane();
+                if (jPDLswimlane != null) {
+                    String swimlaneName = jPDLswimlane.getName();
+                    if (swimlaneContext.getSwimlane(swimlaneName) == null) {
+                        Swimlane swimlane = new Swimlane();
+                        swimlane.setName(swimlaneName);
+                        swimlane.setActorId(jPDLswimlane.getActorIdExpression());
+                        // TODO support other types of actor expressions as well
+                        swimlaneContext.addSwimlane(swimlane);
+                    }
+                }
+            }
+            node = newNode;
+        } else if (jPDLnode instanceof org.jbpm.graph.node.State) {
+            node = new State();
+        }
+        return node;
+    }
+
+    private void generateConnections(Map<org.jbpm.graph.def.Node, Node> mapping) {
+        for (Map.Entry<org.jbpm.graph.def.Node, Node> entry : mapping.entrySet()) {
+            List<org.jbpm.graph.def.Transition> leavingTransitions = (List<org.jbpm.graph.def.Transition>) entry.getKey().getLeavingTransitions();
             if (leavingTransitions != null) {
-                for (org.jbpm.graph.def.Transition transition: leavingTransitions) {
+                for (org.jbpm.graph.def.Transition transition : leavingTransitions) {
                     Node from = mapping.get(transition.getFrom());
                     Node to = mapping.get(transition.getTo());
                     String transitionName = transition.getName();
@@ -208,17 +241,16 @@
                         transitionName = Node.CONNECTION_DEFAULT_TYPE;
                     }
                     // TODO: transition condition, events and exception handlers
-                    JpdlConnection connection =
-                        new JpdlConnection(from, transitionName, to, Node.CONNECTION_DEFAULT_TYPE);
+                    JpdlConnection connection = new JpdlConnection(from, transitionName, to, Node.CONNECTION_DEFAULT_TYPE);
                     Map<String, Event> events = transition.getEvents();
                     if (events != null) {
-                        for (Event event: events.values()) {
+                        for (Event event : events.values()) {
                             connection.addEvent(event);
                         }
                     }
                     List<ExceptionHandler> exceptionHandlers = transition.getExceptionHandlers();
                     if (exceptionHandlers != null) {
-                        for (ExceptionHandler exceptionHandler: exceptionHandlers) {
+                        for (ExceptionHandler exceptionHandler : exceptionHandlers) {
                             connection.addExceptionHandler(exceptionHandler);
                         }
                     }
@@ -226,31 +258,27 @@
                 }
             }
         }
-        
-        errors = JpdlProcessValidator.getInstance().validateProcess(process);
-        return process;
     }
-    
+
     private void setDefaultNodeProperties(org.jbpm.graph.def.Node jPDLnode, JpdlNode newNode) {
         newNode.setName(jPDLnode.getName());
         newNode.setAction(jPDLnode.getAction());
         Map<String, Event> events = jPDLnode.getEvents();
         if (events != null) {
-            for (Event event: events.values()) {
+            for (Event event : events.values()) {
                 newNode.addEvent(event);
                 // TODO: extract timer actions and replace by our timer framework
             }
         }
         List<ExceptionHandler> exceptionHandlers = jPDLnode.getExceptionHandlers();
         if (exceptionHandlers != null) {
-            for (ExceptionHandler exceptionHandler: exceptionHandlers) {
+            for (ExceptionHandler exceptionHandler : exceptionHandlers) {
                 newNode.addExceptionHandler(exceptionHandler);
             }
         }
     }
-    
+
     public ProcessValidationError[] getErrors() {
         return this.errors;
     }
-    
 }

Added: labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/core/node/SuperState.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/core/node/SuperState.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/main/java/org/drools/jpdl/core/node/SuperState.java	2009-07-28 16:38:02 UTC (rev 28542)
@@ -0,0 +1,46 @@
+/*
+ *  Copyright 2009 salaboy.
+ * 
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ * 
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *  under the License.
+ */
+
+package org.drools.jpdl.core.node;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ *
+ * @author salaboy
+ */
+public class SuperState extends JpdlNode{
+    private List<JpdlNode> nodes;
+
+    public List<JpdlNode> getNodes() {
+        return nodes;
+    }
+
+    public void setNodes(List<JpdlNode> nodes) {
+        this.nodes = nodes;
+    }
+    public void addNode(JpdlNode node){
+        if(nodes == null){
+            nodes = new ArrayList<JpdlNode>();
+        }
+        nodes.add(node);
+    }
+
+ 
+}

Modified: labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/java/org/drools/ParseSimpleProcessTest.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/java/org/drools/ParseSimpleProcessTest.java	2009-07-28 16:09:20 UTC (rev 28541)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/java/org/drools/ParseSimpleProcessTest.java	2009-07-28 16:38:02 UTC (rev 28542)
@@ -104,5 +104,13 @@
         EpdlWriter.write(process);
 
       }
+      public void testWriteEPDLSuperState() throws Exception {
+        JpdlParser parser = new JpdlParser();
+        JpdlProcess process = parser.loadJpdlProcess("simple2superState/processdefinition.xml");
+        ProcessValidationError[] errors = parser.getErrors();
 
+        EpdlWriter.write(process);
+
+      }
+
 }

Added: labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2superState/gpd.xml
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2superState/gpd.xml	                        (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2superState/gpd.xml	2009-07-28 16:38:02 UTC (rev 28542)
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root-container name="TwoLeavingTransitionOnActionNodes" width="846" height="499">
+  <node name="start-state1" x="173" y="45" width="132" height="36">
+    <edge>
+      <label x="5" y="-10"/>
+    </edge>
+  </node>
+  <node name="end-state1" x="189" y="383" width="132" height="36"/>
+  <node name="node1" x="171" y="114" width="132" height="36">
+    <edge>
+      <label x="5" y="-10"/>
+    </edge>
+    <edge>
+      <label x="5" y="-10"/>
+    </edge>
+  </node>
+  <node name="state1" x="131" y="181" width="132" height="36">
+    <edge>
+      <label x="5" y="-10"/>
+    </edge>
+    <edge>
+      <label x="5" y="-10"/>
+    </edge>
+  </node>
+  <node name="state2" x="303" y="182" width="132" height="36">
+    <edge>
+      <label x="5" y="-10"/>
+    </edge>
+  </node>
+  <node name="node2" x="178" y="273" width="132" height="36">
+    <edge>
+      <label x="5" y="-10"/>
+    </edge>
+  </node>
+  <node name="node3" x="31" y="274" width="132" height="36">
+    <edge>
+      <label x="5" y="-10"/>
+    </edge>
+  </node>
+</root-container>

Added: labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2superState/processdefinition.xml
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2superState/processdefinition.xml	                        (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-jpdl/src/test/resources/simple2superState/processdefinition.xml	2009-07-28 16:38:02 UTC (rev 28542)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process-definition  xmlns="urn:jbpm.org:jpdl-3.2"  name="SimpleSuperStateNode">
+
+
+	<start-state name="start-state1">
+		<transition to="super-state1"></transition>
+	</start-state>
+
+
+	<super-state name="super-state1">
+		<state name="state1">
+			<transition to="node1"></transition>
+		</state>
+		<node name="node1"></node>
+		<transition to="end-state1"></transition>
+	</super-state>
+
+
+	<end-state name="end-state1"></end-state>
+
+
+</process-definition>
\ No newline at end of file



More information about the jboss-svn-commits mailing list