Author: alexdma
Date: Tue May 31 14:49:00 2011
New Revision: 1129718
URL: http://svn.apache.org/viewvc?rev=1129718&view=rev
Log:
STANBOL-178 :
- ONManager implementation now checks for OfflineMode
- Made ONM configuration a separate interface with default implementation.
- Added metatypes for ONM configuration
Added:
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ONManagerConfiguration.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerConfigurationImpl.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/resources/OSGI-INF/
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/resources/OSGI-INF/metatype/
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/resources/OSGI-INF/metatype/metatype.properties
Modified:
incubator/stanbol/trunk/ontologymanager/ontonet/pom.xml
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/pom.xml?rev=1129718&r1=1129717&r2=1129718&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/pom.xml (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/pom.xml Tue May 31 14:49:00
2011
@@ -129,6 +129,11 @@
<!-- Stanbol deps -->
<dependency>
<groupId>org.apache.stanbol</groupId>
+
<artifactId>org.apache.stanbol.commons.stanboltools.offline</artifactId>
+ <version>${stanbol-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.owl</artifactId>
<version>${stanbol-version}</version>
</dependency>
Added:
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ONManagerConfiguration.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ONManagerConfiguration.java?rev=1129718&view=auto
==============================================================================
---
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ONManagerConfiguration.java
(added)
+++
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ONManagerConfiguration.java
Tue May 31 14:49:00 2011
@@ -0,0 +1,68 @@
+package org.apache.stanbol.ontologymanager.ontonet.api;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * Provides the configuration needed for the {@link ONManager}. A
configuration should only be handled
+ * internally by the {@link ONManager} implementation.
+ *
+ * @author alessandro
+ *
+ */
+public interface ONManagerConfiguration {
+
+ /**
+ * The key used to configure the path of the ontology network
configuration.
+ */
+ String CONFIG_ONTOLOGY_PATH =
"org.apache.stanbol.ontologymanager.ontonet.onconfig";
+
+ /**
+ * The key used to configure the ID of the ontology network manager.
+ */
+ String ID = "org.apache.stanbol.ontologymanager.ontonet.id";
+
+ /**
+ * The key used to configure the base namespace of the ontology network.
+ */
+ String ONTOLOGY_NETWORK_NS =
"org.apache.stanbol.ontologymanager.ontonet.ns";
+
+ /**
+ * The key used to configure the paths of local ontologies.
+ */
+ String ONTOLOGY_PATHS =
"org.apache.stanbol.ontologymanager.ontonet.ontologypaths";
+
+ /**
+ * Returns the ID of the ontology network manager.
+ *
+ * @return the ID of the ontology network manager.
+ */
+ String getID();
+
+ /**
+ * Implementations should be able to create a {@link File} object from
this path.
+ *
+ * @return the local path of the ontology storing the ontology network
configuration.
+ */
+ String getOntologyNetworkConfigurationPath();
+
+ /**
+ * Returns the base namespace to be used for the Stanbol ontology network
(e.g. for the creation of new
+ * scopes). For convenience, it is returned as a string so that it can be
concatenated to form IRIs.
+ *
+ * @return the base namespace of the Stanbol ontology network.
+ */
+ String getOntologyNetworkNamespace();
+
+ /**
+ * Returns the paths of all the directories where the ontology network
manager will try to locate
+ * ontologies. These directories will be prioritaire if the engine is set
to run in offline mode. This
+ * list is ordered in that the higher-ordered directories generally
override lower-ordered ones, that is,
+ * any ontologies found in the directories belonging to the tail of this
list will supersede any
+ * ontologies with the same ID found in the directories belonging to its
head.
+ *
+ * @return an ordered list of directory paths for offline ontologies.
+ */
+ List<String> getOntologySourceDirectories();
+
+}
Added:
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerConfigurationImpl.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerConfigurationImpl.java?rev=1129718&view=auto
==============================================================================
---
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerConfigurationImpl.java
(added)
+++
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerConfigurationImpl.java
Tue May 31 14:49:00 2011
@@ -0,0 +1,121 @@
+package org.apache.stanbol.ontologymanager.ontonet.impl;
+
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.List;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.ontologymanager.ontonet.api.ONManagerConfiguration;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Default implementation of the {@link ONManagerConfiguration}.
+ *
+ * @author alessandro
+ *
+ */
+@Component(immediate = true, metatype = true)
+@Service
+public class ONManagerConfigurationImpl implements ONManagerConfiguration {
+
+ public static final String _CONFIG_ONTOLOGY_PATH_DEFAULT = "";
+
+ public static final String _ID_DEFAULT = "ontonet";
+
+ public static final String _ONTOLOGY_NETWORK_NS_DEFAULT =
"http://kres.iksproject.eu/";
+
+ @Property(name = ONManagerConfiguration.CONFIG_ONTOLOGY_PATH, value =
_CONFIG_ONTOLOGY_PATH_DEFAULT)
+ private String configPath;
+
+ protected Logger log = LoggerFactory.getLogger(getClass());
+
+ /**
+ * TODO how do you use array initializers in Property annotations without
causing compile errors?
+ */
+ @Property(name = ONManagerConfiguration.ONTOLOGY_PATHS, value = {".",
"ontologies"})
+ private String[] ontologyDirs;
+
+ @Property(name = ONManagerConfiguration.ID, value = _ID_DEFAULT)
+ private String ontonetID;
+
+ @Property(name = ONManagerConfiguration.ONTOLOGY_NETWORK_NS, value =
_ONTOLOGY_NETWORK_NS_DEFAULT)
+ private String ontonetNS;
+
+ /**
+ * This default constructor is <b>only</b> intended to be used by the OSGI
environment with Service
+ * Component Runtime support.
+ * <p>
+ * DO NOT USE to manually create instances - the ReengineerManagerImpl
instances do need to be configured!
+ * YOU NEED TO USE {@link #ONManagerConfigurationImpl(Dictionary)} or its
overloads, to parse the
+ * configuration and then initialise the rule store if running outside an
OSGI environment.
+ */
+ public ONManagerConfigurationImpl() {}
+
+ /**
+ * To be invoked by non-OSGi environments.
+ *
+ * @param configuration
+ */
+ public ONManagerConfigurationImpl(Dictionary<String,Object> configuration)
{
+ this();
+ activate(configuration);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Activate
+ protected void activate(ComponentContext context) {
+ log.info("in {} activate with context {}", getClass(), context);
+ if (context == null) {
+ throw new IllegalStateException("No valid" +
ComponentContext.class + " parsed in activate!");
+ }
+ activate((Dictionary<String,Object>) context.getProperties());
+ }
+
+ protected void activate(Dictionary<String,Object> configuration) {
+ // Parse configuration.
+ ontonetID = (String) configuration.get(ONManagerConfiguration.ID);
+ if (ontonetID == null) ontonetID = _ID_DEFAULT;
+ ontologyDirs = (String[])
configuration.get(ONManagerConfiguration.ONTOLOGY_PATHS);
+ if (ontologyDirs == null) ontologyDirs = new String[] {".",
"ontologies"};
+ ontonetNS = (String)
configuration.get(ONManagerConfiguration.ONTOLOGY_NETWORK_NS);
+ if (ontonetNS == null) ontonetNS = _ONTOLOGY_NETWORK_NS_DEFAULT;
+ configPath = (String)
configuration.get(ONManagerConfiguration.CONFIG_ONTOLOGY_PATH);
+ if (configPath == null) configPath = _CONFIG_ONTOLOGY_PATH_DEFAULT;
+ }
+
+ @Deactivate
+ protected void deactivate(ComponentContext context) {
+ ontonetID = null;
+ ontologyDirs = null;
+ ontonetNS = null;
+ configPath = null;
+ log.info("in {} deactivate with context {}", getClass(), context);
+ }
+
+ @Override
+ public String getID() {
+ return ontonetID;
+ }
+
+ @Override
+ public String getOntologyNetworkConfigurationPath() {
+ return configPath;
+ }
+
+ @Override
+ public String getOntologyNetworkNamespace() {
+ return ontonetNS;
+ }
+
+ @Override
+ public List<String> getOntologySourceDirectories() {
+ return Arrays.asList(ontologyDirs);
+ }
+
+}
Modified:
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java?rev=1129718&r1=1129717&r2=1129718&view=diff
==============================================================================
---
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java
(original)
+++
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ONManagerImpl.java
Tue May 31 14:49:00 2011
@@ -11,11 +11,15 @@ import org.apache.clerezza.rdf.core.acce
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.felix.scr.annotations.ReferenceStrategy;
import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.commons.stanboltools.offline.OfflineMode;
import org.apache.stanbol.ontologymanager.ontonet.api.DuplicateIDException;
import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.ONManagerConfiguration;
import org.apache.stanbol.ontologymanager.ontonet.api.io.BlankOntologySource;
import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
import org.apache.stanbol.ontologymanager.ontonet.api.io.RootOntologyIRISource;
@@ -68,11 +72,18 @@ import org.slf4j.LoggerFactory;
// @Property(name="service.ranking",intValue=5)
public class ONManagerImpl implements ONManager {
- public class Helper {
- private Helper() {}
+ /**
+ * Utility class to speed up ontology network startup. <br>
+ * TODO: it's most likely useless, remove it.
+ *
+ * @author enrico
+ *
+ */
+ private class Helper {
/**
- * Adds the ontology from the given iri to the core space of the given
scope
+ * Adds the ontology from the given iri to the core space of the given
scope.
+ *
*
* @param scopeID
* @param locationIri
@@ -164,45 +175,28 @@ public class ONManagerImpl implements ON
}
}
- public static final String _ALIAS_DEFAULT = "/ontology";
- public static final String _CONFIG_FILE_PATH_DEFAULT = "";
-
- public static final String _KRES_NAMESPACE_DEFAULT =
"http://kres.iksproject.eu/";
-
- // @Property(value = _ALIAS_DEFAULT)
- public static final String ALIAS =
"org.apache.stanbol.ontologyNetworkManager.alias";
-
- @Property(value = _CONFIG_FILE_PATH_DEFAULT)
- public static String CONFIG_FILE_PATH =
"org.apache.stanbol.ontologyNetworkManager.config_ont";
-
- @Property(value = _KRES_NAMESPACE_DEFAULT)
- public static String KRES_NAMESPACE = "kres.namespace";
- @SuppressWarnings("unused")
- private String alias = _ALIAS_DEFAULT;
- private String configPath = _CONFIG_FILE_PATH_DEFAULT;
-
- // private static ONManagerImpl me = new ONManagerImpl();
- //
- // public static ONManagerImpl get() {
- // return me;
- // }
-
- // private ComponentContext ce;
+ @Reference
+ private ONManagerConfiguration config;
private Helper helper = null;
- private String kresNs = _KRES_NAMESPACE_DEFAULT;
-
private final Logger log = LoggerFactory.getLogger(getClass());
+ /**
+ * The {@link OfflineMode} is used by Stanbol to indicate that no external
service should be referenced.
+ * For this engine that means it is necessary to check if the used {@link
ReferencedSite} can operate
+ * offline or not.
+ *
+ * @see #enableOfflineMode(OfflineMode)
+ * @see #disableOfflineMode(OfflineMode)
+ */
+ @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY, policy =
ReferencePolicy.DYNAMIC, bind = "enableOfflineMode", unbind =
"disableOfflineMode", strategy = ReferenceStrategy.EVENT)
+ private OfflineMode offlineMode;
+
private OntologyIndex oIndex;
private OntologyManagerFactory omgrFactory;
- public OntologyManagerFactory getOntologyManagerFactory() {
- return omgrFactory;
- }
-
private OntologyScopeFactory ontologyScopeFactory;
private OntologySpaceFactory ontologySpaceFactory;
@@ -236,8 +230,10 @@ public class ONManagerImpl implements ON
* Component Runtime support.
* <p>
* DO NOT USE to manually create instances - the ReengineerManagerImpl
instances do need to be configured!
- * YOU NEED TO USE {@link #ONManagerImpl(TcManager, WeightedTcProvider,
Dictionary)} or its overloads, to
- * parse the configuration and then initialise the rule store if running
outside an OSGI environment.
+ * YOU NEED TO USE
+ * {@link #ONManagerImpl(TcManager, WeightedTcProvider,
ONManagerConfiguration, Dictionary)} or its
+ * overloads, to parse the configuration and then initialise the rule
store if running outside an OSGI
+ * environment.
*/
public ONManagerImpl() {
super();
@@ -262,17 +258,36 @@ public class ONManagerImpl implements ON
}
/**
+ * @deprecated use
+ * {@link #ONManagerImpl(TcManager, WeightedTcProvider,
ONManagerConfiguration, Dictionary)}
+ * instead. Note that if the deprecated method is used
instead, it will copy the Dictionary
+ * context to a new {@link ONManagerConfiguration} object.
+ * @param tcm
+ * @param wtcp
+ * @param configuration
+ */
+ @Deprecated
+ public ONManagerImpl(TcManager tcm, WeightedTcProvider wtcp,
Dictionary<String,Object> configuration) {
+ // Copy the same configuration to the ONManagerConfigurationImpl.
+ this(tcm, wtcp, new ONManagerConfigurationImpl(configuration),
configuration);
+ }
+
+ /**
* To be invoked by non-OSGi environments.
*
* @param tcm
* @param wtcp
* @param configuration
*/
- public ONManagerImpl(TcManager tcm, WeightedTcProvider wtcp,
Dictionary<String,Object> configuration) {
+ public ONManagerImpl(TcManager tcm,
+ WeightedTcProvider wtcp,
+ ONManagerConfiguration onmconfig,
+ Dictionary<String,Object> configuration) {
this();
// Assume this.tcm and this.wtcp were not filled in by OSGi-DS.
this.tcm = tcm;
this.wtcp = wtcp;
+ this.config = onmconfig;
try {
activate(configuration);
} catch (IOException e) {
@@ -303,30 +318,49 @@ public class ONManagerImpl implements ON
*/
protected void activate(Dictionary<String,Object> configuration) throws
IOException {
- // Local directories first
- // try {
- // URI uri =
ONManagerImpl.this.getClass().getResource("/ontologies").toURI();
- // OfflineConfiguration.localDirs.add(new File(uri));
- // } catch (URISyntaxException e3) {
- // log.warn("Could not add ontology resource.", e3);
- // } catch (NullPointerException e3) {
- // log.warn("Could not add ontology resource.", e3);
- // }
+ // Parse configuration
+ if (config.getID() == null || config.getID().isEmpty()) {
+ log.warn("The Ontology Network Manager configuration does not
define a ID for the Ontology Network Manager");
+ } else {
+ log.info("id: {}", config.getID());
+ }
- // if (storage == null) storage = new OntologyStorage(this.tcm,
this.wtcp);
+ // if (config.getOntologySourceDirectories() != null) {
+ // for (String s : config.getOntologySourceDirectories()) {
+ // if (new File(s).exists()) System.out.println(s + " EXISTS");
+ // else System.out.println(s + " DOES NOT EXIST");
+ // }
+ // }
+ //
+ // // Local directories first
+ // // try {
+ // // URI uri =
ONManagerImpl.this.getClass().getResource("/ontologies").toURI();
+ // // OfflineConfiguration.localDirs.add(new File(uri));
+ // // } catch (URISyntaxException e3) {
+ // // log.warn("Could not add ontology resource.", e3);
+ // // } catch (NullPointerException e3) {
+ // // log.warn("Could not add ontology resource.", e3);
+ // // }
+ //
+ // // if (storage == null) storage = new OntologyStorage(this.tcm,
this.wtcp);
+ //
+ // if (isOfflineMode()) System.out.println("DIOCANE!");
bindResources(this.tcm, this.wtcp);
- 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;
+ // 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
*/
+
+ String configPath = config.getOntologyNetworkConfigurationPath();
+
if (configPath != null && !configPath.trim().isEmpty()) {
OWLOntology oConf = null;
OWLOntologyManager tempMgr =
omgrFactory.createOntologyManager(true);
@@ -494,15 +528,37 @@ public class ONManagerImpl implements ON
log.info("in " + ONManagerImpl.class + " deactivate with context " +
context);
}
+ /**
+ * Called by the ConfigurationAdmin to unbind the {@link #offlineMode} if
the service becomes unavailable
+ *
+ * @param mode
+ */
+ protected final void disableOfflineMode(OfflineMode mode) {
+ this.offlineMode = null;
+ }
+
+ /**
+ * Called by the ConfigurationAdmin to bind the {@link #offlineMode} if
the service becomes available
+ *
+ * @param mode
+ */
+ protected final void enableOfflineMode(OfflineMode mode) {
+ this.offlineMode = mode;
+ }
+
@Override
public String getKReSNamespace() {
- return kresNs;
+ return config.getOntologyNetworkNamespace();
}
public OntologyIndex getOntologyIndex() {
return oIndex;
}
+ public OntologyManagerFactory getOntologyManagerFactory() {
+ return omgrFactory;
+ }
+
/**
* Returns the ontology scope factory that was created along with the
manager context.
*
@@ -571,4 +627,13 @@ public class ONManagerImpl implements ON
public String[] getUrisToActivate() {
return toActivate;
}
+
+ /**
+ * Returns <code>true</code> only if Stanbol operates in {@link
OfflineMode}.
+ *
+ * @return the offline state
+ */
+ protected final boolean isOfflineMode() {
+ return offlineMode != null;
+ }
}
Added:
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/resources/OSGI-INF/metatype/metatype.properties
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1129718&view=auto
==============================================================================
---
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/resources/OSGI-INF/metatype/metatype.properties
(added)
+++
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/resources/OSGI-INF/metatype/metatype.properties
Tue May 31 14:49:00 2011
@@ -0,0 +1,17 @@
+#===============================================================================
+#Properties defined by the Ontology Network Manager configuration
+#===============================================================================
+org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerConfigurationImpl.name
= Apache Stanbol Ontology Network Manager configuration
+org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerConfigurationImpl.description
= Holds the properties needed for creating an Ontology Network Manager.
+
+org.apache.stanbol.ontologymanager.ontonet.id.name = ID
+org.apache.stanbol.ontologymanager.ontonet.id.description = The identifier of
this Ontology Network Manager instance.
+
+org.apache.stanbol.ontologymanager.ontonet.ns.name = Ontology network namespace
+org.apache.stanbol.ontologymanager.ontonet.ns.description = The base namespace
that should be used to identify components across the Stanbol ontology network
e.g. scopes and spaces. It can be overridden programmatically.
+
+org.apache.stanbol.ontologymanager.ontonet.onconfig.name = Configuration
ontology
+org.apache.stanbol.ontologymanager.ontonet.onconfig.description = The physical
location of the ontology storing the configuration of the Stanbol ontology
network. Can be an absolute URI or a file path (either absolute or relative to
the bundle resource directory).
+
+org.apache.stanbol.ontologymanager.ontonet.ontologypaths.name = Ontology
directories
+org.apache.stanbol.ontologymanager.ontonet.ontologypaths.description = The
local directories for ontology sources.
\ No newline at end of file