Search in sources :

Example 6 with RegistryOntology

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;
}
Also used : RegistryOntology(org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology) RegistryOntologyNotLoadedException(org.apache.stanbol.ontologymanager.registry.api.RegistryOntologyNotLoadedException) LibraryContentNotLoadedException(org.apache.stanbol.ontologymanager.registry.api.LibraryContentNotLoadedException) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem) HashSet(java.util.HashSet)

Example 7 with RegistryOntology

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;
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) RegistryOntology(org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology) Library(org.apache.stanbol.ontologymanager.registry.api.model.Library) Registry(org.apache.stanbol.ontologymanager.registry.api.model.Registry) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem)

Aggregations

RegistryItem (org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem)7 RegistryOntology (org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology)7 HashSet (java.util.HashSet)3 Registry (org.apache.stanbol.ontologymanager.registry.api.model.Registry)3 IRI (org.semanticweb.owlapi.model.IRI)3 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)3 LibraryContentNotLoadedException (org.apache.stanbol.ontologymanager.registry.api.LibraryContentNotLoadedException)2 Library (org.apache.stanbol.ontologymanager.registry.api.model.Library)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 RegistryContentException (org.apache.stanbol.ontologymanager.registry.api.RegistryContentException)1 RegistryOntologyNotLoadedException (org.apache.stanbol.ontologymanager.registry.api.RegistryOntologyNotLoadedException)1 OWLAnnotationAssertionAxiom (org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom)1 OWLAnnotationValue (org.semanticweb.owlapi.model.OWLAnnotationValue)1 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)1 OWLIndividual (org.semanticweb.owlapi.model.OWLIndividual)1 OWLNamedObject (org.semanticweb.owlapi.model.OWLNamedObject)1 OWLOntologyAlreadyExistsException (org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException)1 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)1 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)1