[jbpm-commits] JBoss JBPM SVN: r4965 - in jbpm4/branches/jimma/modules/migration/src: main/java/org/jbpm/jpdl/internal/convert/util and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Sun May 31 04:49:12 EDT 2009


Author: jim.ma
Date: 2009-05-31 04:49:11 -0400 (Sun, 31 May 2009)
New Revision: 4965

Added:
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/EventsConverter.java
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TimerConverter.java
   jbpm4/branches/jimma/modules/migration/src/test/resources/timer.xml
Removed:
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/EventConverter.java
Modified:
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/JpdlConverter.java
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/DecisionConverter.java
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/EndStateConverter.java
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/EventActionConverter.java
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/ForkConverter.java
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/JoinConverter.java
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/NodeConverter.java
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/StartStateConverter.java
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/StateConverter.java
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/SwimlaneConverter.java
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TaskNodeConverter.java
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TransitionConverter.java
   jbpm4/branches/jimma/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/JpdlConverterTest.java
Log:
Added TimerConverter and enabled event conversion in fork, state and other elments

Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/JpdlConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/JpdlConverter.java	2009-05-30 19:15:30 UTC (rev 4964)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/JpdlConverter.java	2009-05-31 08:49:11 UTC (rev 4965)
@@ -32,9 +32,13 @@
 
 import java.net.URL;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.jbpm.graph.def.Event;
 import org.jbpm.graph.def.Node;
 import org.jbpm.graph.def.ProcessDefinition;
@@ -46,7 +50,7 @@
 import org.jbpm.graph.node.TaskNode;
 import org.jbpm.jpdl.internal.convert.util.DecisionConverter;
 import org.jbpm.jpdl.internal.convert.util.EndStateConverter;
-import org.jbpm.jpdl.internal.convert.util.EventConverter;
+import org.jbpm.jpdl.internal.convert.util.EventsConverter;
 import org.jbpm.jpdl.internal.convert.util.ForkConverter;
 import org.jbpm.jpdl.internal.convert.util.JoinConverter;
 import org.jbpm.jpdl.internal.convert.util.NodeConverter;
@@ -54,19 +58,22 @@
 import org.jbpm.jpdl.internal.convert.util.StateConverter;
 import org.jbpm.jpdl.internal.convert.util.SwimlaneConverter;
 import org.jbpm.jpdl.internal.convert.util.TaskNodeConverter;
+import org.jbpm.jpdl.xml.JpdlXmlReader;
+import org.jbpm.jpdl.xml.Problem;
+import org.jbpm.jpdl.xml.ProblemListener;
+import org.jbpm.jpdl4.model.On;
 import org.jbpm.jpdl4.model.Process;
 import org.jbpm.taskmgmt.def.Swimlane;
 import org.jbpm.taskmgmt.def.TaskMgmtDefinition;
 import org.xml.sax.InputSource;
 
