cz.cuni.versatile.core
Class AbstractValueProvider

java.lang.Object
  extended bycz.cuni.versatile.core.AbstractValueProvider
All Implemented Interfaces:
ValueProvider
Direct Known Subclasses:
ConstantVP

public abstract class AbstractValueProvider
extends java.lang.Object
implements ValueProvider

The default implementation of the ValueProvider interface. It implements the chaining mechanism and all the methods which are generic, independent of a particular attributes/values context. When extending AbstractValueProvider only the following three methods need be implemented:

  1. the two-parameter constructor
  2. getLocalValue() method
  3. hasLocalValue() method

Author:
Jaroslav Gergic

Field Summary
protected  java.lang.String attrName
          Attribute name.
protected  ValueProvider defaultProvider
          Next-in-the-chain value provider (default).
 
Constructor Summary
AbstractValueProvider(java.lang.String attrName, ValueProvider defaultValue)
          Public Constructor
 
Method Summary
 java.lang.String getAttributeName()
          Returns attribute name.
 ValueProvider getDefault()
          Returns the next ValueProvider in the chain.
 java.lang.Object getValue()
          Returns attribute value.
 boolean hasValue()
          Checks whether the attribute is currently set.
 PreferenceChain toPreferenceChain()
          Takes the current snapshot of the ValueProvider chain returning a list of values in the ValueProvider chain.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cz.cuni.versatile.api.ValueProvider
getLocalValue, hasLocalValue
 

Field Detail

attrName

protected java.lang.String attrName
Attribute name.

See Also:
getAttributeName()

defaultProvider

protected ValueProvider defaultProvider
Next-in-the-chain value provider (default).

See Also:
getDefault()
Constructor Detail

AbstractValueProvider

public AbstractValueProvider(java.lang.String attrName,
                             ValueProvider defaultValue)
Public Constructor

Parameters:
attrName - an attribute name in a given attributes/values context
defaultValue - a default value provider (fall-back), can be null
Method Detail

getAttributeName

public final java.lang.String getAttributeName()
Description copied from interface: ValueProvider
Returns attribute name.

Specified by:
getAttributeName in interface ValueProvider
Returns:
a unique name of the attribute this ValueProvider is bound to.
See Also:
ValueProvider.getAttributeName()

getValue

public final java.lang.Object getValue()
Description copied from interface: ValueProvider
Returns attribute value. (Recursive for the entire chain of ValueProvider instances.)

Specified by:
getValue in interface ValueProvider
Returns:
the current value of the attribute at the time of invocation
See Also:
ValueProvider.getValue()

hasValue

public final boolean hasValue()
Description copied from interface: ValueProvider
Checks whether the attribute is currently set. (Recursive for the entire chain of ValueProvider instances.)

Specified by:
hasValue in interface ValueProvider
Returns:
true if the value is set for any ValueProvider in the chain, false otherwise
See Also:
ValueProvider.hasValue()

getDefault

public final ValueProvider getDefault()
Description copied from interface: ValueProvider
Returns the next ValueProvider in the chain.

Specified by:
getDefault in interface ValueProvider
Returns:
the next ValueProvider in the chain or null when invoked for the tail of the chain.
See Also:
ValueProvider.getDefault()

toPreferenceChain

public PreferenceChain toPreferenceChain()
Description copied from interface: ValueProvider
Takes the current snapshot of the ValueProvider chain returning a list of values in the ValueProvider chain. A value is appended to the chain for those value providers, where hasLocaleValue() returns true.

Remarks: Any item in the result PreferenceChain can be the desired property value as well as a PreferenceChain or a PreferenceBag of property values as returned by an individual ValueProvider in the chain. The purpose of this method is mainly for diagnostics (tuning and debugging).

Specified by:
toPreferenceChain in interface ValueProvider
Returns:
PreferenceChain object - a list of values - can be an empty list.
See Also:
ValueProvider.toPreferenceChain()