org.jvnet.ws.wadl.ast
Class WadlAstBuilder

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

public class WadlAstBuilder
extends Object

Encapsulates the act of build an AST from the URI or a WADL. In this AST any "href" references to both to internal and to external WADL elements are resolved making it easier for the user to follow.

Author:
gdavison

Nested Class Summary
static interface WadlAstBuilder.SchemaCallback
          Allow client to process both internal and external schemas.
 
Constructor Summary
WadlAstBuilder(WadlAstBuilder.SchemaCallback schemaCallback, MessageListener messageListener)
          Create a new instance of the AST builder providing a MessageListener for informational messages and a WadlAstBuilder.SchemaCallback instance to allow the caller to be provided with schema instances to process.
 
Method Summary
protected  void addMethodToResource(ResourceNode resource, Method method, URI file)
          Add a method to a resource.
protected  void addMethodToResourceType(ResourceTypeNode resource, Method method, URI file)
          Add a method to a resource type.
protected  void addResourceToResourceType(ResourceTypeNode type, Resource resource, URI file)
          Add a child resource to a resource type.
protected  void addTypeToResource(ResourceNode resourceNode, Resource resource, String href, URI file)
          Add a type to a resource.
protected  ApplicationNode buildAst(Application a, URI rootFile)
          Build an abstract tree from an unmarshalled WADL file.
 ApplicationNode buildAst(URI rootFile)
          Build an abstract tree from an unmarshalled WADL file.
protected  void buildIDMap(Application a, URI desc)
          Build a map of all method, param, representation, fault and resource_type elements that have an ID.
protected  void buildResourceTree(ResourceNode parent, Resource resource, URI file)
          Add a resource and (recursively) its children to a tree starting at the parent.
protected  void buildResourceType(String ifaceId, Application a)
          Build an abstract resource type based on the methods of a resource type in a WADL file.
protected  void buildResourceTypeTree(String ifaceId, Application a)
          Build an abstract resource type tree based on the child resources of a resource type in a WADL file.
protected  RepresentationNode createRepresentationNode(Representation representation, URI file)
          Add a representation to a method's input or output list.
protected  void extractMethodIds(Method m, URI file)
          Extract the id from a method element and add to the method map.
protected  void extractParamId(Param p, URI file)
          Extract the id from a param element and add to the representation map.
protected  void extractRepresentationId(Representation r, URI file)
          Extract the id from a representation element and add to the representation map.
protected  void extractResourceIds(Resource r, URI file)
          Extract the id from a resource element and add to the resource map then recurse into any contained resources.
protected  void extractResourceTypeIds(ResourceType r, URI file)
          Extract the id from a resource_type element and add to the resource map.
 Map<String,ResourceTypeNode> getInterfaceMap()
           
protected static URI getReferencedFile(URI currentFile, String href)
          Get the referenced file, currentFile will be returned if href is a fragment identifier, otherwise href is resolved against currentFile.
static InvalidWADLException messageStringFromObject(String message, Object obj)
          Convert a given message and JAX-B object into a string with location information so that the user can correlate then back to the original file
protected  Application processDescription(URI desc)
          Unmarshall a WADL file, process any schemas referenced in the WADL file, add any items with an ID to a global ID map, and follow any references to additional WADL files.
protected  Application processDescription(URI desc, InputStream is)
          Unmarshall a WADL file, process any schemas referenced in the WADL file, add any items with an ID to a global ID map, and follow any references to additional WADL files.
protected  String processIDHref(URI desc, String id, String href, Object o)
          Adds the object to the ID map if it is identified and process any file pointed to by href.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WadlAstBuilder

public WadlAstBuilder(WadlAstBuilder.SchemaCallback schemaCallback,
                      MessageListener messageListener)
Create a new instance of the AST builder providing a MessageListener for informational messages and a WadlAstBuilder.SchemaCallback instance to allow the caller to be provided with schema instances to process.

Parameters:
schemaCallback - used for processing schemas.
messageListener - informal messages listener.
Method Detail

getInterfaceMap

public Map<String,ResourceTypeNode> getInterfaceMap()

buildAst

public ApplicationNode buildAst(URI rootFile)
                         throws InvalidWADLException,
                                IOException
Build an abstract tree from an unmarshalled WADL file.

Parameters:
rootFile - the URI of the root WADL file. Other WADL files might be included by reference.
Returns:
the resource elements that correspond to the roots of the resource trees.
Throws:
InvalidWADLException - when WADL is invalid and cannot be processed.
IOException - if the specified WADL file cannot be read.

