|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
RuleBaseImpl.java | - | 100% | 100% | 100% |
|
1 | package org.drools.reteoo; | |
2 | ||
3 | /* | |
4 | * $Id: RuleBaseImpl.java,v 1.28 2005/02/02 00:23:22 mproctor Exp $ | |
5 | * | |
6 | * Copyright 2001-2003 (C) The Werken Company. All Rights Reserved. | |
7 | * | |
8 | * Redistribution and use of this software and associated documentation | |
9 | * ("Software"), with or without modification, are permitted provided that the | |
10 | * following conditions are met: | |
11 | * | |
12 | * 1. Redistributions of source code must retain copyright statements and | |
13 | * notices. Redistributions must also contain a copy of this document. | |
14 | * | |
15 | * 2. Redistributions in binary form must reproduce the above copyright notice, | |
16 | * this list of conditions and the following disclaimer in the documentation | |
17 | * and/or other materials provided with the distribution. | |
18 | * | |
19 | * 3. The name "drools" must not be used to endorse or promote products derived | |
20 | * from this Software without prior written permission of The Werken Company. | |
21 | * For written permission, please contact bob@werken.com. | |
22 | * | |
23 | * 4. Products derived from this Software may not be called "drools" nor may | |
24 | * "drools" appear in their names without prior written permission of The Werken | |
25 | * Company. "drools" is a trademark of The Werken Company. | |
26 | * | |
27 | * 5. Due credit should be given to The Werken Company. (http://werken.com/) | |
28 | * | |
29 | * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS'' | |
30 | * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
31 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
32 | * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE | |
33 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
34 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
35 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
36 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
37 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
38 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
39 | * POSSIBILITY OF SUCH DAMAGE. | |
40 | * | |
41 | */ | |
42 | ||
43 | import java.util.HashMap; | |
44 | import java.util.List; | |
45 | import java.util.Map; | |
46 | ||
47 | import org.drools.FactException; | |
48 | import org.drools.FactHandle; | |
49 | import org.drools.RuleBase; | |
50 | import org.drools.WorkingMemory; | |
51 | import org.drools.conflict.DefaultConflictResolver; | |
52 | import org.drools.spi.ConflictResolver; | |
53 | import org.drools.spi.RuleBaseContext; | |
54 | ||
55 | /** | |
56 | * Implementation of <code>RuleBase</code>. | |
57 | * | |
58 | * @author <a href="mailto:bob@werken.com">bob mcwhirter </a> | |
59 | * | |
60 | * @version $Id: RuleBaseImpl.java,v 1.28 2005/02/02 00:23:22 mproctor Exp $ | |
61 | */ | |
62 | class RuleBaseImpl | |
63 | implements | |
64 | RuleBase | |
65 | { | |
66 | // ------------------------------------------------------------ | |
67 | // Instance members | |
68 | // ------------------------------------------------------------ | |
69 | ||
70 | /** The root Rete-OO for this <code>RuleBase</code>. */ | |
71 | private final Rete rete; | |
72 | ||
73 | /** Conflict resolution strategy. */ | |
74 | private final ConflictResolver conflictResolver; | |
75 | ||
76 | /** The fact handle factory. */ | |
77 | private final FactHandleFactory factHandleFactory; | |
78 | ||
79 | private List ruleSets; | |
80 | ||
81 | private Map applicationData; | |
82 | ||
83 | private RuleBaseContext ruleBaseContext; | |
84 | ||
85 | // ------------------------------------------------------------ | |
86 | // Constructors | |
87 | // ------------------------------------------------------------ | |
88 | ||
89 | /** | |
90 | * Construct. | |
91 | * | |
92 | * @param rete | |
93 | * The rete network. | |
94 | */ | |
95 | 19 | RuleBaseImpl(Rete rete) |
96 | { | |
97 | 19 | this( rete, |
98 | DefaultConflictResolver.getInstance( ), | |
99 | new DefaultFactHandleFactory( ), | |
100 | null, | |
101 | new HashMap( ) , | |
102 | new RuleBaseContext( ) ); | |
103 | } | |
104 | ||
105 | /** | |
106 | * Construct. | |
107 | * | |
108 | * @param rete | |
109 | * The rete network. | |
110 | * @param conflictResolver | |
111 | * The conflict resolver. | |
112 | * @param factHandleFactory | |
113 | * The fact handle factory. | |
114 | * @param ruleSets | |
115 | * @param applicationData | |
116 | */ | |
117 | 86 | RuleBaseImpl(Rete rete, |
118 | ConflictResolver conflictResolver, | |
119 | FactHandleFactory factHandleFactory, | |
120 | List ruleSets, | |
121 | Map applicationData, | |
122 | RuleBaseContext ruleBaseContext) | |
123 | { | |
124 | 86 | this.rete = rete; |
125 | 86 | this.factHandleFactory = factHandleFactory; |
126 | 86 | this.conflictResolver = conflictResolver; |
127 | 86 | this.ruleSets = ruleSets; |
128 | 86 | this.applicationData = applicationData; |
129 | 86 | this.ruleBaseContext = ruleBaseContext; |
130 | } | |
131 | ||
132 | // ------------------------------------------------------------ | |
133 | // Instance methods | |
134 | // ------------------------------------------------------------ | |
135 | ||
136 | /** | |
137 | * @see RuleBase | |
138 | */ | |
139 | 66 | public WorkingMemory newWorkingMemory() |
140 | { | |
141 | 66 | return new WorkingMemoryImpl( this ); |
142 | } | |
143 | ||
144 | /** | |
145 | * @see RuleBase | |
146 | */ | |
147 | 872 | public FactHandleFactory getFactHandleFactory() |
148 | { | |
149 | 872 | return this.factHandleFactory; |
150 | } | |
151 | ||
152 | /** | |
153 | * @see RuleBase | |
154 | */ | |
155 | 71 | public ConflictResolver getConflictResolver() |
156 | { | |
157 | 71 | return this.conflictResolver; |
158 | } | |
159 | ||
160 | /** | |
161 | * Retrieve the Rete-OO network for this <code>RuleBase</code>. | |
162 | * | |
163 | * @return The RETE-OO network. | |
164 | */ | |
165 | 1558 | Rete getRete() |
166 | { | |
167 | 1558 | return this.rete; |
168 | } | |
169 | ||
170 | /** | |
171 | * Assert a fact object. | |
172 | * | |
173 | * @param handle | |
174 | * The handle. | |
175 | * @param object | |
176 | * The fact. | |
177 | * @param workingMemory | |
178 | * The working-memory. | |
179 | * | |
180 | * @throws FactException | |
181 | * If an error occurs while performing the assertion. | |
182 | */ | |
183 | 1188 | void assertObject(FactHandle handle, |
184 | Object object, | |
185 | WorkingMemoryImpl workingMemory) throws FactException | |
186 | { | |
187 | 1188 | getRete( ).assertObject( handle, |
188 | object, | |
189 | workingMemory ); | |
190 | } | |
191 | ||
192 | /** | |
193 | * Retract a fact object. | |
194 | * | |
195 | * @param handle | |
196 | * The handle. | |
197 | * @param workingMemory | |
198 | * The working-memory. | |
199 | * | |
200 | * @throws FactException | |
201 | * If an error occurs while performing the retraction. | |
202 | */ | |
203 | 370 | void retractObject(FactHandle handle, |
204 | WorkingMemoryImpl workingMemory) throws FactException | |
205 | { | |
206 | 370 | getRete( ).retractObject( handle, |
207 | workingMemory ); | |
208 | } | |
209 | ||
210 | ||
211 | 1 | public List getRuleSets() |
212 | { | |
213 | 1 | return this.ruleSets; |
214 | } | |
215 | ||
216 | 1 | public Map getApplicationData() |
217 | { | |
218 | 1 | return this.applicationData; |
219 | } | |
220 | ||
221 | 3 | public RuleBaseContext getRuleBaseContext() |
222 | { | |
223 | 3 | return this.ruleBaseContext; |
224 | } | |
225 | } |
|