1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.bpm;
12
13 import org.mule.api.MuleEvent;
14 import org.mule.api.lifecycle.Initialisable;
15 import org.mule.api.lifecycle.InitialisationException;
16 import org.mule.component.AbstractComponent;
17 import org.mule.config.i18n.MessageFactory;
18
19 import java.util.Collection;
20
21
22
23
24 public class RulesComponent extends AbstractComponent
25 {
26
27 protected Rules rules;
28
29
30 protected RulesEngine rulesEngine;
31
32
33 private String resource;
34
35
36 private Collection initialFacts;
37
38
39 private String entryPoint;
40
41
42 private boolean stateless = false;
43
44
45 private boolean cepMode = false;
46
47 @Override
48 protected void doInitialise() throws InitialisationException
49 {
50 if (rulesEngine == null)
51 {
52 try
53 {
54 rulesEngine = muleContext.getRegistry().lookupObject(RulesEngine.class);
55 }
56 catch (Exception e)
57 {
58 throw new InitialisationException(e, this);
59 }
60 }
61 if (rulesEngine == null)
62 {
63 throw new InitialisationException(MessageFactory.createStaticMessage("The rulesEngine property must be set for this component."), this);
64 }
65 if (rulesEngine instanceof Initialisable)
66 {
67 ((Initialisable) rulesEngine).initialise();
68 }
69
70 rules = new Rules(rulesEngine, resource, null, entryPoint, initialFacts, stateless, cepMode, flowConstruct, muleContext);
71
72 rulesEngine.setMessageService(rules);
73 rules.initialise();
74
75 super.doInitialise();
76 }
77
78
79
80
81 @Override
82 protected Object doInvoke(MuleEvent event) throws Exception
83 {
84 return rules.handleEvent(event);
85 }
86
87 public void setResource(String resource)
88 {
89 this.resource = resource;
90 }
91
92 public String getResource()
93 {
94 return resource;
95 }
96
97 public Collection getInitialFacts()
98 {
99 return initialFacts;
100 }
101
102 public void setInitialFacts(Collection initialFacts)
103 {
104 this.initialFacts = initialFacts;
105 }
106
107 public String getEntryPoint()
108 {
109 return entryPoint;
110 }
111
112 public void setEntryPoint(String entryPoint)
113 {
114 this.entryPoint = entryPoint;
115 }
116
117 public void setStateless(boolean stateless)
118 {
119 this.stateless = stateless;
120 }
121
122 public boolean isStateless()
123 {
124 return stateless;
125 }
126
127 public boolean isCepMode()
128 {
129 return cepMode;
130 }
131
132 public void setCepMode(boolean cepMode)
133 {
134 this.cepMode = cepMode;
135 }
136 }
137
138