use of org.semanticweb.owlapi.io.FileDocumentSource in project stanbol by apache.
the class ScopeManagerImpl method activate.
/**
* Called within both OSGi and non-OSGi environments.
*
* @param configuration
* @throws IOException
*/
protected void activate(Dictionary<String, Object> configuration) throws IOException {
long before = System.currentTimeMillis();
// Assign singleton instance
me = this;
// Parse configuration
if (offline != null)
ontonetNS = offline.getDefaultOntologyNetworkNamespace();
scopeRegistryId = (String) configuration.get(ScopeManager.ID_SCOPE_REGISTRY);
if (scopeRegistryId == null)
scopeRegistryId = _ID_SCOPE_REGISTRY_DEFAULT;
configPath = (String) configuration.get(ScopeManager.CONFIG_ONTOLOGY_PATH);
if (configPath == null)
configPath = _CONFIG_ONTOLOGY_PATH_DEFAULT;
// Bind components, starting with the local directories.
List<String> dirs = new ArrayList<String>();
try {
for (IRI iri : offline.getOntologySourceLocations()) dirs.add(iri.toString());
} catch (NullPointerException ex) {
// Ok, go empty
}
bindResources();
// String tfile = (String) configuration.get(CONFIG_FILE_PATH);
// if (tfile != null) this.configPath = tfile;
// String tns = (String) configuration.get(KRES_NAMESPACE);
// if (tns != null) this.kresNs = tns;
// configPath = (String) configuration.get(CONFIG_FILE_PATH);
// If there is no configuration file, just start with an empty scope set
Object connectivityPolicy = configuration.get(ScopeManager.CONNECTIVITY_POLICY);
if (connectivityPolicy == null) {
this.connectivityPolicyString = _CONNECTIVITY_POLICY_DEFAULT;
} else {
this.connectivityPolicyString = connectivityPolicy.toString();
}
String configPath = getOntologyNetworkConfigurationPath();
if (configPath != null && !configPath.trim().isEmpty()) {
OWLOntology oConf = null;
OWLOntologyManager tempMgr = OWLOntologyManagerFactory.createOWLOntologyManager(offline.getOntologySourceLocations().toArray(new IRI[0]));
OWLOntologyDocumentSource oConfSrc = null;
try {
log.debug("Try to load the configuration ontology from a local bundle relative path");
InputStream is = this.getClass().getResourceAsStream(configPath);
oConfSrc = new StreamDocumentSource(is);
} catch (Exception e1) {
try {
log.debug("Cannot load from a local bundle relative path", e1);
log.debug("Try to load the configuration ontology resolving the given IRI");
IRI iri = IRI.create(configPath);
if (!iri.isAbsolute())
throw new Exception("IRI seems to be not absolute! value was: " + iri.toQuotedString());
oConfSrc = new IRIDocumentSource(iri);
} catch (Exception e) {
try {
log.debug("Cannot load from the web", e1);
log.debug("Try to load the configuration ontology as full local file path");
oConfSrc = new FileDocumentSource(new File(configPath));
} catch (Exception e2) {
log.error("Cannot load the configuration ontology from parameter value: " + configPath, e2);
}
}
}
if (oConfSrc == null) {
log.warn("No ONM configuration file found at path " + configPath + ". Starting with blank scope set.");
} else {
try {
oConf = tempMgr.loadOntologyFromOntologyDocument(oConfSrc);
} catch (OWLOntologyCreationException e) {
log.error("Cannot create the configuration ontology", e);
}
}
// Create and populate the scopes from the config ontology.
bootstrapOntologyNetwork(oConf);
} else {
// No ontology supplied. Access the local graph
rebuildScopes();
}
log.debug(ScopeManager.class + " activated. Time : {} ms.", System.currentTimeMillis() - before);
}
use of org.semanticweb.owlapi.io.FileDocumentSource in project stanbol by apache.
the class ODPRegistryCacheManager method getOntologyInputSource.
public static synchronized OWLOntologyDocumentSource getOntologyInputSource(URI uri) throws ODPRegistryCacheException, URIUnresolvableException {
if (getUnresolvedURIs().contains(uri))
throw new URIUnresolvableException();
if (uris.containsKey(uri)) {
File f = uris.get(uri);
FileDocumentSource fds = new FileDocumentSource(f);
return fds;
} else {
try {
retrieveRemoteResource(uri);
return getOntologyInputSource(uri);
} catch (UnknownOWLOntologyException e) {
throw new ODPRegistryCacheException(e);
} catch (OWLOntologyCreationException e) {
throw new ODPRegistryCacheException(e);
} catch (OWLOntologyStorageException e) {
throw new ODPRegistryCacheException(e);
}
}
}
Aggregations