org.deduced.framework
Class RuleDeducedProperty<E>

java.lang.Object
  extended by org.deduced.PropertyImplementation<E>
      extended by org.deduced.framework.RuleDeducedProperty<E>
Type Parameters:
E - the type of object being held in the property
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.EventListener, DeducedProperty<E>, Property<E>, PropertyListener<java.lang.Object,java.lang.Object>

public class RuleDeducedProperty<E>
extends PropertyImplementation<E>
implements PropertyListener<java.lang.Object,java.lang.Object>, DeducedProperty<E>

RuleDeducedProperty is a property implementation that holds a property where the value is controlled by a deduction rule. This object has the responsibility to trigger the change events on all the other objects where the rule apply.

Author:
Steve McDuff
See Also:
Serialized Form

Nested Class Summary
protected static class RuleDeducedProperty.ParameterFetcher
          ParameterFetcher is a class used to breakdown a list of parameters while fetching inputs.
 
Field Summary
private  DeductionRuleAnalyzer<E> analyzer
          analyzer used for the rule
private  RuleExecutionContext context
          rule execution context
private static boolean DEBUG_RULES
          flag used to enable or disable rule debugging.
private static java.util.logging.Logger LOGGER
          logger
private  PropertyCollection<?,?> parent
          property collection that holds the rule
private  PropertyCollection rule
          model of the deduction rule
private  ListenTargetTracker<java.lang.Object,java.lang.Object> ruleTriggerTracker
          list of all the collections to which we listen to for changes in case we need to trigger the rule.
private static long serialVersionUID
          serial ID
 
Constructor Summary
RuleDeducedProperty(PropertyCollection<?,?> instance, PropertyCollection<?,?> setParent, PropertyCollection<?,?> setRule, DeductionRuleAnalyzer<E> setAnalyzer, RuleExecutionContext setContext)
          RuleDeducedProperty Constructor
 
Method Summary
private  void addAllTriggers()
          add All Triggers required to be monitored to execute a rule
private  void addListenerChainSkipLast(PropertyCollection<?,?> newValue, PropertyCollection<?,?> instanceReference, int index)
          add a Listener Chain and Skip the last level since it doesn't need listeners at this point.
private  void addTrigger(PropertyCollection<?,?> newValue)
          add a listener to a collection that could trigger the rule
private static java.util.List<java.lang.Object> breakList(java.util.List<?> returnArray, java.lang.Object childKey, boolean splitSubList)
          break a list of values to fetch a sub value based on a key in each element
private  boolean checkAllEventChain(PropertyChangeEvent<?,?> event)
          check All inputs to see if an event triggered them
private  boolean checkEventChain(PropertyChangeEvent<?,?> event, PropertyCollection<?,?> listenerChain, PropertyCollection<?,?> instance, int index)
          check a chain of possible triggers on an event, move listeners if required
private  boolean checkListEventChain(PropertyChangeEvent<?,?> event, PropertyCollection<?,?> listenerChain, int index, PropertyCollection<?,?> subImplementation)
          check a chain of possible triggers on an event, move listeners if required
private  void clearTriggerList()
          clear the trigger list
 void delete()
          (non-Javadoc)
private  void executeRule()
          execute Rule
private static void fetchNextLevelOfValues(PropertyCollection<?,?> input, PropertyCollection<?,?> rule, RuleDeducedProperty.ParameterFetcher fetcher, java.util.Iterator<?> iterator, PropertyCollection<?,?> propertyInstance)
          fetch Next Level Of Values
private static java.lang.Object fetchParameterFromKeyList(PropertyCollection<?,?> startPoint, PropertyCollection<?,?> input, PropertyCollection<?,?> rule, boolean skipLast)
          fetch all the values that match the defined input by starting at the specified start point and digging down the property tree
private static PropertyCollection<?,?> fetchPotentialValueFixedInstance(java.lang.Object currentReturnValue)
          fetch Potential Value Fixed Instance
private static PropertyCollection<?,?> fetchStartCollection(PropertyCollection<?,?> ruleParent, PropertyCollection<?,?> instanceReference)
          fetch the collection that is used as a starting point to analyze an instance reference.
