use of org.apache.stanbol.ontologymanager.servicesapi.scope.NoSuchScopeException in project stanbol by apache.
the class ScopeRegistryImpl method deregisterScope.
@Override
public synchronized void deregisterScope(Scope scope) {
String id = scope.getID();
if (!containsScope(id))
throw new NoSuchScopeException(id);
// For sure it is deactivated...
setScopeActive(id, false);
// activeScopeIRIs.remove(id);
scopeMap.remove(id);
fireScopeDeregistered(scope);
}
use of org.apache.stanbol.ontologymanager.servicesapi.scope.NoSuchScopeException in project stanbol by apache.
the class ScopeManagerImpl method bootstrapOntologyNetwork.
private void bootstrapOntologyNetwork(OWLOntology configOntology) {
if (configOntology == null) {
log.info("Ontology Network Manager starting with empty scope set.");
return;
}
try {
/**
* We create and register the scopes before activating
*/
for (String scopeId : OntologyNetworkConfigurationUtils.getScopes(configOntology)) {
String[] cores = OntologyNetworkConfigurationUtils.getCoreOntologies(configOntology, scopeId);
String[] customs = OntologyNetworkConfigurationUtils.getCustomOntologies(configOntology, scopeId);
// "Be a man. Use printf"
log.debug("Detected scope \"{}\"", scopeId);
for (String s : cores) log.debug("\tDetected core ontology {}", s);
for (String s : customs) log.debug("\tDetected custom ontology {}", s);
// Create the scope
log.debug("Rebuilding scope \"{}\"", scopeId);
Scope sc = null;
sc = /* factory. */
createOntologyScope(scopeId, new BlankOntologySource());
// Populate the core space
if (cores.length > 0) {
OntologySpace corespc = sc.getCoreSpace();
corespc.tearDown();
for (int i = 0; i < cores.length; i++) try {
corespc.addOntology(new RootOntologySource(IRI.create(cores[i])));
} catch (Exception ex) {
log.warn("Failed to import ontology " + cores[i], ex);
continue;
}
}
sc.setUp();
registerScope(sc);
sc.getCustomSpace().tearDown();
for (String locationIri : customs) {
try {
OntologyInputSource<?> src = new RootOntologySource(IRI.create(locationIri));
sc.getCustomSpace().addOntology(src);
log.debug("Added ontology from location {}", locationIri);
} catch (UnmodifiableOntologyCollectorException e) {
log.error("An error occurred while trying to add the ontology from location: " + locationIri, e);
continue;
}
}
sc.getCustomSpace().setUp();
}
/**
* Try to get activation policies
*/
toActivate = OntologyNetworkConfigurationUtils.getScopesToActivate(configOntology);
for (String scopeID : toActivate) {
try {
scopeID = scopeID.trim();
setScopeActive(scopeID, true);
log.info("Ontology scope " + scopeID + " activated.");
} catch (NoSuchScopeException ex) {
log.warn("Tried to activate unavailable scope " + scopeID + ".");
} catch (Exception ex) {
log.error("Exception caught while activating scope " + scopeID + " . Skipping.", ex);
continue;
}
}
} catch (Throwable e) {
log.warn("Invalid ONM configuration file found. " + "Starting with blank scope set.", e);
}
}
use of org.apache.stanbol.ontologymanager.servicesapi.scope.NoSuchScopeException in project stanbol by apache.
the class ScopeRegistryImpl method setScopeActive.
@Override
public void setScopeActive(String scopeID, boolean active) {
if (!containsScope(scopeID))
throw new NoSuchScopeException(scopeID);
// Prevent no-changes from firing events.
boolean previousStatus = isScopeActive(scopeID);
Scope scope = getScope(scopeID);
if (active == previousStatus)
return;
if (active) {
scope.setUp();
activeScopeIRIs.add(scopeID);
} else {
scope.tearDown();
activeScopeIRIs.remove(scopeID);
}
fireScopeActivationChange(scopeID, active);
}
Aggregations