org.weborganic.furi
Class TokenOperatorD3

java.lang.Object
  extended by org.weborganic.furi.TokenOperatorD3
All Implemented Interfaces:
Expandable, Token, TokenOperator

public class TokenOperatorD3
extends Object
implements TokenOperator

A token using the operators defined in draft 3 of the URI templates specifications. Characters (4.2):

 op          = 1*ALPHA
 arg         = *(reserved / unreserved / pct-encoded)
 var         = varname [ "=" vardefault ]
 vars        = var [ *("," var) ]
 varname     = (ALPHA / DIGIT)*(ALPHA / DIGIT / "." / "_" / "-" )
 vardefault  = *(unreserved / pct-encoded)
 operator    = "-" op "|" arg "|" vars
 

Version:
9 February 2009
Author:
Christophe Lauret
See Also:
URI Template (draft 3)

Nested Class Summary
static class TokenOperatorD3.Operator
          The list of operators currently supported.
 
Constructor Summary
TokenOperatorD3(TokenOperatorD3.Operator op, String arg, List<Variable> vars)
          Creates a new operator token.
 
Method Summary
 String argument()
          Returns the argument part of this token.
 boolean equals(Object o)
          Two tokens are equals if and only if their string expression is equal.
 String expand(Parameters parameters)
          Expands the token operator using the specified parameters.
 String expression()
          The expression corresponding to this token.
 int hashCode()
          
 boolean isResolvable()
          Indicates whether this token can be resolved.
 TokenOperatorD3.Operator operator()
          Returns the operator part of this token.
static TokenOperatorD3 parse(String exp)
          Parses the specified string and returns the corresponding token.
 boolean resolve(String expanded, Map<Variable,Object> values)
          Resolves the specified expanded URI part for this token.
static TokenOperatorD3.Operator toOperator(String op)
          Returns the operator if it is defined in this class.
 String toString()
          
 List<Variable> variables()
          Returns the list of variables used in this token.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.weborganic.furi.Token
expression, isResolvable
 

Constructor Detail

TokenOperatorD3

public TokenOperatorD3(TokenOperatorD3.Operator op,
                       String arg,
                       List<Variable> vars)
                throws NullPointerException
Creates a new operator token.

Parameters:
op - The operator to use.
arg - The argument for this operator.
vars - The variables for this operator.
Throws:
NullPointerException - If any of the argument is null.
Method Detail

expand

public String expand(Parameters parameters)
Expands the token operator using the specified parameters.

Specified by:
expand in interface Expandable
Parameters:
parameters - The parameters for variable substitution.
Returns:
The corresponding expanded string.

operator

public TokenOperatorD3.Operator operator()
Returns the operator part of this token.

Returns:
the operator.

argument

public String argument()
Returns the argument part of this token.

Returns:
the argument.

variables

public List<Variable> variables()
Returns the list of variables used in this token.

Specified by:
variables in interface TokenOperator
Returns:
the list of variables.

toOperator

public static TokenOperatorD3.Operator toOperator(String op)
Returns the operator if it is defined in this class.

Parameters:
op - The string representation of an operator.
Returns:
The corresponding operator instance.

resolve

public boolean resolve(String expanded,
                       Map<Variable,Object> values)
Resolves the specified expanded URI part for this token.

The resolution process requires all variables referenced in the token to be mapped to the value that is present in the expanded URI data.

Specified by:
resolve in interface Token
Parameters:
expanded - The part of the URI that correspond to an expanded version of the token.
values - The variables mapped to their values as a result of resolution.
Returns:
true this operation was successful; false otherwise.

parse

public static TokenOperatorD3 parse(String exp)
                             throws URITemplateSyntaxException
Parses the specified string and returns the corresponding token. This method accepts both the raw expression or the expression wrapped in curly brackets.

Parameters:
exp - The expression to parse.
Returns:
The corresponding token.
Throws:
URITemplateSyntaxException - If the string cannot be parsed as a valid

isResolvable

public boolean isResolvable()
Indicates whether this token can be resolved.

A resolvable token contains variables which can be resolved. By default a token is resolvable if it can be matched.

Specified by:
isResolvable in interface Token
Returns:
true if variables can be resolved from the specified pattern; false otherwise.

expression

public String expression()
The expression corresponding to this token.

Specified by:
expression in interface Token
Returns:
The expression corresponding to this token.

equals

public boolean equals(Object o)
Two tokens are equals if and only if their string expression is equal.

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

toString

public String toString()

Overrides:
toString in class Object