org.xqdoc.conversion
Class XQDocContext

java.lang.Object
  extended by org.xqdoc.conversion.XQDocContext

public class XQDocContext
extends java.lang.Object

This class serves as the 'go between' for XQDocController and the parser. The XQDocController creates (and initializes) the XQDocContext and the parser sets numerous member variables via callbacks. The XQDocContext also has the responsibility for creating the correct XQDocXML and XQDocComment object(s) which eventually constructs the resultant xqDoc XML. Finally, XQDocContext creates the XQDocPaylaod (and sets the member variables) that is returned to XQDocController.

Version:
1.0
Author:
Darin McBeath

Field Summary
static java.lang.String XQDOC_NAMESPACE
           
 
Constructor Summary
XQDocContext(java.lang.String namespace)
          Constructor.
 
Method Summary
 void addPrefixAndURI(java.lang.String prefix, java.lang.String uri)
          Add the namespace prefix and uri to a HashMap.
 void buildFunctionSection()
          Append information to the function section for the returned xqDoc XML.
 void buildImportSection(java.lang.String uri)
          Append information to the import section for the returned xqDoc XML.
 void buildLibraryModuleSection(java.lang.String uri)
          Build the library module section for the returned xqDoc XML (for library modules).
 void buildMainModuleSection()
          Build the main module section for the returned xqDoc XML (for main modules).
 XQDocPayload buildResponse()
          Construct the response payload consisting of serialized xqDoc XML and the module URI.
 void buildVariableSection(java.lang.String uri)
          Append information to the global variable section for the returned xqDoc XML.
 void init(java.lang.String base, java.lang.String name, java.lang.String source, java.util.HashMap map, java.lang.String uri, boolean encode)
          The initialize method for XQDocContext.
 void setDefaultModuleFunctionNamespace(java.lang.String uri)
          Set the default function namespace as specified in the module.
 void setFunctionBody(java.lang.String body)
          Set the source code for the function body so that it can be included when generating the xqDoc XML.
 void setFunctionName(java.lang.String prefix, java.lang.String name)
          Set the function name for the function declaration so that it can be included when generating the xqDoc XML.
 void setFunctionSignature(java.lang.String signature)
          Set the function signature for the function delcaration so that it can be included when generating the xqDoc XML.
 void setInvokedFunction(java.lang.String fName)
          Check if the invoked function (from the current function) has already been identified.
 void setReferencedVariable(java.lang.String vName)
          Check if the referenced global variable (from the current function) has already been identified.
 void setXQDocBuffer(java.lang.String text)
          Set the xqDoc comment block.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XQDOC_NAMESPACE

public static final java.lang.String XQDOC_NAMESPACE
See Also:
Constant Field Values
Constructor Detail

XQDocContext

public XQDocContext(java.lang.String namespace)
Constructor. Currently, the namespace value is ignored since there is only one 'version' of XQDoc XML generated. Eventually, this value could be used to determine what supporting objects need to be created to build the requested version of XQDoc XML.

Parameters:
namespace - The namespace to use for the generated XQDoc XML.
Method Detail

init

public void init(java.lang.String base,
                 java.lang.String name,
                 java.lang.String source,
                 java.util.HashMap map,
                 java.lang.String uri,
                 boolean encode)
The initialize method for XQDocContext. This method will be invoked by XQDocController prior to parsing the requested module.

Parameters:
base - The module base (mostly used for main modules)
name - The common name associated with the module
source - The source code for the module
map - The map of predefined function namespaces (URIs) to prefixes
uri - The default function namespace URI
encode - The document URI encode flag

buildLibraryModuleSection

public void buildLibraryModuleSection(java.lang.String uri)
Build the library module section for the returned xqDoc XML (for library modules). This will consist of the library module uri, friendly name, xqDoc comment block, and the source code for the entire library module. Either this method (or the one for main modules) will be invoked once (from the Parser) for each module processed.

Parameters:
uri - The library module uri.

buildMainModuleSection

public void buildMainModuleSection()
Build the main module section for the returned xqDoc XML (for main modules). This will consist of the main module uri, friendly name, xqDoc comment block, and the source code for the entire main module. Either this method (or the one for library modules) will be invoked once (from the Parser) for each module processed.


