[jboss-svn-commits] JBL Code SVN: r15036 - in labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow: core/impl and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Sep 11 20:13:23 EDT 2007
Author: KrisVerlaenen
Date: 2007-09-11 20:13:23 -0400 (Tue, 11 Sep 2007)
New Revision: 15036
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/RuleFlowProcess.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/RuleFlowProcessValidationError.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/RuleFlowProcessImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/ActionNodeInstanceImpl.java
Log:
JBRULES-1183: Add global support in ruleflow
- added support for globals in ruleflow
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/RuleFlowProcess.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/RuleFlowProcess.java 2007-09-11 23:49:55 UTC (rev 15035)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/RuleFlowProcess.java 2007-09-12 00:13:23 UTC (rev 15036)
@@ -17,6 +17,7 @@
*/
import java.util.List;
+import java.util.Map;
import org.drools.ruleflow.common.core.Process;
@@ -106,4 +107,26 @@
*/
void setImports(List imports);
+ /**
+ * Returns the globals of this RuleFlow process.
+ * They are defined as a Map with the name as key and the type as value.
+ *
+ * @return the imports of this RuleFlow process
+ */
+ Map getGlobals();
+
+ /**
+ * Sets the imports of this RuleFlow process
+ *
+ * @param imports the globals as a Map with the name as key and the type as value
+ */
+ void setGlobals(Map globals);
+
+ /**
+ * Returns the names of the globals used in this RuleFlow process
+ *
+ * @return the names of the globals of this RuleFlow process
+ */
+ String[] getGlobalNames();
+
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/RuleFlowProcessValidationError.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/RuleFlowProcessValidationError.java 2007-09-11 23:49:55 UTC (rev 15035)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/RuleFlowProcessValidationError.java 2007-09-12 00:13:23 UTC (rev 15036)
@@ -50,6 +50,7 @@
String ACTION_NODE_WITHOUT_INCOMING_CONNECTIONS = "Action node has no incoming connection.";
String ACTION_NODE_WITHOUT_OUTGOING_CONNECTIONS = "Action node has no outgoing connection.";
String ACTION_NODE_WITHOUT_ACTION = "An Action node has no action.";
+ String ACTION_NODE_WITH_INVALID_ACTION = "An Action node has an invalid action.";
String getType();
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/RuleFlowProcessImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/RuleFlowProcessImpl.java 2007-09-11 23:49:55 UTC (rev 15035)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/RuleFlowProcessImpl.java 2007-09-12 00:13:23 UTC (rev 15036)
@@ -45,6 +45,7 @@
private List variables;
private long lastNodeId;
private List imports;
+ private Map globals;
public RuleFlowProcessImpl() {
super();
@@ -108,8 +109,10 @@
public String[] getVariableNames() {
final String[] result = new String[this.variables.size()];
- for ( int i = 0; i < this.variables.size(); i++ ) {
- result[i] = ((Variable) this.variables.get( i )).getName();
+ if (this.variables != null) {
+ for ( int i = 0; i < this.variables.size(); i++ ) {
+ result[i] = ((Variable) this.variables.get( i )).getName();
+ }
}
return result;
}
@@ -139,4 +142,23 @@
public void setImports(List imports) {
this.imports = imports;
}
+
+ public Map getGlobals() {
+ return globals;
+ }
+
+ public void setGlobals(Map globals) {
+ this.globals = globals;
+ }
+
+ public String[] getGlobalNames() {
+ final List result = new ArrayList();
+ if (this.globals != null) {
+ for ( Iterator iterator = this.globals.keySet().iterator(); iterator.hasNext(); ) {
+ result.add((String) iterator.next());
+ }
+ }
+ return (String[]) result.toArray(new String[result.size()]);
+ }
+
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/ActionNodeInstanceImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/ActionNodeInstanceImpl.java 2007-09-11 23:49:55 UTC (rev 15035)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/ActionNodeInstanceImpl.java 2007-09-12 00:13:23 UTC (rev 15036)
@@ -18,6 +18,9 @@
import java.io.Serializable;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
import org.drools.base.mvel.DroolsMVELFactory;
import org.drools.ruleflow.core.ActionNode;
@@ -45,7 +48,20 @@
ExpressionCompiler compiler = new ExpressionCompiler(actionString);
ParserContext parserContext = new ParserContext();
Serializable expression = compiler.compile(parserContext);
- DroolsMVELFactory factory = new DroolsMVELFactory(Collections.EMPTY_MAP, null, Collections.EMPTY_MAP);
+ Map globalDefs = getProcessInstance().getRuleFlowProcess().getGlobals();
+ Map globals = new HashMap();
+ if (globalDefs != null) {
+ for (Iterator iterator = globalDefs.entrySet().iterator(); iterator.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ try {
+ globals.put(entry.getKey(), Class.forName((String) entry.getValue()));
+ } catch (ClassNotFoundException exc) {
+ throw new IllegalArgumentException("Could not find type " + entry.getValue() + " of global " + entry.getKey());
+ }
+ }
+ }
+ DroolsMVELFactory factory = new DroolsMVELFactory(Collections.EMPTY_MAP, null, globals);
+ factory.setContext(null, null, null, getProcessInstance().getWorkingMemory(), null);
MVEL.executeExpression(expression, null, factory);
} else {
throw new RuntimeException("Unknown action: " + action);
More information about the jboss-svn-commits
mailing list