org.weborganic.furi
Class VariableResolverList

java.lang.Object
  extended by org.weborganic.furi.VariableResolverList
All Implemented Interfaces:
VariableResolver

public class VariableResolverList
extends Object
implements VariableResolver

A variable resolver using a list to resolve values. For example, to constrain a variable value to a specific list:

  // Create a new variable resolver on a list of values
  VariableResolver vr = new VariableResolverList(new String[]{"foo", "bar"});

  // Bind the variable resolver to variable type 'sample' (eg. {sample:test})
  VariableBinder binder = new VariableBinder();
  binder.bindType("sample", vr);
 

Version:
11 June 2009
Author:
Christophe Lauret
See Also:
VariableBinder

Constructor Summary
VariableResolverList()
          Creates a new variable resolver.
VariableResolverList(List<String> values)
          Creates a new variable resolver from the list of values.
VariableResolverList(String[] values)
          Creates a new variable resolver from the list of values.
 
Method Summary
 boolean exists(String value)
          Indicates whether the given value exists.
 Object resolve(String value)
          Resolves the variable and returns the associated object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VariableResolverList

public VariableResolverList()
Creates a new variable resolver.


VariableResolverList

public VariableResolverList(List<String> values)
Creates a new variable resolver from the list of values.

Parameters:
values - The list of values.

VariableResolverList

public VariableResolverList(String[] values)
Creates a new variable resolver from the list of values.

Parameters:
values - The list of values.
Method Detail

exists

public boolean exists(String value)
Indicates whether the given value exists. This method should return true only if the value can be resolved, that is resolve(value) != null.

Specified by:
exists in interface VariableResolver
Parameters:
value - The value to check for existence.
Returns:
true if the specified value can be resolved; false otherwise.

resolve

public Object resolve(String value)
Resolves the variable and returns the associated object. This method allows implementations to provide a lookup mechanism for variables if bound to particular objects. It must not return null if the value a value exists, but should return null, if the value cannot be resolved. If the implementation does not bind values to objects, this method should return the value if it can be resolved otherwise, it should return null.

Specified by:
resolve in interface VariableResolver
Parameters:
value - The value to resolve.
Returns:
Any associated object.