|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
RuleBaseBuilder.java | - | 100% | 100% | 100% |
|
1 | package org.drools; | |
2 | ||
3 | /* | |
4 | * $Id: RuleBaseBuilder.java,v 1.20.2.1 2005/05/10 12:11:24 mproctor Exp $ | |
5 | * | |
6 | * Copyright 2001-2004 (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 registered trademark of The Werken Company. | |
26 | * | |
27 | * 5. Due credit should be given to The Werken Company. | |
28 | * (http://drools.werken.com/). | |
29 | * | |
30 | * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS'' | |
31 | * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
32 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE | |
34 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
35 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
36 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
37 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
38 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
39 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
40 | * POSSIBILITY OF SUCH DAMAGE. | |
41 | * | |
42 | */ | |
43 | ||
44 | import org.drools.reteoo.Builder; | |
45 | import org.drools.reteoo.FactHandleFactory; | |
46 | import org.drools.rule.RuleSet; | |
47 | import org.drools.spi.ConflictResolver; | |
48 | import org.drools.spi.RuleBaseContext; | |
49 | ||
50 | /** | |
51 | * Factory for constructing a <code>RuleBase</code>. | |
52 | * | |
53 | * <p> | |
54 | * The <code>RuleBaseBuilder</code> integrates the added <code>RuleSet</code> s into the <b>Rete </b> network. A | |
55 | * <code>RuleBaseBuilder</code> may be re-used after building a <code>RuleBase</code> but it may not be used to | |
56 | * build multiple <code>RuleBase</code> s simultaneously by multiple threads. | |
57 | * </p> | |
58 | * | |
59 | * @see #build | |
60 | * @see RuleSet | |
61 | * @see RuleBase | |
62 | * | |
63 | * @author <a href="mailto:bob@werken.com">bob mcwhirter </a> | |
64 | * @author <a href="mailto:mproctor@codehaus.org"> mark proctor </a> | |
65 | * | |
66 | * @version $Id: RuleBaseBuilder.java,v 1.20.2.1 2005/05/10 12:11:24 mproctor Exp $ | |
67 | */ | |
68 | public class RuleBaseBuilder | |
69 | { | |
70 | // ---------------------------------------------------------------------- | |
71 | // Instance members | |
72 | // ---------------------------------------------------------------------- | |
73 | ||
74 | /** Underlying Rete builder. */ | |
75 | private Builder builder; | |
76 | ||
77 | /** The ruleBaseContext */ | |
78 | private RuleBaseContext ruleBaseContext; | |
79 | ||
80 | // ---------------------------------------------------------------------- | |
81 | // Constructors | |
82 | // ---------------------------------------------------------------------- | |
83 | ||
84 | /** | |
85 | * Construct a <code>RuleBaseBuilder</code> with no parameters. | |
86 | */ | |
87 | 65 | public RuleBaseBuilder() |
88 | { | |
89 | 65 | this.ruleBaseContext = new RuleBaseContext( ); |
90 | 65 | this.builder = new Builder( ruleBaseContext ); |
91 | ||
92 | } | |
93 | ||
94 | /** | |
95 | * Construct a <code>RuleBaseBuilder</code> specify a <code>RuleBaseContext</code> | |
96 | * | |
97 | * @see org.drools.spi.RuleBaseContext | |
98 | */ | |
99 | 1 | public RuleBaseBuilder(RuleBaseContext ruleBaseContext) |
100 | { | |
101 | 1 | this.ruleBaseContext = ruleBaseContext; |
102 | 1 | this.builder = new Builder( ruleBaseContext ); |
103 | } | |
104 | ||
105 | // ---------------------------------------------------------------------- | |
106 | // Instance methods | |
107 | // ---------------------------------------------------------------------- | |
108 | ||
109 | /** | |
110 | * Add a <code>RuleSet</code>. | |
111 | * | |
112 | * @see org.drools.rule.RuleSet | |
113 | * | |
114 | * @param ruleSet | |
115 | * The rule-set to add. | |
116 | * | |
117 | * @throws RuleIntegrationException | |
118 | * If an error occurs while attempting to integrate the rules into the Rete network.. | |
119 | */ | |
120 | 65 | public void addRuleSet(RuleSet ruleSet) throws RuleSetIntegrationException, |
121 | RuleIntegrationException | |
122 | { | |
123 | 65 | this.builder.addRuleSet( ruleSet ); |
124 | } | |
125 | ||
126 | /** | |
127 | * Build the <code>RuleBase</code>. | |
128 | * | |
129 | * <p> | |
130 | * Builds the <code>RuleBase</code> based upon all previously added <code>RuleSet</code>s. | |
131 | * </p> | |
132 | * | |
133 | * @see #addRuleSet | |
134 | * | |
135 | * @return The new rule-base. | |
136 | */ | |
137 | 65 | public RuleBase build() |
138 | { | |
139 | 65 | return this.builder.buildRuleBase( ); |
140 | } | |
141 | ||
142 | /** | |
143 | * Drools currently supports two <code>FactHandleFactories</code>. The default and JSR94 implementation This sets | |
144 | * the factory used to generate <code>FactHandle</code>s | |
145 | * | |
146 | * @see org.drools.FactHandle | |
147 | * | |
148 | * @param factHandleFactory | |
149 | */ | |
150 | 61 | public void setFactHandleFactory(FactHandleFactory factHandleFactory) |
151 | { | |
152 | 61 | this.builder.setFactHandleFactory( factHandleFactory ); |
153 | } | |
154 | ||
155 | /** | |
156 | * By default a RuleBase will use the <Code>DefaultConflictResolver</code> This enables a custom ConflictResolver | |
157 | * to be specified for the <code>RuleBase</code>s being built. | |
158 | * | |
159 | * @see org.drools.ConflictResolver | |
160 | * | |
161 | * @param conflictResolver | |
162 | */ | |
163 | 2 | public void setConflictResolver(ConflictResolver conflictResolver) |
164 | { | |
165 | 2 | this.builder.setConflictResolver( conflictResolver ); |
166 | } | |
167 | } |
|