@Override public InputStream getOntology(String syntax) throws IOException { InputStream is; JenaBeanExtension jbe; // check the validity of user request on serialization syntax if (syntax == null || syntax.equalsIgnoreCase("owl") || syntax.equalsIgnoreCase(Syntax.RDF_XML_ABBREV)) syntax = Syntax.RDF_XML; syntax = syntax.toUpperCase(); // get the ontology document in required syntax lock.readLock().lock(); InputStream fileIn = new FileInputStream(ontologyFile); if (!syntax.equals(Syntax.RDF_XML)) { jbe = new JenaBeanExtensionTool(); jbe.loadStatements(fileIn, Syntax.RDF_XML); fileIn.close(); lock.readLock().unlock(); is = jbe.getOntologyDocument(syntax); } else { is = new ByteArrayInputStream(toByteArray(fileIn)); fileIn.close(); lock.readLock().unlock(); } return is; }
/** * Creates an instance of JenaBeanExtension with loaded model. * * @return instance of JenaBeanExtension */ private JenaBeanExtension creatingJenaBean(List<Object> dataList) { JenaBeanExtension jbe = new JenaBeanExtensionTool(); try { jbe.loadStatements(ontologyHeader.getInputStream(), Syntax.RDF_XML_ABBREV); } catch (IOException e) { log.error( "Could not open the input stream associated with the ontology header " + "configuration document: " + ontologyHeader.getFilename(), e); } jbe.loadOOM(dataList); // jbe.declareAllClassesDisjoint(); return jbe; }
@Override public InputStream getOntologySchema(String syntax) throws IOException { InputStream is; JenaBeanExtension jbe; // create the ontology schema lock.readLock().lock(); InputStream fileIn = new FileInputStream(ontologyFile); jbe = new JenaBeanExtensionTool(); jbe.loadStatements(fileIn, Syntax.RDF_XML); fileIn.close(); lock.readLock().unlock(); is = jbe.getOntologySchema(Syntax.RDF_XML_ABBREV); return is; }
/** * Transforms the object-oriented model into the OWL ontology. Serialization of this ontology is * stored in a temporary file. */ public void transformModel() { JenaBeanExtension jbe; OutputStream out; try { List<Object> dataList = loadData(); jbe = creatingJenaBean(dataList); lock.writeLock().lock(); out = new FileOutputStream(ontologyFile); jbe.writeOntologyDocument(out, Syntax.RDF_XML); out.close(); } catch (FileNotFoundException e) { log.error("Could not find the temporary rdf/xml file to store the ontology!", e); } catch (IOException e) { log.error("Could not close the temporary rdf/xml file!", e); } catch (Exception e) { log.error("Could not create the ontology!", e); } finally { lock.writeLock().unlock(); } }