org.weborganic.furi
Class TokenOperatorDX

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

public class TokenOperatorDX
extends Object
implements TokenOperator, Matchable

A token based on the operators defined in the latest draft.

  instruction   = "{" [ operator ] variable-list "}"
  operator      = "/" / "+" / ";" / "?" / op-reserve
  variable-list =  varspec *( "," varspec )
  varspec       =  [ var-type ] varname [ ":" prefix-len ] [ "=" default ]
  var-type      = "@" / "%" / type-reserve
  varname       = ALPHA *( ALPHA | DIGIT | "_" )
  prefix-len    = 1*DIGIT
  default       = *( unreserved / reserved )
  op-reserve    = <anything else that isn't ALPHA or operator>
  type-reserve  = <anything else that isn't ALPHA, ",", or operator>
 

Version:
5 November 2009
Author:
Christophe Lauret
See Also:
URI Template Library draft specifications at Google Code

Nested Class Summary
static class TokenOperatorDX.Operator
          The list of operators currently supported.
 
Constructor Summary
TokenOperatorDX(TokenOperatorDX.Operator op, List<Variable> vars)
          Creates a new operator token.
TokenOperatorDX(TokenOperatorDX.Operator op, Variable var)
          Creates a new operator token for one variable only.
 
Method Summary
 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.
 boolean match(String part)
          Indicates whether this token matches the specified part of a URL.
 TokenOperatorDX.Operator operator()
          Returns the operator part of this token.
static TokenOperatorDX parse(String exp)
          Parses the specified string and returns the corresponding token.
 Pattern pattern()
          Returns a regular expression pattern corresponding to this object.
 boolean resolve(String expanded, Map<Variable,Object> values)
          Resolves the specified expanded URI part for this token.
static TokenOperatorDX.Operator toOperator(char c)
          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
 

Constructor Detail

TokenOperatorDX

public TokenOperatorDX(TokenOperatorDX.Operator op,
                       Variable var)
                throws NullPointerException
Creates a new operator token for one variable only.

Parameters:
op - The operator to use.
var - The variable for this operator.
Throws:
NullPointerException - If any of the argument is null.

TokenOperatorDX

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

Parameters:
op - The operator to use.
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 TokenOperatorDX.Operator operator()
Returns the operator part of this token.

Returns:
the operator.

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.

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.

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.

match

public boolean match(String part)
Indicates whether this token matches the specified part of a URL.

Specified by:
match in interface Matchable
Parameters:
part - The part of URL to test for matching.
Returns:
true if it matches; false otherwise.

pattern

public Pattern pattern()
Returns a regular expression pattern corresponding to this object.

Specified by:
pattern in interface Matchable
Returns:
The regular expression pattern corresponding to this object.

toOperator

public static TokenOperatorDX.Operator toOperator(char c)
Returns the operator if it is defined in this class.

Parameters:
c - The character representation of the operator.
Returns:
The corresponding operator instance.

parse

public static TokenOperatorDX 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

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