|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
KnowledgeHelper.java | - | - | - | - |
|
1 | package org.drools.spi; | |
2 | ||
3 | import java.util.List; | |
4 | ||
5 | import org.drools.FactException; | |
6 | ||
7 | /** | |
8 | * KnowledgeHelper implementation types are injected into consequenses | |
9 | * instrumented at compile time and instances passed at runtime. It provides | |
10 | * convenience methods for users to interact with the WorkingMemory. | |
11 | * <p> | |
12 | * Of particular interest is the modifyObject method as it allows an object to | |
13 | * be modified without having to specify the facthandle, because they are not | |
14 | * passed to the consequence at runtime. To achieve this the implementation will | |
15 | * need to lookup the fact handle of the object form the WorkingMemory. | |
16 | * @author <a href="mailto:bob@werken.com">bob mcwhirter </a> | |
17 | * @author <a href="mailto:mproctor@codehaus.org">mark proctor</a> | |
18 | */ | |
19 | public interface KnowledgeHelper | |
20 | { | |
21 | /** | |
22 | * Asserts an object, notice that it does not return the FactHandle | |
23 | * | |
24 | * @param object - | |
25 | * the object to be asserted | |
26 | * @throws FactException - | |
27 | * Exceptions can be thrown by conditions which are wrapped and | |
28 | * returned as a FactException | |
29 | */ | |
30 | void assertObject(Object object) throws FactException; | |
31 | ||
32 | /** | |
33 | * Asserts an object specifying that it implement the onPropertyChange | |
34 | * listener, notice that it does not return the FactHandle. | |
35 | * | |
36 | * @param object - | |
37 | * the object to be asserted | |
38 | * @param dynamic - | |
39 | * specifies the object implements onPropertyChangeListener | |
40 | * @throws FactException - | |
41 | * Exceptions can be thrown by conditions which are wrapped and | |
42 | * returned as a FactException | |
43 | */ | |
44 | void assertObject(Object object, | |
45 | boolean dynamic) throws FactException; | |
46 | ||
47 | /** | |
48 | * Modifies an object. Notice that the FactHandle is not passed so the | |
49 | * implementation must lookup the FactHandle form the working memory. | |
50 | * | |
51 | * @param object - | |
52 | * the object to be modified | |
53 | * @throws FactException - | |
54 | * Exceptions can be thrown by conditions which are wrapped and | |
55 | * returned as a FactException | |
56 | */ | |
57 | void modifyObject(Object object) throws FactException; | |
58 | ||
59 | /** | |
60 | * Modifies an object by looking up the handle of the oldObject and | |
61 | * replacing the oldObject with the newObject for the FactHandle. This is | |
62 | * used for updating immutable objects. | |
63 | * | |
64 | * @param oldObject - | |
65 | * The old object to be modified | |
66 | * @param newObject - | |
67 | * the new modified object | |
68 | * @throws FactException | |
69 | */ | |
70 | void modifyObject(Object oldObject, | |
71 | Object newObject) throws FactException; | |
72 | ||
73 | /** | |
74 | * Retracts an object from the WorkingMemory. All Activations on the Agenda | |
75 | * that are cancelled should emit ActivationCancelled events. | |
76 | * | |
77 | * @param object - | |
78 | * the object to be retracted. | |
79 | * @throws FactException - | |
80 | * Wraps and returns any exception that may occur. | |
81 | */ | |
82 | void retractObject(Object object) throws FactException; | |
83 | ||
84 | /** | |
85 | * @return - The rule name | |
86 | */ | |
87 | String getRuleName(); | |
88 | ||
89 | /** @return - A List of the objects in the WorkingMemory */ | |
90 | List getObjects(); | |
91 | ||
92 | /** | |
93 | * Retruns a List of Objects that match the given Class in the paremeter. | |
94 | * | |
95 | * @param objectClass - | |
96 | * The Class to filter by | |
97 | * @return - All the Objects in the WorkingMemory that match the given Class | |
98 | * filter | |
99 | */ | |
100 | List getObjects(Class objectClass); | |
101 | ||
102 | /** | |
103 | * Clears the agenda causing all existing Activations to fire | |
104 | * ActivationCancelled events. <br> | |
105 | */ | |
106 | void clearAgenda(); | |
107 | } |
|