buildImportSection

public void buildImportSection(java.lang.String uri)
Append information to the import section for the returned xqDoc XML. This information will include the uri for the import as well as the xqDoc comment block associated with the import. This method will be called (from the Parser) once for each module imported by either a library or main module.

Parameters:
uri - The uri for the module imported.

buildVariableSection

public void buildVariableSection(java.lang.String uri)
Append information to the global variable section for the returned xqDoc XML. This information will include the defined global variable uri as well as the xqDoc comment block associated with the global variable. This method will be called (from the Parser) once for each global variable declared by either a library or main module.

Parameters:
uri - The uri for the global variable.

buildFunctionSection

public void buildFunctionSection()
Append information to the function section for the returned xqDoc XML. This information will include the function name, the xqDoc comment block associated with the function, function signature, function source code, referenced global variables, and list of invoked functions. This method will be called (from the Parser) once for each declared function by either a library or main module.


buildResponse

public XQDocPayload buildResponse()
Construct the response payload consisting of serialized xqDoc XML and the module URI. This meethod will be called by XQDocController.

Returns:
Payload containing string of xqDoc XML and moduleURI

addPrefixAndURI

public void addPrefixAndURI(java.lang.String prefix,
                            java.lang.String uri)
Add the namespace prefix and uri to a HashMap. The HashMap will be used when processing invoked functions and referenced variables to associate the correct uri with the specified prefix in the xqDoc XML for the referenced variable or invoked function. This will be called by the parser when a module is imported (and namespace prefix is specified) or a namespace is declared. If a duplicate prefix is found (from the list specified by XQDocController), this prefix will override any of the 'predefined' values set by XQDocController.

Parameters:
prefix - The namespace prefix
uri - The namespace uri

setDefaultModuleFunctionNamespace

public void setDefaultModuleFunctionNamespace(java.lang.String uri)
Set the default function namespace as specified in the module. This method will be called by the parser. This value will override any 'predefined' default function namespace that might have been specified from XQDocController.

Parameters:
uri - The uri for the default function namespace

setFunctionName

public void setFunctionName(java.lang.String prefix,
                            java.lang.String name)
Set the function name for the function declaration so that it can be included when generating the xqDoc XML. This method will be called by the parser once for each function declaration. If it is a 'main module' the namespace mappings may need to be adjusted in order to allow local linking between functions defined in the main module.

Parameters:
name - The function name (without the uri prefix)

setFunctionSignature

public void setFunctionSignature(java.lang.String signature)
Set the function signature for the function delcaration so that it can be included when generating the xqDoc XML. This method will be called by the parser once for each function signature.

Parameters:
signature - The function signature

setFunctionBody

public void setFunctionBody(java.lang.String body)
Set the source code for the function body so that it can be included when generating the xqDoc XML. This method will be called by the parser once for each function body.

Parameters:
body - The source code for a function body

setXQDocBuffer

public void setXQDocBuffer(java.lang.String text)
Set the xqDoc comment block. The XqDocComment object will then further process this block of text to separate the values into the appropriate xqDoc buckets (i.e. author, version, see, since, etc.). This method will be called by the parser once for each xqDoc comment block.

Parameters:
text - The xqDoc comment block

setInvokedFunction

public void setInvokedFunction(java.lang.String fName)
Check if the invoked function (from the current function) has already been identified. If so, simply ignore this reference. Otherwise, add this function name (uri and local name) to the invokedFunctions HashSet so the proper xqDoc XML will be generated. This method will be called by the parser once for each invoked function.

Parameters:
fName - The function invoked from within the current function

setReferencedVariable

public void setReferencedVariable(java.lang.String vName)
Check if the referenced global variable (from the current function) has already been identified. If so, simply ignore this reference. Otherwise, add this variable name (uri and local name) to the referencedVariables HashSet so the proper xqDoc XML will be generated. This method will be called by the parser once for each referenced global variable. It is currently not possible to find variables referenced if the variable resides within the default function namespace.

Parameters:
vName - The variable referenced from within the current function