org.drools.reteoo
Class Builder

java.lang.Object
  |
  +--org.drools.reteoo.Builder

public class Builder
extends java.lang.Object

Builds the Rete-OO network for a RuleSet.

Author:
bob mcwhirter
See Also:
RuleSet

Constructor Summary
Builder(Rete rete)
          Construct a Builder against an existing Rete network.
 
Method Summary
 void addRule(Rule rule)
          Add a Rule to the network.
protected  void attachConditions(java.util.Set conds, java.util.Set leafNodes)
          Create and attach Conditions to the network.
protected  boolean attachExtractions(java.util.Set factExtracts, java.util.Set leafNodes)
          Create and attach Extractions to the network.
protected  boolean canBeJoined(TupleSource left, TupleSource right)
          Determine if two TupleSources can be joined.
protected  boolean createJoinNodes(java.util.Set leafNodes)
          Create and attach JoinNodes to the network.
protected  java.util.Set createParameterNodes(Rule rule)
          Create the ParameterNodes for the Rule, and link into the network.
protected  TupleSourceImpl findMatchingTupleSourceForCondition(Condition condition, java.util.Set sources)
          Locate a TupleSource suitable for attaching the Condition.
protected  TupleSourceImpl findMatchingTupleSourceForExtraction(Extraction extract, java.util.Set sources)
          Locate a TupleSource suitable for attaching the Extraction.
 Rete getRete()
          Retrieve the Rete this Builder appends to.
protected  boolean joinArbitrary(java.util.Set leafNodes)
          Join two arbitrary leaves in order to satisfy a filter that currently cannot be applied.
protected  boolean joinForCondition(java.util.Set conds, java.util.Set leafNodes)
          Join two arbitrary leaves in order to satisfy a filter that currently cannot be applied.
protected  boolean matches(Condition condition, java.util.Set declarations)
          Determine if a set of Declarations match those required by a Condition.
protected  boolean matches(Declaration[] requiredDecls, java.util.Set declarations)
          Determine if a set of Declarations is a super set of required Declarations
protected  boolean matches(Extraction extract, java.util.Set declarations)
          Determine if a set of Declarations match those required by a Extraction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Builder

public Builder(Rete rete)
Construct a Builder against an existing Rete network.
Parameters:
rete - The network to add to.
Method Detail

getRete

public Rete getRete()
Retrieve the Rete this Builder appends to.
Returns:
The Rete.

addRule

public void addRule(Rule rule)
             throws RuleIntegrationException
Add a Rule to the network.
Parameters:
rule - The rule to add.
Throws:
RuleIntegrationException - if an error prevents complete construction of the network for the Rule.

createParameterNodes

protected java.util.Set createParameterNodes(Rule rule)
Create the ParameterNodes for the Rule, and link into the network.
Parameters:
rule - The rule.
Returns:
A Set of ParameterNodes created and linked into the network.

attachConditions

protected void attachConditions(java.util.Set conds,
                                java.util.Set leafNodes)
Create and attach Conditions to the network.

It may not be possible to satisfy all filder conditions on the first pass. This method removes satisfied conditions from the Condition parameter, and leaves unsatisfied ones in the Set.

Parameters:
conds - Set of Conditions to attempt attaching.
leafNodes - The current attachable leaf nodes of the network.

joinForCondition

protected boolean joinForCondition(java.util.Set conds,
                                   java.util.Set leafNodes)
Join two arbitrary leaves in order to satisfy a filter that currently cannot be applied.
Parameters:
conds - The filter conditions remaining.
leafNodes - Available leaf nodes.
Returns:
true if a join was possible, otherwise, false.

joinArbitrary

protected boolean joinArbitrary(java.util.Set leafNodes)
Join two arbitrary leaves in order to satisfy a filter that currently cannot be applied.
Parameters:
leafNodes - Available leaf nodes.

createJoinNodes

protected boolean createJoinNodes(java.util.Set leafNodes)
Create and attach JoinNodes to the network.

It may not be possible to join all leafNodes.

Any leafNodes member that particiates in a join is removed from the leafNodes collection, and replaced by the joining JoinNode.

Parameters:
leafNodes - The current attachable leaf nodes of the network.
Returns:
true if at least one JoinNode was created, else false.

canBeJoined

protected boolean canBeJoined(TupleSource left,
                              TupleSource right)
Determine if two TupleSources can be joined.
Parameters:
left - The left tuple source
right - The right tuple source
Returns:
true if they can be joined (they share at least one common member declaration), else false.

attachExtractions

protected boolean attachExtractions(java.util.Set factExtracts,
                                    java.util.Set leafNodes)
Create and attach Extractions to the network.

It may not be possible to satisfy all Extraction, in which case, unsatisfied conditions will remain in the Set passed in as Extraction.

Parameters:
factExtracts - Set of Extractions to attach to the network.
leafNodes - The current attachable leaf nodes of the network.
Returns:
true if fact extractions have been attached, otherwise false.

findMatchingTupleSourceForCondition

protected TupleSourceImpl findMatchingTupleSourceForCondition(Condition condition,
                                                              java.util.Set sources)
Locate a TupleSource suitable for attaching the Condition.
Parameters:
condition - The Condition to attach.
sources - Candidate TupleSources.
Returns:
Matching TupleSource if a suitable one can be found, else null.

findMatchingTupleSourceForExtraction

protected TupleSourceImpl findMatchingTupleSourceForExtraction(Extraction extract,
                                                               java.util.Set sources)
Locate a TupleSource suitable for attaching the Extraction.
Parameters:
extract - The Extraction to attach.
sources - Candidate TupleSources.
Returns:
Matching TupleSource if a suitable one can be found, else null.

matches

protected boolean matches(Condition condition,
                          java.util.Set declarations)
Determine if a set of Declarations match those required by a Condition.
Parameters:
condition - The Condition.
declarations - The set of Declarations to compare against.
Returns:
true if the set of Declarations is a super-set of the Declarations required by the Condition.

matches

protected boolean matches(Extraction extract,
                          java.util.Set declarations)
Determine if a set of Declarations match those required by a Extraction.
Parameters:
extract - The Extraction.
declarations - The set of Declarations to compare against.
Returns:
true if the set of Declarations is a super-set of the Declarations required by the Condition.

matches

protected boolean matches(Declaration[] requiredDecls,
                          java.util.Set declarations)
Determine if a set of Declarations is a super set of required Declarations
Parameters:
requiredDecls - The required Declarations.
declarations - The set of Declarations to compare against.
Returns:
true if the set of Declarations is a super-set of the Declarations required by the Condition.


Copyright © 2001-2003 The Werken Company. All Rights Reserved.