You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by al...@apache.org on 2012/07/19 19:10:07 UTC
svn commit: r1363428 [2/4] - in /incubator/stanbol/trunk:
commons/owl/src/main/java/org/apache/stanbol/commons/owl/util/
commons/owl/src/test/java/org/apache/stanbol/commons/owl/util/
enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/...
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/session/SessionListener.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/session/SessionListener.java?rev=1363428&r1=1363427&r2=1363428&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/session/SessionListener.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/session/SessionListener.java Thu Jul 19 17:10:05 2012
@@ -1,36 +1,61 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.stanbol.ontologymanager.ontonet.api.session;
+import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologyScope;
+
/**
- * Objects that want to listen to events affecting KReS sessions should
- * implement this interface and add themselves as listener to a manager.
+ * Objects that want to listen to events affecting sessions should implement this interface and add themselves
+ * as listener to a manager.
*
* @author alexdma
*
*/
public interface SessionListener {
- /**
- * Called whenever an event affecting a KReS session is fired.
- *
- * @param event
- * the session event.
- */
+ /**
+ * Called whenever a scope is appended to a session.
+ *
+ * @param session
+ * the affected session
+ * @param scopeId
+ * the identifier of the scope that was attached.
+ */
+ void scopeAppended(Session session, String scopeId);
+
+ /**
+ * Called whenever a scope is detached from a session.
+ *
+ * @param session
+ * the affected session
+ * @param scopeId
+ * the identifier of the scope that was attached. Note that the corresponding
+ * {@link OntologyScope} could be null if detachment occurred as a consequence of a scope
+ * deletion.
+ * */
+ void scopeDetached(Session session, String scopeId);
+
+ /**
+ * Called whenever an event affecting a session is fired. This method encompasses all and only the event
+ * where it only interesting to know the affected session.
+ *
+ * @param event
+ * the session event.
+ */
void sessionChanged(SessionEvent event);
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/session/SessionManager.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/session/SessionManager.java?rev=1363428&r1=1363427&r2=1363428&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/session/SessionManager.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/session/SessionManager.java Thu Jul 19 17:10:05 2012
@@ -45,11 +45,6 @@ public interface SessionManager extends
String MAX_ACTIVE_SESSIONS = "org.apache.stanbol.ontologymanager.ontonet.session_limit";
/**
- * The key used to configure the base namespace of the ontology network.
- */
- String SESSIONS_NS = "org.apache.stanbol.ontologymanager.ontonet.session_ns";
-
- /**
* Generates <b>and registers</b> a new session and assigns a unique session ID generated internally. This
* will not cause {@link DuplicateSessionIDException}s to be thrown.
*
@@ -115,6 +110,9 @@ public interface SessionManager extends
/**
* Stores the session identified by <code>sessionID</code> using the output stream <code>out</code>.
*
+ * @deprecated As of now, session contents are always stored. Deprecation will be removed if a new policy
+ * is implemented.
+ *
* @param sessionID
* the IRI that uniquely identifies the session
* @param out
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=1363428&r1=1363427&r2=1363428&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 Thu Jul 19 17:10:05 2012
@@ -83,56 +83,9 @@ import org.slf4j.LoggerFactory;
@Service(ONManager.class)
public class ONManagerImpl extends ScopeRegistryImpl implements ONManager {
- /**
- * 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 fromt he given iri to the custom space of the given scope
- *
- * @param scopeID
- * @param locationIri
- */
- public synchronized void addToCustomSpace(String scopeID, String[] locationIris) {
- OntologyScope scope = ONManagerImpl.this.getScope(scopeID);
-
- scope.getCustomSpace().tearDown();
- for (String locationIri : locationIris) {
- try {
- scope.getCustomSpace().addOntology(createOntologyInputSource(locationIri));
- log.debug("Added " + locationIri + " to scope " + scopeID + " in the custom space.", this);
- } catch (UnmodifiableOntologyCollectorException e) {
- log.error("An error occurred while trying to add the ontology from location: "
- + locationIri, e);
- }
- }
- scope.getCustomSpace().setUp();
- }
-
- private OntologyInputSource createOntologyInputSource(final String uri) {
- try {
- return new RootOntologyIRISource(IRI.create(uri));
- } catch (OWLOntologyCreationException e) {
- log.error("Cannot load the ontology {}", uri, e);
- return null;
- } catch (Exception e) {
- log.error("Cannot load the ontology {}", uri, e);
- return null;
- }
- }
-
- }
-
public static final String _CONFIG_ONTOLOGY_PATH_DEFAULT = "";
public static final String _CONNECTIVITY_POLICY_DEFAULT = "TIGHT";
- public static final String _ID_DEFAULT = "ontonet";
public static final String _ID_SCOPE_REGISTRY_DEFAULT = "ontology";
- public static final String _ONTOLOGY_NETWORK_NS_DEFAULT = "http://localhost:8080/ontonet/";
@Property(name = ONManager.CONFIG_ONTOLOGY_PATH, value = _CONFIG_ONTOLOGY_PATH_DEFAULT)
private String configPath;
@@ -146,8 +99,6 @@ public class ONManagerImpl extends Scope
+ ".option.loose", name = "LOOSE")}, value = _CONNECTIVITY_POLICY_DEFAULT)
private String connectivityPolicyString;
- private Helper helper = null;
-
private final Logger log = LoggerFactory.getLogger(getClass());
@Reference
@@ -170,11 +121,7 @@ public class ONManagerImpl extends Scope
@Reference
private OntologySpaceFactory ontologySpaceFactory;
- @Property(name = ONManager.ID, value = _ID_DEFAULT)
- private String ontonetID;
-
- @Property(name = ONManager.ONTOLOGY_NETWORK_NS, value = _ONTOLOGY_NETWORK_NS_DEFAULT)
- private String ontonetNS;
+ private IRI ontonetNS = null;
@Property(name = ONManager.ID_SCOPE_REGISTRY, value = _ID_SCOPE_REGISTRY_DEFAULT)
private String scopeRegistryId;
@@ -236,20 +183,16 @@ public class ONManagerImpl extends Scope
*/
protected void activate(Dictionary<String,Object> configuration) throws IOException {
+ long before = System.currentTimeMillis();
+
// Parse configuration
- ontonetID = (String) configuration.get(ONManager.ID);
- if (ontonetID == null) ontonetID = _ID_DEFAULT;
- ontonetNS = (String) configuration.get(ONManager.ONTOLOGY_NETWORK_NS);
- if (ontonetNS == null) ontonetNS = _ONTOLOGY_NETWORK_NS_DEFAULT;
+ if (offline != null) ontonetNS = offline.getDefaultOntologyNetworkNamespace();
+
scopeRegistryId = (String) configuration.get(ONManager.ID_SCOPE_REGISTRY);
if (scopeRegistryId == null) scopeRegistryId = _ID_SCOPE_REGISTRY_DEFAULT;
configPath = (String) configuration.get(ONManager.CONFIG_ONTOLOGY_PATH);
if (configPath == null) configPath = _CONFIG_ONTOLOGY_PATH_DEFAULT;
- if (ontonetID == null || ontonetID.isEmpty()) {
- log.warn("The Ontology Network Manager configuration does not define a ID for the Ontology Network Manager");
- }
-
// Bind components, starting with the local directories.
List<String> dirs = new ArrayList<String>();
try {
@@ -329,7 +272,7 @@ public class ONManagerImpl extends Scope
rebuildScopes();
}
- log.debug(ONManager.class + " activated.");
+ log.debug(ONManager.class + " activated. Time : {} ms.", System.currentTimeMillis() - before);
}
@@ -338,16 +281,14 @@ public class ONManagerImpl extends Scope
listeners.add(listener);
}
+ @SuppressWarnings("unchecked")
protected void bindResources() {
if (ontologySpaceFactory == null) {
- IRI ns = IRI.create(getOntologyNetworkNamespace());
if (ontologyProvider.getStore() instanceof TcProvider) ontologySpaceFactory = new OntologySpaceFactoryImpl(
(OntologyProvider<TcProvider>) ontologyProvider, new Hashtable<String,Object>());
- else ontologySpaceFactory = new org.apache.stanbol.ontologymanager.ontonet.impl.owlapi.OntologySpaceFactoryImpl(
- this, offline, ns);
}
IRI iri = IRI.create(getOntologyNetworkNamespace() + scopeRegistryId + "/");
- ontologySpaceFactory.setNamespace(iri);
+ ontologySpaceFactory.setDefaultNamespace(iri);
// Add listeners
if (ontologyProvider instanceof ScopeEventListener) this
@@ -364,25 +305,23 @@ public class ONManagerImpl extends Scope
/**
* We create and register the scopes before activating
*/
- for (String scopeIRI : OntologyNetworkConfigurationUtils.getScopes(configOntology)) {
+ for (String scopeId : OntologyNetworkConfigurationUtils.getScopes(configOntology)) {
- String[] cores = OntologyNetworkConfigurationUtils
- .getCoreOntologies(configOntology, scopeIRI);
+ String[] cores = OntologyNetworkConfigurationUtils.getCoreOntologies(configOntology, scopeId);
String[] customs = OntologyNetworkConfigurationUtils.getCustomOntologies(configOntology,
- scopeIRI);
+ scopeId);
// "Be a man. Use printf"
- log.debug("Scope " + scopeIRI);
- for (String s : cores) {
- log.debug("\tCore ontology " + s);
- }
- for (String s : customs) {
- log.debug("\tCustom ontology " + s);
- }
+ log.debug("Detected scope \"{}\"", scopeId);
+ for (String s : cores)
+ log.debug("\tDetected core ontology {}", s);
+ for (String s : customs)
+ log.debug("\tDetected custom ontology {}", s);
// Create the scope
+ log.debug("Rebuilding scope \"{}\"", scopeId);
OntologyScope sc = null;
- sc = createOntologyScope(scopeIRI, new BlankOntologySource());
+ sc = createOntologyScope(scopeId, new BlankOntologySource());
// Populate the core space
if (cores.length > 0) {
@@ -399,10 +338,19 @@ public class ONManagerImpl extends Scope
sc.setUp();
registerScope(sc);
-
- // getScopeHelper().createScope(scopeIRI);
- // getScopeHelper().addToCoreSpace(scopeIRI, cores);
- getScopeHelper().addToCustomSpace(scopeIRI, customs);
+ sc.getCustomSpace().tearDown();
+ for (String locationIri : customs) {
+ try {
+ OntologyInputSource<?> src = new RootOntologyIRISource(IRI.create(locationIri));
+ sc.getCustomSpace().addOntology(src);
+ log.debug("Added ontology from location {}", locationIri);
+ } catch (UnmodifiableOntologyCollectorException e) {
+ log.error("An error occurred while trying to add the ontology from location: "
+ + locationIri, e);
+ continue;
+ }
+ }
+ sc.getCustomSpace().setUp();
}
/**
@@ -435,7 +383,7 @@ public class ONManagerImpl extends Scope
}
@Override
- public OntologyScope createOntologyScope(String scopeID, OntologyInputSource<?,?>... coreSources) throws DuplicateIDException {
+ public OntologyScope createOntologyScope(String scopeID, OntologyInputSource<?>... coreSources) throws DuplicateIDException {
if (this.containsScope(scopeID)) throw new DuplicateIDException(scopeID,
"Scope registry already contains ontology scope with ID " + scopeID);
// Scope constructor also creates core and custom spaces
@@ -471,7 +419,6 @@ public class ONManagerImpl extends Scope
*/
@Deactivate
protected void deactivate(ComponentContext context) {
- ontonetID = null;
ontonetNS = null;
configPath = null;
log.info("in " + ONManagerImpl.class + " deactivate with context " + context);
@@ -512,7 +459,7 @@ public class ONManagerImpl extends Scope
@Override
public String getOntologyNetworkNamespace() {
- return ontonetNS;
+ return ontonetNS.toString();
}
/**
@@ -540,13 +487,6 @@ public class ONManagerImpl extends Scope
return listeners;
}
- public Helper getScopeHelper() {
- if (helper == null) {
- helper = new Helper();
- }
- return helper;
- }
-
@Override
public ScopeRegistry getScopeRegistry() {
return this;
@@ -567,7 +507,7 @@ public class ONManagerImpl extends Scope
long before = System.currentTimeMillis();
log.debug("Rebuilding scope with ID \"{}\".", scopeId);
Collection<String> coreOnts = struct.getCoreOntologyKeysForScope(scopeId);
- OntologyInputSource<?,?>[] srcs = new OntologyInputSource<?,?>[coreOnts.size()];
+ OntologyInputSource<?>[] srcs = new OntologyInputSource<?>[coreOnts.size()];
int i = 0;
for (String coreOnt : coreOnts) {
log.debug("Core ontology key : {}", coreOnts);
@@ -585,7 +525,7 @@ public class ONManagerImpl extends Scope
// Register even if some ontologies were to fail to be restored afterwards.
scopeMap.put(scopeId, scope);
for (String key : struct.getCustomOntologyKeysForScope(scopeId)) {
- log.debug("Core ontology key : {}", key);
+ log.debug("Custom ontology key : {}", key);
custom.addOntology(new GraphSource(key));
}
log.info("Scope \"{}\" rebuilt in {} ms.", scopeId, System.currentTimeMillis() - before);
@@ -617,7 +557,7 @@ public class ONManagerImpl extends Scope
log.warn("OntoNet namespaces must be slash URIs, adding '/'.");
namespace += "/";
}
- this.ontonetNS = namespace;
+ this.ontonetNS = IRI.create(namespace);
}
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/OfflineConfigurationImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/OfflineConfigurationImpl.java?rev=1363428&r1=1363427&r2=1363428&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/OfflineConfigurationImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/OfflineConfigurationImpl.java Thu Jul 19 17:10:05 2012
@@ -39,16 +39,21 @@ import org.slf4j.LoggerFactory;
@Service
public class OfflineConfigurationImpl implements OfflineConfiguration {
+ public static final String _DEFAULT_NS_DEFAULT = "http://localhost:8080/ontonet/";
+
+ private List<IRI> locations = new ArrayList<IRI>();
+
protected Logger log = LoggerFactory.getLogger(getClass());
+ @Property(name = OfflineConfiguration.DEFAULT_NS, value = _DEFAULT_NS_DEFAULT)
+ private String ns;
+
/**
* TODO how do you use array initializers in Property annotations without causing compile errors?
*/
@Property(name = OfflineConfiguration.ONTOLOGY_PATHS, value = {".", "/ontologies"})
private String[] ontologyDirs;
- private List<IRI> locations = new ArrayList<IRI>();
-
/**
* This default constructor is <b>only</b> intended to be used by the OSGI environment with Service
* Component Runtime support.
@@ -80,7 +85,12 @@ public class OfflineConfigurationImpl im
}
protected void activate(Dictionary<String,Object> configuration) {
+
// Parse configuration.
+
+ ns = (String) configuration.get(OfflineConfiguration.DEFAULT_NS);
+ if (ns == null || ns.isEmpty()) ns = _DEFAULT_NS_DEFAULT;
+
ontologyDirs = (String[]) configuration.get(OfflineConfiguration.ONTOLOGY_PATHS);
if (ontologyDirs == null) ontologyDirs = new String[] {".", "/ontologies"};
@@ -115,6 +125,20 @@ public class OfflineConfigurationImpl im
}
@Override
+ public boolean equals(Object obj) {
+ if (obj == null) return false;
+ if (!(obj instanceof OfflineConfiguration)) return false;
+ if (!this.ns.equals(((OfflineConfiguration) obj).getDefaultOntologyNetworkNamespace())) return false;
+ if (!this.locations.equals(((OfflineConfiguration) obj).getOntologySourceLocations())) return false;
+ return true;
+ }
+
+ @Override
+ public IRI getDefaultOntologyNetworkNamespace() {
+ return IRI.create(ns);
+ }
+
+ @Override
public List<IRI> getOntologySourceLocations() {
return locations;
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologyCollectorImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologyCollectorImpl.java?rev=1363428&r1=1363427&r2=1363428&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologyCollectorImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologyCollectorImpl.java Thu Jul 19 17:10:05 2012
@@ -47,6 +47,7 @@ import org.apache.stanbol.ontologymanage
import org.apache.stanbol.ontologymanager.ontonet.api.collector.UnmodifiableOntologyCollectorException;
import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSourceHandler;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.Origin;
import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OWLExportable;
import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyProvider;
import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologySpace;
@@ -121,32 +122,18 @@ public abstract class AbstractOntologyCo
}
@Override
- public synchronized String addOntology(OntologyInputSource<?,?> ontologySource) throws UnmodifiableOntologyCollectorException {
+ public synchronized String addOntology(OntologyInputSource<?> ontologySource) throws UnmodifiableOntologyCollectorException {
long before = System.currentTimeMillis();
if (locked) throw new UnmodifiableOntologyCollectorException(this);
- log.debug("Adding ontology {} to space {}", ontologySource != null ? ontologySource : "<NULL>",
- getNamespace() + getID());
+ log.debug("Adding ontology to space {}", getID());
if (ontologySource == null || !ontologySource.hasRootOntology()) // No ontology to add
throw new IllegalArgumentException(
"Ontology source cannot be null and must provide an ontology object.");
Object o = ontologySource.getRootOntology();
- /*
- * Note for the developer: make sure the call to guessOntologyIdentifier() is only performed once
- * during all the storage process, otherwise multiple calls could return different results for
- * anonymous ontologies.
- */
- OWLOntologyID id;
- if (o instanceof TripleCollection) {
- id = OWLUtils.guessOntologyIdentifier((TripleCollection) o);
- } else if (o instanceof OWLOntology) {
- id = OWLUtils.guessOntologyIdentifier((OWLOntology) o);
- } else throw new UnsupportedOperationException(
- "This ontology collector implementation cannot handle " + o.getClass().getCanonicalName()
- + " objects.");
// Now for the actual storage. We pass the ontology object directly.
String key = null;
@@ -154,15 +141,47 @@ public abstract class AbstractOntologyCo
// if (ontologyProvider.hasOntology(id.getOntologyIRI())) if (o instanceof MGraph)
// claimOwnership((MGraph) o);
// else if (o instanceof OWLOntology) claimOwnership((OWLOntology) o);
- key = ontologyProvider.loadInStore(o, false);
- if (ontologySource.hasPhysicalIRI()) ontologyProvider.setLocatorMapping(
- ontologySource.getPhysicalIRI(), key);
+
+ if (ontologySource.hasOrigin()) key = ontologyProvider.loadInStore(o, false,
+ ontologySource.getOrigin());
+ else key = ontologyProvider.loadInStore(o, false);
/*
* Actually we are not interested in knowing the key here (ontology collectors are not concerned with
* them), but knowing it is non-null and non-empty indicates the operation was successful.
*/
if (key != null && !key.isEmpty()) {
+ if (ontologySource.hasOrigin() && ontologySource.getOrigin().getReference() instanceof IRI) ontologyProvider
+ .setLocatorMapping((IRI) ontologySource.getOrigin().getReference(), key);
+
+ /*
+ * Used for mappings.
+ */
+ OWLOntologyID id;
+ if (o instanceof TripleCollection) {
+ id = OWLUtils.guessOntologyIdentifier((TripleCollection) o);
+ } else if (o instanceof OWLOntology) {
+ id = OWLUtils.guessOntologyIdentifier((OWLOntology) o);
+ } else throw new UnsupportedOperationException(
+ "This ontology collector implementation cannot handle " + o.getClass().getCanonicalName()
+ + " objects.");
+
+ // Null id? use the origin trick
+ if (id == null) {
+
+ if (ontologySource.hasOrigin()) {
+ Origin<?> origin = ontologySource.getOrigin();
+ Object reff = origin.getReference();
+ if (reff instanceof IRI) id = new OWLOntologyID((IRI) reff); // No version IRI here
+ else if (reff instanceof UriRef) id = new OWLOntologyID(IRI.create(((UriRef) reff)
+ .getUnicodeString()));
+ else id = ontologyProvider.getOntologyId(key);
+
+ } else {
+ id = ontologyProvider.getOntologyId(key);
+ }
+ }
+
// add to index
managedOntologies.add(id.getOntologyIRI());
// Always add sanitized version
@@ -180,6 +199,11 @@ public abstract class AbstractOntologyCo
listeners.add(listener);
}
+ /**
+ * FIXME use dynamic prefix?
+ *
+ * @param ontology
+ */
protected void claimOwnership(MGraph ontology) {
UriRef owl_viri = new UriRef("http://www.w3.org/2002/07/owl#versionIRI");
UriRef ontologyId = null;
@@ -205,6 +229,11 @@ public abstract class AbstractOntologyCo
}
}
+ /**
+ * FIXME use dynamic prefix?
+ *
+ * @param ontology
+ */
protected void claimOwnership(OWLOntology ontology) {
log.info("Checking ownership of {} {}", OWLOntology.class.getSimpleName(), ontology.getOntologyID());
OWLOntologyID id = ontology.getOntologyID();
@@ -228,14 +257,19 @@ public abstract class AbstractOntologyCo
listeners.clear();
}
- @SuppressWarnings("unchecked")
@Override
public <O> O export(Class<O> returnType, boolean merge) {
+ return export(returnType, merge, getNamespace());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <O> O export(Class<O> returnType, boolean merge, IRI universalPrefix) {
if (OWLOntology.class.isAssignableFrom(returnType)) {
- return (O) exportToOWLOntology(merge);
+ return (O) exportToOWLOntology(merge, universalPrefix);
}
if (TripleCollection.class.isAssignableFrom(returnType)) {
- TripleCollection root = exportToMGraph(merge);
+ TripleCollection root = exportToMGraph(merge, universalPrefix);
// A Clerezza graph has to be cast properly.
if (returnType == Graph.class) root = ((MGraph) root).getGraph();
else if (returnType == MGraph.class) {}
@@ -252,7 +286,7 @@ public abstract class AbstractOntologyCo
* @param merge
* @return
*/
- protected MGraph exportToMGraph(boolean merge) {
+ protected MGraph exportToMGraph(boolean merge, IRI prefix) {
// if (merge) throw new UnsupportedOperationException(
// "Merge not implemented yet for Clerezza triple collections.");
@@ -260,7 +294,7 @@ public abstract class AbstractOntologyCo
// No need to store, give it a name, or anything.
MGraph root = new SimpleMGraph();
- UriRef iri = new UriRef(namespace + _id);
+ UriRef iri = new UriRef(prefix + _id);
// Add the import declarations for directly managed ontologies.
if (root != null) {
// Set the ontology ID
@@ -310,7 +344,7 @@ public abstract class AbstractOntologyCo
} else {
- String base = getNamespace() + getID();
+ String base = prefix + getID();
for (int i = 0; i < backwardPathLength; i++)
base = URIUtils.upOne(URI.create(base)).toString();
base += "/";
@@ -338,14 +372,14 @@ public abstract class AbstractOntologyCo
* @param merge
* @return
*/
- protected OWLOntology exportToOWLOntology(boolean merge) {
+ protected OWLOntology exportToOWLOntology(boolean merge, IRI prefix) {
long before = System.currentTimeMillis();
// Create a new ontology
OWLOntology root;
OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
- IRI iri = IRI.create(namespace + _id);
+ IRI iri = IRI.create(prefix + _id);
try {
root = ontologyManager.createOntology(iri);
} catch (OWLOntologyAlreadyExistsException e) {
@@ -396,7 +430,7 @@ public abstract class AbstractOntologyCo
List<OWLOntologyChange> changes = new LinkedList<OWLOntologyChange>();
OWLDataFactory df = ontologyManager.getOWLDataFactory();
- String base = getNamespace() + getID();
+ String base = prefix + getID();
for (int i = 0; i < backwardPathLength; i++)
base = URIUtils.upOne(URI.create(base)).toString();
base += "/";
@@ -439,8 +473,8 @@ public abstract class AbstractOntologyCo
}
@Override
- public IRI getDocumentIRI() {
- return IRI.create(getNamespace() + getID());
+ public IRI getDefaultNamespace() {
+ return this.namespace;
}
@Override
@@ -460,7 +494,7 @@ public abstract class AbstractOntologyCo
@Override
public IRI getNamespace() {
- return namespace;
+ return getDefaultNamespace();
}
@Override
@@ -468,14 +502,19 @@ public abstract class AbstractOntologyCo
return getOntology(ontologyIri, returnType, false);
}
- @SuppressWarnings("unchecked")
@Override
public <O> O getOntology(IRI ontologyIri, Class<O> returnType, boolean merge) {
+ return getOntology(ontologyIri, returnType, merge, getNamespace());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <O> O getOntology(IRI ontologyIri, Class<O> returnType, boolean merge, IRI universalPrefix) {
if (OWLOntology.class.isAssignableFrom(returnType)) {
- return (O) getOntologyAsOWLOntology(ontologyIri, merge);
+ return (O) getOntologyAsOWLOntology(ontologyIri, merge, universalPrefix);
}
if (TripleCollection.class.isAssignableFrom(returnType)) {
- TripleCollection root = getOntologyAsMGraph(ontologyIri, merge);
+ TripleCollection root = getOntologyAsMGraph(ontologyIri, merge, universalPrefix);
// A Clerezza graph has to be cast properly.
if (returnType == Graph.class) root = ((MGraph) root).getGraph();
else if (returnType == MGraph.class) {}
@@ -486,7 +525,12 @@ public abstract class AbstractOntologyCo
+ returnType);
}
- protected MGraph getOntologyAsMGraph(IRI ontologyIri, boolean merge) {
+ @Override
+ public <O> O getOntology(IRI ontologyIri, Class<O> returnType, IRI universalPrefix) {
+ return getOntology(ontologyIri, returnType, false, universalPrefix);
+ }
+
+ protected MGraph getOntologyAsMGraph(IRI ontologyIri, boolean merge, IRI universalPrefix) {
if (merge) throw new UnsupportedOperationException(
"Merge not implemented yet for Clerezza triple collections.");
/*
@@ -500,7 +544,6 @@ public abstract class AbstractOntologyCo
// Now rewrite import statements
// Scan import statements for each owl:Ontology instance (hopefully one).
- IRI ns = getNamespace();
String tid = getID();
// Bit of a hack : since ontology spaces are named like {scopeid}/{core|custom}, in that particular
// case we go back to {scopeid}, whereas for sessions we maintain their original id.
@@ -520,7 +563,9 @@ public abstract class AbstractOntologyCo
// FIXME note the different import targets in the OWLOntology and TripleColllection objects!
// s = s.substring(s.indexOf("::") + 2, s.length());
boolean managed = managedOntologies.contains(IRI.create(s));
- UriRef target = new UriRef((managed ? ns + "/" + tid + "/" : URIUtils.upOne(ns) + "/") + s);
+ UriRef target = new UriRef((managed ? universalPrefix + "/" + tid + "/"
+ : URIUtils.upOne(universalPrefix) + "/")
+ + s);
o.remove(t);
newImports.add(new TripleImpl(t.getSubject(), OWL.imports, target));
}
@@ -534,7 +579,7 @@ public abstract class AbstractOntologyCo
return o;
}
- protected OWLOntology getOntologyAsOWLOntology(IRI ontologyIri, boolean merge) {
+ protected OWLOntology getOntologyAsOWLOntology(IRI ontologyIri, boolean merge, IRI universalPrefix) {
// if (merge) throw new UnsupportedOperationException("Merge not implemented yet for OWLOntology.");
// Remove the check below. It might be an unmanaged dependency (TODO remove from collector and
@@ -581,12 +626,13 @@ public abstract class AbstractOntologyCo
s = s.substring(s.indexOf("::") + 2, s.length());
boolean managed = managedOntologies.contains(oldImp.getIRI());
// For space, always go up at least one
- IRI ns = getNamespace();
String tid = getID();
if (backwardPathLength > 0) tid = tid.split("/")[0];
- IRI target = IRI.create((managed ? ns + "/" + tid + "/" : URIUtils.upOne(ns) + "/") + s);
+ IRI target = IRI.create((managed ? universalPrefix + "/" + tid + "/" : URIUtils
+ .upOne(universalPrefix) + "/")
+ + s);
changes.add(new AddImport(o, df.getOWLImportsDeclaration(target)));
}
o.getOWLOntologyManager().applyChanges(changes);
@@ -638,8 +684,6 @@ public abstract class AbstractOntologyCo
listeners.remove(listener);
}
- protected abstract void setID(String id);
-
/**
* @param namespace
* The OntoNet namespace that will prefix the space ID in Web references. This implementation
@@ -650,7 +694,7 @@ public abstract class AbstractOntologyCo
* @see OntologySpace#setNamespace(IRI)
*/
@Override
- public void setNamespace(IRI namespace) {
+ public void setDefaultNamespace(IRI namespace) {
if (namespace == null) throw new IllegalArgumentException("Namespace cannot be null.");
if (namespace.toURI().getQuery() != null) throw new IllegalArgumentException(
"URI Query is not allowed in OntoNet namespaces.");
@@ -666,6 +710,13 @@ public abstract class AbstractOntologyCo
this.namespace = namespace;
}
+ protected abstract void setID(String id);
+
+ @Override
+ public void setNamespace(IRI namespace) {
+ setDefaultNamespace(namespace);
+ }
+
@Override
public void setUp() {
this.locked = true;
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java?rev=1363428&r1=1363427&r2=1363428&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java Thu Jul 19 17:10:05 2012
@@ -16,6 +16,8 @@
*/
package org.apache.stanbol.ontologymanager.ontonet.impl.clerezza;
+import static org.apache.stanbol.ontologymanager.ontonet.api.Vocabulary.APPENDED_TO;
+import static org.apache.stanbol.ontologymanager.ontonet.api.Vocabulary.HAS_APPENDED;
import static org.apache.stanbol.ontologymanager.ontonet.api.Vocabulary.HAS_SPACE_CORE;
import static org.apache.stanbol.ontologymanager.ontonet.api.Vocabulary.HAS_SPACE_CUSTOM;
import static org.apache.stanbol.ontologymanager.ontonet.api.Vocabulary.IS_MANAGED_BY;
@@ -83,6 +85,7 @@ import org.apache.stanbol.ontologymanage
import org.apache.stanbol.ontologymanager.ontonet.api.collector.ImportManagementPolicy;
import org.apache.stanbol.ontologymanager.ontonet.api.collector.OntologyCollector;
import org.apache.stanbol.ontologymanager.ontonet.api.collector.OntologyCollectorListener;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.Origin;
import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyProvider;
import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologyScope;
import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologySpace;
@@ -268,20 +271,24 @@ public class ClerezzaOntologyProvider im
return null;
}
- Set<OWLOntologyID> keys() {
- Set<OWLOntologyID> result = new HashSet<OWLOntologyID>();
- Iterator<Triple> it = graph.filter(null, new UriRef(Vocabulary.MAPS_TO_GRAPH), null);
+ OWLOntologyID getReverseMapping(UriRef graphName) {
+ // Logical mappings first.
+ Iterator<Triple> it = graph.filter(null, new UriRef(Vocabulary.MAPS_TO_GRAPH), graphName);
while (it.hasNext()) {
- NonLiteral subj = it.next().getSubject();
- if (subj instanceof UriRef) result.add(buildOntologyId((UriRef) subj));
+ Resource obj = it.next().getSubject();
+ if (obj instanceof UriRef) return new OWLOntologyID(IRI.create(((UriRef) obj)
+ .getUnicodeString()));
}
- it = graph.filter(null, new UriRef(Vocabulary.RETRIEVED_FROM), null);
+ Literal litloc = LiteralFactory.getInstance().createTypedLiteral(
+ new UriRef(graphName.getUnicodeString()));
+ // Logical mappings failed, try physical mappings.
+ it = graph.filter(null, new UriRef(Vocabulary.RETRIEVED_FROM), litloc);
while (it.hasNext()) {
- Resource subj = it.next().getObject();
- if (subj instanceof UriRef) result.add(buildOntologyId((UriRef) subj));
- else if (subj instanceof Literal) System.out.println(((Literal) subj).getLexicalForm());
+ Resource obj = it.next().getSubject();
+ if (obj instanceof UriRef) return new OWLOntologyID(IRI.create(((UriRef) obj)
+ .getUnicodeString()));
}
- return result;
+ return null;
}
void mapLocator(IRI locator, UriRef graphName) {
@@ -317,9 +324,11 @@ public class ClerezzaOntologyProvider im
Set<String> stringValues() {
Set<String> result = new HashSet<String>();
- Iterator<Triple> it = graph.filter(null, new UriRef(Vocabulary.MAPS_TO_GRAPH), null);
+ Iterator<Triple> it = graph.filter(
+ // null, new UriRef(Vocabulary.MAPS_TO_GRAPH), null
+ null, RDF.type, new UriRef(Vocabulary.ENTRY));
while (it.hasNext()) {
- Resource obj = it.next().getObject();
+ Resource obj = it.next().getSubject();
if (obj instanceof UriRef) result.add(((UriRef) obj).getUnicodeString());
}
return result;
@@ -549,9 +558,9 @@ public class ClerezzaOntologyProvider im
}
}
- private UriRef getIRIforScope(OntologyScope scope) {
+ private UriRef getIRIforScope(String scopeId) {
// Use the Stanbol-internal namespace, so that the whole configuration can be ported.
- return new UriRef(_NS_STANBOL_INTERNAL + OntologyScope.shortName + "/" + scope.getID());
+ return new UriRef(_NS_STANBOL_INTERNAL + OntologyScope.shortName + "/" + scopeId);
}
private UriRef getIRIforSession(Session session) {
@@ -567,19 +576,12 @@ public class ClerezzaOntologyProvider im
@Override
public String getKey(IRI ontologyIri) {
ontologyIri = URIUtils.sanitizeID(ontologyIri);
- return getKey(new OWLOntologyID(ontologyIri));
+ return getPublicKey(new OWLOntologyID(ontologyIri));
}
@Override
public String getKey(OWLOntologyID ontologyId) {
- UriRef ur = keymap.getMapping(ontologyId);
- log.debug("key for {} is {}", ontologyId, ur);
- return (ur == null) ? null : ur.getUnicodeString();
- }
-
- @Override
- public Set<String> getKeys() {
- return keymap.stringValues();
+ return getPublicKey(ontologyId);
}
@SuppressWarnings("unchecked")
@@ -590,8 +592,13 @@ public class ClerezzaOntologyProvider im
return (O) store.getTriples(new UriRef(metaGraphId));
}
+ @Override
+ public OWLOntologyID getOntologyId(String storageKey) {
+ return keymap.getReverseMapping(new UriRef(storageKey));
+ }
+
public OntologyNetworkConfiguration getOntologyNetworkConfiguration() {
- Map<String,Collection<String>> coreOntologies = new HashMap<String,Collection<String>>(), customOntologies = new HashMap<String,Collection<String>>();
+ Map<String,Collection<String>> coreOntologies = new HashMap<String,Collection<String>>(), customOntologies = new HashMap<String,Collection<String>>(), attachedScopes = new HashMap<String,Collection<String>>();
final TripleCollection meta = store.getTriples(new UriRef(metaGraphId));
// Scopes first
@@ -689,22 +696,41 @@ public class ClerezzaOntologyProvider im
String sessionId = s.substring(prefix.length());
log.info("Rebuilding session \"{}\".", sessionId);
sessionOntologies.put(sessionId, new HashSet<String>());
+ attachedScopes.put(sessionId, new HashSet<String>());
// retrieve the ontologies
if (ses_ur != null) {
- for (Iterator<Triple> it2 = meta.filter(ses_ur, null, null); it2.hasNext();) {
- Triple t = it2.next();
- UriRef predicate = t.getPredicate();
- if (predicate.equals(MANAGES)) {
- if (t.getObject() instanceof UriRef) sessionOntologies.get(sessionId).add(
- ((UriRef) t.getObject()).getUnicodeString());
+ for (Iterator<Triple> it2 = meta.filter(ses_ur, MANAGES, null); it2.hasNext();) {
+ Resource obj = it2.next().getObject();
+ if (obj instanceof UriRef) sessionOntologies.get(sessionId).add(
+ ((UriRef) obj).getUnicodeString());
+
+ }
+ for (Iterator<Triple> it2 = meta.filter(null, IS_MANAGED_BY, ses_ur); it2.hasNext();) {
+ Resource subj = it2.next().getSubject();
+ if (subj instanceof UriRef) sessionOntologies.get(sessionId).add(
+ ((UriRef) subj).getUnicodeString());
+
+ }
+ for (Iterator<Triple> it2 = meta.filter(null, APPENDED_TO, ses_ur); it2.hasNext();) {
+ Resource subj = it2.next().getSubject();
+ if (subj instanceof UriRef) {
+ String s1 = ((UriRef) subj).getUnicodeString();
+ String prefix1 = _NS_STANBOL_INTERNAL + OntologyScope.shortName + "/";
+ if (s1.startsWith(prefix1)) {
+ String scopeId = s1.substring(prefix1.length());
+ attachedScopes.get(sessionId).add(scopeId);
+ }
}
}
- for (Iterator<Triple> it2 = meta.filter(null, null, ses_ur); it2.hasNext();) {
- Triple t = it2.next();
- UriRef predicate = t.getPredicate();
- if (predicate.equals(IS_MANAGED_BY)) {
- if (t.getSubject() instanceof UriRef) sessionOntologies.get(sessionId).add(
- ((UriRef) t.getSubject()).getUnicodeString());
+ for (Iterator<Triple> it2 = meta.filter(ses_ur, HAS_APPENDED, null); it2.hasNext();) {
+ Resource obj = it2.next().getObject();
+ if (obj instanceof UriRef) {
+ String s1 = ((UriRef) obj).getUnicodeString();
+ String prefix1 = _NS_STANBOL_INTERNAL + OntologyScope.shortName + "/";
+ if (s1.startsWith(prefix1)) {
+ String scopeId = s1.substring(prefix1.length());
+ attachedScopes.get(sessionId).add(scopeId);
+ }
}
}
}
@@ -712,12 +738,20 @@ public class ClerezzaOntologyProvider im
}
}
- return new OntologyNetworkConfiguration(coreOntologies, customOntologies, sessionOntologies);
+ return new OntologyNetworkConfiguration(coreOntologies, customOntologies, sessionOntologies,
+ attachedScopes);
}
@Override
- public Set<String> getOntologyVersionKeys(IRI ontologyIRI) {
- throw new UnsupportedOperationException("Method not implemented yet.");
+ public String getPublicKey(OWLOntologyID ontologyId) {
+ UriRef ur = keymap.getMapping(ontologyId);
+ log.debug("key for {} is {}", ontologyId, ur);
+ return (ur == null) ? null : ur.getUnicodeString();
+ }
+
+ @Override
+ public Set<String> getPublicKeys() {
+ return keymap.stringValues();
}
@Override
@@ -792,6 +826,11 @@ public class ClerezzaOntologyProvider im
}
@Override
+ public Set<String> getVersionKeys(IRI ontologyIRI) {
+ throw new UnsupportedOperationException("Method not implemented yet.");
+ }
+
+ @Override
public boolean hasOntology(IRI ontologyIri) {
return hasOntology(new OWLOntologyID(ontologyIri));
}
@@ -893,7 +932,7 @@ public class ClerezzaOntologyProvider im
}
@Override
- public String loadInStore(Object ontology, boolean force) {
+ public String loadInStore(Object ontology, final boolean force, Origin<?>... origins) {
if (ontology == null) throw new IllegalArgumentException("No ontology supplied.");
long before = System.currentTimeMillis();
@@ -911,26 +950,31 @@ public class ClerezzaOntologyProvider im
// Force is ignored for the content, but the imports?
- String s = prefix + "::"; // This will become the graph name
IRI ontologyIri = null;
// FIXME Profile this method. Are we getting rid of rdfData after adding its triples?
- // preferredKey should be the "guessed" ontology id
String iri = null;
- OWLOntologyID realId = OWLUtils.guessOntologyIdentifier(rdfData);
+ OWLOntologyID realId = OWLUtils.guessOntologyIdentifier(rdfData); // used for public and storage key.
- // String alternateId = OWLUtils.guessOntologyIdentifier(rdfData).getUnicodeString();
- if ((iri == null || iri.isEmpty()) && realId != null) {
+ if (realId == null) {
+ IRI z;
+ if (origins.length > 0 && origins[0] != null) {
+ Object reff = origins[0].getReference();
+ if (reff instanceof IRI) z = (IRI) reff; // No version IRI here
+ else if (reff instanceof UriRef) z = IRI.create(((UriRef) reff).getUnicodeString());
+ else z = IRI.create(getClass().getCanonicalName() + "-time:" + System.currentTimeMillis());
+ } else z = IRI.create(getClass().getCanonicalName() + "-time:" + System.currentTimeMillis());
+ realId = new OWLOntologyID(z);
+ }
+
+ if (realId != null) {
if (realId.getOntologyIRI() != null) iri = realId.getOntologyIRI().toString();
if (realId.getVersionIRI() != null) iri += ":::" + realId.getVersionIRI().toString();
}
- // else try {
- // new UriRef(iri); // Can I make a UriRef from it?
- // } catch (Exception ex) {
- // iri = OWLUtils.guessOntologyIdentifier(rdfData).getUnicodeString();
- // }
+ // s will become the graph name
+ String s = (iri.startsWith(prefix + "::")) ? "" : (prefix + "::");
ontologyIri = IRI.create(iri);
while (s.endsWith("#"))
s = s.substring(0, s.length() - 1);
@@ -944,12 +988,41 @@ public class ClerezzaOntologyProvider im
* TODO this occupies twice as much space, which should not be necessary if the provider is the same
* as the one used by the input source.
*/
- UriRef uriref = new UriRef(s);
- log.debug("Storing ontology with graph ID {}", uriref);
+
+ // Check if it is possible to avoid reloading the ontology content from its source.
+ boolean mustLoad = true;
+ if (!force) {
+ Set<UriRef> stored = store.listTripleCollections();
+ if (origins.length > 0 && origins[0] != null && origins[0].getReference() instanceof UriRef) {
+ UriRef ref = (UriRef) origins[0].getReference();
+
+ if (stored.contains(ref)) {
+ boolean condition = true; // Any failed check will make it false
+
+ /*
+ * Check if the stored Ontology ID (versionIRI included) matches matches that of the
+ * ontology source. XXX note that anonymous ontologies should be considered a match... or
+ * should they not?
+ */
+ OWLOntologyID idFromSrc = OWLUtils.guessOntologyIdentifier(rdfData);
+ OWLOntologyID idFromStore = OWLUtils.guessOntologyIdentifier(store.getTriples(ref));
+ condition &= (idFromSrc == null && idFromStore == null) || idFromSrc.equals(idFromStore);
+
+ // Finally, a size check
+ if (condition && rdfData instanceof TripleCollection) condition &= store.getTriples(ref)
+ .size() == rdfData.size();
+
+ mustLoad &= !condition;
+ }
+ }
+ }
// The policy here is to avoid copying the triples from a graph already in the store.
// FIXME not a good policy for graphs that change
- if (!getStore().listTripleCollections().contains(uriref) || force) {
+ UriRef uriref;
+ if (mustLoad) {
+ uriref = new UriRef(s);
+ log.debug("Storing ontology with graph ID {}", uriref);
try {
graph = store.createMGraph(uriref);
} catch (EntityAlreadyExistsException e) {
@@ -958,7 +1031,12 @@ public class ClerezzaOntologyProvider im
}
graph.addAll(rdfData);
} else {
- log.debug("Graph with ID {} already in store. Default action is to skip storage.", uriref);
+ try {
+ uriref = (UriRef) origins[0].getReference();
+ } catch (ClassCastException cex) {
+ uriref = new UriRef(s);
+ }
+ log.debug("Graph with ID {} already in store. Default action is to skip storage.", origins[0]);
graph = store.getTriples(uriref);
}
@@ -971,14 +1049,17 @@ public class ClerezzaOntologyProvider im
// Versioned or not, the real ID mapping is always added
keymap.setMapping(realId, uriref);
mappedIds += realId;
- if (realId.getVersionIRI() != null) {
- // If the unversioned variant of a versioned ID wasn't mapped, map it too.
- OWLOntologyID unvId = new OWLOntologyID(realId.getOntologyIRI());
- if (keymap.getMapping(unvId) == null) {
- keymap.setMapping(unvId, uriref);
- mappedIds += realId;
- }
- }
+ /*
+ * TODO not sure I should always map the unversioned ID as a key too?
+ */
+ // if (realId.getVersionIRI() != null) {
+ // // If the unversioned variant of a versioned ID wasn't mapped, map it too.
+ // OWLOntologyID unvId = new OWLOntologyID(realId.getOntologyIRI());
+ // if (keymap.getMapping(unvId) == null) {
+ // keymap.setMapping(unvId, uriref);
+ // mappedIds += realId;
+ // }
+ // }
}
/*
* Make an ontology ID out of the originally supplied IRI (which might be the physical one and differ
@@ -1012,6 +1093,7 @@ public class ClerezzaOntologyProvider im
UriRef target = (UriRef) obj;
OWLOntologyID id = new OWLOntologyID(IRI.create(target.getUnicodeString()));
if (keymap.getMapping(id) == null) {
+ // TODO manage origins for imported ontologies too?
loadInStore(IRI.create(((UriRef) obj).getUnicodeString()), null, false);
}
}
@@ -1046,7 +1128,10 @@ public class ClerezzaOntologyProvider im
else if (collector instanceof OntologySpace) colltype = OntologySpace.shortName + "/";
else if (collector instanceof Session) colltype = Session.shortName + "/";
UriRef c = new UriRef(_NS_STANBOL_INTERNAL + colltype + collector.getID());
- UriRef u = new UriRef(prefix + "::" + keymap.buildResource(addedOntology).getUnicodeString());
+ keymap.getMapping(addedOntology);
+ UriRef u =
+ // new UriRef(prefix + "::" + keymap.buildResource(addedOntology).getUnicodeString());
+ keymap.getMapping(addedOntology);
// TODO OntologyProvider should not be aware of scopes, spaces or sessions. Move elsewhere.
MGraph meta = getMetaGraph(MGraph.class);
@@ -1077,7 +1162,7 @@ public class ClerezzaOntologyProvider im
collector.getID());
return;
}
- synchronized (meta) {
+ if (u != null) synchronized (meta) {
Triple t;
if (predicate1 != null) {
t = new TripleImpl(c, predicate1, u);
@@ -1103,8 +1188,9 @@ public class ClerezzaOntologyProvider im
else if (collector instanceof OntologySpace) colltype = OntologySpace.shortName + "/";
else if (collector instanceof Session) colltype = Session.shortName + "/";
UriRef c = new UriRef(_NS_STANBOL_INTERNAL + colltype + collector.getID());
- UriRef u = new UriRef(prefix + "::" + keymap.buildResource(removedOntology).getUnicodeString());
-
+ UriRef u =
+ // new UriRef(prefix + "::" + keymap.buildResource(removedOntology).getUnicodeString());
+ keymap.getMapping(removedOntology);
// XXX condense the following code
MGraph meta = getMetaGraph(MGraph.class);
boolean badState = true;
@@ -1137,6 +1223,12 @@ public class ClerezzaOntologyProvider im
}
@Override
+ public boolean removeOntology(String publicKey) {
+ throw new UnsupportedOperationException(
+ "Not implemented yet. Must implement dependency management support first.");
+ }
+
+ @Override
public void scopeActivated(OntologyScope scope) {}
@Override
@@ -1300,7 +1392,7 @@ public class ClerezzaOntologyProvider im
*/
private void updateScopeRegistration(OntologyScope scope) {
final TripleCollection meta = store.getTriples(new UriRef(metaGraphId));
- final UriRef scopeur = getIRIforScope(scope);
+ final UriRef scopeur = getIRIforScope(scope.getID());
final UriRef coreur = getIRIforSpace(scope.getCoreSpace());
final UriRef custur = getIRIforSpace(scope.getCustomSpace());
// If this method was called after a scope rebuild, the following will have little to no effect.
@@ -1328,7 +1420,7 @@ public class ClerezzaOntologyProvider im
long before = System.currentTimeMillis();
final TripleCollection meta = store.getTriples(new UriRef(metaGraphId));
boolean removable = false, conflict = false;
- final UriRef scopeur = getIRIforScope(scope);
+ final UriRef scopeur = getIRIforScope(scope.getID());
final UriRef coreur = getIRIforSpace(scope.getCoreSpace());
final UriRef custur = getIRIforSpace(scope.getCustomSpace());
Set<Triple> removeUs = new HashSet<Triple>();
@@ -1413,4 +1505,29 @@ public class ClerezzaOntologyProvider im
}
}
+ @Override
+ public void scopeAppended(Session session, String scopeId) {
+ final TripleCollection meta = store.getTriples(new UriRef(metaGraphId));
+ final UriRef sessionur = getIRIforSession(session), scopeur = getIRIforScope(scopeId);
+ if (sessionur == null || scopeur == null) throw new IllegalArgumentException(
+ "UriRefs for scope and session cannot be null.");
+ if (meta instanceof MGraph) synchronized (meta) {
+ meta.add(new TripleImpl(sessionur, HAS_APPENDED, scopeur));
+ meta.add(new TripleImpl(scopeur, APPENDED_TO, sessionur));
+ }
+ }
+
+ @Override
+ public void scopeDetached(Session session, String scopeId) {
+ final TripleCollection meta = store.getTriples(new UriRef(metaGraphId));
+ final UriRef sessionur = getIRIforSession(session), scopeur = getIRIforScope(scopeId);
+ if (sessionur == null || scopeur == null) throw new IllegalArgumentException(
+ "UriRefs for scope and session cannot be null.");
+ if (meta instanceof MGraph) synchronized (meta) {
+ // TripleImpl implements equals() and hashCode() ...
+ meta.remove(new TripleImpl(sessionur, HAS_APPENDED, scopeur));
+ meta.remove(new TripleImpl(scopeur, APPENDED_TO, sessionur));
+ }
+ }
+
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomSpaceImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomSpaceImpl.java?rev=1363428&r1=1363427&r2=1363428&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomSpaceImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomSpaceImpl.java Thu Jul 19 17:10:05 2012
@@ -60,8 +60,8 @@ public class CustomSpaceImpl extends Abs
}
@Override
- protected MGraph getOntologyAsMGraph(IRI ontologyIri, boolean merge) {
- MGraph o = super.getOntologyAsMGraph(ontologyIri, merge);
+ protected MGraph getOntologyAsMGraph(IRI ontologyIri, boolean merge, IRI universalPrefix) {
+ MGraph o = super.getOntologyAsMGraph(ontologyIri, merge, universalPrefix);
switch (getConnectivityPolicy()) {
case LOOSE:
break;
@@ -75,7 +75,7 @@ public class CustomSpaceImpl extends Abs
String s = getID();
s = s.substring(0, s.indexOf(SUFFIX)); // strip "custom"
s += SpaceType.CORE.getIRISuffix(); // concatenate "core"
- UriRef target = new UriRef(getNamespace() + s);
+ UriRef target = new UriRef(universalPrefix + s);
for (NonLiteral subject : onts)
o.add(new TripleImpl(subject, OWL.imports, target));
break;
@@ -87,8 +87,8 @@ public class CustomSpaceImpl extends Abs
}
@Override
- protected OWLOntology getOntologyAsOWLOntology(IRI ontologyIri, boolean merge) {
- OWLOntology o = super.getOntologyAsOWLOntology(ontologyIri, merge);
+ protected OWLOntology getOntologyAsOWLOntology(IRI ontologyIri, boolean merge, IRI universalPrefix) {
+ OWLOntology o = super.getOntologyAsOWLOntology(ontologyIri, merge, universalPrefix);
switch (getConnectivityPolicy()) {
case LOOSE:
break;
@@ -96,7 +96,7 @@ public class CustomSpaceImpl extends Abs
String s = getID();
s = s.substring(0, s.indexOf(SUFFIX)); // strip "custom"
s += SpaceType.CORE.getIRISuffix(); // concatenate "core"
- IRI target = IRI.create(getNamespace() + s);
+ IRI target = IRI.create(universalPrefix + s);
o.getOWLOntologyManager().applyChange(
new AddImport(o, OWLManager.getOWLDataFactory().getOWLImportsDeclaration(target)));
break;
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/OntologySpaceFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/OntologySpaceFactoryImpl.java?rev=1363428&r1=1363427&r2=1363428&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/OntologySpaceFactoryImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/OntologySpaceFactoryImpl.java Thu Jul 19 17:10:05 2012
@@ -102,7 +102,7 @@ public class OntologySpaceFactoryImpl im
* @param scopeID
* @param rootSource
*/
- private void configureSpace(OntologySpace s, String scopeID, OntologyInputSource<?,?>... ontologySources) {
+ private void configureSpace(OntologySpace s, String scopeID, OntologyInputSource<?>... ontologySources) {
// // FIXME: ensure that this is not null AND convert to using Strings for scope IDs
// OntologyScope parentScope = registry.getScope(scopeID);
//
@@ -115,7 +115,7 @@ public class OntologySpaceFactoryImpl im
// Set the supplied ontology's parent as the root for this space.
if (ontologySources != null) try {
- for (OntologyInputSource<?,?> src : ontologySources)
+ for (OntologyInputSource<?> src : ontologySources)
s.addOntology(src);
} catch (UnmodifiableOntologyCollectorException e) {
log.error("Ontology space " + s.getID() + " was found locked at creation time!", e);
@@ -124,7 +124,7 @@ public class OntologySpaceFactoryImpl im
}
@Override
- public CoreOntologySpace createCoreOntologySpace(String scopeId, OntologyInputSource<?,?>... coreSources) {
+ public CoreOntologySpace createCoreOntologySpace(String scopeId, OntologyInputSource<?>... coreSources) {
CoreOntologySpace s = new CoreSpaceImpl(scopeId, namespace, ontologyProvider);
configureSpace(s, scopeId, coreSources);
return s;
@@ -132,7 +132,7 @@ public class OntologySpaceFactoryImpl im
@Override
public CustomOntologySpace createCustomOntologySpace(String scopeId,
- OntologyInputSource<?,?>... customSources) {
+ OntologyInputSource<?>... customSources) {
CustomOntologySpace s = new CustomSpaceImpl(scopeId, namespace, ontologyProvider);
configureSpace(s, scopeId, customSources);
return s;
@@ -141,7 +141,7 @@ public class OntologySpaceFactoryImpl im
@Override
public OntologySpace createOntologySpace(String scopeId,
SpaceType type,
- OntologyInputSource<?,?>... ontologySources) {
+ OntologyInputSource<?>... ontologySources) {
switch (type) {
case CORE:
return createCoreOntologySpace(scopeId, ontologySources);
@@ -162,18 +162,28 @@ public class OntologySpaceFactoryImpl im
}
@Override
+ public IRI getDefaultNamespace() {
+ return this.namespace;
+ }
+
+ @Override
public String getID() {
return this.toString();
}
@Override
public IRI getNamespace() {
- return this.namespace;
+ return getDefaultNamespace();
}
@Override
- public void setNamespace(IRI namespace) {
+ public void setDefaultNamespace(IRI namespace) {
this.namespace = namespace;
}
+ @Override
+ public void setNamespace(IRI namespace) {
+ setDefaultNamespace(namespace);
+ }
+
}
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ontology/OntologyScopeImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ontology/OntologyScopeImpl.java?rev=1363428&r1=1363427&r2=1363428&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ontology/OntologyScopeImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/ontology/OntologyScopeImpl.java Thu Jul 19 17:10:05 2012
@@ -42,6 +42,7 @@ import org.apache.stanbol.ontologymanage
import org.apache.stanbol.ontologymanager.ontonet.api.scope.CustomOntologySpace;
import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologyScope;
import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologySpace.SpaceType;
import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologySpaceFactory;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.AddImport;
@@ -95,13 +96,13 @@ public class OntologyScopeImpl implement
public OntologyScopeImpl(String id,
IRI namespace,
OntologySpaceFactory factory,
- OntologyInputSource<?,?>... coreOntologies) {
+ OntologyInputSource<?>... coreOntologies) {
setID(id);
setNamespace(namespace);
this.coreSpace = factory.createCoreOntologySpace(id/* , coreOntologies */);
this.coreSpace.addOntologyCollectorListener(this); // Set listener before adding core ontologies
- for (OntologyInputSource<?,?> src : coreOntologies)
+ for (OntologyInputSource<?> src : coreOntologies)
this.coreSpace.addOntology(src);
// let's just lock it. Once the core space is done it's done.
this.coreSpace.setUp();
@@ -129,14 +130,19 @@ public class OntologyScopeImpl implement
listeners.clear();
}
- @SuppressWarnings("unchecked")
@Override
public <O> O export(Class<O> returnType, boolean merge) {
+ return export(returnType, merge, getNamespace());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <O> O export(Class<O> returnType, boolean merge, IRI universalPrefix) {
if (OWLOntology.class.isAssignableFrom(returnType)) {
- return (O) exportToOWLOntology(merge);
+ return (O) exportToOWLOntology(merge, universalPrefix);
}
if (TripleCollection.class.isAssignableFrom(returnType)) {
- TripleCollection root = exportToMGraph(merge);
+ TripleCollection root = exportToMGraph(merge, universalPrefix);
// A Clerezza graph has to be cast properly.
if (returnType == Graph.class) root = ((MGraph) root).getGraph();
else if (returnType == MGraph.class) {}
@@ -153,11 +159,11 @@ public class OntologyScopeImpl implement
* otherwise owl:imports statements will be added.
* @return the RDF representation of the scope as a modifiable graph.
*/
- protected MGraph exportToMGraph(boolean merge) {
+ protected MGraph exportToMGraph(boolean merge, IRI universalPrefix) {
// No need to store, give it a name, or anything.
MGraph root = new SimpleMGraph();
- UriRef iri = new UriRef(getNamespace() + getID());
+ UriRef iri = new UriRef(universalPrefix + getID());
if (root != null) {
// Set the ontology ID
@@ -210,9 +216,11 @@ public class OntologyScopeImpl implement
root.add(new TripleImpl(iri, OWL.imports, target));
} else {
- UriRef physIRI = new UriRef(this.getCustomSpace().getDocumentIRI().toString());
+ UriRef physIRI = new UriRef(universalPrefix.toString() + this.getID() + "/"
+ + SpaceType.CUSTOM.getIRISuffix());
root.add(new TripleImpl(iri, OWL.imports, physIRI));
- physIRI = new UriRef(this.getCoreSpace().getDocumentIRI().toString());
+ physIRI = new UriRef(universalPrefix.toString() + this.getID() + "/"
+ + SpaceType.CORE.getIRISuffix());
root.add(new TripleImpl(iri, OWL.imports, physIRI));
}
}
@@ -228,7 +236,7 @@ public class OntologyScopeImpl implement
* otherwise owl:imports statements will be added.
* @return the OWL representation of the scope.
*/
- protected OWLOntology exportToOWLOntology(boolean merge) {
+ protected OWLOntology exportToOWLOntology(boolean merge, IRI universalPrefix) {
// if (merge) throw new UnsupportedOperationException(
// "Ontology merging only implemented for managed ontologies, not for collectors. "
// + "Please set merge parameter to false.");
@@ -263,12 +271,12 @@ public class OntologyScopeImpl implement
}
} else {
// The root ontology ID is in the form [namespace][scopeId]
- ont = mgr.createOntology(IRI.create(getNamespace() + getID()));
+ ont = mgr.createOntology(IRI.create(universalPrefix + getID()));
List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
// Add the import statement for the custom space, if existing and not empty
OntologySpace spc = getCustomSpace();
if (spc != null && spc.listManagedOntologies().size() > 0) {
- IRI spaceIri = IRI.create(getNamespace() + spc.getID());
+ IRI spaceIri = IRI.create(universalPrefix + spc.getID());
additions.add(new AddImport(ont, df.getOWLImportsDeclaration(spaceIri)));
}
// Add the import statement for the core space, if existing and not empty
@@ -307,8 +315,8 @@ public class OntologyScopeImpl implement
}
@Override
- public IRI getDocumentIRI() {
- return IRI.create(getNamespace() + getID());
+ public IRI getDefaultNamespace() {
+ return this.namespace;
}
@Override
@@ -318,7 +326,7 @@ public class OntologyScopeImpl implement
@Override
public IRI getNamespace() {
- return this.namespace;
+ return getDefaultNamespace();
}
@Override
@@ -361,16 +369,6 @@ public class OntologyScopeImpl implement
}
}
- protected void setID(String id) {
- if (id == null) throw new IllegalArgumentException("Scope ID cannot be null.");
- id = id.trim();
- if (id.isEmpty()) throw new IllegalArgumentException("Scope ID cannot be empty.");
- if (!id.matches("[\\w-\\.]+")) throw new IllegalArgumentException(
- "Illegal scope ID " + id
- + " - Must be an alphanumeric sequence, with optional underscores, dots or dashes.");
- this.id = id;
- }
-
/**
* @param namespace
* The OntoNet namespace that will prefix the scope ID in Web references. This implementation
@@ -381,7 +379,7 @@ public class OntologyScopeImpl implement
* @see OntologyScope#setNamespace(IRI)
*/
@Override
- public void setNamespace(IRI namespace) {
+ public void setDefaultNamespace(IRI namespace) {
if (namespace == null) throw new IllegalArgumentException("Namespace cannot be null.");
if (namespace.toURI().getQuery() != null) throw new IllegalArgumentException(
"URI Query is not allowed in OntoNet namespaces.");
@@ -397,6 +395,21 @@ public class OntologyScopeImpl implement
this.namespace = namespace;
}
+ protected void setID(String id) {
+ if (id == null) throw new IllegalArgumentException("Scope ID cannot be null.");
+ id = id.trim();
+ if (id.isEmpty()) throw new IllegalArgumentException("Scope ID cannot be empty.");
+ if (!id.matches("[\\w-\\.]+")) throw new IllegalArgumentException(
+ "Illegal scope ID " + id
+ + " - Must be an alphanumeric sequence, with optional underscores, dots or dashes.");
+ this.id = id;
+ }
+
+ @Override
+ public void setNamespace(IRI namespace) {
+ setDefaultNamespace(namespace);
+ }
+
@Override
public synchronized void setUp() {
if (locked || (customSpace != null && !customSpace.isLocked())) return;
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionImpl.java?rev=1363428&r1=1363427&r2=1363428&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionImpl.java Thu Jul 19 17:10:05 2012
@@ -17,11 +17,9 @@
package org.apache.stanbol.ontologymanager.ontonet.impl.session;
import java.util.Collection;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import org.apache.clerezza.rdf.core.MGraph;
@@ -29,7 +27,6 @@ import org.apache.clerezza.rdf.core.UriR
import org.apache.clerezza.rdf.core.impl.TripleImpl;
import org.apache.clerezza.rdf.ontologies.OWL;
import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyProvider;
-import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologyScope;
import org.apache.stanbol.ontologymanager.ontonet.api.session.NonReferenceableSessionException;
import org.apache.stanbol.ontologymanager.ontonet.api.session.Session;
import org.apache.stanbol.ontologymanager.ontonet.api.session.SessionEvent;
@@ -53,7 +50,7 @@ import org.slf4j.LoggerFactory;
*/
public class SessionImpl extends AbstractOntologyCollectorImpl implements Session {
- protected Map<String,OntologyScope> attachedScopes;
+ protected Set<String> attachedScopes;
protected Set<SessionListener> listeners;
@@ -73,7 +70,7 @@ public class SessionImpl extends Abstrac
super(sessionID, namespace, ontologyProvider);
backwardPathLength = 0;
// setNamespace(namespace);
- attachedScopes = new HashMap<String,OntologyScope>();
+ attachedScopes = new HashSet<String>();
listeners = new HashSet<SessionListener>();
}
@@ -83,8 +80,9 @@ public class SessionImpl extends Abstrac
}
@Override
- public void attachScope(OntologyScope scope) {
- attachedScopes.put(scope.getID(), scope);
+ public void attachScope(String scopeId) {
+ attachedScopes.add(scopeId);
+ fireScopeAppended(scopeId);
}
@Override
@@ -108,15 +106,18 @@ public class SessionImpl extends Abstrac
@Override
public void detachScope(String scopeId) {
attachedScopes.remove(scopeId);
+ fireScopeDetached(scopeId);
}
@Override
- protected MGraph exportToMGraph(boolean merge) {
- MGraph mg = super.exportToMGraph(merge);
+ protected MGraph exportToMGraph(boolean merge, IRI universalPrefix) {
+ MGraph mg = super.exportToMGraph(merge, universalPrefix);
// Add import declarations for attached scopes.
- for (String scopeID : attachedScopes.keySet()) {
- UriRef iri = new UriRef(namespace + _id);
- UriRef physIRI = new UriRef(attachedScopes.get(scopeID).getDocumentIRI().toString());
+ UriRef iri = new UriRef(universalPrefix + _id);
+ String scopePrefix = universalPrefix.toString();
+ scopePrefix = scopePrefix.substring(0, scopePrefix.lastIndexOf("/" + shortName + "/")) + "/ontology/";
+ for (String scopeID : attachedScopes) {
+ UriRef physIRI = new UriRef(scopePrefix + scopeID);
mg.add(new TripleImpl(iri, OWL.imports, physIRI));
}
return mg;
@@ -126,15 +127,18 @@ public class SessionImpl extends Abstrac
* TODO support merging for attached scopes as well?
*/
@Override
- protected OWLOntology exportToOWLOntology(boolean merge) {
- OWLOntology o = super.exportToOWLOntology(merge);
+ protected OWLOntology exportToOWLOntology(boolean merge, IRI universalPrefix) {
+ OWLOntology o = super.exportToOWLOntology(merge, universalPrefix);
if (!attachedScopes.isEmpty()) {
+ String scopePrefix = universalPrefix.toString();
+ scopePrefix = scopePrefix.substring(0, scopePrefix.lastIndexOf("/" + shortName + "/"))
+ + "/ontology/";
List<OWLOntologyChange> changes = new LinkedList<OWLOntologyChange>();
OWLOntologyManager ontologyManager = o.getOWLOntologyManager();
OWLDataFactory df = ontologyManager.getOWLDataFactory();
// Add import declarations for attached scopes.
- for (String scopeID : attachedScopes.keySet()) {
- IRI physIRI = attachedScopes.get(scopeID).getDocumentIRI();
+ for (String scopeID : attachedScopes) {
+ IRI physIRI = IRI.create(scopePrefix + scopeID);
changes.add(new AddImport(o, df.getOWLImportsDeclaration(physIRI)));
}
// Commit
@@ -155,9 +159,19 @@ public class SessionImpl extends Abstrac
l.sessionChanged(e);
}
+ protected void fireScopeAppended(String scopeId) {
+ for (SessionListener l : listeners)
+ l.scopeAppended(this, scopeId);
+ }
+
+ protected void fireScopeDetached(String scopeId) {
+ for (SessionListener l : listeners)
+ l.scopeDetached(this, scopeId);
+ }
+
@Override
public Set<String> getAttachedScopes() {
- return attachedScopes.keySet();
+ return attachedScopes;
}
@Override
Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionManagerImpl.java?rev=1363428&r1=1363427&r2=1363428&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionManagerImpl.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionManagerImpl.java Thu Jul 19 17:10:05 2012
@@ -31,6 +31,7 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.ontologymanager.ontonet.api.OfflineConfiguration;
import org.apache.stanbol.ontologymanager.ontonet.api.OntologyNetworkConfiguration;
import org.apache.stanbol.ontologymanager.ontonet.api.collector.OntologyCollectorListener;
import org.apache.stanbol.ontologymanager.ontonet.api.io.GraphSource;
@@ -72,8 +73,7 @@ public class SessionManagerImpl implemen
* Concatenated with the sessionManager ID, it identifies the Web endpoint and default base URI for all
* sessions.
*/
- @Property(name = SessionManager.SESSIONS_NS, value = _ONTOLOGY_NETWORK_NS_DEFAULT)
- private String baseNS;
+ private IRI baseNS;
@Property(name = SessionManager.ID, value = _ID_DEFAULT)
protected String id;
@@ -88,6 +88,9 @@ public class SessionManagerImpl implemen
private int maxSessions;
@Reference
+ private OfflineConfiguration offline;
+
+ @Reference
private OntologyProvider<?> ontologyProvider;
private Map<String,Session> sessionsByID;
@@ -113,9 +116,12 @@ public class SessionManagerImpl implemen
* ontology provider that will store and provide ontologies for this session manager.
* @param configuration
*/
- public SessionManagerImpl(OntologyProvider<?> ontologyProvider, Dictionary<String,Object> configuration) {
+ public SessionManagerImpl(OntologyProvider<?> ontologyProvider,
+ OfflineConfiguration offline,
+ Dictionary<String,Object> configuration) {
this();
this.ontologyProvider = ontologyProvider;
+ this.offline = offline;
try {
activate(configuration);
} catch (IOException e) {
@@ -146,22 +152,25 @@ public class SessionManagerImpl implemen
*/
protected void activate(Dictionary<String,Object> configuration) throws IOException {
+ long before = System.currentTimeMillis();
+
// Parse configuration
id = (String) configuration.get(SessionManager.ID);
if (id == null) id = _ID_DEFAULT;
String s = null;
try {
- s = (String) configuration.get(SessionManager.SESSIONS_NS);
- setNamespace(IRI.create(s));
+ setNamespace(offline.getDefaultOntologyNetworkNamespace());
} catch (Exception e) {
- log.warn("Invalid namespace {}. Setting to default value {}", s, _ONTOLOGY_NETWORK_NS_DEFAULT);
+ log.warn("Invalid namespace {}. Setting to default value {}",
+ offline.getDefaultOntologyNetworkNamespace(), _ONTOLOGY_NETWORK_NS_DEFAULT);
setNamespace(IRI.create(_ONTOLOGY_NETWORK_NS_DEFAULT));
}
try {
s = (String) configuration.get(SessionManager.MAX_ACTIVE_SESSIONS);
maxSessions = Integer.parseInt(s);
} catch (Exception e) {
- log.warn("Invalid session limit {}. Setting to default value {}", s, _MAX_ACTIVE_SESSIONS_DEFAULT);
+ log.warn("Invalid session limit {}. Setting to default value {}",
+ configuration.get(SessionManager.MAX_ACTIVE_SESSIONS), _MAX_ACTIVE_SESSIONS_DEFAULT);
maxSessions = _MAX_ACTIVE_SESSIONS_DEFAULT;
}
@@ -178,7 +187,8 @@ public class SessionManagerImpl implemen
// Rebuild sessions
rebuildSessions();
- log.debug(SessionManager.class + " activated.");
+ log.debug(SessionManager.class + " activated. Time : {} ms.", System.currentTimeMillis() - before);
+
}
protected synchronized void addSession(Session session) {
@@ -230,6 +240,8 @@ public class SessionManagerImpl implemen
// Have the ontology provider listen to ontology events
if (ontologyProvider instanceof OntologyCollectorListener) session
.addOntologyCollectorListener((OntologyCollectorListener) ontologyProvider);
+ if (ontologyProvider instanceof SessionListener) session
+ .addSessionListener((SessionListener) ontologyProvider);
addSession(session);
fireSessionCreated(session);
@@ -299,13 +311,18 @@ public class SessionManagerImpl implemen
}
@Override
+ public IRI getDefaultNamespace() {
+ return baseNS;
+ }
+
+ @Override
public String getID() {
return id;
}
@Override
public IRI getNamespace() {
- return IRI.create(baseNS);
+ return getDefaultNamespace();
}
@Override
@@ -337,7 +354,15 @@ public class SessionManagerImpl implemen
sessionsByID.put(sessionId, session);
session.setActive(false); // Restored sessions are inactive at first.
for (String key : struct.getOntologyKeysForSession(sessionId))
- session.addOntology(new GraphSource(key));
+ session.addOntology(new GraphSource(key)); // TODO use the public key instead!
+ for (String scopeId : struct.getAttachedScopes(sessionId)) {
+ /*
+ * The scope is attached by reference, so we won't have to bother checking if the scope
+ * has been rebuilt by then (which could not happen if the SessionManager is being
+ * activated first).
+ */
+ session.attachScope(scopeId);
+ }
} catch (DuplicateSessionIDException e) {
log.warn("Session \"{}\" already exists and will be reused.", sessionId);
session = getSession(sessionId);
@@ -365,7 +390,7 @@ public class SessionManagerImpl implemen
}
@Override
- public void setNamespace(IRI namespace) {
+ public void setDefaultNamespace(IRI namespace) {
if (namespace == null) throw new IllegalArgumentException("Namespace cannot be null.");
if (namespace.toURI().getQuery() != null) throw new IllegalArgumentException(
"URI Query is not allowed in OntoNet namespaces.");
@@ -376,10 +401,15 @@ public class SessionManagerImpl implemen
if (!namespace.toString().endsWith("/")) {
log.warn("Namespace {} does not end with slash character ('/'). It will be added automatically.",
namespace);
- this.baseNS = namespace + "/";
+ this.baseNS = IRI.create(namespace + "/");
return;
}
- this.baseNS = namespace.toString();
+ this.baseNS = namespace;
+ }
+
+ @Override
+ public void setNamespace(IRI namespace) {
+ setDefaultNamespace(namespace);
}
@Override