return (Library) lib;
}
protected RegistryOntology populateOntology(OWLNamedObject ind, Set<OWLOntology> registries) throws RegistryContentException {
IRI ontId = ind.getIRI();
RegistryItem ront = null;
if (population.containsKey(ontId)) {
// We are not allowing multityping either.
ront = population.get(ontId);
if (!(ront instanceof RegistryOntology)) throw new RegistryContentException(
"Inconsistent multityping: for item " + ontId + " : {" + RegistryOntology.class + ", "
+ ront.getClass() + "}");
} else {
ront = riFactory.createRegistryOntology(ind);
try {
population.put(ront.getIRI(), ront);
} catch (Exception e) {
log.error("Invalid identifier for library item " + ront, e);
return null;
}
}
// EXIT nodes.
Set<OWLNamedObject> libs = new HashSet<OWLNamedObject>();
OWLDataFactory df = OWLManager.getOWLDataFactory();
for (OWLOntology o : registries) {
if (ind instanceof OWLIndividual) {
// Get usages of isOntologyOf as an object property
for (OWLIndividual value : ((OWLIndividual) ind).getObjectPropertyValues(isOntologyOf, o))
if (value.isNamed()) libs.add(value.asOWLNamedIndividual());
// Get usages of isOntologyOf as an annotation property
for (OWLAnnotationAssertionAxiom ann : o.getAnnotationAssertionAxioms(ind.getIRI()))
if (isOntologyOfAnn.equals(ann.getProperty())) {
OWLAnnotationValue value = ann.getValue();
if (value instanceof OWLNamedObject) libs.add((OWLNamedObject) value);
else if (value instanceof IRI) libs.add(df.getOWLNamedIndividual((IRI) value));
}
}
}
for (OWLNamedObject ilib : libs) {
IRI parentId = ilib.getIRI();
// If some populate*() method has created it, it will be there.
RegistryItem rlib = population.get(parentId);
// Otherwise populating it will also put it in population.
if (rlib == null) rlib = populateLibrary(ilib, registries);
ront.addParent(rlib);
if (ontologyIndex.get(ontId) == null) ontologyIndex.put(ontId, new HashSet<IRI>());
ontologyIndex.get(ontId).add(parentId);