2ronwalf// The MIT License
2ronwalf//
2ronwalf// Copyright (c) 2004 Evren Sirin
2ronwalf//
2ronwalf// Permission is hereby granted, free of charge, to any person obtaining a copy
2ronwalf// of this software and associated documentation files (the "Software"), to
2ronwalf// deal in the Software without restriction, including without limitation the
2ronwalf// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
2ronwalf// sell copies of the Software, and to permit persons to whom the Software is
2ronwalf// furnished to do so, subject to the following conditions:
2ronwalf//
2ronwalf// The above copyright notice and this permission notice shall be included in
2ronwalf// all copies or substantial portions of the Software.
2ronwalf//
2ronwalf// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2ronwalf// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2ronwalf// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2ronwalf// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2ronwalf// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2ronwalf// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2ronwalf// IN THE SOFTWARE.
2ronwalf
2ronwalf/*
2ronwalf * Created on Dec 29, 2003
2ronwalf *
2ronwalf */
2ronwalfpackage org.mindswap.owl;
2ronwalf
2ronwalfimport java.net.URI;
2ronwalfimport java.util.Map;
2ronwalf
2ronwalfimport org.mindswap.owls.vocabulary.OWLS;
2ronwalfimport org.mindswap.query.ABoxQueryParser;
2ronwalf
2ronwalf
2ronwalf/**
2ronwalf * @author Evren Sirin
2ronwalf *
2ronwalf */
2ronwalfpublic class OWLFactory {
2ronwalf private static OWLKnowledgeBase kb;
2ronwalf private static OWLOntology owlsService;
2ronwalf private static OWLOntology owlsProfile;
2ronwalf private static OWLOntology owlsGrounding;
2ronwalf private static OWLOntology owlsProcess;
2ronwalf
2ronwalf public interface Interface {
2ronwalf public Map getReasoners();
2ronwalf
2ronwalf public Object getReasoner(String reasonerName);
2ronwalf
2ronwalf public OWLKnowledgeBase createKB();
2ronwalf
2ronwalf public OWLOntology createOntology();
2ronwalf
2ronwalf public OWLOntology createOntology(URI uri);
2ronwalf
2ronwalf public OWLReader createReader();
2ronwalf
2ronwalf public OWLWriter createWriter();
2ronwalf
2ronwalf public OWLDataValueList createDataValueList();
2ronwalf
2ronwalf public OWLIndividualList createIndividualList();
2ronwalf
2ronwalf public ABoxQueryParser createRDQLParser(OWLModel model);
2ronwalf
2ronwalf public Map getDefaultConverters();
2ronwalf }
2ronwalf
2ronwalf private static String[] implementations = {"impl.jena.JenaOWLFactory"};
2ronwalf
2ronwalf private static OWLFactory.Interface factory = createFactory();
2ronwalf
2ronwalf private static OWLFactory.Interface createFactory() {
2ronwalf for(int i = 0; (factory == null) && (i < implementations.length); i++) {
2ronwalf try {
2ronwalf Class impl = Class.forName(implementations[i]);
2ronwalf factory = (OWLFactory.Interface) impl.newInstance();
2ronwalf } catch(Exception e) {
2ronwalf System.err.println("Cannot create OWLFactory!");
2ronwalf e.printStackTrace();
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf return factory;
2ronwalf }
2ronwalf
2ronwalf public static OWLKnowledgeBase createKB() {
2ronwalf return factory.createKB();
2ronwalf }
2ronwalf
2ronwalf public static OWLOntology createOntology() {
2ronwalf return createOntology(false);
2ronwalf }
2ronwalf
2ronwalf public static OWLOntology createOntology(URI uri) {
2ronwalf return createOntology(uri, false);
2ronwalf }
2ronwalf
2ronwalf /**
2ronwalf * Create an empty OWL ontology and optionally import the
2ronwalf * OWL-S ontologies (Service, Profile, Process and Grounding
2ronwalf * ontologies).
2ronwalf *
2ronwalf * @param importOWLS
2ronwalf * @return
2ronwalf */
2ronwalf public static OWLOntology createOntology( boolean importOWLS ) {
2ronwalf OWLOntology ont = factory.createOntology();
2ronwalf if( importOWLS )
2ronwalf addOWLSImports( ont );
2ronwalf return ont;
2ronwalf }
2ronwalf
2ronwalf /**
2ronwalf * Create an empty OWL ontology with the given logical URI
2ronwalf * and optionally import the OWL-S ontologies (Service, Profile, Process
2ronwalf * and Grounding ontologies)
2ronwalf *
2ronwalf * @param importOWLS
2ronwalf * @return
2ronwalf */
2ronwalf public static OWLOntology createOntology( URI uri, boolean importOWLS ) {
2ronwalf OWLOntology ont = factory.createOntology(uri);
2ronwalf if( importOWLS )
2ronwalf addOWLSImports( ont );
2ronwalf return ont;
2ronwalf }
2ronwalf
2ronwalf /**
2ronwalf * Import the OWL-S ontologies (Service, Profile, Process
2ronwalf * and Grounding ontologies) in the given ontology
2ronwalf *
2ronwalf * @param ont
2ronwalf * @return
2ronwalf */
2ronwalf
2ronwalf public static void addOWLSImports( OWLOntology ont ) {
2ronwalf loadOWLSOntologies();
2ronwalf
2ronwalf ont.addImport( owlsService );
2ronwalf ont.addImport( owlsProfile );
2ronwalf ont.addImport( owlsProcess );
2ronwalf ont.addImport( owlsGrounding );
2ronwalf }
2ronwalf
2ronwalf private static void loadOWLSOntologies() {
2ronwalf if( kb == null ) {
2ronwalf kb = createKB();
2ronwalf
2ronwalf try {
2ronwalf owlsService = kb.read( OWLS.Service.URI );
2ronwalf owlsProfile = kb.read( OWLS.Profile.URI );
2ronwalf owlsProcess = kb.read( OWLS.Process.URI );
2ronwalf owlsGrounding = kb.read( OWLS.Grounding.URI );
2ronwalf }
2ronwalf catch( Exception e ) {
2ronwalf owlsService = kb.createOntology( URI.create( OWLS.Service.URI ) );
2ronwalf owlsProfile = kb.createOntology( URI.create( OWLS.Profile.URI ) );
2ronwalf owlsProcess = kb.createOntology( URI.create( OWLS.Process.URI ) );
2ronwalf owlsGrounding = kb.createOntology( URI.create( OWLS.Grounding.URI ) );
2ronwalf }
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf public static OWLReader createReader() {
2ronwalf return factory.createReader();
2ronwalf }
2ronwalf
2ronwalf public static OWLWriter createWriter() {
2ronwalf return factory.createWriter();
2ronwalf }
2ronwalf
2ronwalf public static OWLDataValueList createDataValueList() {
2ronwalf return factory.createDataValueList();
2ronwalf }
2ronwalf
2ronwalf public static OWLIndividualList createIndividualList() {
2ronwalf return factory.createIndividualList();
2ronwalf }
2ronwalf
2ronwalf
2ronwalf public static Map getReasoners() {
2ronwalf return factory.getReasoners();
2ronwalf }
2ronwalf
2ronwalf public static Object getReasoner(String reasonerName) {
2ronwalf return factory.getReasoner(reasonerName);
2ronwalf }
2ronwalf
2ronwalf public static ABoxQueryParser createRDQLParser(OWLModel model) {
2ronwalf return factory.createRDQLParser(model);
2ronwalf }
2ronwalf
2ronwalf public static Map getDefaultConverters() {
2ronwalf return factory.getDefaultConverters();
2ronwalf }
2ronwalf}