-public class JpdlConverter {
-	private ConverterContext context;
-	public JpdlConverter(ConverterContext ctx) {
-		context = ctx;
-	}
+public class JpdlConverter implements ProblemListener {
+	public List<Problem> problems = new CopyOnWriteArrayList<Problem>();
+	
+	private static final long serialVersionUID = 1L;
+	private static final Log log = LogFactory.getLog(JpdlXmlReader.class);
 
-	public Process run() throws ConvertException {
-		URL url = (URL) context.get(ConverterContext.PROCESS_FILE_URL);
+	public Process run(URL url) throws ConvertException {
 		Jpdl3Reader reader = new Jpdl3Reader(new InputSource(url.toString()));
 		ProcessDefinition processDef = reader.readProcessDefinition();
 		if (!reader.isValid()) {
@@ -132,28 +139,27 @@
 				process.getSwimlaneAndOnAndTimer().add(NodeConverter.run(tmpNode));
 				break;
 			case Decision :
-				org.jbpm.graph.node.Decision decision = (org.jbpm.graph.node.Decision)node;
-				process.getSwimlaneAndOnAndTimer().add(DecisionConverter.run(decision));
+				try {
+					org.jbpm.graph.node.Decision decision = (org.jbpm.graph.node.Decision) node;
+					process.getSwimlaneAndOnAndTimer().add(DecisionConverter.run(decision));
+				} catch (Exception e) {
+					log.error("Failed to convert Decision node [" + node.getName() + "}", e);
+					Problem problem = new Problem(Problem.LEVEL_ERROR, e.getMessage());
+					this.addProblem(problem);
+				}
 			}
 			
 		}
 		
 		//Process Event
-	    Map events = def.getEvents();
-	    if (events != null) {
-	    	Set entries= events.entrySet();
-	    	for (Object entry : entries)  {
-	    		Event event = ((Map.Entry<String, Event>)entry).getValue();
-	    		org.jbpm.jpdl4.model.On on = EventConverter.run(event);
-	    		process.getSwimlaneAndOnAndTimer().add(on);
-	    	}
-	    }
+	    List<On> ons = EventsConverter.run(def.getEvents());
+	    process.getSwimlaneAndOnAndTimer().addAll(ons);
 		return process;
 	}
 
 	
-
-	
-
-
+    public void addProblem(Problem problem) {
+    	this.problems.add(problem);
+    }
+    
 }

Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/DecisionConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/DecisionConverter.java	2009-05-30 19:15:30 UTC (rev 4964)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/DecisionConverter.java	2009-05-31 08:49:11 UTC (rev 4965)
@@ -21,20 +21,62 @@
  */
 package org.jbpm.jpdl.internal.convert.util;
 
+import java.lang.reflect.Field;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jbpm.graph.def.Event;
 import org.jbpm.graph.def.Transition;
 import org.jbpm.graph.node.Decision;
+import org.jbpm.instantiation.Delegation;
+import org.jbpm.jpdl.internal.convert.ConvertException;
+import org.jbpm.jpdl4.model.On;
 import org.jbpm.jpdl4.model.Process;
+import org.jbpm.jpdl4.model.WireObjectType;
 
 public class DecisionConverter {
-	public static Process.Decision run(Decision node) {
+	public static Process.Decision run(Decision node) throws Exception {
 		Process.Decision result = new Process.Decision();
 		result.setName(node.getName());
-		//TODO: talk to Tom to find out if we should support separate DecisionCondition's
-		//node.getDecisionConditions()
+		//Process transition
 		for (Transition trans : node.getLeavingTransitions()) {
 			result.getTransition().add(TransitionConverter.run(trans, Process.Decision.Transition.class));
-		}		
+		}
+		//process the class handler
+		try {
+			Field field = Decision.class.getDeclaredField("decisionDelegation");
+			//There is no getDelegation(),set the accessible to true to get the Delegation object
+		    field.setAccessible(true);
+			Object obj = field.get(node);
+			if (obj != null) {
+				Delegation del = (Delegation) obj;
+				WireObjectType wireType = new WireObjectType();
+				wireType.setClazz(del.getClassName());
+				result.setHandler(wireType);
+			}
+		} catch (Exception e) {
+            throw new ConvertException("Failed to read the handler calss name from Decision node [" + node.getName() +']', e);
+		}
+		
+		try {
+			Field field = Decision.class.getDeclaredField("decisionExpression");
+			//There is no getExpression(),set the accessible to true to get the Delegation object
+		    field.setAccessible(true);
+			Object obj = field.get(node);
+			if (obj != null) {
+				String expression = (String) obj;
+				result.setExpr(expression);				
+			}
+		} catch (Exception e) {
+            throw new ConvertException("Failed to read the expression attribute from Decision node [" + node.getName() +']', e);
+		}
+		
+		List<On> ons = EventsConverter.run(node.getEvents());
+	    result.getOn().addAll(ons);
+		//TODO: process exceptions
+
 		return result;
 	}
 
-}
+}
\ No newline at end of file

Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/EndStateConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/EndStateConverter.java	2009-05-30 19:15:30 UTC (rev 4964)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/EndStateConverter.java	2009-05-31 08:49:11 UTC (rev 4965)
@@ -21,13 +21,17 @@
  */
 package org.jbpm.jpdl.internal.convert.util;
 
+import java.util.List;
+
 import org.jbpm.graph.node.EndState;
+import org.jbpm.jpdl4.model.On;
 import org.jbpm.jpdl4.model.Process;
 
 public class EndStateConverter {	
 	public static Process.End run(EndState endState) {
 		Process.End end = new Process.End();
 		end.setName(endState.getName());
+		//TODO: process exception
 		return end;
 	}
 }

Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/EventActionConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/EventActionConverter.java	2009-05-30 19:15:30 UTC (rev 4964)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/EventActionConverter.java	2009-05-31 08:49:11 UTC (rev 4965)
@@ -1,3 +1,24 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
 package org.jbpm.jpdl.internal.convert.util;
 
 import java.util.Set;
