wt.rule.impl
Class DefaultRuleSelector

java.lang.Object
  extended bywt.rule.impl.DefaultRuleSelector
All Implemented Interfaces:
RuleSelector

public class DefaultRuleSelector
extends Object
implements RuleSelector

This is a default implementation of the RuleSelector interface.

This class has public visibility due to an implementation side effect. This class should have package visibility. Do not create instances of this class directly. Instead use the wt.rule.RuleSelectorFactory class to obtain an instance.

Given a target object O and a rule type R, this delegate picks a rule from the set of default enabled rules of type R based on the following precedence rules:

  1. InstanceBasedRule that references O
  2. InstanceBasedRule that references O's master
  3. TypeBasedRule that references O's class
If no rule is found in the specified container, then its parent container is searched. This repeats until a rule is found or the top of the hierarchy is reached. If a rule cannot be found then null is returned.

Supported API: false

Extendable: false


Field Summary
private static String CLASSNAME
           
private static String RESOURCE
           
private static String RULE_RESOURCE
           
 
Constructor Summary
DefaultRuleSelector()
           
 
Method Summary
private static InstanceBasedRule findIBR(RuleType ruleType, Persistable object, WTContainerRef container)
          Find the default-enabled InstanceBasedRule that satisfies the specified search criteria.
private static TypeBasedRule findTBR(RuleType ruleType, Class objType, WTContainerRef container)
          Find the default-enabled TypeBasedRule that satisfies the specified search criteria.
 Rule getRule(Object object, RuleType ruleType, WTContainerRef container)
          Select a rule of type ruleType that is applicable to object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

CLASSNAME

private static final String CLASSNAME

RULE_RESOURCE

private static final String RULE_RESOURCE
See Also:
Constant Field Values
Constructor Detail

DefaultRuleSelector

public DefaultRuleSelector()
Method Detail

getRule

public Rule getRule(Object object,
                    RuleType ruleType,
                    WTContainerRef container)
             throws WTException
Select a rule of type ruleType that is applicable to object. If no rule can be found, return null.

The object argument may be a type identifier or a normal object. A type identifier is one of the following:

Different implementations of this interface will use the criteria in different ways to select a rule.

Specified by:
getRule in interface RuleSelector
Parameters:
object - the object that the rule should be applicable to (cannot be null)
ruleType - the type of rule to select (cannot be null)
container - the container in which to search for the rule
Returns:
Rule
Throws:
WTException

findIBR

private static final InstanceBasedRule findIBR(RuleType ruleType,
                                               Persistable object,
                                               WTContainerRef container)
                                        throws WTException
Find the default-enabled InstanceBasedRule that satisfies the specified search criteria. Start the search for the rule in the specified container. Continue the search up the hierarchy until a rule is found or the top of the hierarchy is reached.

Parameters:
ruleType -
object -
container - the container to start searching in
Returns:
InstanceBasedRule
Throws:
WTException

findTBR

private static final TypeBasedRule findTBR(RuleType ruleType,
                                           Class objType,
                                           WTContainerRef container)
                                    throws WTException
Find the default-enabled TypeBasedRule that satisfies the specified search criteria. Start the search for the rule in the specified container. Continue the search up the hierarchy until a rule is found or the top of the hierarchy is reached.

Parameters:
ruleType -
objType -
container - the container to start searching in
Returns:
TypeBasedRule
Throws:
WTException