use of org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology in project stanbol by apache.
the class LibraryImpl method getOntologies.
@Override
public <O> Set<O> getOntologies(Class<O> returnType) throws RegistryContentException {
/*
* Note that this implementation is not synchronized. Listeners may indefinitely be notified before or
* after the rest of this method is executed. If listeners call loadOntologies(), they could still get
* a RegistryContentException, which however they can catch by calling loadOntologies() and
* getOntologies() in sequence.
*/
fireContentRequested(this);
// If no listener has saved the day by loading the ontologies by now, an exception will be thrown.
if (!loaded)
throw new LibraryContentNotLoadedException(this);
Set<O> ontologies = new HashSet<O>();
for (RegistryItem child : getChildren()) {
if (child instanceof RegistryOntology) {
O o = getCache().getStoredOntology(child.getIRI(), returnType);
// thrown when loading it), but just in case.
if (o != null)
ontologies.add(o);
else
throw new RegistryOntologyNotLoadedException((RegistryOntology) child);
}
}
return ontologies;
}
use of org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology in project stanbol by apache.
the class RegistryUtils method containsOntologyRecursive.
/**
* Utility method to recurse into registry items.
*
* TODO: move this to main?
*
* @param item
* @param ontologyId
* @return
*/
public static boolean containsOntologyRecursive(RegistryItem item, IRI ontologyId) {
boolean result = false;
if (item instanceof RegistryOntology) {
// An Ontology MUST have a non-null URI.
try {
IRI iri = item.getIRI();
result |= iri.equals(ontologyId);
} catch (Exception e) {
return false;
}
} else if (item instanceof Library || item instanceof Registry)
// Inspect children
for (RegistryItem child : item.getChildren()) {
result |= containsOntologyRecursive(child, ontologyId);
if (result)
break;
}
return result;
}
Aggregations