wt.rule.impl
Class StandardRuleService

java.lang.Object
  extended bywt.services.StandardManager
      extended bywt.rule.impl.StandardRuleService
All Implemented Interfaces:
Manager, NetFactor, RuleCache, RuleService, RuleServiceSvr, Serializable

public class StandardRuleService
extends StandardManager
implements RuleService, RuleServiceSvr, RuleCache, Serializable

The standard implementation of the RuleService interface.

Use the newStandardRuleService static factory method(s), not the StandardRuleService constructor, to construct instances of this class. Instances must be constructed using the static factory(s), in order to ensure proper initialization of the instance.



Supported API: false

Extendable: false

See Also:
Serialized Form

Nested Class Summary
private static class StandardRuleService.CompareByName
          A comparator that can be used to determine if two rules have the same name.
 
Field Summary
private  RuleApplierFactory _applierFactory
           
private  Map _managedCaches
           
private  RuleMergerFactory _mergerFactory
           
private  Map _postStoreWork
           
private  RuleSelectorFactory _selectorFactory
           
private  RuleValidatorFactory _validatorFactory
           
private static boolean AUTO_INIT
           
private static String CLASSNAME
           
private  StandardRuleService.CompareByName NAME_COMPARATOR
           
private static String RESOURCE
           
private static String RULE_RESOURCE
           
 
Fields inherited from class wt.services.StandardManager
 
Fields inherited from interface wt.services.Manager
MANAGER_SERVICE, STARTUP_AUTOMATIC, STARTUP_MANUAL, STATUS_EMERGENCY_SHUTDOWN, STATUS_EMERGENCY_SHUTTING_DOWN, STATUS_SHUTDOWN, STATUS_SHUTDOWN_ERRORS, STATUS_SHUTDOWN_FAILURE, STATUS_SHUTTING_DOWN, STATUS_STARTED, STATUS_STARTED_ERRORS, STATUS_STARTING_UP, STATUS_STARTUP_FAILURE
 
Constructor Summary
StandardRuleService()
           
 
Method Summary
 void addCache(RuleCache cache, RuleType ruleType)
          Add a CacheManager to the list of caches managed by this service for the specified RuleType.
 void addPostStoreTask(Persistable object, com.objectspace.jgl.UnaryFunction task)
          Add a task to be executed when a POST_STORE event is received for the specified object.
 Object applyRule(Object object, Rule rule)
          Apply rule to the object.
 Object applyRule(Object object, Rule rule, WTContainerRef container)
          Apply rule to the object.
 Rule disableRule(Rule rule)
          Disable the specified Rule.
 Rule enableRule(Rule rule)
          Enable the specified Rule.
 QueryResult findRules(Class objType, RuleType ruleType, boolean enabled)
          Find all TypeBasedRules in the Classic container that are of type ruleType and whose object type attribute equals objType.
 QueryResult findRules(Class objType, RuleType ruleType, WTContainerRef container, boolean enabled)
          Find all TypeBasedRules in the specified container that are of type ruleType and whose object type attribute equals objType.
private  RuleApplierFactory getApplierFactory()
          Get the RuleApplierFactory used by this service to obtain RuleAppliers.
 String getConceptualClassname()
          Deprecated.  
private  RuleMergerFactory getMergerFactory()
          Get the RuleMergerFactory used by this service to obtain RuleMergers.
 Rule getRule(Object object, RuleType ruleType)
          Select an appropriate rule from the Classic container based on the object and ruleType supplied as arguments.
 Rule getRule(Object object, RuleType ruleType, WTContainerRef container)
          Select an appropriate rule from the specified container based on the object and ruleType supplied as arguments.
private  RuleSelectorFactory getSelectorFactory()
          Get the RuleSelectorFactory used by this service to obtain RuleSelectors.
private  RuleValidatorFactory getValidatorFactory()
          Get the RuleValidatorFactory used by this service to obtain RuleValidators.
 Rule mergeRules(Rule[] rules, RuleType ruleType)
          Merge the provided rules into a composite rule.
static StandardRuleService newStandardRuleService()
          Default factory for the class.
 void notifyPostDelete(Rule target)
          Notify the cache that a wt.fc.PersistenceManagerEvent.POST_DELETE event for a Rule has occured.
 void notifyPostStore(Rule target)
          Notify the cache that a wt.fc.PersistenceManagerEvent.POST_STORE event for a Rule has occured.
 void notifyUpdate(Rule target)
          Notify the cache that a wt.fc.PersistenceManagerEvent.UPDATE event for a Rule has occured.
protected  void performStartupProcess()
          Add listeners for the following events: wt.fc.PersistenceManagerEvent.PRE_STORE wt.fc.PersistenceManagerEvent.POST_STORE wt.fc.PersistenceManagerEvent.POST_DELETE wt.fc.PersistenceManagerEvent.UPDATE wt.fc.PersistenceManagerEvent.PRE_MODIFY
