* @return An in-memory document describing the webservice
*/
private org.exist.memtree.DocumentImpl describeWebService(Module modXQWS, XmldbURI xqwsFileUri, HttpServletRequest request, String path, String functionName, Sequence functionResult) throws XPathException,SAXException
{
final FunctionSignature[] xqwsFunctions = modXQWS.listFunctions();
final MemTreeBuilder builderWebserviceDoc = new MemTreeBuilder(broker.getXQueryService().newContext(AccessContext.REST));
builderWebserviceDoc.startDocument();
builderWebserviceDoc.startElement(new QName("webservice", null, null), null);
builderWebserviceDoc.startElement(new QName("name", null, null), null);
builderWebserviceDoc.characters(xqwsFileUri.toString().substring(0, xqwsFileUri.toString().indexOf(WEBSERVICE_MODULE_EXTENSION)));
builderWebserviceDoc.endElement();
builderWebserviceDoc.startElement(new QName("description", null, null), null);
builderWebserviceDoc.characters(modXQWS.getDescription());
builderWebserviceDoc.endElement();
builderWebserviceDoc.startElement(new QName("host", null, null), null);
builderWebserviceDoc.characters(request.getServerName() + ":" + request.getServerPort());
builderWebserviceDoc.endElement();
builderWebserviceDoc.startElement(new QName("path", null, null), null);
builderWebserviceDoc.characters(path);
builderWebserviceDoc.endElement();
builderWebserviceDoc.startElement(new QName("URL", null, null), null);
builderWebserviceDoc.characters(request.getRequestURL());
builderWebserviceDoc.endElement();
builderWebserviceDoc.startElement(new QName("functions", null, null), null);
for(int f = 0; f < xqwsFunctions.length; f++)
{
if(functionName == null)
{
//All Function Descriptions
describeWebServiceFunction(xqwsFunctions[f], builderWebserviceDoc, null);
}
else
{
//Only a Single Function Description for showing function call results
if(xqwsFunctions[f].getName().getLocalName().equals(functionName))
{
describeWebServiceFunction(xqwsFunctions[f], builderWebserviceDoc, functionResult);
break;
}
}
}
builderWebserviceDoc.endElement();
builderWebserviceDoc.endElement();
builderWebserviceDoc.endDocument();
return builderWebserviceDoc.getDocument();
}