public Sequence eval(Sequence[] args, Sequence contextSequence)
throws XPathException {
if("get-module-description".equals(getSignature().getName().getLocalName())) {
final String uri = args[0].getStringValue();
final Module module = context.getModule(uri);
if(module == null)
{throw new XPathException(this, "No module found matching namespace URI: " + uri);}
return new StringValue(module.getDescription());
} else if ("is-module-registered".equals(getSignature().getName().getLocalName())) {
final String uri = args[0].getStringValue();
final Module module = context.getModule(uri);
return new BooleanValue(module != null);
} else if ("mapped-modules".equals(getSignature().getName().getLocalName())) {
final ValueSequence resultSeq = new ValueSequence();
for (final Iterator<String> i = context.getMappedModuleURIs(); i.hasNext();) {
resultSeq.add(new StringValue(i.next().toString()));
}
return resultSeq;
} else if ("is-module-mapped".equals(getSignature().getName().getLocalName())) {
final String uri = args[0].getStringValue();
return new BooleanValue(((Map<String, String>)context.getBroker().getConfiguration().getProperty(XQueryContext.PROPERTY_STATIC_MODULE_MAP)).get(uri) != null);
} else if ("map-module".equals(getSignature().getName().getLocalName())) {
if (!context.getSubject().hasDbaRole()) {
final XPathException xPathException = new XPathException(this, "Permission denied, calling user '" + context.getSubject().getName() + "' must be a DBA to call this function.");
logger.error("Invalid user", xPathException);
throw xPathException;
}
final String namespace = args[0].getStringValue();
final String location = args[1].getStringValue();
final Map <String, String> moduleMap = (Map<String, String>)context.getBroker().getConfiguration().getProperty(XQueryContext.PROPERTY_STATIC_MODULE_MAP);
moduleMap.put(namespace, location);
return Sequence.EMPTY_SEQUENCE;
} else if ("unmap-module".equals(getSignature().getName().getLocalName())) {
if (!context.getSubject().hasDbaRole()) {
final XPathException xPathException = new XPathException(this, "Permission denied, calling user '" + context.getSubject().getName() + "' must be a DBA to call this function.");
logger.error("Invalid user", xPathException);
throw xPathException;
}
final String namespace = args[0].getStringValue();
final Map <String, String> moduleMap = (Map<String, String>)context.getBroker().getConfiguration().getProperty(XQueryContext.PROPERTY_STATIC_MODULE_MAP);
moduleMap.remove(namespace);
return Sequence.EMPTY_SEQUENCE;
} else if ("get-module-info".equals(getSignature().getName().getLocalName())) {
context.pushDocumentContext();
try {
final MemTreeBuilder builder = context.getDocumentBuilder();
builder.startElement(MODULES_QNAME, null);
if (getArgumentCount() == 1) {
final Module module = context.getModule(args[0].getStringValue());
if (module != null)
{outputModule(builder, module);}
} else {
for(final Iterator<Module> i = context.getRootModules(); i.hasNext(); ) {
final Module module = i.next();
outputModule(builder, module);
}
}
return builder.getDocument().getNode(1);
} finally {
context.popDocumentContext();
}
} else {
final ValueSequence resultSeq = new ValueSequence();
final XQueryContext tempContext = new XQueryContext(context.getBroker().getBrokerPool(), AccessContext.XMLDB);
for(final Iterator<Module> i = tempContext.getRootModules(); i.hasNext(); ) {
final Module module = i.next();
resultSeq.add(new StringValue(module.getNamespaceURI()));
}
for (final URI uri : tempContext.getRepository().getJavaModules()) {
resultSeq.add(new StringValue(uri.toString()));
}
return resultSeq;