📄 genericowlsreader.java
字号:
// The MIT License
//
// Copyright (c) 2004 Evren Sirin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
/*
* Created on Dec 27, 2003
*
*/
package org.mindswap.owls.io.impl;
import java.net.URI;
import java.util.List;
import org.mindswap.owl.Util;
import org.mindswap.owls.OWLSFactory;
import org.mindswap.owls.grounding.Grounding;
import org.mindswap.owls.io.OWLSReader;
import org.mindswap.owls.profile.Profile;
import org.mindswap.owls.service.Service;
import org.mindswap.owls.process.Process;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.RDFErrorHandler;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.RDF;
/**
* @author Evren Sirin
*
*/
public class GenericOWLSReader extends OWLSReaderImpl {
public static boolean DEBUG = false;
/**
*
*/
public GenericOWLSReader() {
version = "X.X";
}
private OWLSReader findReader(Model model) {
for(int i = 0; i < OWLSFactory.supportedVersions.length; i++) {
String version = OWLSFactory.supportedVersions[i];
URI service = OWLSFactory.getVocabulary(version).getService().Service;
if(model.listStatements(null, RDF.type, Util.toResource(service)).hasNext()) {
OWLSReader r = OWLSFactory.createOWLSReader(version);
r.setListener(listener);
return r;
}
}
return null;
}
private OWLSReader findReader(URI fileURI) throws Exception {
reader.setErrorHandler(new RDFErrorHandler() {
public void warning(Exception e) {
GenericOWLSReader.this.warning(e.toString());
}
public void error(Exception e) {
GenericOWLSReader.this.error(e.toString());
}
public void fatalError(Exception e) {
GenericOWLSReader.this.error(e.toString());
}
});
Model model = reader.read(fileURI, false);
OWLSReader reader = findReader(model);
if(reader == null) {
warning("Warning: Cannot determine the OWL-S version of service " + fileURI);
reader = OWLSFactory.createOWLSReader(OWLSFactory.getLatestVersion());
}
return reader;
}
/* (non-Javadoc)
* @see org.mindswap.OWLS_0_9.parser.Parser#parse(java.lang.String)
*/
public Service read(URI fileURI) throws Exception {
OWLSReader reader = findReader(fileURI);
return reader.read(fileURI);
}
/* (non-Javadoc)
* @see org.mindswap.OWLS_0_9.parser.Parser#parse(java.lang.String)
*/
public List readAll(URI fileURI) throws Exception {
OWLSReader reader = findReader(fileURI);
return reader.readAll(fileURI);
}
/* (non-Javadoc)
* @see org.mindswap.owls.io.impl.OWLSReaderImpl#createService(java.net.URI, com.hp.hpl.jena.rdf.model.Model)
*/
protected List createService(URI fileURI, Model model) {
throw new RuntimeException("Generic reader should find an appropriate reader");
}
/* (non-Javadoc)
* @see org.mindswap.owls.io.OWLSReader#createProcess(com.hp.hpl.jena.rdf.model.Resource)
*/
public Process createProcess(Service service, Resource processInfo) {
OWLSReader reader = findReader(processInfo.getModel());
return reader.createProcess(service, processInfo);
}
/* (non-Javadoc)
* @see org.mindswap.owls.io.OWLSReader#createProfile(com.hp.hpl.jena.rdf.model.Resource)
*/
public Profile createProfile(Service service, Resource profileInfo) {
OWLSReader reader = findReader(profileInfo.getModel());
return reader.createProfile(service, profileInfo);
}
/* (non-Javadoc)
* @see org.mindswap.owls.io.OWLSReader#createGrounding(com.hp.hpl.jena.rdf.model.Resource)
*/
public Grounding createGrounding(Service service, Resource groundingInfo) {
OWLSReader reader = findReader(groundingInfo.getModel());
return reader.createGrounding(service, groundingInfo);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -