org.jvnet.ws.wadl.ast
Class PathSegment

java.lang.Object
  extended by org.jvnet.ws.wadl.ast.PathSegment

public class PathSegment
extends Object

Represents a segment of a URI with zero or more embedded parameters as found in the path attribute of a WADL resource element. Embedded parameters are represented as {name} where name is the name of the parameter. This class also maintains the list of matrix parameters, query parameters and any addition parameter information supplied using a child WADL param element.


Constructor Summary
PathSegment(ResourceType resource, URI file, ElementResolver idMap)
          Creates a new instance of PathSegment from a WADL resource type element.
PathSegment(Resource resource, URI file, ElementResolver idMap)
          Creates a new instance of PathSegment from a WADL resource element.
PathSegment(String template)
          Construct a PathSegment instance using a string representation.
PathSegment(String template, List<String> matrixParameters)
          Construct a PathSegment instance using a string representation and a list of matrix parameter names.
 
Method Summary
protected static Param derefIfRequired(Param p, URI file, ElementResolver idMap)
          Dereference a param reference element if required.
 String evaluate(Map<String,Object> parameterValues)
          Merges the supplied parameter values into the path segment template and returns the resulting path segment.
 List<Param> getHeaderParameters()
          Get list of header parameters attached to the path segment.
 List<Param> getMatrixParameters()
          Get list of matrix parameters attached to the path segment.
 List<Param> getQueryParameters()
          Get list of query parameters attached to the path segment.
 String getTemplate()
          Get the underlying path segment template string.
 List<Param> getTemplateParameters()
          Get a list of parameters embedded within the underlying path segment template.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PathSegment

public PathSegment(String template)
Construct a PathSegment instance using a string representation. All parameters will be treated as string types and no matrix parameters will be specified.

Parameters:
template - the string version of the template.

PathSegment

public PathSegment(String template,
                   List<String> matrixParameters)
Construct a PathSegment instance using a string representation and a list of matrix parameter names. All parameters will be treated as string types.

Parameters:
template - the string version of the template.
matrixParameters - a list of matrix parameter names.

PathSegment

public PathSegment(Resource resource,
                   URI file,
                   ElementResolver idMap)
            throws InvalidWADLException
Creates a new instance of PathSegment from a WADL resource element.

Parameters:
resource - the WADL resource element.
file - the URI of the WADL file that contains the resource element.
idMap - a map of URI reference to WADL definition element.
Throws:
InvalidWADLException - when WADL is invalid and cannot be processed.

PathSegment

public PathSegment(ResourceType resource,
                   URI file,
                   ElementResolver idMap)
            throws InvalidWADLException
Creates a new instance of PathSegment from a WADL resource type element.

Parameters:
resource - the WADL resource type element.
file - the URI of the WADL file that contains the resource type element.
idMap - a map of URI reference to WADL definition element.
Throws:
InvalidWADLException - when WADL is invalid and cannot be processed.
Method Detail

derefIfRequired

protected static Param derefIfRequired(Param p,
                                       URI file,
                                       ElementResolver idMap)
                                throws InvalidWADLException
Dereference a param reference element if required.

Parameters:
p - the param reference or definition.
file - the URI of the WADL file containing the param reference or definition.
idMap - a map of URI reference to WADL definition element.
Returns:
the param definition element.
Throws:
InvalidWADLException - when WADL is invalid and cannot be processed.

getTemplate

public String getTemplate()
Get the underlying path segment template string.

Returns:
the path segment template string.

getTemplateParameters

public List<Param> getTemplateParameters()
Get a list of parameters embedded within the underlying path segment template. E.g. if the template string is {p1}/xyzzy/{p2} this will return a list of two parameters: p1 and p2.

Returns:
the names of the parameters embedded within the template.

getMatrixParameters

public List<Param> getMatrixParameters()
Get list of matrix parameters attached to the path segment.

Returns:
a list of matrix parameter names.

getQueryParameters

public List<Param> getQueryParameters()
Get list of query parameters attached to the path segment.

Returns:
a list of query parameter names.

getHeaderParameters

public List<Param> getHeaderParameters()
Get list of header parameters attached to the path segment.

Returns:
a list of header parameter names.

evaluate

public String evaluate(Map<String,Object> parameterValues)
Merges the supplied parameter values into the path segment template and returns the resulting path segment. E.g. if the template is "{p1}/{p2}" with a matrix parameter p3 and the values of p1, p2 and p3 are "v1", "v2" and "v3" respectively the returned path segment would be "v1/v2;p3=v3". Query parameters are ignored.

Parameters:
parameterValues - a map of parameter names to values. Values can be of any class, evaluate uses the object's toString method to obtain the stringified value.
Returns:
the path segment resulting from inserting the parameter values into the template.


Copyright © 2012. All Rights Reserved.