private  void validateRule(Rule rule)
           
 
Methods inherited from class wt.services.StandardManager
emergencyShutdown, emergencyShutdownComplete, emergencyShuttingDown, getClassInfo, getManagerService, getManagerStatus, getName, getStartupType, init, initialize, initialize, isStarted, newStandardManager, newStandardManager, performEmergencyShutdownProcess, performShutdownProcess, registerEvents, setManagerService, shutdown, shutdownFailure, shutdownSuccess, shuttingDown, started, startedErrors, startingUp, startup, startupFailure, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, 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

_selectorFactory

private final RuleSelectorFactory _selectorFactory

_applierFactory

private final RuleApplierFactory _applierFactory

_mergerFactory

private final RuleMergerFactory _mergerFactory

_validatorFactory

private final RuleValidatorFactory _validatorFactory

_postStoreWork

private final Map _postStoreWork

_managedCaches

private final Map _managedCaches

NAME_COMPARATOR

private final StandardRuleService.CompareByName NAME_COMPARATOR

AUTO_INIT

private static final boolean AUTO_INIT
Constructor Detail

StandardRuleService

public StandardRuleService()
Method Detail

getConceptualClassname

public String getConceptualClassname()
Deprecated.  

Returns the conceptual (modeled) name for the class.

Supported API: false

Specified by:
getConceptualClassname in interface NetFactor
Overrides:
getConceptualClassname in class StandardManager
Returns:
String

newStandardRuleService

public static StandardRuleService newStandardRuleService()
                                                  throws WTException
Default factory for the class.

Supported API: false

Returns:
StandardRuleService
Throws:
WTException

getRule

public Rule getRule(Object object,
                    RuleType ruleType)
             throws WTException
Select an appropriate rule from the Classic container based on the object and ruleType supplied as arguments.

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

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

getRule

public Rule getRule(Object object,
                    RuleType ruleType,
                    WTContainerRef container)
             throws WTException
Select an appropriate rule from the specified container based on the object and ruleType supplied as arguments.

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

Specified by:
getRule in interface RuleService
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 -
Returns:
Rule
Throws:
WTException

applyRule

public Object applyRule(Object object,
                        Rule rule,
                        WTContainerRef container)
                 throws WTException,
                        WTPropertyVetoException
Apply rule to the object. Return the resulting object. The result object might be the same object or a different one depending on the semantics of the rule. The specified container is used to lookup resource objects that are required while applying the rule.

If the rule is null then nothing is done and the original object is returned.

NOTE: This interface does not support operations that require returning multiple objects.

Supported API: false

Specified by:
applyRule in interface RuleService
Parameters:
object - the object that the rule should be applied to (cannot be null)
rule - the rule to be applied
container - the container to use for resource object lookups
Returns:
Object
Throws:
WTException
WTPropertyVetoException

applyRule

public Object applyRule(Object object,
                        Rule rule)
                 throws WTException,
                        WTPropertyVetoException
Apply rule to the object. Return the resulting object. The result object might be the same object or a different one depending on the semantics of the rule. The Classic container is used to lookup resource objects that are required while applying the rule.

If the rule is null then nothing is done and the original object is returned.

NOTE: This interface does not support operations that require returning multiple objects.

Supported API: false

Specified by:
applyRule in interface RuleService
Parameters:
object - the object that the rule should be applied to (cannot be null)
rule - the rule to be applied
Returns:
Object
Throws:
WTException
WTPropertyVetoException

findRules

public QueryResult findRules(Class objType,
                             RuleType ruleType,
                             boolean enabled)
                      throws WTException
Find all TypeBasedRules in the Classic container that are of type ruleType and whose object type attribute equals objType.

If enabled is true then only return those rules that are enabled. If enabled is false then all matching rules are returned.

Supported API: false

Specified by:
findRules in interface RuleService
Parameters:
objType - the object type that the returned rules should reference
ruleType - the type of rule that should be returned
enabled - whether only enabled rules should be returned
Returns:
QueryResult
Throws:
WTException

findRules

public QueryResult findRules(Class objType,
                             RuleType ruleType,
                             WTContainerRef container,
                             boolean enabled)
                      throws WTException
Find all TypeBasedRules in the specified container that are of type ruleType and whose object type attribute equals objType.

If enabled is true then only return those rules that are enabled. If enabled is false then all matching rules are returned.

Supported API: false

Specified by:
findRules in interface RuleService
Parameters:
objType - the object type that the returned rules should reference
ruleType - the type of rule that should be returned
container - the container to start searching in
enabled - whether only enabled rules should be returned
Returns:
QueryResult
Throws:
WTException

disableRule

public Rule disableRule(Rule rule)
                 throws WTException
Disable the specified Rule.

Supported API: false

