[jboss-svn-commits] JBL Code SVN: r21662 - in labs/jbossrules/trunk: drools-core/src/main/java/org/drools/process/core/datatype/impl/type and 6 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Aug 21 11:38:11 EDT 2008


Author: KrisVerlaenen
Date: 2008-08-21 11:38:11 -0400 (Thu, 21 Aug 2008)
New Revision: 21662

Added:
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/view/datatype/editor/impl/ObjectDataTypeEditor.java
Modified:
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ProcessMarchallingTest.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/core/datatype/impl/type/ObjectDataType.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/workflow/core/node/CompositeNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/workflow/core/node/ForEachNode.java
   labs/jbossrules/trunk/drools-core/src/main/resources/META-INF/WorkDefinitions.conf
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/ProcessInstancesViewContentProvider.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/datatype/DefaultDataTypeRegistry.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/variable/VariableDialog.java
Log:
JBRULES-1730: Add support for other data types when writing processes to XML
 - added Object support in IDE

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ProcessMarchallingTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ProcessMarchallingTest.java	2008-08-21 15:21:13 UTC (rev 21661)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ProcessMarchallingTest.java	2008-08-21 15:38:11 UTC (rev 21662)
@@ -25,7 +25,8 @@
 
 public class ProcessMarchallingTest extends TestCase {
 
-    public void test1() throws Exception {
+    @SuppressWarnings("unchecked")
+	public void test1() throws Exception {
         String rule = "package org.test;\n";
         rule += "import org.drools.Person\n";
         rule += "global java.util.List list\n";
@@ -66,7 +67,7 @@
 
         StatefulSession session = ruleBase.newStatefulSession();
 
-        List list = new ArrayList();
+        List<Object> list = new ArrayList<Object>();
         session.setGlobal( "list", list );
 
         Person p = new Person( "bobba fet", 32);
@@ -80,8 +81,8 @@
         
         session.fireAllRules();
 
-        assertEquals( 1, ((List) session.getGlobal("list")).size());
-        assertEquals( p, ((List) session.getGlobal("list")).get(0));
+        assertEquals( 1, ((List<Object>) session.getGlobal("list")).size());
+        assertEquals( p, ((List<Object>) session.getGlobal("list")).get(0));
         assertEquals(0, session.getProcessInstances().size());
     }
     
@@ -104,10 +105,22 @@
     		"    <start id=\"1\" name=\"Start\" />\n" +
     		"    <workItem id=\"2\" name=\"Email\" >\n" +
     		"      <work name=\"Email\" >\n" +
-    		"        <parameter name=\"Subject\" type=\"org.drools.process.core.datatype.impl.type.StringDataType\" >Mail</parameter>\n" +
-    		"        <parameter name=\"Text\" type=\"org.drools.process.core.datatype.impl.type.StringDataType\" >This is an email</parameter>\n" +
-    		"        <parameter name=\"To\" type=\"org.drools.process.core.datatype.impl.type.StringDataType\" >you at mail.com</parameter>\n" +
-    		"        <parameter name=\"From\" type=\"org.drools.process.core.datatype.impl.type.StringDataType\" >me at mail.com</parameter>\n" +
+    		"        <parameter name=\"Subject\" >\n" +
+    		"          <type name=\"org.drools.process.core.datatype.impl.type.StringDataType\" />\n" +
+    		"          <value>Mail</value>\n" +
+    		"        </parameter>\n" +
+    		"        <parameter name=\"Text\" >\n" +
+    		"          <type name=\"org.drools.process.core.datatype.impl.type.StringDataType\" />\n" +
+    		"          <value>This is an email</value>\n" +
+    		"        </parameter>\n" +
+    		"        <parameter name=\"To\" >\n" +
+    		"          <type name=\"org.drools.process.core.datatype.impl.type.StringDataType\" />\n" +
+    		"          <value>you at mail.com</value>\n" +
+    		"        </parameter>\n" +
+    		"        <parameter name=\"From\" >\n" +
+    		"          <type name=\"org.drools.process.core.datatype.impl.type.StringDataType\" />\n" +
+    		"          <value>me at mail.com</value>\n" +
+    		"        </parameter>\n" +
     		"      </work>\n" +
     		"    </workItem>\n" +
     		"    <end id=\"3\" name=\"End\" />\n" +
@@ -175,7 +188,10 @@
             "    <milestone id=\"11\" name=\"Event Wait\" >Person( )</milestone>\n" +
             "    <workItem id=\"12\" name=\"Log\" >\n" +
             "      <work name=\"Log\" >\n" +
-            "        <parameter name=\"Message\" type=\"org.drools.process.core.datatype.impl.type.StringDataType\" >This is a log message</parameter>\n" +
+            "        <parameter name=\"Message\" >\n" +
+            "          <type name=\"org.drools.process.core.datatype.impl.type.StringDataType\" />\n" +
+            "          <value>This is a log message</value>\n" +
+            "        </parameter>\n" +
             "      </work>\n" +
             "    </workItem>\n" +
             "  </nodes>\n" +

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/core/datatype/impl/type/ObjectDataType.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/core/datatype/impl/type/ObjectDataType.java	2008-08-21 15:21:13 UTC (rev 21661)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/core/datatype/impl/type/ObjectDataType.java	2008-08-21 15:38:11 UTC (rev 21662)
@@ -59,8 +59,11 @@
     }
 
     public boolean verifyDataType(final Object value) {
+    	if (value == null) {
+        	return true;
+        }
         try {
-            Class<?> clazz = ObjectDataType.class.forName(className);
+            Class<?> clazz = Class.forName(className);
             if (clazz.isInstance(value)) {
                 return true;
             }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/workflow/core/node/CompositeNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/workflow/core/node/CompositeNode.java	2008-08-21 15:21:13 UTC (rev 21661)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/workflow/core/node/CompositeNode.java	2008-08-21 15:38:11 UTC (rev 21662)
@@ -73,6 +73,10 @@
         node.setNodeContainer(null);
     }
     
+    protected void internalRemoveNode(Node node) {
+    	removeNode(node);
+    }
+    
 	public boolean acceptsEvent(String type, Object event) {
 		for (Node node: getNodes()) {
 			if (node instanceof EventNodeInterface) {
@@ -237,7 +241,7 @@
             if (((CompositeNodeStart) inConnection.getFrom()).getInNodeId() == connection.getFrom().getId()) {
                 Node compositeNodeStart = inConnection.getFrom();
                 ((ConnectionImpl) inConnection).terminate();
-                removeNode(compositeNodeStart);
+                internalRemoveNode(compositeNodeStart);
                 return;
             }
         }
@@ -264,7 +268,7 @@
             if (((CompositeNodeEnd) outConnection.getTo()).getOutNodeId() == connection.getTo().getId()) {
                 Node compositeNodeEnd = outConnection.getTo();
                 ((ConnectionImpl) outConnection).terminate();
-                removeNode(compositeNodeEnd);
+                internalRemoveNode(compositeNodeEnd);
                 return;
             }
         }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/workflow/core/node/ForEachNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/workflow/core/node/ForEachNode.java	2008-08-21 15:21:13 UTC (rev 21661)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/workflow/core/node/ForEachNode.java	2008-08-21 15:38:11 UTC (rev 21662)
@@ -106,6 +106,14 @@
     	return getCompositeNode().getNodes();
     }
     
+    public void removeNode(Node node) {
+    	getCompositeNode().removeNode(node);
+    }
+    
+    protected void internalRemoveNode(Node node) {
+    	super.removeNode(node);
+    }
+    
     public void linkIncomingConnections(String inType, long inNodeId, String inNodeType) {
     	getCompositeNode().linkIncomingConnections(inType, inNodeId, inNodeType);
     }

Modified: labs/jbossrules/trunk/drools-core/src/main/resources/META-INF/WorkDefinitions.conf
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/resources/META-INF/WorkDefinitions.conf	2008-08-21 15:21:13 UTC (rev 21661)
+++ labs/jbossrules/trunk/drools-core/src/main/resources/META-INF/WorkDefinitions.conf	2008-08-21 15:38:11 UTC (rev 21662)
@@ -25,7 +25,7 @@
       "Message" : new StringDataType()
     ],
     "displayName" : "Log",
-    "icon" : "icons/open.gif"
+    "icon" : "icons/open.gif",
     "customEditor" : "org.drools.eclipse.flow.common.editor.editpart.work.SampleCustomEditor"
   ]
     

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/ProcessInstancesViewContentProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/ProcessInstancesViewContentProvider.java	2008-08-21 15:21:13 UTC (rev 21661)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/ProcessInstancesViewContentProvider.java	2008-08-21 15:38:11 UTC (rev 21662)
@@ -4,6 +4,8 @@
 import java.util.List;
 
 import org.drools.eclipse.DroolsEclipsePlugin;
