org.drools.spi
Interface KnowledgeHelper

All Known Implementing Classes:
DefaultKnowledgeHelper

public interface KnowledgeHelper

KnowledgeHelper implementation types are injected into consequenses instrumented at compile time and instances passed at runtime. It provides convenience methods for users to interact with the WorkingMemory.

Of particular interest is the modifyObject method as it allows an object to be modified without having to specify the facthandle, because they are not passed to the consequence at runtime. To achieve this the implementation will need to lookup the fact handle of the object form the WorkingMemory.


Method Summary
 void assertObject(java.lang.Object object)
          Asserts an object, notice that it does not return the FactHandle
 void assertObject(java.lang.Object object, boolean dynamic)
          Asserts an object specifying that it implement the onPropertyChange listener, notice that it does not return the FactHandle.
 void clearAgenda()
          Clears the agenda causing all existing Activations to fire ActivationCancelled events.
 java.util.List getObjects()
           
 java.util.List getObjects(java.lang.Class objectClass)
          Retruns a List of Objects that match the given Class in the paremeter.
 java.lang.String getRuleName()
           
 void modifyObject(java.lang.Object object)
          Modifies an object.
 void modifyObject(java.lang.Object oldObject, java.lang.Object newObject)
          Modifies an object by looking up the handle of the oldObject and replacing the oldObject with the newObject for the FactHandle.
 void retractObject(java.lang.Object object)
          Retracts an object from the WorkingMemory.
 

Method Detail

assertObject

void assertObject(java.lang.Object object)
                  throws FactException
Asserts an object, notice that it does not return the FactHandle

Parameters:
object - - the object to be asserted
Throws:
FactException - - Exceptions can be thrown by conditions which are wrapped and returned as a FactException

assertObject

void assertObject(java.lang.Object object,
                  boolean dynamic)
                  throws FactException
Asserts an object specifying that it implement the onPropertyChange listener, notice that it does not return the FactHandle.

Parameters:
object - - the object to be asserted
dynamic - - specifies the object implements onPropertyChangeListener
Throws:
FactException - - Exceptions can be thrown by conditions which are wrapped and returned as a FactException

modifyObject

void modifyObject(java.lang.Object object)
                  throws FactException
Modifies an object. Notice that the FactHandle is not passed so the implementation must lookup the FactHandle form the working memory.

Parameters:
object - - the object to be modified
Throws:
FactException - - Exceptions can be thrown by conditions which are wrapped and returned as a FactException

modifyObject

void modifyObject(java.lang.Object oldObject,
                  java.lang.Object newObject)
                  throws FactException
Modifies an object by looking up the handle of the oldObject and replacing the oldObject with the newObject for the FactHandle. This is used for updating immutable objects.

Parameters:
oldObject - - The old object to be modified
newObject - - the new modified object
Throws:
FactException

retractObject

void retractObject(java.lang.Object object)
                   throws FactException
Retracts an object from the WorkingMemory. All Activations on the Agenda that are cancelled should emit ActivationCancelled events.

Parameters:
object - - the object to be retracted.
Throws:
FactException - - Wraps and returns any exception that may occur.

getRuleName

java.lang.String getRuleName()
Returns:
- The rule name

getObjects

java.util.List getObjects()
Returns:
- A List of the objects in the WorkingMemory

getObjects

java.util.List getObjects(java.lang.Class objectClass)
Retruns a List of Objects that match the given Class in the paremeter.

Parameters:
objectClass - - The Class to filter by
Returns:
- All the Objects in the WorkingMemory that match the given Class filter

clearAgenda

void clearAgenda()
Clears the agenda causing all existing Activations to fire ActivationCancelled events.