View Javadoc
1 package org.drools.reteoo.impl; 2 3 /* 4 $Id: TerminalNodeImpl.java,v 1.3 2002/08/10 19:16:17 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.AssertionException; 51 import org.drools.reteoo.TerminalNode; 52 import org.drools.reteoo.TupleSource; 53 import org.drools.rule.Rule; 54 55 /*** Leaf Rete-OO node responsible for enacting <code>Action</code>s 56 * on a matched <code>Rule</code>. 57 * 58 * @see org.drools.rule.Rule 59 * @see org.drools.spi.Action 60 * 61 * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a> 62 */ 63 public class TerminalNodeImpl implements TerminalNode, TupleSinkImpl 64 { 65 // ------------------------------------------------------------ 66 // Instance members 67 // ------------------------------------------------------------ 68 69 /*** Total-ordering priority of this terminal node for rule-firings. */ 70 private int priority; 71 72 /*** The rule to invoke upon match. */ 73 private Rule rule; 74 75 // ------------------------------------------------------------ 76 // Constructors 77 // ------------------------------------------------------------ 78 79 /*** Construct. 80 * 81 * @param inputSource The parent tuple source. 82 * @param rule The rule. 83 * @param priority The priority. 84 */ 85 public TerminalNodeImpl(TupleSource inputSource, 86 Rule rule, 87 int priority) 88 { 89 this.rule = rule; 90 91 this.priority = priority; 92 93 if ( inputSource != null ) 94 { 95 ((TupleSourceImpl)inputSource).setTupleSink( this ); 96 } 97 } 98 99 // ------------------------------------------------------------ 100 // Instance methods 101 // ------------------------------------------------------------ 102 103 /*** Retrieve the priority 104 * 105 * @return The priority. 106 */ 107 public int getPriority() 108 { 109 return this.priority; 110 } 111 112 /*** Retrieve the <code>Action</code> associated with 113 * this node. 114 * 115 * @return The <code>Action</code> associated with 116 * this node. 117 */ 118 public Rule getRule() 119 { 120 return this.rule; 121 } 122 123 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 124 // org.drools.impl.TupleSink 125 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 126 127 /*** Assert a new <code>Tuple</code>. 128 * 129 * @param tuple The <code>Tuple</code> being asserted. 130 * @param workingMemory The working memory seesion. 131 * 132 * @throws AssertionException If an error occurs while asserting. 133 */ 134 public void assertTuple(ReteTuple tuple, 135 WorkingMemory workingMemory) throws AssertionException 136 { 137 AgendaImpl agenda = (AgendaImpl) workingMemory.getAgenda(); 138 139 agenda.addToAgenda( tuple, 140 getRule(), 141 getPriority() ); 142 } 143 144 /*** Retract tuples. 145 * 146 * @param key The tuple key. 147 * @param workingMemory The working memory seesion. 148 */ 149 public void retractTuples(TupleKey key, 150 WorkingMemory workingMemory) 151 { 152 AgendaImpl agenda = (AgendaImpl) workingMemory.getAgenda(); 153 154 agenda.removeFromAgenda( key, 155 getRule() ); 156 } 157 158 /*** Modify tuples. 159 * 160 * @param trigger The root fact object. 161 * @param newTuples Modification replacement tuples. 162 * @param workingMemory The working memory session. 163 */ 164 public void modifyTuples(Object trigger, 165 TupleSet newTuples, 166 WorkingMemory workingMemory) 167 { 168 AgendaImpl agenda = (AgendaImpl) workingMemory.getAgenda(); 169 170 agenda.modifyAgenda( trigger, 171 newTuples, 172 getRule(), 173 getPriority() ); 174 } 175 }

This page was automatically generated by Maven