+import org.drools.process.instance.ProcessInstance;
+import org.drools.reteoo.ReteooStatefulSession;
 import org.eclipse.debug.core.DebugException;
 import org.eclipse.debug.core.model.IValue;
 import org.eclipse.debug.core.model.IVariable;
@@ -79,4 +81,9 @@
         return null;
     }
     
+    @SuppressWarnings("unused")
+	private ProcessInstance[] getProcessInstances(ReteooStatefulSession session) {
+    	return (ProcessInstance[]) session.getProcessInstances().toArray();
+    }
+    
 }

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/datatype/DefaultDataTypeRegistry.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/datatype/DefaultDataTypeRegistry.java	2008-08-21 15:21:13 UTC (rev 21661)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/datatype/DefaultDataTypeRegistry.java	2008-08-21 15:38:11 UTC (rev 21662)
@@ -20,12 +20,15 @@
 import org.drools.eclipse.flow.common.view.datatype.editor.impl.EmptyEditor;
 import org.drools.eclipse.flow.common.view.datatype.editor.impl.FloatEditor;
 import org.drools.eclipse.flow.common.view.datatype.editor.impl.IntegerEditor;
+import org.drools.eclipse.flow.common.view.datatype.editor.impl.ObjectDataTypeEditor;
 import org.drools.eclipse.flow.common.view.datatype.editor.impl.StringEditor;
 import org.drools.process.core.datatype.DataTypeFactory;
 import org.drools.process.core.datatype.impl.InstanceDataTypeFactory;
