Package sc.bind
Class VariableBinding
- java.lang.Object
-
- sc.bind.AbstractListener
-
- sc.bind.DestinationListener
-
- sc.bind.VariableBinding
-
- Direct Known Subclasses:
ArrayElementBinding
public class VariableBinding extends DestinationListener
VariableBinding manages an instance of a binding expression like "a.b.c". It has a direction attribute - for which way to apply the binding: forward, reverse, or bi-directional. It has a list of the properties "a.b.c" in the binding. It computes the current array of intermediate or last known values of the binding and stores them in the bound values. The dstObj is the object who "owns" the binding - the one which defined it. If this is the top-level binding in an expression, the dstObj is the object which defined the expression. If not, the dstObj is the parent object in the binding expression. In this case, the dstProp==dstObj. The binding is applied to the destination property which we store both in terms of its property id and the index of that property in the property table of the dstObj's type.The bound parent is the evaluated parent of the leaf reference. It is not the value of the binding, but the object whose property is being bound to. If we are evaluating the reverse binding, we are setting a property on the bound parent. The bound value is the current value of the binding.
If any node along the binding chain evaluated to null, the bound value is null.
As intermediate nodes change, we have to remove and re-add our listeners on the intermediate objects. If the binding is a forward binding, we add listeners onto the boundProps and cache the binding's current state in the boundValues array. If the binding is reverse only, we do not cache the values - instead they are evaluated each time the binding fires.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface sc.bind.IListener
IListener.SyncType
-
-
Field Summary
-
Fields inherited from interface sc.bind.IListener
ARRAY_ELEMENT_CHANGED, ARRAY_ELEMENT_INVALIDATED, ARRAY_ELEMENT_VALIDATED, LISTENER_ADDED, PENDING_VALUE_SENTINEL, UNSET_VALUE_SENTINEL, VALUE_CHANGED, VALUE_CHANGED_MASK, VALUE_INVALIDATED, VALUE_REQUESTED, VALUE_VALIDATED
-
-
Constructor Summary
Constructors Constructor Description VariableBinding(java.lang.Object srcObject, java.lang.Object[] boundProperties)
Use this form for chaining together this binding with another bindingVariableBinding(java.lang.Object dstObject, IBinding dstProperty, java.lang.Object srcObject, java.lang.Object[] boundProperties, BindingDirection bindingDirection, int flags, BindOptions opts)
Use this form for a top level binding
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accessBinding()
void
activate(boolean state, java.lang.Object obj, boolean chained)
Called to deactive/re-activate a child binding for a condition or ternary expressionvoid
addBindingListener(java.lang.Object eventObject, IListener listener, int event)
These are implemented for VariableBindings but not for AbstractMethodBindings.boolean
applyBinding(java.lang.Object obj, java.lang.Object value, IBinding src, boolean refresh, boolean pendingChild)
protected void
applyPendingChildValue(java.lang.Object val, IBinding src)
protected boolean
applyReverseBinding()
void
applyReverseBinding(java.lang.Object obj, java.lang.Object value, java.lang.Object src)
protected void
bindingInvalidated(boolean apply)
protected boolean
cacheValue()
protected boolean
equalValues(int index, java.lang.Object newValue)
protected java.lang.Object
getBoundParent()
Returns the parent of the last valueprotected java.lang.Object
getBoundProperty()
Returns the last property in the chainprotected java.lang.Object
getBoundProperty(java.lang.Object bindingParent, int i)
protected java.lang.Object
getBoundValue(boolean pendingChild)
protected java.lang.Object
getBoundValueForChild(IBinding child)
java.lang.Object
getChainElement(int ix)
Returns the String property name, IBinding, or IBeanMapperint
getNumInChain()
Number of properties in the binding - e.g.java.lang.Object
getPropertyValue(java.lang.Object obj, boolean getField, boolean pendingChild)
Retrieves the current value of the binding given the current object.ISet<java.lang.Object>
getReads()
ISet<java.lang.Object>
getWrites()
protected void
initBinding()
protected void
initFlagsOnChildren(int flags)
java.lang.Object
initializeBinding()
Called to initialize and retrieve the value of a top-level bindingvoid
invalidateBinding(java.lang.Object obj, boolean sendEvent, int event, boolean includeParams)
boolean
isConstant()
boolean
isReversible()
boolean
isValid()
protected void
reactivate(java.lang.Object obj)
int
refreshBinding()
void
removeBindingListener(java.lang.Object eventObject, IListener listener, int event)
void
removeListener()
protected boolean
sameValues(int index, java.lang.Object newValue)
void
setBindingParent(IBinding parent, BindingDirection dir)
Called by the parent when this is a hierarchical binding - i.e.java.lang.String
toString(java.lang.String operation, boolean displayValue)
protected boolean
validateBinding()
protected boolean
validateBinding(int validateTo)
boolean
valueInvalidated(java.lang.Object srcObject, java.lang.Object srcProp, java.lang.Object eventDetail, boolean apply)
void
valueRequested(java.lang.Object obj, IBeanMapper prop)
boolean
valueValidated(java.lang.Object srcObject, java.lang.Object srcProp, java.lang.Object eventDetail, boolean apply)
-
Methods inherited from class sc.bind.DestinationListener
accessObj, addCurrentScopeContext, getCurrentScopeContexts, getTrace, getUnsetOrPending, getVerbose, initFlags, isCrossScope, isDefinedObject, isValidObject, toString, toString
-
Methods inherited from class sc.bind.AbstractListener
arrayElementChanged, arrayElementInvalidated, arrayElementValidated, getPriority, getSync, listenerAdded, parentBindingChanged, performCast, valueChanged, valueRequested
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface sc.bind.IBinding
parentBindingChanged, performCast
-
-
-
-
Constructor Detail
-
VariableBinding
public VariableBinding(java.lang.Object srcObject, java.lang.Object[] boundProperties)
Use this form for chaining together this binding with another binding
-
VariableBinding
public VariableBinding(java.lang.Object dstObject, IBinding dstProperty, java.lang.Object srcObject, java.lang.Object[] boundProperties, BindingDirection bindingDirection, int flags, BindOptions opts)
Use this form for a top level binding
-
-
Method Detail
-
isValid
public boolean isValid()
- Specified by:
isValid
in classDestinationListener
-
setBindingParent
public void setBindingParent(IBinding parent, BindingDirection dir)
Called by the parent when this is a hierarchical binding - i.e. one expression in another
-
initializeBinding
public java.lang.Object initializeBinding()
Called to initialize and retrieve the value of a top-level binding
-
initBinding
protected void initBinding()
-
cacheValue
protected boolean cacheValue()
-
reactivate
protected void reactivate(java.lang.Object obj)
-
getNumInChain
public int getNumInChain()
Number of properties in the binding - e.g. a.b.c = 3
-
getChainElement
public java.lang.Object getChainElement(int ix)
Returns the String property name, IBinding, or IBeanMapper
-
getBoundProperty
protected java.lang.Object getBoundProperty()
Returns the last property in the chain
-
getBoundParent
protected java.lang.Object getBoundParent()
Returns the parent of the last value
-
getBoundValue
protected java.lang.Object getBoundValue(boolean pendingChild)
-
removeListener
public void removeListener()
-
valueRequested
public void valueRequested(java.lang.Object obj, IBeanMapper prop)
-
valueInvalidated
public boolean valueInvalidated(java.lang.Object srcObject, java.lang.Object srcProp, java.lang.Object eventDetail, boolean apply)
- Specified by:
valueInvalidated
in interfaceIListener
- Overrides:
valueInvalidated
in classAbstractListener
-
valueValidated
public boolean valueValidated(java.lang.Object srcObject, java.lang.Object srcProp, java.lang.Object eventDetail, boolean apply)
- Specified by:
valueValidated
in interfaceIListener
- Overrides:
valueValidated
in classAbstractListener
-
getBoundProperty
protected java.lang.Object getBoundProperty(java.lang.Object bindingParent, int i)
-
validateBinding
protected boolean validateBinding()
-
validateBinding
protected boolean validateBinding(int validateTo)
-
bindingInvalidated
protected void bindingInvalidated(boolean apply)
-
sameValues
protected boolean sameValues(int index, java.lang.Object newValue)
-
equalValues
protected boolean equalValues(int index, java.lang.Object newValue)
-
applyReverseBinding
protected boolean applyReverseBinding()
-
getReads
public ISet<java.lang.Object> getReads()
-
getWrites
public ISet<java.lang.Object> getWrites()
-
invalidateBinding
public void invalidateBinding(java.lang.Object obj, boolean sendEvent, int event, boolean includeParams)
-
applyBinding
public boolean applyBinding(java.lang.Object obj, java.lang.Object value, IBinding src, boolean refresh, boolean pendingChild)
-
applyReverseBinding
public void applyReverseBinding(java.lang.Object obj, java.lang.Object value, java.lang.Object src)
-
getPropertyValue
public java.lang.Object getPropertyValue(java.lang.Object obj, boolean getField, boolean pendingChild)
Description copied from interface:IBinding
Retrieves the current value of the binding given the current object. Use getField = true to force use of the field, rather than the getX method if one exists. Use pendingChild = true for a special case where we are getting the property value of a binding that is part of a reverse binding but where the cached value is up-to-update because we are updating a child remote property.
-
addBindingListener
public void addBindingListener(java.lang.Object eventObject, IListener listener, int event)
These are implemented for VariableBindings but not for AbstractMethodBindings. These listeners are invoked when the previous binding in the chain's value changes. Since the bound props of the variable binding depend on the value of the previous value, we need to remove/re-add them on any upstream change. Method parameters listeners do not respond to changes in the previous value so they don't implement this method.
-
removeBindingListener
public void removeBindingListener(java.lang.Object eventObject, IListener listener, int event)
-
isConstant
public boolean isConstant()
-
toString
public java.lang.String toString(java.lang.String operation, boolean displayValue)
- Overrides:
toString
in classDestinationListener
-
activate
public void activate(boolean state, java.lang.Object obj, boolean chained)
Description copied from interface:IBinding
Called to deactive/re-activate a child binding for a condition or ternary expression- Specified by:
activate
in interfaceIBinding
- Overrides:
activate
in classAbstractListener
-
refreshBinding
public int refreshBinding()
- Specified by:
refreshBinding
in classDestinationListener
-
accessBinding
public void accessBinding()
- Overrides:
accessBinding
in classDestinationListener
-
isReversible
public boolean isReversible()
-
applyPendingChildValue
protected void applyPendingChildValue(java.lang.Object val, IBinding src)
- Overrides:
applyPendingChildValue
in classDestinationListener
-
getBoundValueForChild
protected java.lang.Object getBoundValueForChild(IBinding child)
- Specified by:
getBoundValueForChild
in classDestinationListener
-
initFlagsOnChildren
protected void initFlagsOnChildren(int flags)
- Overrides:
initFlagsOnChildren
in classDestinationListener
-
-