private  void fireChangeEventIfNecessary(E newValue, E oldValue)
          fire Change Event If Necessary
private  void fireNewValueChange(E newValue, E oldValue)
          fire New Value Change
private  void fireNewValueOnOutput(E newValue, E oldValue, PropertyCollection<?,?> lastInstance, java.lang.Integer instanceKey, java.lang.Object output)
          fire New Value On Output
 PropertyCollection<?,?> getParent()
          (non-Javadoc)
 PropertyCollection<?,?> getRule()
          (non-Javadoc)
static java.util.List<PropertyCollection<java.lang.Integer,java.lang.Object>> getRuleOutputList(PropertyCollection<?,?> startPoint, PropertyCollection<?,?> rule)
          get Rule Output List
private static boolean isListInstance(PropertyCollection<?,?> propertyInstance)
          is List Instance
private static boolean isNextInstanceInInputValidForList(PropertyCollection<?,?> input, PropertyCollection<?,?> rule, PropertyCollection<?,?> propertyInstance, boolean isPropertyCollectionList, PropertyCollection<?,?> fixedInstance, PropertyCollection<?,?> listItemPropertyInstance)
          is the Next Instance In Input Valid For List
private static boolean isSplittingOfSingleListRequired(java.util.Iterator<?> iterator, boolean isPropertyCollectionList, PropertyCollection<?,?> fixedInstance, java.lang.Object currentRetVal)
          test if Splitting Of Single List is Required
private static boolean isSplittingOfSubListRequired(PropertyCollection<?,?> input, PropertyCollection<?,?> rule, RuleDeducedProperty.ParameterFetcher fetcher, java.util.Iterator<?> iterator, PropertyCollection<?,?> propertyInstance, java.util.List<?> currentValue)
          is Splitting Of Sub List Required
private  void logRuleExecutionException(java.lang.Exception e)
          log Rule Execution Exception
private  void moveListenerChainSkipLast(PropertyChangeEvent<?,?> event, PropertyCollection<?,?> propertyKey, int index)
          move collection Listener Chain and Skip the last level since it doesn't need listeners at this point.
private  void moveListenerChainSkipLast(PropertyCollection<?,?> propertyKey, PropertyCollection<?,?> oldValue, PropertyCollection<?,?> newValue, int index)
          move List Listener Chain and Skip the last level since it doesn't need listeners at this point.
private  void moveListListenerChainSkipLast(PropertyChangeEvent<?,?> event, PropertyCollection<?,?> propertyKey, int index)
          move List Listener Chain and Skip the last level since it doesn't need listeners at this point.
 void propertyChanged(PropertyChangeEvent<?,?> event)
          (non-Javadoc)
private  void removeListenerChainSkipLast(PropertyCollection<?,?> oldValue, PropertyCollection<?,?> propertyKey, int index)
          remove Listener Chain and Skip the Last level since we didn't put listeners on it.
private  void removeTrigger(PropertyCollection<?,?> oldValue)
          remove a listener on a collection that can't trigger the rule anymore
static boolean validateListChildInstance(PropertyCollection<?,?> input, PropertyCollection<?,?> listItemPropertyInstance, PropertyCollection<?,?> listInstance, PropertyCollection<?,?> rule)
          validate List Child Instance matches the expected list instance
 
Methods inherited from class org.deduced.PropertyImplementation
arePropertiesEqual, arePropertyValuesEqual, clonePropertyValue, copy, equals, getInstance, getValue, getValueType, hashCode, isValueEqual, resetParentOnValue, setValue, setValueOnProperty, setValueParent, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.deduced.Property
copy, getInstance, getValue, getValueType, isValueEqual, setValue
 

Field Detail

LOGGER

private static final java.util.logging.Logger LOGGER
logger


serialVersionUID

private static final long serialVersionUID
serial ID

See Also:
Constant Field Values

DEBUG_RULES

private static final boolean DEBUG_RULES
flag used to enable or disable rule debugging. Setting this flag to true will trigger a log event of the FINEST level for each change in value