@@ -11,7 +32,8 @@
 import org.jbpm.jpdl4.model.JavaType;
 import org.jbpm.jpdl4.model.ObjectFactory;
 import org.jbpm.jpdl4.model.ScriptType;
-
+import org.jbpm.jpdl4.model.Timer;
+import org.jbpm.scheduler.def.CreateTimerAction;
 public class EventActionConverter {
 	public static JAXBElement<?> run(Action action) {
 		JAXBElement<?> result = null;

Deleted: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/EventConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/EventConverter.java	2009-05-30 19:15:30 UTC (rev 4964)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/EventConverter.java	2009-05-31 08:49:11 UTC (rev 4965)
@@ -1,35 +0,0 @@
-package org.jbpm.jpdl.internal.convert.util;
-
-import java.util.List;
-
-import org.jbpm.graph.def.Action;
-import org.jbpm.graph.def.Event;
-import org.jbpm.jpdl4.model.On;
-
-public class EventConverter {
-	public static On run(Event event) {
-		On result = new On();
-		//process-start and process-end
-		result.setEvent(convertEnvetType(event.getEventType()));
-		List<Action> actions = (List<Action>)event.getActions();
-		for (Action action : actions) {
-			result.getEventListenerGroup().add(EventActionConverter.run(action));
-		}
-		
-		//There is no corresponding element in jpdl3 map to event listener...
-		return result;
-		
-	}
-	
-	private static String convertEnvetType(String type) {
-		if (type.toLowerCase().equals("process-start")) {
-			return "start";
-		}
-		if (type.toLowerCase().equals("process-end")) {
-			return "end";
-		}
-		
-		return null;
-	}
-
-}

Added: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/EventsConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/EventsConverter.java	                        (rev 0)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/EventsConverter.java	2009-05-31 08:49:11 UTC (rev 4965)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.jpdl.internal.convert.util;
+
+import java.util.List;
+import java.util.Map;
+
+import org.jbpm.graph.def.Action;
+import org.jbpm.graph.def.Event;
+import org.jbpm.jpdl4.model.On;
+import org.jbpm.scheduler.def.CreateTimerAction;
+
+public class EventsConverter {
+   public static List<On> run(Map<String,Event> eventsMap) {
+	   List<On> results = new java.util.concurrent.CopyOnWriteArrayList<On>();
+	   if (eventsMap != null && !eventsMap.isEmpty()) {
+	    	for (Event event : eventsMap.values())  {
+	    		if (event.getEventType().equals(Event.EVENTTYPE_NODE_LEAVE)) {
+	    			continue;
+	    		}
+	    		org.jbpm.jpdl4.model.On on = run(event);
+	    		results.add(on);
+	    	}
+	    }	    
+	   return results;
+   }
+	
+	
+	public static On run(Event event) {
+		On result = new On();
+		//process-start and process-end
+		result.setEvent(convertEnvetType(event.getEventType()));
+		List<Action> actions = (List<Action>)event.getActions();
+		for (Action action : actions) {
+			if (action instanceof CreateTimerAction) {
+			    result.setTimer(TimerConverter.run((CreateTimerAction)action));
+			} else {
+				result.getEventListenerGroup().add(EventActionConverter.run(action));
+			}
+		}
+		return result;
+		
+	}
+	
+	private static String convertEnvetType(String type) {
+		if (type.toLowerCase().equals("process-start")) {
+			return "start";
+		}
+		if (type.toLowerCase().equals("process-end")) {
+			return "end";
+		}
+		
+		return type;
+	}
+
+}

Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/ForkConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/ForkConverter.java	2009-05-30 19:15:30 UTC (rev 4964)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/ForkConverter.java	2009-05-31 08:49:11 UTC (rev 4965)
@@ -21,7 +21,10 @@
  */
 package org.jbpm.jpdl.internal.convert.util;
 
+import java.util.List;
+
 import org.jbpm.graph.def.Transition;
+import org.jbpm.jpdl4.model.On;
 import org.jbpm.jpdl4.model.TransitionType;
 import org.jbpm.jpdl4.model.Process.Fork;;
 
@@ -34,6 +37,10 @@
 	    	TransitionType transType = TransitionConverter.run(trans, TransitionType.class);
 	    	result.getTransition().add(transType);
 	    }
+	    
+	    //TODO: process exceptions
+	    List<On> ons = EventsConverter.run(node.getEvents());
+	    result.getOn().addAll(ons);
 		return result;
 	}
 

Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/JoinConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/JoinConverter.java	2009-05-30 19:15:30 UTC (rev 4964)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/JoinConverter.java	2009-05-31 08:49:11 UTC (rev 4965)
@@ -21,7 +21,10 @@
  */
 package org.jbpm.jpdl.internal.convert.util;
 
