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

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Jun 18 05:52:17 EDT 2009


Author: jim.ma
Date: 2009-06-18 05:52:17 -0400 (Thu, 18 Jun 2009)
New Revision: 5055

Added:
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/action/Script.java
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/node/Decision.java
Modified:
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/Jpdl3ConverterReader.java
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/action/Action.java
   jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/node/Node.java
   jbpm4/branches/jimma/modules/migration/src/main/resources/action.converter.types.xml
   jbpm4/branches/jimma/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/Jpdl3ConverterReaderTest.java
   jbpm4/branches/jimma/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/JpdlConverterTest.java
Log:
Added event and script conversion support

Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/Jpdl3ConverterReader.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/Jpdl3ConverterReader.java	2009-06-17 21:20:43 UTC (rev 5054)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/Jpdl3ConverterReader.java	2009-06-18 09:52:17 UTC (rev 5055)
@@ -165,7 +165,8 @@
       readActions(root, null, null);
       readNodes(root, jpdl4Document.getRootElement());
       
-      /* readEvents(root, jpdl4Document);
+      readEvents(root, jpdl4Document.getRootElement());
+      /* 
       readExceptionHandlers(root, jpdl4Document);
       */
       readTasks(root, jpdl4Document.getRootElement());
@@ -303,15 +304,18 @@
     if (tasks != null && tasks.length > 0) {
 		for (int i = 0 ; i < tasks.length; i++) {
 			Element tmpTask = tasks[i];
-	        Element task4 = readTask(tmpTask, jpdl4Element); 					
+	        Element task4 = readTask(tmpTask, jpdl4Element);
+	      
 			if (i ==0 ) {
 				task4.addAttribute("name", element.attributeValue("name"));
+			} else{
+				task4.addAttribute("name", tmpTask.attributeValue("name"));
 			}
 			if (i+1 < tasks.length) {
 				Element newTransistion = task4.addElement("transition");
 				String to = tasks[i+1].attributeValue("name");
 				newTransistion.addAttribute("name", to);
-				newTransistion.addAttribute("to", "to");
+				newTransistion.addAttribute("to", to);
 			} else {
 				//The last task node
 				List<Element> transitions = element.elements("transition");
@@ -359,7 +363,7 @@
     // parse common subelements
     //TODO: convert the task timer
     //readTaskTimers(taskElement, task);
-    //readEvents(taskElement, task);
+    readEvents(taskElement, jpdlElement);
     //readExceptionHandlers(taskElement, task);
 
     // TODO:duedate and priority
@@ -567,7 +571,7 @@
 */
     // parse common subelements
     readNodeTimers(nodeElement, jpdl4Element);
-    //readEvents(nodeElement, jpdl4Element);
+    readEvents(nodeElement, jpdl4Element);
     //readExceptionHandlers(nodeElement, jpdl4Element);
 
     // save the transitions and parse them at the end
@@ -616,13 +620,25 @@
   protected void readTaskTimer(Element timerElement, Task task)
   {
   }
-
-  protected void readEvents(Element parentElement, Element jpdl4doc)
+  */
+  public void readEvents(Element parentElement, Element jpdl4Element)
   {
+      Iterator<?> iter = parentElement.elementIterator("event");
+    while (iter.hasNext())
+    {
+      Element eventElement = (Element)iter.next();
+      //String eventType = eventElement.attributeValue("type");
+      //TODO:how to handle the event type
+      Element onElement = jpdl4Element.addElement("on");
+      //TODO:look at how to convert event type
+      String type = eventElement.attributeValue("type");
+      onElement.addAttribute("event", type);
+      readActions(eventElement, onElement, type);
+    }
   }
 
 
-  */
+
   public void readActions(Element eventElement, Element jpdl4Element, String eventType)
   {  // for all the elements in the event element
 	    Iterator<?> nodeElementIter = eventElement.elementIterator();

Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/action/Action.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/action/Action.java	2009-06-17 21:20:43 UTC (rev 5054)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/action/Action.java	2009-06-18 09:52:17 UTC (rev 5055)
@@ -54,7 +54,7 @@
 	public void read(Element actionElement, Jpdl3ConverterReader jpdlReader) {
 	    String expression = actionElement.attributeValue("expression");
 	    if (expression!=null) {
-	    	convertedElement.addAttribute("expr", "expression");
+	    	convertedElement.addAttribute("expr", expression);
 			convertedElement.addAttribute("lang", "juel");
 
 	    } else if (actionElement.attribute("ref-name")!=null) {

Added: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/action/Script.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/action/Script.java	                        (rev 0)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/action/Script.java	2009-06-18 09:52:17 UTC (rev 5055)
@@ -0,0 +1,51 @@
+/*
+ * 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.action;
+
+import org.dom4j.Element;
+import org.jbpm.jpdl.internal.convert.Jpdl3ConverterReader;
+
+public class Script extends Action {
+	@Override
+	public Element createConvertedElement(Element actionElement,
+			Element jpdl4Doc) {
+		convertedElement = jpdl4Doc.addElement("script");
+		return convertedElement;
+	}
+
+	@Override
+	public void read(Element actionElement, Jpdl3ConverterReader jpdlReader) {
+		String expression = null;
+		if (actionElement.isTextOnly()) {
+			expression = actionElement.getText();
+		} else {
+			/*
+			 * this.variableAccesses = new HashSet<VariableAccess>(
+			 * jpdlReader.readVariableAccesses(scriptElement));
+			 */
+			expression = actionElement.element("expression").getText();
+		}
+		Element txtElement = convertedElement.addElement("text");
+		txtElement.addText(expression);
+	}
+
+}

Added: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/node/Decision.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/node/Decision.java	                        (rev 0)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/node/Decision.java	2009-06-18 09:52:17 UTC (rev 5055)
@@ -0,0 +1,37 @@
+/*
+ * 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.node;
+
+import org.dom4j.Element;
+import org.jbpm.jpdl.internal.convert.Jpdl3ConverterReader;
+
+public class Decision extends Node  {
+	public Element createConvertedElement(Element jpdl4Doc) {
+		convertedElement = jpdl4Doc.addElement("decision");
+		return convertedElement;
+	}
+	
+	public void read(Jpdl3ConverterReader reader) {
+		
+		
+	}
+}

Modified: jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/node/Node.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/node/Node.java	2009-06-17 21:20:43 UTC (rev 5054)
+++ jbpm4/branches/jimma/modules/migration/src/main/java/org/jbpm/jpdl/internal/convert/node/Node.java	2009-06-18 09:52:17 UTC (rev 5055)
@@ -39,6 +39,7 @@
 		//TODO:implement it
 		Element actionElement = nodeElement.element("action");
 		action.read(actionElement, reader);
+		
 	}
 	
 	public Element getConvertedElement()  {

Modified: jbpm4/branches/jimma/modules/migration/src/main/resources/action.converter.types.xml
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/main/resources/action.converter.types.xml	2009-06-17 21:20:43 UTC (rev 5054)
+++ jbpm4/branches/jimma/modules/migration/src/main/resources/action.converter.types.xml	2009-06-18 09:52:17 UTC (rev 5055)
@@ -2,6 +2,6 @@
   <action-type element="action"       class="org.jbpm.jpdl.internal.convert.action.Action" />
   <action-type element="create-timer" class="org.jbpm.scheduler.def.CreateTimerAction" />
   <action-type element="cancel-timer" class="org.jbpm.scheduler.def.CancelTimerAction" />
-  <action-type element="script"       class="org.jbpm.graph.action.Script" />
+  <action-type element="script"       class="org.jbpm.jpdl.internal.convert.action.Script" />
   <action-type element="mail"         class="org.jbpm.graph.action.MailAction" />
 </action-types>
\ No newline at end of file

Modified: jbpm4/branches/jimma/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/Jpdl3ConverterReaderTest.java
===================================================================
--- jbpm4/branches/jimma/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/Jpdl3ConverterReaderTest.java	2009-06-17 21:20:43 UTC (rev 5054)
+++ jbpm4/branches/jimma/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/Jpdl3ConverterReaderTest.java	2009-06-18 09:52:17 UTC (rev 5055)
@@ -26,13 +26,14 @@
 
 import org.dom4j.Document;
 import org.jbpm.api.Problem;
+import org.jbpm.api.env.EnvironmentFactory;
 import org.jbpm.jpdl.internal.xml.JpdlParser;
+import org.jbpm.pvm.internal.cfg.JbpmConfiguration;
 import org.junit.Assert;
 import org.junit.Test;
 import org.xml.sax.InputSource;
 
-public class Jpdl3ConverterReaderTest {
-	
+public class Jpdl3ConverterReaderTest {	
 	@Test
 	public void testSimpleProcesss() throws Exception {
 		testConvert("simple.xml");
@@ -43,7 +44,19 @@
 		testConvert("businesstrip.xml");
 	}
 	
-	public void testConvert(String resourcefile) throws Exception {
+	@Test
+	public void testAssignment() throws Exception {
+		testConvert("assignment.xml");
+	}
+	
+	@Test
+	public void testEvent() throws Exception {
+		setUpScriptManager();
+		testConvert("process-event.xml");
+	}
+	
+	
+	private void testConvert(String resourcefile) throws Exception {
 		InputStream inputStream = getClass().getClassLoader().getResourceAsStream(resourcefile);
 		//Convert to process file to jpdl4
 		InputSource ins = new InputSource(inputStream);
@@ -54,4 +67,19 @@
 		List<Problem> problems = new JpdlParser().createParse().setString(doc.asXML()).execute().getProblems();
 		Assert.assertEquals(problems.toString(), 0, problems.size());
 	}
+	
+
+	private void setUpScriptManager() throws Exception {
+	    EnvironmentFactory environmentFactory = JbpmConfiguration.parseXmlString("<jbpm-configuration>" 
+	    		+ "  <process-engine-context>"
+	    		+ "    <script-manager default-expression-language='juel'" 
+	            +  "                    default-script-language='juel'" 
+	            +  "                    read-contexts='execution, environment, process-engine' " 
+	            +  "                    write-context='execution'>" 
+	            +  "      <script-language name='juel' factory='com.sun.script.juel.JuelScriptEngineFactory' />"
+	            +  "    </script-manager>" 
+	            +  "  </process-engine-context> </jbpm-configuration>");
+		
+	    environmentFactory.openEnvironment();
+	}
 }

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-06-17 21:20:43 UTC (rev 5054)
+++ jbpm4/branches/jimma/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/JpdlConverterTest.java	2009-06-18 09:52:17 UTC (rev 5055)
@@ -24,7 +24,9 @@
 import java.net.URL;
 import java.util.List;
 
+import org.jbpm.pvm.internal.cfg.JbpmConfiguration;
 import org.jbpm.api.Problem;
+import org.jbpm.api.env.EnvironmentFactory;
 import org.jbpm.jpdl.internal.xml.JpdlParser;
 import org.junit.Assert;
 import org.junit.Ignore;
@@ -47,8 +49,19 @@
 	public void testDescision() throws Exception {
 		testConvert("testDecision.xml");
 	}
-	@Ignore
+	@Test
 	public void testEvent() throws Exception {
+	    EnvironmentFactory environmentFactory = JbpmConfiguration.parseXmlString("<jbpm-configuration>" 
+	    		+ "  <process-engine-context>"
+	    		+ "    <script-manager default-expression-language='juel'" 
+	            +  "                    default-script-language='juel'" 
+	            +  "                    read-contexts='execution, environment, process-engine' " 
+	            +  "                    write-context='execution'>" 
+	            +  "      <script-language name='juel' factory='com.sun.script.juel.JuelScriptEngineFactory' />"
+	            +  "    </script-manager>" 
+	            +  "  </process-engine-context> </jbpm-configuration>");
+		
+	    environmentFactory.openEnvironment();
 		testConvert("process-event.xml");
 	}
 	




More information about the jbpm-commits mailing list