1 package org.drools.reteoo.impl;
2
3 /*
4 $Id: TupleSourceImpl.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.FactException;
51 import org.drools.AssertionException;
52 import org.drools.RetractionException;
53 import org.drools.reteoo.TupleSink;
54 import org.drools.reteoo.TupleSource;
55
56 /*** A source of <code>ReteTuple</code>s for a <code>TupleSink</code>.
57 *
58 * <p>
59 * Nodes that propagate <code>Tuples</code> extend this class.
60 * </p>
61 *
62 * @see TupleSource
63 * @see TupleSinkImpl
64 * @see ReteTuple
65 *
66 * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a>
67 */
68 public abstract class TupleSourceImpl implements TupleSource
69 {
70 // ------------------------------------------------------------
71 // Instance members
72 // ------------------------------------------------------------
73
74 /*** The destination for <code>Tuples</code>. */
75 private TupleSinkImpl tupleSink;
76
77 // ------------------------------------------------------------
78 // Constructors
79 // ------------------------------------------------------------
80
81 /*** Construct.
82 */
83 protected TupleSourceImpl()
84 {
85 // intentionally left blank.
86 }
87
88 // ------------------------------------------------------------
89 // Instance methods
90 // ------------------------------------------------------------
91
92 /*** Set the <code>TupleSink</code> that receives <code>Tuples</code>
93 * propagated from this <code>TupleSource</code>.
94 *
95 * @param tupleSink The <code>TupleSink</code> to receive
96 * propagated <code>Tuples</code>.
97 */
98 protected void setTupleSink(TupleSinkImpl tupleSink)
99 {
100 this.tupleSink = tupleSink;
101 }
102
103 /*** Propagate the assertion of a <code>Tuple</code>
104 * to this node's <code>TupleSink</code>.
105 *
106 * @param tuple The <code>Tuple</code> to propagate.
107 * @param workingMemory the working memory session.
108 *
109 * @throws AssertionException If an errors occurs while
110 * attempting assertion.
111 */
112 protected void propagateAssertTuple(ReteTuple tuple,
113 WorkingMemory workingMemory) throws AssertionException
114 {
115 TupleSinkImpl sink = (TupleSinkImpl) getTupleSink();
116
117 if ( sink != null )
118 {
119 sink.assertTuple( tuple,
120 workingMemory );
121 }
122 }
123
124 /*** Propagate the retration of a <code>Tuple</code>
125 * to this node's <code>TupleSink</code>.
126 *
127 * @param key The tuple key.
128 * @param workingMemory The working memory session.
129 *
130 * @throws RetractionException If an error occurs while
131 * attempting retraction
132 *
133 */
134 protected void propagateRetractTuples(TupleKey key,
135 WorkingMemory workingMemory) throws RetractionException
136 {
137 TupleSinkImpl sink = (TupleSinkImpl) getTupleSink();
138
139 if ( sink != null )
140 {
141 sink.retractTuples( key,
142 workingMemory );
143 }
144 }
145
146 /*** Propagate the modification of <code>Tuple</code>s
147 * to this node's <code>TupleSink</code>.
148 *
149 * @param trigger The modification trigger object.
150 * @param newTuples Modification replacement tuples.
151 * @param workingMemory The working memory session.
152 *
153 * @throws FactException If an error occurs while
154 * attempting modification.
155 */
156 protected void propagateModifyTuples(Object trigger,
157 TupleSet newTuples,
158 WorkingMemory workingMemory) throws FactException
159 {
160 TupleSinkImpl sink = (TupleSinkImpl) getTupleSink();
161
162 if ( sink != null )
163 {
164 sink.modifyTuples( trigger,
165 newTuples,
166 workingMemory );
167 }
168 }
169
170 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
171 // org.drools.reteoo.TupleSource
172 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
173
174 /*** Retrieve the <code>TupleSink</code> that receives
175 * propagated <code>Tuples</code>.
176 *
177 * @return The <code>TupleSink</code> that receives
178 * propagated <code>Tuples</code>.
179 */
180 public TupleSink getTupleSink()
181 {
182 return this.tupleSink;
183 }
184 }
This page was automatically generated by Maven