use of org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace.SpaceType in project stanbol by apache.
the class GraphMultiplexer method checkHandle.
private void checkHandle(IRI candidate, Set<OntologyCollector> handles) {
/*
* We have to do it like this because we cannot make this class a Component and reference ONManager
* and SessionManager, otherwise an activation cycle will occur.
*/
// FIXME get rid of this.
ScopeManager scopeManager = ScopeManagerImpl.get();
SessionManager sessionManager = SessionManagerImpl.get();
String prefix_scope = _NS_STANBOL_INTERNAL + Scope.shortName + "/", prefix_session = _NS_STANBOL_INTERNAL + Session.shortName + "/";
// TODO check when not explicitly typed.
SpaceType spaceType;
if (meta.contains(new TripleImpl(candidate, RDF.type, SPACE_URIREF))) {
RDFTerm rScope;
Iterator<Triple> parentSeeker = meta.filter(candidate, IS_SPACE_CORE_OF_URIREF, null);
if (parentSeeker.hasNext()) {
rScope = parentSeeker.next().getObject();
spaceType = SpaceType.CORE;
} else {
parentSeeker = meta.filter(candidate, IS_SPACE_CUSTOM_OF_URIREF, null);
if (parentSeeker.hasNext()) {
rScope = parentSeeker.next().getObject();
spaceType = SpaceType.CUSTOM;
} else {
parentSeeker = meta.filter(null, HAS_SPACE_CORE_URIREF, candidate);
if (parentSeeker.hasNext()) {
rScope = parentSeeker.next().getSubject();
spaceType = SpaceType.CORE;
} else {
parentSeeker = meta.filter(null, HAS_SPACE_CUSTOM_URIREF, candidate);
if (parentSeeker.hasNext()) {
rScope = parentSeeker.next().getSubject();
spaceType = SpaceType.CUSTOM;
} else
throw new InvalidMetaGraphStateException("Ontology space " + candidate + " does not declare a parent scope.");
}
}
}
if (!(rScope instanceof IRI))
throw new InvalidMetaGraphStateException(rScope + " is not a legal scope identifier.");
String scopeId = ((IRI) rScope).getUnicodeString().substring(prefix_scope.length());
Scope scope = scopeManager.getScope(scopeId);
switch(spaceType) {
case CORE:
handles.add(scope.getCoreSpace());
break;
case CUSTOM:
handles.add(scope.getCustomSpace());
break;
}
} else if (meta.contains(new TripleImpl(candidate, RDF.type, SESSION_URIREF))) {
String sessionId = candidate.getUnicodeString().substring(prefix_session.length());
handles.add(sessionManager.getSession(sessionId));
}
}
Aggregations