use of org.exquery.restxq.RestXqService in project exist by eXist-db.
the class ExistXqueryRegistry method reexamineModulesWithResolvedDependencies.
/**
* Gets the modules that have a missing dependency
* on the module indicated by compiledModuleURI
* and attempts to re-compile them and register their
* services
*/
private void reexamineModulesWithResolvedDependencies(final DBBroker broker, final String compiledModuleUri) {
final Set<String> dependants;
synchronized (missingDependencies) {
final Set<String> deps = missingDependencies.get(compiledModuleUri);
if (deps != null) {
dependants = new HashSet<>(deps);
} else {
dependants = new HashSet<>();
}
}
for (final String dependant : dependants) {
try {
final DocumentImpl dependantModule = broker.getResource(XmldbURI.create(dependant), Permission.READ);
/*
* This null check is needed, as a dependency module may have been renamed,
* and so is no longer accessible under its old URI.
*
* However if its dependant module (compiledModuleUri) compiles
* (which it must have for this function to be invoked)
* then we can assume that the dependant module references the new
* module dependency (in the case of a module move/rename)
* or the dependency has been removed
*/
if (dependantModule != null) {
LOG.info("Missing dependency '{}' has been added to the database, re-examining '{}'...", compiledModuleUri, dependant);
final List<RestXqService> services = findServices(broker, dependantModule);
LOG.info("Discovered {} resource functions for {}", services.size(), dependant);
registerServices(broker, services);
} else {
LOG.info("Dependant '{}' has been resolved. Dependency on: {} was removed", compiledModuleUri, dependant);
// we need to remove dependant from the dependenciesTree of dependant
removeDependency(dependant, compiledModuleUri);
}
} catch (final PermissionDeniedException | ExQueryException pde) {
LOG.error(pde.getMessage(), pde);
}
// remove the resolve dependencies from the missing dependencies
removeMissingDependency(compiledModuleUri, dependant);
}
}
use of org.exquery.restxq.RestXqService in project exist by eXist-db.
the class RegistryFunctions method findService.
private RestXqService findService(final Iterator<RestXqService> services, final SignatureDetail signatureDetail) {
RestXqService result = null;
if (services != null) {
while (services.hasNext()) {
final RestXqService service = services.next();
final org.exquery.xquery.FunctionSignature signature = service.getResourceFunction().getFunctionSignature();
if (signature.getName().equals(signatureDetail.name) && signature.getArgumentCount() == signatureDetail.arity) {
result = service;
break;
}
}
}
return result;
}
use of org.exquery.restxq.RestXqService in project exist by eXist-db.
the class RegistryFunctions method eval.
@Override
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
final ExistXqueryRegistry xqueryRegistry = ExistXqueryRegistry.getInstance();
final RestXqServiceRegistry registry = RestXqServiceRegistryManager.getRegistry(getContext().getBroker().getBrokerPool());
Sequence result = Sequence.EMPTY_SEQUENCE;
context.pushDocumentContext();
try {
if (isCalledAs(qnRegisterModule.getLocalPart())) {
final XmldbURI moduleUri = args[0].toJavaObject(XmldbURI.class);
final DocumentImpl module = getContext().getBroker().getResource(moduleUri, Permission.READ);
if (xqueryRegistry.isXquery(module)) {
try {
final List<RestXqService> resourceFunctions = xqueryRegistry.findServices(getContext().getBroker(), module);
xqueryRegistry.registerServices(getContext().getBroker(), resourceFunctions);
result = (NodeValue) org.exist.extensions.exquery.restxq.impl.xquery.RegistryFunctions.serializeRestXqServices(context.getDocumentBuilder(), resourceFunctions).getDocumentElement();
} catch (final ExQueryException e) {
LOG.warn(e.getMessage(), e);
result = Sequence.EMPTY_SEQUENCE;
}
} else {
result = Sequence.EMPTY_SEQUENCE;
}
} else if (isCalledAs(qnDeregisterModule.getLocalPart())) {
final XmldbURI moduleUri = args[0].toJavaObject(XmldbURI.class);
final DocumentImpl module = getContext().getBroker().getResource(moduleUri, Permission.READ);
if (xqueryRegistry.isXquery(module)) {
final List<RestXqService> deregisteringServices = new ArrayList<>();
for (final RestXqService service : registry) {
if (XmldbURI.create(service.getResourceFunction().getXQueryLocation()).equals(moduleUri)) {
deregisteringServices.add(service);
}
}
xqueryRegistry.deregisterServices(getContext().getBroker(), moduleUri);
result = (NodeValue) org.exist.extensions.exquery.restxq.impl.xquery.RegistryFunctions.serializeRestXqServices(context.getDocumentBuilder(), deregisteringServices).getDocumentElement();
} else {
result = Sequence.EMPTY_SEQUENCE;
}
} else if (isCalledAs(qnFindResourceFunctions.getLocalPart())) {
final XmldbURI moduleUri = args[0].toJavaObject(XmldbURI.class);
final DocumentImpl module = getContext().getBroker().getResource(moduleUri, Permission.READ);
if (xqueryRegistry.isXquery(module)) {
try {
final List<RestXqService> resourceFunctions = xqueryRegistry.findServices(getContext().getBroker(), module);
xqueryRegistry.deregisterServices(getContext().getBroker(), moduleUri);
result = (NodeValue) org.exist.extensions.exquery.restxq.impl.xquery.RegistryFunctions.serializeRestXqServices(context.getDocumentBuilder(), resourceFunctions).getDocumentElement();
} catch (final ExQueryException e) {
LOG.warn(e.getMessage(), e);
result = Sequence.EMPTY_SEQUENCE;
}
} else {
result = Sequence.EMPTY_SEQUENCE;
}
} else if (isCalledAs(qnRegisterResourceFunction.getLocalPart())) {
final XmldbURI moduleUri = args[0].toJavaObject(XmldbURI.class);
final String resourceFunctionIdentifier = args[1].getStringValue();
final DocumentImpl module = getContext().getBroker().getResource(moduleUri, Permission.READ);
if (xqueryRegistry.isXquery(module)) {
final SignatureDetail signatureDetail = extractSignatureDetail(resourceFunctionIdentifier);
if (signatureDetail != null) {
try {
final RestXqService serviceToRegister = findService(xqueryRegistry.findServices(getContext().getBroker(), module).iterator(), signatureDetail);
if (serviceToRegister != null) {
xqueryRegistry.registerServices(context.getBroker(), Collections.singletonList(serviceToRegister));
result = BooleanValue.TRUE;
} else {
result = BooleanValue.FALSE;
}
} catch (final ExQueryException e) {
LOG.warn(e.getMessage(), e);
result = BooleanValue.FALSE;
}
} else {
result = BooleanValue.FALSE;
}
} else {
result = Sequence.EMPTY_SEQUENCE;
}
} else if (isCalledAs(qnDeregisterResourceFunction.getLocalPart())) {
// TODO
final String resourceFunctionIdentifier = args[1].getStringValue();
final SignatureDetail signatureDetail = extractSignatureDetail(resourceFunctionIdentifier);
if (signatureDetail != null) {
final RestXqService serviceToDeregister = findService(xqueryRegistry.registered(context.getBroker()), signatureDetail);
if (serviceToDeregister != null) {
xqueryRegistry.deregisterService(context.getBroker(), serviceToDeregister);
result = BooleanValue.TRUE;
} else {
result = BooleanValue.FALSE;
}
} else {
result = BooleanValue.FALSE;
}
} else if (isCalledAs(qnInvalidModules.getLocalPart())) {
result = serializeInvalidQueries(xqueryRegistry.getInvalidQueries());
} else if (isCalledAs(qnMissingDependencies.getLocalPart())) {
result = serializeMissingDependencies(xqueryRegistry.getMissingDependencies());
} else if (isCalledAs(qnDependencies.getLocalPart())) {
result = serializeDependenciesTree(xqueryRegistry.getDependenciesTree());
}
return result;
} catch (final PermissionDeniedException pde) {
throw new XPathException(this, pde.getMessage(), pde);
} finally {
context.popDocumentContext();
}
}
use of org.exquery.restxq.RestXqService in project exist by eXist-db.
the class RegistryFunctions method serializeRestXqServices.
/**
* Serializes RESTXQ Services to an XML description
*
* @param builder The receiver for the serialization
* @param services The services to describe
*
* @return The XML Document constructed from serializing the
* services to the MemTreeBuilder
*/
public static Document serializeRestXqServices(final MemTreeBuilder builder, final Iterable<RestXqService> services) {
builder.startDocument();
builder.startElement(RESOURCE_FUNCTIONS, null);
for (final RestXqService service : services) {
final ResourceFunction resourceFn = service.getResourceFunction();
serializeResourceFunction(builder, resourceFn);
}
builder.endElement();
builder.endDocument();
return builder.getDocument();
}
Aggregations