01: /*
02: * Copyright 2005 JBoss Inc
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.drools.reteoo;
17:
18: import java.util.ArrayList;
19: import java.util.Collections;
20: import java.util.List;
21:
22: import org.drools.WorkingMemory;
23: import org.drools.common.InternalFactHandle;
24: import org.drools.rule.Declaration;
25: import org.drools.spi.Accumulator;
26: import org.drools.spi.Tuple;
27:
28: /**
29: * A Mock accumulate object.
30: *
31: * @author etirelli
32: *
33: */
34: public class MockAccumulator implements Accumulator {
35:
36: private static final long serialVersionUID = 400L;
37:
38: private Tuple leftTuple = null;
39: private List matchingObjects = Collections.EMPTY_LIST;
40: private WorkingMemory workingMemory = null;
41:
42: public Tuple getLeftTuple() {
43: return this .leftTuple;
44: }
45:
46: public List getMatchingObjects() {
47: return this .matchingObjects;
48: }
49:
50: public WorkingMemory getWorkingMemory() {
51: return this .workingMemory;
52: }
53:
54: public Object createContext() {
55: return this ;
56: }
57:
58: public void init(Object workingMemoryContext, Object context,
59: Tuple leftTuple, Declaration[] declarations,
60: WorkingMemory workingMemory) throws Exception {
61: this .leftTuple = leftTuple;
62: this .matchingObjects = new ArrayList();
63: this .workingMemory = workingMemory;
64: }
65:
66: public void accumulate(Object workingMemoryContext, Object context,
67: Tuple leftTuple, InternalFactHandle handle,
68: Declaration[] declarations,
69: Declaration[] innerDeclarations, WorkingMemory workingMemory)
70: throws Exception {
71: this .matchingObjects.add(handle.getObject());
72: }
73:
74: public Object getResult(Object workingMemoryContext,
75: Object context, Tuple leftTuple,
76: Declaration[] declarations, WorkingMemory workingMemory)
77: throws Exception {
78: return this .matchingObjects;
79: }
80:
81: public void reverse(Object workingMemoryContext, Object context,
82: Tuple leftTuple, InternalFactHandle handle,
83: Declaration[] declarations,
84: Declaration[] innerDeclarations, WorkingMemory workingMemory)
85: throws Exception {
86: // nothing to do yet
87: }
88:
89: public boolean supportsReverse() {
90: return false;
91: }
92:
93: public Object createWorkingMemoryContext() {
94: return null;
95: }
96:
97: }
|