Specified by:
disableRule in interface RuleService
Parameters:
rule - the rule to disable
Returns:
Rule
Throws:
WTException

enableRule

public Rule enableRule(Rule rule)
                throws WTException
Enable the specified Rule.

Supported API: false

Specified by:
enableRule in interface RuleService
Parameters:
rule - the rule to enable
Returns:
Rule
Throws:
WTException

mergeRules

public Rule mergeRules(Rule[] rules,
                       RuleType ruleType)
                throws WTException,
                       WTPropertyVetoException
Merge the provided rules into a composite rule.

Supported API: false

Specified by:
mergeRules in interface RuleService
Parameters:
rules - the rules to be merged
ruleType - the ruleType of the rules to be merged
Returns:
Rule
Throws:
WTException
WTPropertyVetoException

addPostStoreTask

public void addPostStoreTask(Persistable object,
                             com.objectspace.jgl.UnaryFunction task)
Add a task to be executed when a POST_STORE event is received for the specified object.

The task is a UnaryFunction that takes one argument. When a POST_STORE event is received for the specified object, the function is called with that object as its sole argument.

The functions are held in a weak map, so if the object is garbage collected before it is persisted, the task will be removed.

Supported API: false

Specified by:
addPostStoreTask in interface RuleServiceSvr
Parameters:
object -
task -

addCache

public void addCache(RuleCache cache,
                     RuleType ruleType)
Add a CacheManager to the list of caches managed by this service for the specified RuleType.

These caches will be notified when the following events occur for a rule with the specified rule type:



Supported API: false

Specified by:
addCache in interface RuleServiceSvr
Parameters:
cache -
ruleType -

notifyPostStore

public void notifyPostStore(Rule target)
Notify the cache that a wt.fc.PersistenceManagerEvent.POST_STORE event for a Rule has occured.

Supported API: false

Specified by:
notifyPostStore in interface RuleCache
Parameters:
target -

notifyPostDelete

public void notifyPostDelete(Rule target)
Notify the cache that a wt.fc.PersistenceManagerEvent.POST_DELETE event for a Rule has occured.

Supported API: false

Specified by:
notifyPostDelete in interface RuleCache
Parameters:
target -

notifyUpdate

public void notifyUpdate(Rule target)
Notify the cache that a wt.fc.PersistenceManagerEvent.UPDATE event for a Rule has occured.

Supported API: false

Specified by:
notifyUpdate in interface RuleCache
Parameters:
target -

performStartupProcess

protected void performStartupProcess()
                              throws ManagerException
Add listeners for the following events:

PRE_STORE

The StandardRuleService listens for PersistenceManagerEvent.PRE_STORE events. If AUTO_INIT is true, then in response to this event, it applies the appropriate INIT rule to the target object in order to supply default values for the object. The auto-initialization only occurs for the following types of objects:

This service also validates rules in response to this event. If the target of the event is a rule, then a validator is obtained and used to validate the rule. If the rule is not valid then the create is rejected.

POST_STORE

The StandardRuleService listens for PersistenceManagerEvent.POST_STORE events. When it receives a POST_STORE event it checks to see if there are any tasks to be performed on the object. If there is, it performs those tasks (see wt.rule.RuleService#addPostStoreTask for more details). If it detects that a Rule has been created, it calls notifyPostStore on all the RuleCaches it manages that have registed for the RuleType of the that was created.

POST_DELETE

The StandardRuleService listens for PersistenceManagerEvent.POST_DELETE events. If it detects that a Rule has been deleted, it calls notifyPostDelete on all the RuleCaches it manages that have registed for the RuleType of the rule that was deleted.

PRE_MODIFY

The StandardRuleService listens for PersistenceManagerEvent.PRE_MODIFY events. If it detects that a rule is being modified then a validator is obtained and used to validate the rule. If the rule is not valid then the modification is rejected.

UPDATE

The StandardRuleService listens for PersistenceManagerEvent.UPDATE events. If it detects that a Rule has been updated, it calls notifyUpdate on all the RuleCaches it manages that have registed for the RuleType of the rule that has been updated.

Overrides:
performStartupProcess in class StandardManager
Throws:
ManagerException

validateRule

private void validateRule(Rule rule)
                   throws WTException
Throws:
WTException

getSelectorFactory

private RuleSelectorFactory getSelectorFactory()
Get the RuleSelectorFactory used by this service to obtain RuleSelectors.


getApplierFactory

private RuleApplierFactory getApplierFactory()
Get the RuleApplierFactory used by this service to obtain RuleAppliers.


getMergerFactory

private RuleMergerFactory getMergerFactory()
Get the RuleMergerFactory used by this service to obtain RuleMergers.


getValidatorFactory

private RuleValidatorFactory getValidatorFactory()
Get the RuleValidatorFactory used by this service to obtain RuleValidators.