[jboss-svn-commits] JBL Code SVN: r14339 - 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
Fri Aug 17 20:10:11 EDT 2007
Author: KrisVerlaenen
Date: 2007-08-17 20:10:11 -0400 (Fri, 17 Aug 2007)
New Revision: 14339
Added:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/ActionNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/ActionNodeImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/DroolsConsequenceAction.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/ActionNodeInstanceImpl.java
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/MilestoneNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowProcessInstanceImpl.java
Log:
JBRULES-1098: Add action support in ruleflow
- initial implementation of an action node, supporting MVEL consequence code
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/ActionNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/ActionNode.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/ActionNode.java 2007-08-18 00:10:11 UTC (rev 14339)
@@ -0,0 +1,57 @@
+package org.drools.ruleflow.core;
+
+/*
+ * 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.
+ */
+
+/**
+ * Represents an actino in a RuleFlow.
+ * An action represents the task that should be performed
+ * when executing this node.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public interface ActionNode
+ extends
+ Node {
+
+ /**
+ * Returns the incoming connection of the ActionNode.
+ *
+ * @return the incoming connection of the ActionNode.
+ */
+ Connection getFrom();
+
+ /**
+ * Returns the outgoing connection of the ActionNode.
+ *
+ * @return the outgoing connection of the ActionNode.
+ */
+ Connection getTo();
+
+ /**
+ * Returns the action of the ActionNode.
+ *
+ * @return the action of the ActionNode.
+ */
+ Object getAction();
+
+ /**
+ * Sets the action of the ActionNode.
+ *
+ * @param constraint The action of the ActionNode
+ */
+ void setAction(Object action);
+}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/MilestoneNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/MilestoneNode.java 2007-08-18 00:10:05 UTC (rev 14338)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/MilestoneNode.java 2007-08-18 00:10:11 UTC (rev 14339)
@@ -49,7 +49,7 @@
String getConstraint();
/**
- * Sets the ruleflow-group of the MilestoneNode.
+ * Sets the constraint of the MilestoneNode.
*
* @param constraint The constraint of the MilestoneNode
*/
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/ActionNodeImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/ActionNodeImpl.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/ActionNodeImpl.java 2007-08-18 00:10:11 UTC (rev 14339)
@@ -0,0 +1,79 @@
+package org.drools.ruleflow.core.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.Iterator;
+import java.util.List;
+
+import org.drools.ruleflow.core.ActionNode;
+import org.drools.ruleflow.core.Connection;
+
+/**
+ * Default implementation of an action node.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ActionNodeImpl extends NodeImpl
+ implements
+ ActionNode {
+
+ private static final long serialVersionUID = -2899376492708393815L;
+
+ private Object action;
+
+ public Object getAction() {
+ return action;
+ }
+
+ public void setAction(Object action) {
+ this.action = action;
+ }
+
+ public Connection getFrom() {
+ final List list = getIncomingConnections();
+ if ( list.size() > 0 ) {
+ return (Connection) list.get( 0 );
+ }
+ return null;
+ }
+
+ public Connection getTo() {
+ final List list = getOutgoingConnections();
+ if ( list.size() > 0 ) {
+ return (Connection) list.get( 0 );
+ }
+ return null;
+ }
+
+ protected void validateAddIncomingConnection(final Connection connection) {
+ super.validateAddIncomingConnection( connection );
+ if ( getIncomingConnections().size() > 0 ) {
+ throw new IllegalArgumentException( "An ActionNode cannot have more than one incoming node" );
+ }
+ }
+
+ protected void validateAddOutgoingConnection(final Connection connection) {
+ super.validateAddOutgoingConnection( connection );
+ for ( final Iterator it = getOutgoingConnections().iterator(); it.hasNext(); ) {
+ final Connection conn = (Connection) it.next();
+ if ( conn.getType() == connection.getType() ) {
+ throw new IllegalArgumentException( "An ActionNode can have at most one outgoing node" );
+ }
+ }
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/DroolsConsequenceAction.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/DroolsConsequenceAction.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/DroolsConsequenceAction.java 2007-08-18 00:10:11 UTC (rev 14339)
@@ -0,0 +1,22 @@
+package org.drools.ruleflow.core.impl;
+
+public class DroolsConsequenceAction {
+
+ private String consequence;
+
+ public DroolsConsequenceAction(String consequence) {
+ this.consequence = consequence;
+ }
+
+ public void setConsequence(String consequence) {
+ this.consequence = consequence;
+ }
+
+ public String getConsequence() {
+ return consequence;
+ }
+
+ public String toString() {
+ return consequence;
+ }
+}
Added: 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 (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/ActionNodeInstanceImpl.java 2007-08-18 00:10:11 UTC (rev 14339)
@@ -0,0 +1,61 @@
+package org.drools.ruleflow.instance.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.io.Serializable;
+import java.util.Collections;
+
+import org.drools.base.mvel.DroolsMVELFactory;
+import org.drools.ruleflow.core.ActionNode;
+import org.drools.ruleflow.core.impl.DroolsConsequenceAction;
+import org.drools.ruleflow.instance.RuleFlowNodeInstance;
+import org.mvel.ExpressionCompiler;
+import org.mvel.MVEL;
+import org.mvel.ParserContext;
+
+/**
+ * Runtime counterpart of an action node.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ActionNodeInstanceImpl extends RuleFlowNodeInstanceImpl {
+
+ protected ActionNode getActionNode() {
+ return (ActionNode) getNode();
+ }
+
+ public void trigger(final RuleFlowNodeInstance from) {
+ Object action = getActionNode().getAction();
+ if (action instanceof DroolsConsequenceAction) {
+ String actionString = ((DroolsConsequenceAction) action).getConsequence();
+ 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);
+ MVEL.executeExpression(expression, null, factory);
+ } else {
+ throw new RuntimeException("Unknown action: " + action);
+ }
+ triggerCompleted();
+ }
+
+ public void triggerCompleted() {
+ getProcessInstance().getNodeInstance( getActionNode().getTo().getTo() ).trigger( this );
+ getProcessInstance().removeNodeInstance(this);
+ }
+
+}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowProcessInstanceImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowProcessInstanceImpl.java 2007-08-18 00:10:05 UTC (rev 14338)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowProcessInstanceImpl.java 2007-08-18 00:10:11 UTC (rev 14339)
@@ -39,6 +39,7 @@
import org.drools.event.RuleFlowGroupDeactivatedEvent;
import org.drools.event.RuleFlowStartedEvent;
import org.drools.ruleflow.common.instance.impl.ProcessInstanceImpl;
+import org.drools.ruleflow.core.ActionNode;
import org.drools.ruleflow.core.EndNode;
import org.drools.ruleflow.core.Join;
import org.drools.ruleflow.core.MilestoneNode;
@@ -154,6 +155,11 @@
result.setNodeId( node.getId() );
addNodeInstance( result );
return result;
+ } else if ( node instanceof ActionNode ) {
+ final RuleFlowNodeInstance result = new ActionNodeInstanceImpl();
+ result.setNodeId( node.getId() );
+ addNodeInstance( result );
+ return result;
}
throw new IllegalArgumentException( "Illegal node type: " + node.getClass() );
}
More information about the jboss-svn-commits
mailing list