+import java.util.List;
+
 import org.jbpm.graph.def.Transition;
+import org.jbpm.jpdl4.model.On;
 import org.jbpm.jpdl4.model.TransitionType;
 import org.jbpm.jpdl4.model.Process.Join;
 
@@ -33,6 +36,9 @@
 			join.getTransition().add(
 					TransitionConverter.run(trans, TransitionType.class));
 		}
+	    //TODO: process exceptions
+		List<On> ons = EventsConverter.run(node.getEvents());
+	    join.getOn().addAll(ons);
 		return join;
 
 	}

Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/NodeConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/NodeConverter.java	2009-05-30 19:15:30 UTC (rev 4964)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/NodeConverter.java	2009-05-31 08:49:11 UTC (rev 4965)
@@ -1,3 +1,24 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
 package org.jbpm.jpdl.internal.convert.util;
 
 import java.util.Set;
@@ -34,7 +55,7 @@
 					}					
 				}
 			}
-			return result;
+		    
 			
 		}
 		if (action instanceof Action) {
@@ -50,6 +71,9 @@
 			return result;
 		}
 		//TODO:convert other action types:create-timer,cancel-timer, mail
+	    //TODO: Process exceptions
+		//TODO: Process events
+		//TODO: process timers
 		
 		return null;
 		

Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/StartStateConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/StartStateConverter.java	2009-05-30 19:15:30 UTC (rev 4964)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/StartStateConverter.java	2009-05-31 08:49:11 UTC (rev 4965)
@@ -22,10 +22,12 @@
 package org.jbpm.jpdl.internal.convert.util;
 
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import org.jbpm.graph.def.Transition;
 import org.jbpm.graph.node.StartState;
+import org.jbpm.jpdl4.model.On;
 import org.jbpm.jpdl4.model.Process;
 import org.jbpm.jpdl4.model.TransitionType;
 
@@ -33,13 +35,18 @@
 	public static Process.Start run(StartState jpdl3start) {
 		Process.Start start = new Process.Start();
 		start.setName(jpdl3start.getName());
-		Iterator iterator = jpdl3start.getLeavingTransitionsMap().entrySet()
-				.iterator();
+		
+		Iterator iterator = jpdl3start.getLeavingTransitionsMap().entrySet().iterator();
 		while (iterator.hasNext()) {
 			Map.Entry entry = (Map.Entry) iterator.next();
 			Transition trans = (Transition) entry.getValue();
 			start.getTransition().add(TransitionConverter.run(trans, TransitionType.class));
 		}
+		//TODO: process Task
+		List<On> ons = EventsConverter.run(jpdl3start.getEvents());
+	    start.getOn().addAll(ons);
+		//TODO: process exceptions
+	
 		return start;
 	}
 }

Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/StateConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/StateConverter.java	2009-05-30 19:15:30 UTC (rev 4964)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/StateConverter.java	2009-05-31 08:49:11 UTC (rev 4965)
@@ -22,24 +22,30 @@
 package org.jbpm.jpdl.internal.convert.util;
 
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
+import org.jbpm.graph.def.Event;
 import org.jbpm.graph.def.Transition;
 import org.jbpm.graph.node.State;