buildAst

protected ApplicationNode buildAst(Application a,
                                   URI rootFile)
                            throws InvalidWADLException
Build an abstract tree from an unmarshalled WADL file.

Parameters:
a - the application element of the root WADL file.
rootFile - the URI of the root WADL file. Other WADL files might be included by reference.
Returns:
the resource elements that correspond to the roots of the resource trees.
Throws:
InvalidWADLException - when WADL is invalid and cannot be processed.

buildResourceType

protected void buildResourceType(String ifaceId,
                                 Application a)
                          throws InvalidWADLException
Build an abstract resource type based on the methods of a resource type in a WADL file.

Parameters:
ifaceId - the identifier of the resource type.
a - the application element of the root WADL file.
Throws:
InvalidWADLException - when WADL is invalid and cannot be processed.

buildResourceTypeTree

protected void buildResourceTypeTree(String ifaceId,
                                     Application a)
                              throws InvalidWADLException
Build an abstract resource type tree based on the child resources of a resource type in a WADL file.

Parameters:
ifaceId - the identifier of the resource type.
a - the application element of the root WADL file.
Throws:
InvalidWADLException - when WADL is invalid and cannot be processed.

buildResourceTree

protected void buildResourceTree(ResourceNode parent,
                                 Resource resource,
                                 URI file)
                          throws InvalidWADLException
Add a resource and (recursively) its children to a tree starting at the parent. Follow references to resources across WADL file boundaries.

Parameters:
parent - the parent resource in the tree being built.
resource - the WADL resource to process.
file - the URI of the current WADL file being processed.
Throws:
InvalidWADLException - when WADL is invalid and cannot be processed.

addTypeToResource

protected void addTypeToResource(ResourceNode resourceNode,
                                 Resource resource,
                                 String href,
                                 URI file)
                          throws InvalidWADLException
Add a type to a resource.

Follow references to types across WADL file boundaries.

Parameters:
href - the identifier of the resource_type element to process.
resourceNode - the resource AST node.
resource - the resource object from the model.
file - the URI of the current WADL file being processed.
Throws:
InvalidWADLException - when WADL is invalid and cannot be processed.

addMethodToResourceType

protected void addMethodToResourceType(ResourceTypeNode resource,
                                       Method method,
                                       URI file)
                                throws InvalidWADLException
Add a method to a resource type.

Follow references to methods across WADL file boundaries.

Parameters:
method - the WADL method element to process.
resource - the resource type.
file - the URI of the current WADL file being processed.
Throws:
InvalidWADLException - when WADL is invalid and cannot be processed.

addResourceToResourceType

protected void addResourceToResourceType(ResourceTypeNode type,
                                         Resource resource,
                                         URI file)
                                  throws InvalidWADLException
Add a child resource to a resource type.

Follow references to resources across WADL file boundaries.

Parameters:
resource - the WADL resource element to process.
type - the parent resource type.
file - the URI of the current WADL file being processed.
Throws:
InvalidWADLException - when WADL is invalid and cannot be processed.

addMethodToResource

protected void addMethodToResource(ResourceNode resource,
                                   Method method,
                                   URI file)
                            throws InvalidWADLException
Add a method to a resource.

Follow references to methods across WADL file boundaries.

Parameters:
method - the WADL method element to process.
resource - the resource.
file - the URI of the current WADL file being processed.
Throws:
InvalidWADLException - when WADL is invalid and cannot be processed.

createRepresentationNode

protected RepresentationNode createRepresentationNode(Representation representation,
                                                      URI file)
                                               throws InvalidWADLException
Add a representation to a method's input or output list.

Follow references to representations across WADL file boundaries.

Parameters:
list - the list to add the representation to.
representation - the WADL representation element to process.
file - the URI of the current WADL file being processed.
Throws:
InvalidWADLException - when WADL is invalid and cannot be processed.

processDescription

protected Application processDescription(URI desc)
                                  throws JAXBException,
                                         IOException
Unmarshall a WADL file, process any schemas referenced in the WADL file, add any items with an ID to a global ID map, and follow any references to additional WADL files.

Parameters:
desc - the URI of the description file, the description is fetched by converting the URI into a URL and then using a HTTP GET. Use processDescription(java.net.URI, java.io.InputStream) to supply the InputStream directly.
Returns:
the unmarshalled WADL application element.
Throws:
JAXBException - if the WADL file is invalid or if the code generator encounters a problem.
IOException - if the specified WADL file cannot be read.

