org.weborganic.furi
Class VariableBinder

java.lang.Object
  extended by org.weborganic.furi.VariableBinder

public class VariableBinder
extends Object

A convenience class is to bind variables to resolvers in a set of URI patterns. Variables can be bound to a resolver by type or by name. To assign a VariableResolver to variables of a specific type, use bindType(String, VariableResolver). The following example will bind all variables typed int to return the corresponding integer value.

   VariableBinder binder = new VariableBinder();
   b.bindType("int", new VariableResolver(){
     public boolean exists(String v) {return v.matches("\\d+");}
     public Integer resolve(String v) {return exists(v)? Integer.valueOf(v) : null;};
   });
 
To assign a VariableResolver to variables of a specific name, use bindName(String, VariableResolver). The following example will bind all variables typed int to return the corresponding integer value.
   VariableBinder binder = new VariableBinder();
   b.bindName("name", new VariableResolver(){
     public boolean exists(String v) {return true;}
     public Integer resolve(String v) {return exists(v)? Integer.valueOf(v) : null;};
   });
 

Version:
11 June 2009
Author:
Christophe Lauret

Constructor Summary
VariableBinder()
           
 
Method Summary
 void bind(String name, VariableResolver resolver)
          Deprecated. use #bindName() or #bindType() instead
 void bindName(String name, VariableResolver resolver)
          Binds the variables with the specified name to the specified resolver.
 void bindType(String type, VariableResolver resolver)
          Binds the variables with the specified name to the specified resolver.
 VariableResolver getResolver(String name)
          Returns the resolver used for the variable of the specified name.
 VariableResolver getResolver(String name, VariableType type)
          Returns the resolver used for the variable of the specified name or type.
 VariableResolver getResolver(VariableType type)
          Returns the resolver used for the variable of the specified type.
 boolean isNameBound(String name)
          Indicates whether the given variable name is bound to a VariableResolver.
 boolean isTypeBound(String type)
          Indicates whether the given variable type is bound to a VariableResolver.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VariableBinder

public VariableBinder()
Method Detail

bind

public void bind(String name,
                 VariableResolver resolver)
Deprecated. use #bindName() or #bindType() instead

Binds the variables with the specified name to the specified resolver.

Parameters:
name - The name of the variable.
resolver - The resolver to use with these variables.

bindName

public void bindName(String name,
                     VariableResolver resolver)
Binds the variables with the specified name to the specified resolver.

Parameters:
name - The name of the variable.
resolver - The resolver to use with these variables.

bindType

public void bindType(String type,
                     VariableResolver resolver)
Binds the variables with the specified name to the specified resolver.

Parameters:
type - The variable type.
resolver - The resolver to use with these variables.

getResolver

public VariableResolver getResolver(String name,
                                    VariableType type)
Returns the resolver used for the variable of the specified name or type.

By default, looks for the resolver assigned to the specified variable name; if no resolver is bound to the variable name, it will return the resolver bound to the given variable type.

This method does not return null. If the specified variable name or type is not bound to any resolver the default resolver if returned instead.

Parameters:
name - The name of the variable.
type - The type of the variable.
Returns:
the corresponding resolver.

getResolver

public VariableResolver getResolver(String name)
Returns the resolver used for the variable of the specified name.

This method does not return null. If the specified variable name is no bound to any resolver the default resolver if returned instead.

Parameters:
name - The name of the variables.
Returns:
the corresponding resolver.

getResolver

public VariableResolver getResolver(VariableType type)
Returns the resolver used for the variable of the specified type.

This method does not return null. If the specified variable name is no bound to any resolver the default resolver if returned instead.

Parameters:
type - The type of the variable.
Returns:
the corresponding resolver.

isNameBound

public boolean isNameBound(String name)
Indicates whether the given variable name is bound to a VariableResolver.

Parameters:
name - The variable name.
Returns:
true if a given variable resolver is bound to the specific name; false otherwise (including if the name is null.

isTypeBound

public boolean isTypeBound(String type)
Indicates whether the given variable type is bound to a VariableResolver.

Parameters:
type - The variable type.
Returns:
true if a given variable resolver is bound to the specific type; false otherwise (including if the type is null.