cz.cuni.versatile.api
Interface ValueProvider

All Known Implementing Classes:
AbstractValueProvider

public interface ValueProvider

ValueProvider interface represents a concept an attribute value getter, which can be chained in order to implement a particular fall-back strategy.

An implementation of the ValueProvider is specific to a particular value source, e.g. a flat-file, an XML file, relational database, HttpServletRequest, HttpSession, CC/PP profile and other. When instantiating a ValueProvider, the user must specify a unique name of an attribute and optionally can also provide a default -- another instance of the ValueProvider interface which is used as a fall-back in the case the attribute value is not set in the former ValueProvider instance. This defaulting principle can be applied recursively thus forming a chain of ValueProvider instances to implement a particular fall-back strategy: for example, to retrieve a value from command line parameters, if not set, than from a configuration file and eventually to fall-back to a built-in constant.

It is important to note that attribute name can differ for each ValueProvider in the chain as the same semantical entity can have different names in different contexts.

Author:
Jaroslav Gergic

Method Summary
 java.lang.String getAttributeName()
          Returns attribute name.
 ValueProvider getDefault()
          Returns the next ValueProvider in the chain.
 java.lang.Object getLocalValue()
          Returns attribute value.
 java.lang.Object getValue()
          Returns attribute value.
 boolean hasLocalValue()
          Checks whether the attribute is currently set.
 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.
 

Method Detail

getAttributeName

public java.lang.String getAttributeName()
Returns attribute name.

Returns:
a unique name of the attribute this ValueProvider is bound to.

getValue

public java.lang.Object getValue()
Returns attribute value. (Recursive for the entire chain of ValueProvider instances.)

Returns:
the current value of the attribute at the time of invocation

hasValue

public boolean hasValue()
Checks whether the attribute is currently set. (Recursive for the entire chain of ValueProvider instances.)

Returns:
true if the value is set for any ValueProvider in the chain, false otherwise

getLocalValue

public java.lang.Object getLocalValue()
Returns attribute value.

Returns:
the current value of the attribute at the time of invocation

hasLocalValue

public boolean hasLocalValue()
Checks whether the attribute is currently set.

Returns:
true if the value is set for this ValueProvider instance, false otherwise

getDefault

public ValueProvider getDefault()
Returns the next ValueProvider in the chain.

Returns:
the next ValueProvider in the chain or null when invoked for the tail of the chain.

toPreferenceChain

public PreferenceChain toPreferenceChain()
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).

Returns:
PreferenceChain object - a list of values - can be an empty list.