01: package org.drools.ruleflow.instance.impl;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import java.io.Serializable;
20: import java.util.Collections;
21:
22: import org.drools.base.mvel.DroolsMVELFactory;
23: import org.drools.ruleflow.core.ActionNode;
24: import org.drools.ruleflow.core.impl.DroolsConsequenceAction;
25: import org.drools.ruleflow.instance.RuleFlowNodeInstance;
26: import org.mvel.ExpressionCompiler;
27: import org.mvel.MVEL;
28: import org.mvel.ParserContext;
29:
30: /**
31: * Runtime counterpart of an action node.
32: *
33: * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
34: */
35: public class ActionNodeInstanceImpl extends RuleFlowNodeInstanceImpl {
36:
37: protected ActionNode getActionNode() {
38: return (ActionNode) getNode();
39: }
40:
41: public void trigger(final RuleFlowNodeInstance from) {
42: Object action = getActionNode().getAction();
43: if (action instanceof DroolsConsequenceAction) {
44: String actionString = ((DroolsConsequenceAction) action)
45: .getConsequence();
46: ExpressionCompiler compiler = new ExpressionCompiler(
47: actionString);
48: ParserContext parserContext = new ParserContext();
49: Serializable expression = compiler.compile(parserContext);
50: DroolsMVELFactory factory = new DroolsMVELFactory(
51: Collections.EMPTY_MAP, null, Collections.EMPTY_MAP);
52: MVEL.executeExpression(expression, null, factory);
53: } else {
54: throw new RuntimeException("Unknown action: " + action);
55: }
56: triggerCompleted();
57: }
58:
59: public void triggerCompleted() {
60: getProcessInstance().getNodeInstance(
61: getActionNode().getTo().getTo()).trigger(this);
62: getProcessInstance().removeNodeInstance(this);
63: }
64:
65: }
|