@Context UriInfo uriInfo,
@Context HttpHeaders headers,
@Context ServletContext servletContext) {
ScopeRegistry reg = onm.getScopeRegistry();
OntologyScopeFactory f = onm.getOntologyScopeFactory();
log.debug("Request URI {}", uriInfo.getRequestUri());
OntologyScope scope;
OntologyInputSource<?,?> coreSrc = null, custSrc = null;
// First thing, check the core source.
if (coreRegistry != null && !coreRegistry.isEmpty()) try {
coreSrc = new LibrarySource(IRI.create(coreRegistry.replace("%23", "#")), regMgr);
} catch (Exception e1) {
throw new WebApplicationException(e1, BAD_REQUEST);
// Bad or not supplied core registry, try the ontology.
}
else if (coreOntology != null && !coreOntology.isEmpty()) try {
coreSrc = new RootOntologyIRISource(IRI.create(coreOntology));
} catch (Exception e2) {
// If this fails too, throw a bad request.
throw new WebApplicationException(e2, BAD_REQUEST);
}
// Don't bother if no custom was supplied at all...
if (customRegistry != null && !customRegistry.isEmpty())
// ...but if it was, be prepared to throw exceptions.
try {
coreSrc = new LibrarySource(IRI.create(customRegistry.replace("%23", "#")), regMgr);
} catch (Exception e1) {
throw new WebApplicationException(e1, BAD_REQUEST);
// Bad or not supplied custom registry, try the ontology.
}
if (customOntology != null && !customOntology.isEmpty()) try {
custSrc = new RootOntologyIRISource(IRI.create(customOntology));
} catch (Exception e2) {
// If this fails too, throw a bad request.
throw new WebApplicationException(e2, BAD_REQUEST);
}
// Now the creation.
try {
// Expand core sources
List<OntologyInputSource<?,?>> expanded = new ArrayList<OntologyInputSource<?,?>>();
if (coreSrc != null) {
if (coreSrc instanceof OntologySetInputSource) {
for (OWLOntology o : ((OntologySetInputSource) coreSrc).getOntologies()) {
expanded.add(new RootOntologySource(o));
}
} else expanded.add(coreSrc);
}
if (custSrc != null) {
if (custSrc instanceof OntologySetInputSource) for (OWLOntology o : ((OntologySetInputSource) custSrc)
.getOntologies())
expanded.add(new RootOntologySource(o));
else expanded.add(custSrc);
}
// Invoke the appropriate factory method depending on the
// availability of a custom source.
// scope = (custSrc != null) ? f.createOntologyScope(scopeid, coreSrc, custSrc) : f
// .createOntologyScope(scopeid, coreSrc);
scope = f.createOntologyScope(scopeid, expanded.toArray(new OntologyInputSource[0]));
// Setup and register the scope. If no custom space was set, it will
// still be open for modification.
scope.setUp();
reg.registerScope(scope);
reg.setScopeActive(scopeid, activate);