+import org.drools.process.core.datatype.impl.NewInstanceDataTypeFactory;
 import org.drools.process.core.datatype.impl.type.BooleanDataType;
 import org.drools.process.core.datatype.impl.type.FloatDataType;
 import org.drools.process.core.datatype.impl.type.IntegerDataType;
+import org.drools.process.core.datatype.impl.type.ObjectDataType;
 import org.drools.process.core.datatype.impl.type.StringDataType;
 import org.drools.process.core.datatype.impl.type.UndefinedDataType;
 
@@ -60,6 +63,9 @@
 		registerVariableDataType(StringDataType.class,
 				new InstanceDataTypeFactory(StringDataType.class), "String",
 				StringEditor.class, EmptyEditor.class);
+		registerVariableDataType(ObjectDataType.class,
+				new NewInstanceDataTypeFactory(ObjectDataType.class), "Object",
+				EmptyEditor.class, ObjectDataTypeEditor.class);
 	}
 
 	public static void registerVariableDataType(Class type,

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/view/datatype/editor/impl/ObjectDataTypeEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/view/datatype/editor/impl/ObjectDataTypeEditor.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/view/datatype/editor/impl/ObjectDataTypeEditor.java	2008-08-21 15:38:11 UTC (rev 21662)
@@ -0,0 +1,101 @@
+package org.drools.eclipse.flow.common.view.datatype.editor.impl;
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.drools.eclipse.flow.common.view.datatype.editor.DataTypeEditor;
+import org.drools.eclipse.flow.common.view.datatype.editor.Editor;
+import org.drools.process.core.datatype.DataType;
+import org.drools.process.core.datatype.impl.type.ObjectDataType;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Default empty editor.
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ObjectDataTypeEditor extends Composite implements Editor, DataTypeEditor {
+
+    private ObjectDataType dataType;
+    private Object value;
+    private Label label;
+    private Text text;
+    private List<DataTypeEditor.DataTypeListener> listeners = new ArrayList<DataTypeEditor.DataTypeListener>();
+    
+    public ObjectDataTypeEditor(Composite parent) {
+        super(parent, SWT.NONE);
+        setLayout(new FillLayout());
+        label = new Label(this, SWT.NONE);
+        label.setText("ClassName");
+        text = new Text(this, SWT.NONE);
+        text.addModifyListener(new ModifyListener() {
+			public void modifyText(ModifyEvent e) {
+				notifyListeners();
+			}
+        });
+    }
+    
+    public DataType getDataType() {
+    	dataType.setClassName(text.getText());
+        return dataType;
+    }
+    
+    public void setDataType(DataType dataType) {
+        this.dataType = (ObjectDataType) dataType;
+        String className = this.dataType.getClassName();
+        text.setText(className == null ? "" : className);
+    }
+
+    public Object getValue() {
+        return value;
+    }
+
+    public void setValue(Object value) {
+        this.value = value;
+    }
+
+    public void reset() {
+        text.setText("");
+    }
+
+    public void addListener(DataTypeEditor.DataTypeListener listener) {
+        listeners.add(listener);
+    }
+    
+    public void removeListener(DataTypeEditor.DataTypeListener listener) {
+        listeners.remove(listener);
+    }
+    
+    private void notifyListeners() {
+    	for (DataTypeEditor.DataTypeListener listener: listeners) {
+    		listener.dataTypeChanged(getDataType());
+    	}
+    }
+    
+    public void setBackground(Color color) {
+    	super.setBackground(color);
+    	label.setBackground(color);
+    }
+}

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/variable/VariableDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/variable/VariableDialog.java	2008-08-21 15:21:13 UTC (rev 21661)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/variable/VariableDialog.java	2008-08-21 15:38:11 UTC (rev 21662)
@@ -127,7 +127,13 @@
     
     protected Object updateValue(Object value) {
         Variable variable = (Variable) getValue();
-        variable.setName(nameText.getText());
+        String name = nameText.getText();
+        if ("".equals(name)) {
+        	String message = "Name should not be empty";
+        	showError(message);
+        	throw new IllegalArgumentException(message);
+        }
+        variable.setName(name);
         try {
             variable.setType(dataTypeEditorComposite.getDataType());
         } catch (IllegalArgumentException e) {




More information about the jboss-svn-commits mailing list