processDescription

protected Application processDescription(URI desc,
                                         InputStream is)
                                  throws JAXBException,
                                         IOException
Unmarshall a WADL file, process any schemas referenced in the WADL file, add any items with an ID to a global ID map, and follow any references to additional WADL files.

Parameters:
desc - the URI of the description file.
is - an input stream from which the description can be read.
Returns:
the unmarshalled WADL application element.
Throws:
JAXBException - if the WADL file is invalid or if the code generator encounters a problem.
IOException - if the specified WADL file cannot be read.

buildIDMap

protected void buildIDMap(Application a,
                          URI desc)
                   throws JAXBException,
                          IOException
Build a map of all method, param, representation, fault and resource_type elements that have an ID. These are used to dereference href values when building the ast.

Parameters:
desc - the URI of the WADL file being processed.
a - the root element of an unmarshalled WADL document.
Throws:
JAXBException - if the WADL file is invalid or if the code generator encounters a problem.
IOException - if the specified WADL file cannot be read.

messageStringFromObject

public static InvalidWADLException messageStringFromObject(String message,
                                                           Object obj)
Convert a given message and JAX-B object into a string with location information so that the user can correlate then back to the original file


processIDHref

protected String processIDHref(URI desc,
                               String id,
                               String href,
                               Object o)
                        throws JAXBException,
                               IOException
Adds the object to the ID map if it is identified and process any file pointed to by href.

Parameters:
desc - The URI of the current file being processed, used when resolving relative paths in href.
id - The identifier of o or null if o isn't identified.
href - A link to a another element, the document in which the element resides will be recursively processed.
o - The object that is being identified or from which the link occurs.
Returns:
a unique identifier for the element or null if not identified.
Throws:
JAXBException - if the WADL file is invalid or if the code generator encounters a problem.
IOException - if the specified WADL file cannot be read.

extractRepresentationId

protected void extractRepresentationId(Representation r,
                                       URI file)
                                throws JAXBException,
                                       IOException
Extract the id from a representation element and add to the representation map.

Parameters:
file - the URI of the current WADL file being processed.
r - the representation element.
Throws:
JAXBException - if the WADL file is invalid or if the code generator encounters a problem.
IOException - if the specified WADL file cannot be read.

extractParamId

protected void extractParamId(Param p,
                              URI file)
                       throws JAXBException,
                              IOException
Extract the id from a param element and add to the representation map.

Parameters:
file - the URI of the current WADL file being processed.
p - the param element.
Throws:
JAXBException - if the WADL file is invalid or if the code generator encounters a problem.
IOException - if the specified WADL file cannot be read.

extractMethodIds

protected void extractMethodIds(Method m,
                                URI file)
                         throws JAXBException,
                                IOException
Extract the id from a method element and add to the method map. Also extract the ids from any contained representation or fault elements.

Parameters:
file - the URI of the current WADL file being processed.
m - the method element.
Throws:
JAXBException - if the WADL file is invalid or if the code generator encounters a problem.
IOException - if the specified WADL file cannot be read.

extractResourceIds

protected void extractResourceIds(Resource r,
                                  URI file)
                           throws JAXBException,
                                  IOException
Extract the id from a resource element and add to the resource map then recurse into any contained resources. Also extract the ids from any contained param, method and its representation or fault elements.

Parameters:
file - the URI of the current WADL file being processed.
r - the resource element.
Throws:
JAXBException - if the WADL file is invalid or if the code generator encounters a problem.
IOException - if the specified WADL file cannot be read.

extractResourceTypeIds

protected void extractResourceTypeIds(ResourceType r,
                                      URI file)
                               throws JAXBException,
                                      IOException
Extract the id from a resource_type element and add to the resource map.

Also extract the ids from any contained method and its param, representation or fault elements.

Parameters:
file - the URI of the current WADL file being processed.
r - the resource_type element.
Throws:
JAXBException - if the WADL file is invalid or if the code generator encounters a problem.
IOException - if the specified WADL file cannot be read.

getReferencedFile

protected static URI getReferencedFile(URI currentFile,
                                       String href)
Get the referenced file, currentFile will be returned if href is a fragment identifier, otherwise href is resolved against currentFile.

Parameters:
currentFile - the uri of the file that contains the reference, used to provide a base for relative paths.
href - the reference.
Returns:
the URI of the referenced file.


Copyright © 2014. All Rights Reserved.