See Also:
Constant Field Values

analyzer

private DeductionRuleAnalyzer<E> analyzer
analyzer used for the rule


parent

private PropertyCollection<?,?> parent
property collection that holds the rule


rule

private PropertyCollection rule
model of the deduction rule


ruleTriggerTracker

private ListenTargetTracker<java.lang.Object,java.lang.Object> ruleTriggerTracker
list of all the collections to which we listen to for changes in case we need to trigger the rule.


context

private RuleExecutionContext context
rule execution context

Constructor Detail

RuleDeducedProperty

public RuleDeducedProperty(PropertyCollection<?,?> instance,
                           PropertyCollection<?,?> setParent,
                           PropertyCollection<?,?> setRule,
                           DeductionRuleAnalyzer<E> setAnalyzer,
                           RuleExecutionContext setContext)
RuleDeducedProperty Constructor

Parameters:
instance - instance of the rule output
setParent - object that owns the rule
setRule - the deduction rule model
setAnalyzer - the deduction rule analyzer
setContext - the rule execution context
Method Detail

getRule

public PropertyCollection<?,?> getRule()
(non-Javadoc)

Specified by:
getRule in interface DeducedProperty<E>
Returns:
the deduction rule model
See Also:
DeducedProperty.getRule()

addAllTriggers

private void addAllTriggers()
add All Triggers required to be monitored to execute a rule


fetchStartCollection

private static PropertyCollection<?,?> fetchStartCollection(PropertyCollection<?,?> ruleParent,
                                                            PropertyCollection<?,?> instanceReference)
fetch the collection that is used as a starting point to analyze an instance reference. There are 2 kinds of instance reference : those that start from the collection that owns the rule and those that start from a statically referenced collection.

Parameters:
ruleParent - the parent of the rule
instanceReference - the instance reference to use
Returns:
the instance reference starting point

propertyChanged

public void propertyChanged(PropertyChangeEvent<?,?> event)
(non-Javadoc)

Specified by:
propertyChanged in interface PropertyListener<java.lang.Object,java.lang.Object>
Parameters:
event - the event that was generated
See Also:
PropertyListener.propertyChanged(org.deduced.PropertyChangeEvent)

executeRule

private void executeRule()
execute Rule


logRuleExecutionException

private void logRuleExecutionException(java.lang.Exception e)
log Rule Execution Exception

Parameters:
e - the unexpected exception

fireChangeEventIfNecessary

private void fireChangeEventIfNecessary(E newValue,
                                        E oldValue)
fire Change Event If Necessary

Parameters:
newValue - the property new value
oldValue - the property new value

fireNewValueChange

private void fireNewValueChange(E newValue,
                                E oldValue)
fire New Value Change

Parameters:
newValue - the property new value
oldValue - the property old value

getRuleOutputList

public static java.util.List<PropertyCollection<java.lang.Integer,java.lang.Object>> getRuleOutputList(PropertyCollection<?,?> startPoint,
                                                                                                       PropertyCollection<?,?> rule)
get Rule Output List

Parameters:
startPoint - the point where the rule is executed
rule - the rule model
Returns:
the list of property collections that are affected by the rule.

fireNewValueOnOutput

private void fireNewValueOnOutput(E newValue,
                                  E oldValue,
                                  PropertyCollection<?,?> lastInstance,
                                  java.lang.Integer instanceKey,
                                  java.lang.Object output)
fire New Value On Output

Parameters:
newValue - the new property value
oldValue - the old property value
lastInstance - the property instance of the property
instanceKey - the instance key
output - the collection that was modified by this event

fetchParameterFromKeyList

private static java.lang.Object fetchParameterFromKeyList(PropertyCollection<?,?> startPoint,
                                                          PropertyCollection<?,?> input,
                                                          PropertyCollection<?,?> rule,
                                                          boolean skipLast)
fetch all the values that match the defined input by starting at the specified start point and digging down the property tree