+import org.jbpm.jpdl4.model.On;
 import org.jbpm.jpdl4.model.Process;
 
 public class StateConverter {
 
-	public static Process.State run(State jpdl3state) {
+	public static Process.State run(State node) {
 		Process.State state = new Process.State();
-		state.setName(jpdl3state.getName());
-		Iterator iterator = jpdl3state.getLeavingTransitionsMap().entrySet().iterator();
+		state.setName(node.getName());
+		Iterator iterator = node.getLeavingTransitionsMap().entrySet().iterator();
 		while (iterator.hasNext()) {
 		    Map.Entry entry = (Map.Entry)iterator.next();
 		    Transition trans = (Transition)entry.getValue();
 		    state.getTransition().add((Process.State.Transition)TransitionConverter.run(trans, Process.State.Transition.class));
 		}		
-		
+	    List<On> ons = EventsConverter.run(node.getEvents());
+	    state.getOn().addAll(ons);
+		//TODO: process exceptions
 		return state;
 		
 	}

Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/SwimlaneConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/SwimlaneConverter.java	2009-05-30 19:15:30 UTC (rev 4964)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/SwimlaneConverter.java	2009-05-31 08:49:11 UTC (rev 4965)
@@ -1,3 +1,24 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
 package org.jbpm.jpdl.internal.convert.util;
 import org.jbpm.instantiation.Delegation;
 import org.jbpm.jpdl4.model.Swimlane;

Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TaskNodeConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TaskNodeConverter.java	2009-05-30 19:15:30 UTC (rev 4964)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TaskNodeConverter.java	2009-05-31 08:49:11 UTC (rev 4965)
@@ -1,10 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
 package org.jbpm.jpdl.internal.convert.util;
 
+import java.util.List;
 import java.util.Set;
 
 import org.jbpm.graph.node.TaskNode;
 import org.jbpm.instantiation.Delegation;
 import org.jbpm.jpdl4.model.ObjectFactory;
+import org.jbpm.jpdl4.model.On;
 import org.jbpm.jpdl4.model.Process;
 import org.jbpm.jpdl4.model.WireObjectType;
 import org.jbpm.taskmgmt.def.Task;
@@ -55,6 +78,9 @@
 				
 			}
 		}
+		//TODO: Process exceptions
+        //TODO: Process events
+		//TODO: Process Timers
 
 		return result;
 	}

Added: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TimerConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TimerConverter.java	                        (rev 0)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TimerConverter.java	2009-05-31 08:49:11 UTC (rev 4965)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.jpdl.internal.convert.util;
+
+import org.jbpm.instantiation.Delegation;
+import org.jbpm.jpdl4.model.JavaType;
+import org.jbpm.jpdl4.model.ObjectFactory;
+import org.jbpm.jpdl4.model.ScriptType;
+import org.jbpm.jpdl4.model.Timer;
+import org.jbpm.scheduler.def.CreateTimerAction;
+
+public class TimerConverter {
+	public static Timer run(CreateTimerAction node) {
+		Timer timer = new Timer();
+		timer.setDuedate(node.getDueDate());
+		timer.setRepeat(node.getRepeat());
+		if (node.getTimerAction().getActionExpression() != null) {
+			ScriptType scriptType = new ScriptType();
+			scriptType.setExpr(node.getTimerAction().getActionExpression());
+			timer.getEventListenerGroup().add(new ObjectFactory().createOnScript(scriptType));
+		}
+		if (node.getTimerAction().getActionDelegation()!= null) {
+			Delegation delegation = node.getTimerAction().getActionDelegation();
+			String className = delegation.getClassName();
+			JavaType javaType = new ObjectFactory().createJavaType();
+			javaType.setClazz(className);
+			javaType.setMethod("execute");
+			timer.getEventListenerGroup().add(new ObjectFactory().createOnJava(javaType));
+
+		}
+
+		return timer;
+	}
+
+}

Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TransitionConverter.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TransitionConverter.java	2009-05-30 19:15:30 UTC (rev 4964)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/util/TransitionConverter.java	2009-05-31 08:49:11 UTC (rev 4965)
@@ -31,6 +31,7 @@
 import org.jbpm.jpdl4.model.JavaType;
 import org.jbpm.jpdl4.model.ObjectFactory;
 import org.jbpm.jpdl4.model.Process;
+import org.jbpm.jpdl4.model.ScriptType;
 import org.jbpm.jpdl4.model.TransitionType;
 import org.jbpm.jpdl4.model.Process.Decision.Transition.Condition;
 
@@ -48,12 +49,13 @@
 			Process.Decision.Transition decTrans = (Process.Decision.Transition)transType;
 			if (transition.getCondition() != null) {
 				Condition condition = new Condition();
-				condition.setExpr(transition.getCondition());
-				decTrans.getCondition().add(condition);
+				//Revisit: check if jbpm4 can process both expression and script
+				condition.setExpr(transition.getCondition());			    
+				decTrans.getCondition().add(condition);				
 			}
 		}
 		
