org.deduced.dynamic
Class RuleDeducedProperty<E>

java.lang.Object
  extended by org.deduced.PropertyImplementation<E>
      extended by org.deduced.dynamic.AbstractDeducedProperty<E>
          extended by org.deduced.dynamic.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 AbstractDeducedProperty<E>
implements PropertyListener<java.lang.Object,java.lang.Object>

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

Field Summary
private  DeductionRuleAnalyzer<E> analyzer
          analyzer used for the rule
private static boolean DEBUG_RULES
          flag used to enable or disable rule debugging.
private static java.util.logging.Logger LOGGER
          logger
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, ContextualPropertyCollection<?,?> setParent, PropertyCollection<?,?> setRule, DeductionRuleAnalyzer<E> setAnalyzer, E initialValue)
          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
 void applyRuleOverrideOnNewValueIfNecessary(E newValue, PropertyCollection<?,?> lastInstance, java.lang.Object objectOutput, boolean isReference)
          apply Rule Override On New Value If Necessary
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 checkEventChainOnChild(PropertyChangeEvent<?,?> event, PropertyCollection<?,?> listenerChain, int index, PropertyCollection<?,?> childCollection)
          check a chain of possible triggers on an event by looking at a specific child value, 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)
 void deleteOldValueIfNecessary(E oldValue, boolean isReference)
          delete Old Value If Necessary
protected  void executeRule()
          (non-JSDoc)
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.Object instanceKey, java.lang.Object output)
          fire New Value On Output
static java.util.List<PropertyCollection<java.lang.Object,java.lang.Object>> getRuleOutputList(PropertyCollection<?,?> startPoint, PropertyCollection<?,?> rule)
          get Rule Output List
private  boolean isEventRelatedToRuleInput(PropertyChangeEvent<?,?> event, PropertyCollection<?,?> currentRuleInputCollection, PropertyCollection<?,?> currentInputInstance)
          test if an event is related to a rule input by verifying if it is either the "All Property Values" instance, or the event instance matches the current collection fixed instance or the current event key matches the rule input key.
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
 void updateParentOnValueChange(E newValue, E oldValue, java.lang.Object instanceKey, PropertyCollection<?,?> startCollection, boolean isReference)
          update Parent On Value Change
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.dynamic.AbstractDeducedProperty
decrementUseCounter, executeRuleAnalyzer, getParent, getRule, getUseCounter, incrementUseCounter, logRuleExecutionException
 
Methods inherited from class org.deduced.PropertyImplementation
arePropertiesEqual, arePropertyValuesEqual, clonePropertyValue, copy, equals, getInstance, getValue, getValueType, hashCode, isValueEqual, resetParentOnValue, setInstance, 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


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.

Constructor Detail

RuleDeducedProperty

public RuleDeducedProperty(PropertyCollection<?,?> instance,
                           ContextualPropertyCollection<?,?> setParent,
                           PropertyCollection<?,?> setRule,
                           DeductionRuleAnalyzer<E> setAnalyzer,
                           E initialValue)
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
initialValue - initial value to use in case the rule execution fails
Method Detail

addAllTriggers

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


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

protected void executeRule()
(non-JSDoc)

Specified by:
executeRule in class AbstractDeducedProperty<E>
See Also:
AbstractDeducedProperty.executeRule()

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

applyRuleOverrideOnNewValueIfNecessary

public void applyRuleOverrideOnNewValueIfNecessary(E newValue,
                                                   PropertyCollection<?,?> lastInstance,
                                                   java.lang.Object objectOutput,
                                                   boolean isReference)
apply Rule Override On New Value If Necessary

Parameters:
newValue - the new value
lastInstance - the instance for the new value
objectOutput - the object on which the override might apply
isReference - is the new value a reference

deleteOldValueIfNecessary

public void deleteOldValueIfNecessary(E oldValue,
                                      boolean isReference)
delete Old Value If Necessary

Parameters:
oldValue - the old value
isReference - is the old value a reference

updateParentOnValueChange

public void updateParentOnValueChange(E newValue,
                                      E oldValue,
                                      java.lang.Object instanceKey,
                                      PropertyCollection<?,?> startCollection,
                                      boolean isReference)
update Parent On Value Change

Parameters:
newValue - the new value
oldValue - the old value
instanceKey - the instance key
startCollection - the collection that will potentially be the new parent
isReference - is the new value a reference.

getRuleOutputList

public static java.util.List<PropertyCollection<java.lang.Object,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.Object 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

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

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

isEventRelatedToRuleInput

private boolean isEventRelatedToRuleInput(PropertyChangeEvent<?,?> event,
                                          PropertyCollection<?,?> currentRuleInputCollection,
                                          PropertyCollection<?,?> currentInputInstance)
test if an event is related to a rule input by verifying if it is either the "All Property Values" instance, or the event instance matches the current collection fixed instance or the current event key matches the rule input key.

Parameters:
event - the current change event
currentRuleInputCollection - the collection that might be related to the change event
currentInputInstance - the rule input instance being analyzed
Returns:
true if the event is related, false otherwise

checkEventChainOnChild

private boolean checkEventChainOnChild(PropertyChangeEvent<?,?> event,
                                       PropertyCollection<?,?> listenerChain,
                                       int index,
                                       PropertyCollection<?,?> childCollection)
check a chain of possible triggers on an event by looking at a specific child value, move listeners if required

Parameters:
event - the event that was triggered
listenerChain - the instance reference object used to create the listener chain
index - index of they key in the instance reference
childCollection - the child collection for which we want to verify if the event might be related.
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>
Overrides:
delete in class AbstractDeducedProperty<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