Parameters:
startPoint - the key list start point
input - the JavaRuleInput containing a key list
rule - the rule model
skipLast - option to skip the last level of the key list. Useful to extract the list of collections that contain the last level of values.
Returns:
the final value at the end of the key list

fetchNextLevelOfValues

private static void fetchNextLevelOfValues(PropertyCollection<?,?> input,
                                           PropertyCollection<?,?> rule,
                                           RuleDeducedProperty.ParameterFetcher fetcher,
                                           java.util.Iterator<?> iterator,
                                           PropertyCollection<?,?> propertyInstance)
fetch Next Level Of Values

Parameters:
input - the rule input
rule - the rule we are fetching information for
fetcher - the current fetching results
iterator - the input instance iterator
propertyInstance - the current instance we are fetching

isNextInstanceInInputValidForList

private static boolean isNextInstanceInInputValidForList(PropertyCollection<?,?> input,
                                                         PropertyCollection<?,?> rule,
                                                         PropertyCollection<?,?> propertyInstance,
                                                         boolean isPropertyCollectionList,
                                                         PropertyCollection<?,?> fixedInstance,
                                                         PropertyCollection<?,?> listItemPropertyInstance)
is the Next Instance In Input Valid For List

Parameters:
input - the input we are validating
rule - the rule which contains the input
propertyInstance - the current property instance
isPropertyCollectionList - is the instance a property collection list
fixedInstance - the required list fixed instance
listItemPropertyInstance - the actual next instance in the input list
Returns:
true if the input order matches the actual schema structure

isSplittingOfSingleListRequired

private static boolean isSplittingOfSingleListRequired(java.util.Iterator<?> iterator,
                                                       boolean isPropertyCollectionList,
                                                       PropertyCollection<?,?> fixedInstance,
                                                       java.lang.Object currentRetVal)
test if Splitting Of Single List is Required

Parameters:
iterator - the input iterator
isPropertyCollectionList - is the current
fixedInstance - the actual fixed instance of the current value we are splitting
currentRetVal - the current value we are splitting
Returns:
true if a list split is required

fetchPotentialValueFixedInstance

private static PropertyCollection<?,?> fetchPotentialValueFixedInstance(java.lang.Object currentReturnValue)
fetch Potential Value Fixed Instance

Parameters:
currentReturnValue - the current value
Returns:
the fixed instance associated with the value, if there is one

isSplittingOfSubListRequired

private static boolean isSplittingOfSubListRequired(PropertyCollection<?,?> input,
                                                    PropertyCollection<?,?> rule,
                                                    RuleDeducedProperty.ParameterFetcher fetcher,
                                                    java.util.Iterator<?> iterator,
                                                    PropertyCollection<?,?> propertyInstance,
                                                    java.util.List<?> currentValue)
is Splitting Of Sub List Required

Parameters:
input - the rule input we are splitting
rule - the rule we are analyzing
fetcher - the fetching results
iterator - the input iterator
propertyInstance - the current instance we are potentially splitting
currentValue - the list of current values
Returns:
true if we need to further split down the list of current values. Can also set the fetcher.searchFailed flag to true if the input list isn't coherent.

isListInstance

private static boolean isListInstance(PropertyCollection<?,?> propertyInstance)
is List Instance

Parameters:
propertyInstance - the possible list instance
Returns:
true if the instance is a list instance

validateListChildInstance

public static boolean validateListChildInstance(PropertyCollection<?,?> input,
                                                PropertyCollection<?,?> listItemPropertyInstance,
                                                PropertyCollection<?,?> listInstance,
                                                PropertyCollection<?,?> rule)
validate List Child Instance matches the expected list instance

Parameters:
input - rule input model
listItemPropertyInstance - the property instance used in the list
listInstance - the expected list instance from the rule
rule - the deduction rule model
Returns:
true if the instance is valid

breakList

private static java.util.List<java.lang.Object> breakList(java.util.List<?> returnArray,
                                                          java.lang.Object childKey,
                                                          boolean splitSubList)
break a list of values to fetch a sub value based on a key in each element

Parameters:
returnArray - the array of value to fetch the sub value
childKey - the key of the sub value
splitSubList - option to also break the sub values right away in the output
Returns:
the list of sub objects

