Search in sources :

Example 1 with LibraryContentNotLoadedException

use of org.apache.stanbol.ontologymanager.registry.api.LibraryContentNotLoadedException in project stanbol by apache.

the class LibraryImpl method getOntology.

@Override
public <O> O getOntology(IRI id, 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);
    O ontology = null;
    RegistryItem child = getChild(id);
    if (child instanceof RegistryOntology) {
        ontology = getCache().getStoredOntology(child.getIRI(), returnType);
    }
    return ontology;
}
Also used : RegistryOntology(org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology) LibraryContentNotLoadedException(org.apache.stanbol.ontologymanager.registry.api.LibraryContentNotLoadedException) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem)

Example 2 with LibraryContentNotLoadedException

use of org.apache.stanbol.ontologymanager.registry.api.LibraryContentNotLoadedException 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)

Aggregations

LibraryContentNotLoadedException (org.apache.stanbol.ontologymanager.registry.api.LibraryContentNotLoadedException)2 RegistryItem (org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem)2 RegistryOntology (org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology)2 HashSet (java.util.HashSet)1 RegistryOntologyNotLoadedException (org.apache.stanbol.ontologymanager.registry.api.RegistryOntologyNotLoadedException)1