|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ParameterNode.java | 75% | 93.8% | 100% | 92.9% |
|
1 | package org.drools.reteoo; | |
2 | ||
3 | /* | |
4 | * $Id: ParameterNode.java,v 1.46 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.Collections; | |
44 | import java.util.Set; | |
45 | ||
46 | import org.drools.AssertionException; | |
47 | import org.drools.FactHandle; | |
48 | import org.drools.RetractionException; | |
49 | import org.drools.rule.Declaration; | |
50 | ||
51 | /** | |
52 | * Receives <code>Objects</code> from an <code>ObjectTypeNode</code>, and | |
53 | * creates a <code>ReteTuple</code>, passing the result to the following | |
54 | * node. | |
55 | * | |
56 | * <p> | |
57 | * The <code>ParameterNode</code> is the first node that works in terms of | |
58 | * <code>Tuples</code>. An instance of <code>ParameterNode</code> exists | |
59 | * for each <i>root fact object </i> parameter of each rule. | |
60 | * </p> | |
61 | * | |
62 | * @see ObjectTypeNode | |
63 | * @see TupleSink | |
64 | * | |
65 | * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter </a> | |
66 | */ | |
67 | class ParameterNode extends TupleSource | |
68 | { | |
69 | // ------------------------------------------------------------ | |
70 | // Instance members | |
71 | // ------------------------------------------------------------ | |
72 | ||
73 | /** The object type node we attach to. */ | |
74 | private final ObjectTypeNode objectTypeNode; | |
75 | ||
76 | /** The parameter declaration. */ | |
77 | private final Declaration declaration; | |
78 | ||
79 | /** The parameter declaration as a set. */ | |
80 | private final Set declarations; | |
81 | ||
82 | // ------------------------------------------------------------ | |
83 | // Constructors | |
84 | // ------------------------------------------------------------ | |
85 | ||
86 | /** | |
87 | * Construct. | |
88 | * | |
89 | * @param objectTypeNode The <code>ObjectTypeNode</code> input to this. | |
90 | * @param declaration The root fact object <code>Declaration</code>. | |
91 | */ | |
92 | 195 | public ParameterNode( ObjectTypeNode objectTypeNode, |
93 | Declaration declaration ) | |
94 | { | |
95 | 195 | this.objectTypeNode = objectTypeNode; |
96 | 195 | this.declaration = declaration; |
97 | 195 | this.declarations = Collections.singleton( declaration ); |
98 | } | |
99 | ||
100 | // ------------------------------------------------------------ | |
101 | // Instance methods | |
102 | // ------------------------------------------------------------ | |
103 | ||
104 | 150 | public void attach( ) |
105 | { | |
106 | 150 | this.objectTypeNode.addParameterNode( this ); |
107 | } | |
108 | ||
109 | /** | |
110 | * Assert a new fact object into this <code>RuleBase</code> and the | |
111 | * specified <code>WorkingMemory</code>. | |
112 | * | |
113 | * @param handle The fact handle. | |
114 | * @param object The object to assert. | |
115 | * @param workingMemory The working memory session. | |
116 | * | |
117 | * @throws AssertionException if an error occurs during assertion. | |
118 | */ | |
119 | 1246 | void assertObject( FactHandle handle, |
120 | Object object, | |
121 | WorkingMemoryImpl workingMemory ) throws AssertionException | |
122 | { | |
123 | 1246 | ReteTuple tuple = new ReteTuple( workingMemory, getDeclaration( ), |
124 | handle ); | |
125 | ||
126 | 1246 | propagateAssertTuple( tuple, |
127 | workingMemory ); | |
128 | } | |
129 | ||
130 | /** | |
131 | * Retract a fact object from this <code>RuleBase</code> and the specified | |
132 | * <code>WorkingMemory</code>. | |
133 | * | |
134 | * @param handle The handle to the fact to retract. | |
135 | * @param workingMemory The working memory session. | |
136 | * | |
137 | * @throws RetractionException if an error occurs during retraction. | |
138 | */ | |
139 | 667 | void retractObject( FactHandle handle, |
140 | WorkingMemoryImpl workingMemory ) throws RetractionException | |
141 | { | |
142 | 667 | TupleKey key = new TupleKey( getDeclaration( ), |
143 | handle ); | |
144 | ||
145 | 667 | propagateRetractTuples( key, |
146 | workingMemory ); | |
147 | } | |
148 | ||
149 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
150 | // org.drools.reteoo.ParameterNode | |
151 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
152 | ||
153 | /** | |
154 | * Retrieve the root fact object <code>Declaration</code>. | |
155 | * | |
156 | * @return The <code>Declaration</code>. | |
157 | */ | |
158 | 1915 | public Declaration getDeclaration() |
159 | { | |
160 | 1915 | return this.declaration; |
161 | } | |
162 | ||
163 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
164 | // org.drools.reteoo.impl.TupleSource | |
165 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
166 | ||
167 | /** | |
168 | * Retrieve the <code>Set</code> of <code>Declaration</code> s in the | |
169 | * propagated <code>Tuples</code>. | |
170 | * | |
171 | * @return The <code>Set</code> of <code>Declarations</code> in progated | |
172 | * <code>Tuples</code>. | |
173 | */ | |
174 | 884 | public Set getTupleDeclarations() |
175 | { | |
176 | 884 | return declarations; |
177 | } | |
178 | ||
179 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
180 | ||
181 | 10398 | public int hashCode() |
182 | { | |
183 | 10398 | return this.declaration.hashCode( ); |
184 | } | |
185 | ||
186 | 1274 | public boolean equals( Object object ) |
187 | { | |
188 | 1274 | if ( this == object ) |
189 | { | |
190 | 232 | return true; |
191 | } | |
192 | ||
193 | 1042 | if ( object == null || getClass( ) != object.getClass( ) ) |
194 | { | |
195 | 0 | return false; |
196 | } | |
197 | ||
198 | 1042 | return this.declaration.equals( ( ( ParameterNode ) object ).declaration ); |
199 | } | |
200 | } |
|