checkAllEventChain

private boolean checkAllEventChain(PropertyChangeEvent<?,?> event)
check All inputs to see if an event triggered them

Parameters:
event - the event that was monitored
Returns:
true if the event might have triggered a change in the rule

checkEventChain

private boolean checkEventChain(PropertyChangeEvent<?,?> event,
                                PropertyCollection<?,?> listenerChain,
                                PropertyCollection<?,?> instance,
                                int index)
check a chain of possible triggers on an event, move listeners if required

Parameters:
event - the event that was triggered
listenerChain - the instance reference object used to create the listener chain
instance - the current instance being monitored
index - index of they key in the instance reference
Returns:
true if the event triggered a change in the input

checkListEventChain

private boolean checkListEventChain(PropertyChangeEvent<?,?> event,
                                    PropertyCollection<?,?> listenerChain,
                                    int index,
                                    PropertyCollection<?,?> subImplementation)
check a chain of possible triggers on an event, move listeners if required

Parameters:
event - the event that was triggered
listenerChain - the instance reference object used to create the listener chain
subImplementation - the current instance being monitored
index - index of they key in the instance reference
Returns:
true if the event triggered a change in the input

moveListListenerChainSkipLast

private void moveListListenerChainSkipLast(PropertyChangeEvent<?,?> event,
                                           PropertyCollection<?,?> propertyKey,
                                           int index)
move List Listener Chain and Skip the last level since it doesn't need listeners at this point.

Parameters:
event - the event that was triggered
propertyKey - the instance reference that changed
index - index of they key in the instance reference

moveListenerChainSkipLast

private void moveListenerChainSkipLast(PropertyChangeEvent<?,?> event,
                                       PropertyCollection<?,?> propertyKey,
                                       int index)
move collection Listener Chain and Skip the last level since it doesn't need listeners at this point.

Parameters:
event - the event that was triggered
propertyKey - the instance reference that changed
index - index of they key in the instance reference

moveListenerChainSkipLast

private void moveListenerChainSkipLast(PropertyCollection<?,?> propertyKey,
                                       PropertyCollection<?,?> oldValue,
                                       PropertyCollection<?,?> newValue,
                                       int index)
move List Listener Chain and Skip the last level since it doesn't need listeners at this point.

Parameters:
propertyKey - the instance reference that changed
oldValue - the value that we don't need to listen to anymore
newValue - the new value we should listen to now
index - index of they key in the instance reference

addListenerChainSkipLast

private void addListenerChainSkipLast(PropertyCollection<?,?> newValue,
                                      PropertyCollection<?,?> instanceReference,
                                      int index)
add a Listener Chain and Skip the last level since it doesn't need listeners at this point.

Parameters:
instanceReference - the instance reference that changed
newValue - the new value we should listen to now
index - index of they key in the instance reference

addTrigger

private void addTrigger(PropertyCollection<?,?> newValue)
add a listener to a collection that could trigger the rule

Parameters:
newValue - the collection to listen to

delete

public void delete()
(non-Javadoc)

Specified by:
delete in interface DeducedProperty<E>
See Also:
DeducedProperty.delete()

clearTriggerList

private void clearTriggerList()
clear the trigger list


removeListenerChainSkipLast

private void removeListenerChainSkipLast(PropertyCollection<?,?> oldValue,
                                         PropertyCollection<?,?> propertyKey,
                                         int index)
remove Listener Chain and Skip the Last level since we didn't put listeners on it.

Parameters:
oldValue - the old value we don't need to listen to anymore
propertyKey - the instance reference being used
index - the index of the key in the instance reference

removeTrigger

private void removeTrigger(PropertyCollection<?,?> oldValue)
remove a listener on a collection that can't trigger the rule anymore

Parameters:
oldValue - the collection we don't need to listen to anymore

getParent

public PropertyCollection<?,?> getParent()
(non-Javadoc)

Specified by:
getParent in interface DeducedProperty<E>
Returns:
the collection that owns the rule
See Also:
DeducedProperty.getParent()