@Override public HeavyLoadedOntology loadOntology( URI uri ) throws OntowrapException { OWLAPI3Ontology onto = null; //System.err.println( " Loading ontology "+uri ); // Cache seems to be implemented in API 3.0 anyway // and it seems to not work well with this one onto = cache.getOntologyFromURI( uri ); //System.err.println( " cache1: "+onto ); if ( onto != null ) return onto; onto = cache.getOntology( uri ); //System.err.println( " cache2: "+onto ); if ( onto != null ) return onto; // OWLAPI's own cache IRI ontoIRI = IRI.create( uri ); OWLOntology ontology = manager.getOntology( ontoIRI ); //System.err.println( " cache3: "+ontology ); try { // This below does not seem to work! //ontology = manager.loadOntologyFromOntologyDocument( IRI.create( uri ) ); if ( ontology == null ) ontology = manager.loadOntology( ontoIRI ); //System.err.println( " loaded: "+ontology ); // I must retrieve it from cache and return it! } catch ( OWLOntologyDocumentAlreadyExistsException oodaeex ) { // should never happen // This is a cache failure throw new OntowrapException("Already loaded [doc cache failure] " + uri, oodaeex ); } catch ( OWLOntologyAlreadyExistsException ooaeex ) { // This happens when the ontology has been loaded from a different URIs ontology = manager.getOntology( ooaeex.getOntologyID() ); if ( ontology == null ) throw new OntowrapException("Already loaded [owl cache failure] " + uri, ooaeex ); } catch ( OWLOntologyCreationException oocex ) { oocex.printStackTrace(); throw new OntowrapException("Cannot load " + uri, oocex ); } onto = new OWLAPI3Ontology(); onto.setFormalism( formalismId ); onto.setFormURI( formalismUri ); onto.setOntology( ontology ); onto.setFile( uri ); try { onto.setURI( ontology.getOntologyID().getOntologyIRI().toURI() ); } catch ( Exception e ) { // Should be a NullPointerException // Better put in the OntowrapException of loaded // The ontology has no URI. In principle, it is not valid // It may be possible to put the uri instead (now it is void) e.printStackTrace(); } cache.recordOntology( uri, onto ); //System.err.println( " after-cache: "+cache.getOntology( uri ) ); return onto; }