View Javadoc
1 package org.drools.reteoo.impl; 2 3 /* 4 $Id: ParameterNodeImpl.java,v 1.5 2002/08/01 21:00:21 bob Exp $ 5 6 Copyright 2002 (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 10 that the following conditions are met: 11 12 1. Redistributions of source code must retain copyright 13 statements and notices. Redistributions must also contain a 14 copy of this document. 15 16 2. Redistributions in binary form must reproduce the 17 above copyright notice, this list of conditions and the 18 following disclaimer in the documentation and/or other 19 materials provided with the distribution. 20 21 3. The name "drools" must not be used to endorse or promote 22 products derived from this Software without prior written 23 permission of The Werken Company. For written permission, 24 please contact bob@werken.com. 25 26 4. Products derived from this Software may not be called "drools" 27 nor may "drools" appear in their names without prior written 28 permission of The Werken Company. "drools" is a registered 29 trademark of The Werken Company. 30 31 5. Due credit should be given to The Werken Company. 32 (http://drools.werken.com/). 33 34 THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS 35 ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 36 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 37 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 38 THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 39 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 40 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 41 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 42 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 43 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 44 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 45 OF THE POSSIBILITY OF SUCH DAMAGE. 46 47 */ 48 49 import org.drools.WorkingMemory; 50 import org.drools.FactException; 51 import org.drools.AssertionException; 52 import org.drools.RetractionException; 53 import org.drools.reteoo.ParameterNode; 54 import org.drools.rule.Declaration; 55 56 import java.util.Set; 57 import java.util.Collections; 58 59 /*** Receives <code>Objects</code> from an <code>ObjectTypeNode</code>, 60 * and creates a <code>ReteTuple</code>, passing the result to the following node. 61 * 62 * <p> 63 * The <code>ParameterNode</code> is the first node that works in 64 * terms of <code>Tuples</code>. An instance of <code>ParameterNode</code> 65 * exists for each <i>root fact object</i> parameter of each rule. 66 * </p> 67 * 68 * @see ObjectTypeNodeImpl 69 * @see org.drools.reteoo.TupleSink 70 * 71 * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a> 72 */ 73 public class ParameterNodeImpl extends TupleSourceImpl implements ParameterNode 74 { 75 // ------------------------------------------------------------ 76 // Instance members 77 // ------------------------------------------------------------ 78 79 /*** The parameter declaration. */ 80 private Declaration declaration; 81 82 // ------------------------------------------------------------ 83 // Constructors 84 // ------------------------------------------------------------ 85 86 /*** Construct. 87 * 88 * @param inputNode The <code>ObjectTypeNode</code> input to this. 89 * @param declaration The root fact object <code>Declaration</code>. 90 */ 91 public ParameterNodeImpl(ObjectTypeNodeImpl inputNode, 92 Declaration declaration) 93 { 94 this.declaration = declaration; 95 96 if ( inputNode != null ) 97 { 98 inputNode.addParameterNode( this ); 99 } 100 } 101 102 // ------------------------------------------------------------ 103 // Instance methods 104 // ------------------------------------------------------------ 105 106 /*** Assert a new fact object into this <code>RuleBase</code> 107 * and the specified <code>WorkingMemory</code>. 108 * 109 * @param object The object to assert. 110 * @param workingMemory The working memory session. 111 * 112 * @throws AssertionException if an error occurs during assertion. 113 */ 114 void assertObject(Object object, 115 WorkingMemory workingMemory) throws AssertionException 116 { 117 ReteTuple tuple = new ReteTuple( getDeclaration(), 118 object ); 119 120 propagateAssertTuple( tuple, 121 workingMemory ); 122 } 123 124 /*** Retract a fact object from this <code>RuleBase</code> 125 * and the specified <code>WorkingMemory</code>. 126 * 127 * @param object The object to retract. 128 * @param workingMemory The working memory session. 129 * 130 * @throws RetractionException if an error occurs during retraction. 131 */ 132 void retractObject(Object object, 133 WorkingMemory workingMemory) throws RetractionException 134 { 135 TupleKey key = new TupleKey( getDeclaration(), 136 object ); 137 138 propagateRetractTuples( key, 139 workingMemory ); 140 } 141 142 /*** Modify a fact object in this <code>RuleBase</code> 143 * and the specified <code>WorkingMemory</code>. 144 * 145 * With the exception of time-based nodes, modification of 146 * a fact object is semantically equivelent to retracting and 147 * re-asserting it. 148 * 149 * @param object The object to modify. 150 * @param workingMemory The working memory session. 151 * 152 * @throws FactException if an error occurs during modification. 153 */ 154 void modifyObject(Object object, 155 WorkingMemory workingMemory) throws FactException 156 { 157 ReteTuple tuple = new ReteTuple( getDeclaration(), 158 object ); 159 160 TupleSet tupleSet = new TupleSet( tuple ); 161 162 propagateModifyTuples( object, 163 tupleSet, 164 workingMemory ); 165 } 166 167 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 168 // org.drools.reteoo.ParameterNode 169 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 170 171 /*** Retrieve the root fact object <code>Declaration</code>. 172 * 173 * @return The <code>Declaration</code>. 174 */ 175 public Declaration getDeclaration() 176 { 177 return this.declaration; 178 } 179 180 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 181 // org.drools.reteoo.impl.TupleSource 182 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 183 184 /*** Retrieve the <code>Set</code> of <code>Declaration</code>s 185 * in the propagated <code>Tuples</code>. 186 * 187 * @return The <code>Set</code> of <code>Declarations</code> 188 * in progated <code>Tuples</code>. 189 */ 190 public Set getTupleDeclarations() 191 { 192 return Collections.singleton( this.declaration ); 193 } 194 195 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 196 // java.lang.Object 197 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 198 199 /*** Produce a debug string. 200 * 201 * @return The debug string. 202 */ 203 public String toString() 204 { 205 return "[ParameterNodeImpl: decl=" + this.declaration + "]"; 206 } 207 }

This page was automatically generated by Maven