01: /**
02: *
03: */package org.drools.concurrent;
04:
05: import java.util.ArrayList;
06: import java.util.Iterator;
07: import java.util.List;
08:
09: import org.drools.WorkingMemory;
10:
11: public class AssertObjects implements Command, Future {
12: private Object object;
13: private volatile List results;
14: private Exception e;
15:
16: public AssertObjects(final Object object) {
17: this .object = object;
18: }
19:
20: public void execute(final WorkingMemory workingMemory) {
21: try {
22: if (this .object instanceof Object[]) {
23: final Object[] objects = (Object[]) this .object;
24: this .results = new ArrayList(objects.length);
25: for (int i = 0; i < objects.length; i++) {
26: this .results.add(workingMemory.insert(objects[i]));
27: }
28: } else if (this .object instanceof List) {
29: final List list = (List) this .object;
30: this .results = new ArrayList(list.size());
31: for (final Iterator it = list.iterator(); it.hasNext();) {
32: this .results.add(workingMemory.insert(it.next()));
33: }
34: }
35: } catch (Exception e) {
36: this .e = e;
37: }
38: }
39:
40: public Object getObject() {
41: return this .results;
42: }
43:
44: public boolean isDone() {
45: return this .results != null;
46: }
47:
48: public boolean exceptionThrown() {
49: return e != null;
50: }
51:
52: public Exception getException() {
53: return this.e;
54: }
55: }
|