-		// get the actions
+		// process transition events
 		if (transition.getEvents() != null) {
 			Iterator ite = transition.getEvents().entrySet().iterator();
 			while (ite.hasNext()) {
@@ -63,19 +65,29 @@
 					if (entry.getValue().getActions() != null) {
 						for (Action action : (List<Action>) entry.getValue()
 								.getActions()) {
-							JavaType javaType = new JavaType();
-							javaType.setClazz(action.getActionDelegation()
-									.getClassName());
-							// TODO:Check this java method
-							javaType.setMethod("execute");
-							transType.getEventListenerGroup().add(
-									objectFactory.createOnJava(javaType));
+							if (action.getActionDelegation() != null) {
+								JavaType javaType = new JavaType();
+								javaType.setClazz(action.getActionDelegation()
+										.getClassName());
+								// TODO:Check this java method
+								javaType.setMethod("execute");
+								transType.getEventListenerGroup().add(
+										objectFactory.createOnJava(javaType));
+							}
+							
+							if (action.getActionExpression() != null) {
+								ScriptType scriptType = new ScriptType();
+								scriptType.setExpr(action.getActionExpression());
+								transType.getEventListenerGroup().add(objectFactory.createOnScript(scriptType));
+								
+							}
 						}
 
 					}
 				}
 			}
 		}
+        
 		transType.setName(transition.getName());
 		transType.setTo(transition.getTo().getName());
 		return (T)transType;

Modified: jbpm4/branches/jimma/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/JpdlConverterTest.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/JpdlConverterTest.java	2009-05-30 19:15:30 UTC (rev 4964)
+++ jbpm4/branches/jimma/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/JpdlConverterTest.java	2009-05-31 08:49:11 UTC (rev 4965)
@@ -42,7 +42,6 @@
 	public void runBusinessTrip() throws Exception {
 		testConvert("businesstrip.xml");
 	}
-	
 	@Test
 	public void testDescision() throws Exception {
 		testConvert("testDecision.xml");
@@ -52,15 +51,16 @@
 		testConvert("process-event.xml");
 	}
 	
+	@Test
+	public void testTimer() throws Exception {
+		testConvert("timer.xml");
+	}
 	
-	
 	public void testConvert(String resourcefile) throws Exception {
 		URL url = getClass().getClassLoader().getResource(resourcefile);
-		ConverterContext context = new ConverterContext();
-		context.put(ConverterContext.PROCESS_FILE_URL, url);
 		//Convert to process file to jpdl4
-		JpdlConverter converter = new JpdlConverter(context);
-		org.jbpm.jpdl4.model.Process process = converter.run();
+		JpdlConverter converter = new JpdlConverter();
+		org.jbpm.jpdl4.model.Process process = converter.run(url);
 		Jpdl4Writer writer = new Jpdl4Writer();
 		java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream();
 		writer.write(process, bout, false);
@@ -68,9 +68,9 @@
 		
 		//Validate it with Jpdl4Parser
 		String jpdl4xml = new String(bout.toByteArray());
+		//System.out.println(jpdl4xml);
 		List<Problem> problems = new JpdlParser().createParse().setString(jpdl4xml).execute().getProblems();
 		Assert.assertEquals(problems.toString(), 0, problems.size());
 	}
-	
 
 }

Added: jbpm4/branches/jimma/modules/migration/src/test/resources/timer.xml
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/test/resources/timer.xml	                        (rev 0)
+++ jbpm4/branches/jimma/modules/migration/src/test/resources/timer.xml	2009-05-31 08:49:11 UTC (rev 4965)
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process-definition 
+  xmlns="urn:jbpm.org:jpdl-3.2"
+  name="simple">
+   <start-state name="start">
+      <transition name="to_state" to="first">
+         <action name="action" class="com.sample.action.MessageActionHandler">
+            <message>Going to the first state!</message>
+         </action>
+      </transition>
+   </start-state>
+   <state name="first">
+      <timer duedate="2 business minutes">
+           <action name="timer-action1" class="com.sample.action.MessageActionHandler"/>
+      </timer>
+      <event type="task-create">
+           <create-timer duedate="3 business minutes">
+               <action name="timer-action2" class="com.sample.action.MessageActionHandler2"/>
+           </create-timer>
+           <action class="org.jbpm.AnotherEventAction"/>
+      </event>
+      <transition name="to_end" to="end">
+         <action name="action" class="com.sample.action.MessageActionHandler">
+            <message>About to finish!</message>
+         </action>
+      </transition>
+   </state>
+   <end-state name="end"></end-state>   
+</process-definition>
\ No newline at end of file




More information about the jbpm-commits mailing list