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 2011/10/17 09:46:11 UTC
svn commit: r1185033 [1/2] - in /incubator/stanbol/trunk:
ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/
ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/
ontologyma...
Author: alexdma
Date: Mon Oct 17 07:46:10 2011
New Revision: 1185033
URL: http://svn.apache.org/viewvc?rev=1185033&view=rev
Log:
Sorry, committing new files missed in previous version.
Added:
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractClerezzaGraphInputSource.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractGenericInputSource.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/OntologySetInputSource.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/LockableOntologyCollector.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OWLExportable.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyCollector.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyInputSourceHandler.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologyCollectorImpl.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologySpaceImpl.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaUtils.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CoreOntologySpaceImpl.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomOntologySpaceImpl.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/OntologySpaceFactoryImpl.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/io/TestClerezzaInputSources.java
incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestClerezzaSpaces.java
incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/RegistryManagerResource.java
incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/RegistryManagerResource/
incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/RegistryManagerResource/index.ftl
incubator/stanbol/trunk/owl/src/test/java/org/apache/stanbol/owl/util/TestOWLUtils.java
incubator/stanbol/trunk/owl/src/test/resources/owl/
incubator/stanbol/trunk/owl/src/test/resources/owl/maincharacters.owl
incubator/stanbol/trunk/owl/src/test/resources/owl/nameless_ontology.owl
Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractClerezzaGraphInputSource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractClerezzaGraphInputSource.java?rev=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractClerezzaGraphInputSource.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractClerezzaGraphInputSource.java Mon Oct 17 07:46:10 2011
@@ -0,0 +1,73 @@
+/*
+ * 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.io;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.clerezza.rdf.ontologies.OWL;
+import org.apache.stanbol.owl.util.OWLUtils;
+
+/**
+ * Default implementation of an {@link OntologyInputSource} that returns {@link Graph} objects as ontologies.
+ *
+ * Subclasses must implement the {@link #getImports(boolean)} method, as the availability of imported
+ * ontologies might depend on the input source being able to access the {@link TcManager} where they are
+ * stored.
+ *
+ * @author alexdma
+ *
+ */
+public abstract class AbstractClerezzaGraphInputSource extends AbstractGenericInputSource<Graph> {
+
+ protected UriRef ontologyId = null;
+
+ @Override
+ protected void bindRootOntology(Graph ontology) {
+ super.bindRootOntology(ontology);
+ this.ontologyId = OWLUtils.guessOntologyIdentifier(ontology);
+ }
+
+ @Override
+ public Set<Graph> getImports(boolean recursive) {
+ return getImportedGraphs(rootOntology, recursive);
+ }
+
+ protected Set<Graph> getImportedGraphs(TripleCollection g, boolean recursive) {
+ Set<Graph> result = new HashSet<Graph>();
+ Iterator<Triple> it = g.filter(OWLUtils.guessOntologyIdentifier((Graph) g), OWL.imports, null);
+ while (it.hasNext()) {
+ Resource r = it.next().getObject();
+ if (r instanceof UriRef) {
+ TripleCollection gr = TcManager.getInstance().getTriples((UriRef) r);
+ if (gr instanceof Graph) result.add((Graph) gr);
+ else if (gr instanceof MGraph) result.add(((MGraph) gr).getGraph());
+ if (recursive) result.addAll(getImportedGraphs(gr, true));
+ }
+ }
+ return result;
+ }
+
+}
Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractGenericInputSource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractGenericInputSource.java?rev=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractGenericInputSource.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/AbstractGenericInputSource.java Mon Oct 17 07:46:10 2011
@@ -0,0 +1,91 @@
+/*
+ * 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.io;
+
+import org.semanticweb.owlapi.model.IRI;
+
+/**
+ *
+ * @author alexdma
+ *
+ * @param <O>
+ * the ontologuy returned by this input source.
+ */
+public abstract class AbstractGenericInputSource<O> implements OntologyInputSource<O> {
+
+ protected IRI physicalIri = null;
+
+ protected O rootOntology = null;
+
+ /**
+ * This method is used to remind developers to bind a physical IRI to the {@link OntologyInputSource} if
+ * intending to do so.
+ *
+ * Implementation should assign a value to {@link #physicalIri}.
+ *
+ * @param iri
+ * the physical ontology IRI.
+ */
+ protected void bindPhysicalIri(IRI iri) {
+ this.physicalIri = iri;
+ }
+
+ /**
+ * This method is used to remind developers to bind a root ontology to the {@link OntologyInputSource} if
+ * intending to do so.
+ *
+ * Implementation should assign a value to {@link #rootOntology}.
+ *
+ * @param ontology
+ * the root ontology.
+ */
+ protected void bindRootOntology(O ontology) {
+ this.rootOntology = ontology;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof OntologyInputSource<?>)) return false;
+ OntologyInputSource<?> src = (OntologyInputSource<?>) obj;
+ return this.physicalIri.equals(src.getPhysicalIRI())
+ && this.rootOntology.equals(src.getRootOntology());
+ }
+
+ @Override
+ public IRI getPhysicalIRI() {
+ return physicalIri;
+ }
+
+ @Override
+ public O getRootOntology() {
+ return rootOntology;
+ }
+
+ @Override
+ public boolean hasPhysicalIRI() {
+ return physicalIri != null;
+ }
+
+ @Override
+ public boolean hasRootOntology() {
+ return rootOntology != null;
+ }
+
+ @Override
+ public abstract String toString();
+
+}
Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/OntologySetInputSource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/OntologySetInputSource.java?rev=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/OntologySetInputSource.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/OntologySetInputSource.java Mon Oct 17 07:46:10 2011
@@ -0,0 +1,11 @@
+package org.apache.stanbol.ontologymanager.ontonet.api.io;
+
+import java.util.Set;
+
+import org.semanticweb.owlapi.model.OWLOntology;
+
+public interface OntologySetInputSource {
+
+ Set<OWLOntology> getOntologies();
+
+}
Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/LockableOntologyCollector.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/LockableOntologyCollector.java?rev=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/LockableOntologyCollector.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/LockableOntologyCollector.java Mon Oct 17 07:46:10 2011
@@ -0,0 +1,28 @@
+/*
+ * 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.ontology;
+
+public interface LockableOntologyCollector extends OntologyCollector {
+
+ /**
+ * Determines if it is no longer possible to modify this space until it is torn down.
+ *
+ * @return true if this space is write-locked, false otherwise.
+ */
+ boolean isLocked();
+
+}
Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OWLExportable.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OWLExportable.java?rev=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OWLExportable.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OWLExportable.java Mon Oct 17 07:46:10 2011
@@ -0,0 +1,39 @@
+/*
+ * 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.ontology;
+
+import org.semanticweb.owlapi.model.OWLOntology;
+
+/**
+ * An object that can be represented as an {@link OWLOntology} instance.
+ *
+ * @author alexdma
+ *
+ */
+public interface OWLExportable {
+
+ /**
+ * Returns the OWL ontology form of this object.
+ *
+ * @param merge
+ * if true, all imported ontologies will be merged and no import statements will appear.
+ * @return the OWL ontology that represents this object.
+ *
+ */
+ OWLOntology asOWLOntology(boolean merge);
+
+}
Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyCollector.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyCollector.java?rev=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyCollector.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyCollector.java Mon Oct 17 07:46:10 2011
@@ -0,0 +1,166 @@
+/*
+ * 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.ontology;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLOntology;
+
+/**
+ * It is not literally an ontology <i>collection</i>, in that it only collects references to ontologies, not
+ * the ontologies themselves. Unless implementations specify a different behaviour, removing ontologies from
+ * the collector does not delete them from their persistence system.
+ *
+ * @author alexdma
+ *
+ */
+public interface OntologyCollector extends OntologyInputSourceHandler {
+
+ /**
+ * Registers a new listener for changes in this ontology space. Has no effect if the same listener is
+ * already registered with this ontology space.
+ *
+ * @param listener
+ * the ontology space listener to be added.
+ */
+ void addListener(OntologyCollectorListener listener);
+
+ /**
+ * Adds the given ontology to the ontology space.
+ *
+ * @param ontology
+ * the ontology to be added
+ * @throws UnmodifiableOntologyCollectorException
+ * if the ontology space is read-only
+ */
+ void addOntology(OntologyInputSource<?> ontologySource) throws UnmodifiableOntologyCollectorException;
+
+ /**
+ * Removes all ontology space listeners registered with this space.
+ */
+ void clearListeners();
+
+ /**
+ * Returns a Unique Resource Identifier (URI) that identifies this ontology space. For instance, this URI
+ * could be the parent of (some/most of) the base URIs for the ontologies within this space.<br/>
+ * <br/>
+ * A possible way to construct these IDs is by concatenating <code>/{spacetype}</code> (e.g.
+ * <code>/custom</code>) to the scope IRI. However, this is implementation-dependent.
+ *
+ * @return the URI that identifies this ontology space
+ */
+ String getID();
+
+ /**
+ * Returns all the listeners registered with this ontology space. Whether the collection reflects or not
+ * the order in which they were registered depends on the implementation.
+ *
+ * @return the registered ontology space listeners.
+ */
+ Collection<OntologyCollectorListener> getListeners();
+
+ /**
+ * The namespace can change dynamically (e.g. if the ontology network is relocated), so it is not part of
+ * the scope identifier (although its concatenation with the identifier will still be unique).
+ *
+ * @param namespace
+ */
+ IRI getNamespace();
+
+ /**
+ * Returns the ontologies managed by this ontology space.
+ *
+ * @param withClosure
+ * if true, also the ontologies imported by those directly managed by this space will be
+ * included.
+ * @return the set of ontologies in the ontology space
+ */
+ Set<OWLOntology> getOntologies(boolean withClosure);
+
+ /**
+ * Returns the ontology identified by the supplied <i>logical</i> IRI, if such an ontology has been loaded
+ * in this space.<br>
+ * <br>
+ * Note that ontologies are not identified by physical IRI here. There's no need to ask KReS for
+ * ontologies by physical IRI, use a browser or some other program instead!
+ *
+ * @param ontologyIri
+ * the <i>logical</i> identifier of the ontology to query for.
+ *
+ * @return the requested ontology, or null if no ontology with this ID has been loaded.
+ */
+ OWLOntology getOntology(IRI ontologyIri);
+
+ /**
+ * Determines if the ontology identified by the supplied <i>logical</i> IRI has been loaded in this space.<br>
+ * <br>
+ * Note that ontologies are not identified by physical IRI here. There's no need to ask KReS for
+ * ontologies by physical IRI, use a browser or some other program instead!
+ *
+ * @param ontologyIri
+ * the <i>logical</i> identifier of the ontology to query for.
+ *
+ * @return true if an ontology with this ID has been loaded in this space.
+ */
+ boolean hasOntology(IRI ontologyIri);
+
+ /**
+ * Unregisters the supplied for changes in this ontology space. Has no effect if the same listener was not
+ * registered with this ontology space.
+ *
+ * @param listener
+ * the ontology space listener to be removed.
+ */
+ void removeListener(OntologyCollectorListener listener);
+
+ /**
+ * Removes the given ontology from the ontology space, if the ontology is a direct child of the top
+ * ontology.<br/>
+ * <u>Note</u> that this will NOT delete the ontology from the store! This method simply states that the
+ * ontology is no longer managed by this space and its axioms will no longer appear when the space is
+ * serialized as an ontology. To delete the ontology itself, please use the Ontology Manager Store.
+ *
+ * @param ontologyIri
+ * the identifier of this ontology.
+ */
+ void removeOntology(IRI ontologyId) throws OntologyCollectorModificationException;
+
+ /**
+ * The namespace can be changed dynamically (e.g. if the ontology network is relocated).
+ *
+ * @param namespace
+ * Must end with a slash character. If the IRI ends with a has, and
+ * {@link IllegalArgumentException} will be thrown. If it ends with neither, a slash will be
+ * added.
+ */
+ void setNamespace(IRI namespace);
+
+ /**
+ * Bootstraps the ontology space. In some cases (such as with core and custom spaces) this also implies
+ * write-locking its ontologies.
+ */
+ void setUp();
+
+ /**
+ * Performs all required operations for disposing of an ontology space and releasing its resources (e.g.
+ * removing the writelock).
+ */
+ void tearDown();
+}
Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyInputSourceHandler.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyInputSourceHandler.java?rev=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyInputSourceHandler.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/OntologyInputSourceHandler.java Mon Oct 17 07:46:10 2011
@@ -0,0 +1,39 @@
+/*
+ * 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.ontology;
+
+import java.util.Set;
+
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
+
+/**
+ *
+ * An object that can manipulate {@link OntologyInputSource} objects;
+ *
+ * @author alexdma
+ *
+ */
+public interface OntologyInputSourceHandler {
+
+ /**
+ * Gets the the types representing ontologies and RDF graphs that this object is able to manage.
+ *
+ * @return the ontology types that can be handled by this object.
+ */
+ Set<Class<?>> getSupportedTypes();
+
+}
Added: 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=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologyCollectorImpl.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologyCollectorImpl.java Mon Oct 17 07:46:10 2011
@@ -0,0 +1,277 @@
+/*
+ * 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.impl.clerezza;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.EntityAlreadyExistsException;
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.LockableOntologyCollector;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyCollectorListener;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyCollectorModificationException;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyInputSourceHandler;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.UnmodifiableOntologyCollectorException;
+import org.apache.stanbol.owl.transformation.OWLAPIToClerezzaConverter;
+import org.apache.stanbol.owl.util.OWLUtils;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A basic Clerezza-native implementation of an ontology collector.
+ *
+ * @author alexdma
+ *
+ */
+public abstract class AbstractOntologyCollectorImpl implements LockableOntologyCollector,
+ OntologyInputSourceHandler {
+
+ protected String _id = null;
+
+ private Set<OntologyCollectorListener> listeners = new HashSet<OntologyCollectorListener>();
+
+ /**
+ * Indicates whether this ontology space is marked as read-only. Default value is false.
+ */
+ protected volatile boolean locked = false;
+
+ protected Logger log = LoggerFactory.getLogger(getClass());
+
+ /**
+ * The identifier of the ontologies directly managed by this collector (i.e. that were directly added to
+ * this space, hence not including those just pulled in via import statements).
+ */
+ protected Set<IRI> managedOntologies;
+
+ protected IRI namespace = null;
+
+ protected Set<Class<?>> supportedTypes;
+
+ private TcManager tcManager;
+
+ public AbstractOntologyCollectorImpl(String id, IRI namespace, TcManager tcManager) {
+ // Supports OWL API and Clerezza
+ supportedTypes = new HashSet<Class<?>>();
+ supportedTypes.add(OWLOntology.class);
+ supportedTypes.add(TripleCollection.class);
+ setID(id);
+ setNamespace(namespace);
+ this.tcManager = tcManager;
+ this.managedOntologies = new HashSet<IRI>();
+ }
+
+ @Override
+ public void addListener(OntologyCollectorListener listener) {
+ listeners.add(listener);
+ }
+
+ @Override
+ public synchronized void addOntology(OntologyInputSource<?> ontologySource) throws UnmodifiableOntologyCollectorException {
+ if (locked) throw new UnmodifiableOntologyCollectorException(this);
+ log.debug("Adding ontology {} to space {}", ontologySource != null ? ontologySource.getRootOntology()
+ : "<NULL>", getNamespace() + getID());
+ if (ontologySource == null || !ontologySource.hasRootOntology()) return; // No ontology to add
+
+ Object o = ontologySource.getRootOntology();
+ UriRef uri;
+ if (o instanceof Graph) {
+ uri = OWLUtils.guessOntologyIdentifier((Graph) o);
+ } else if (o instanceof OWLOntology) {
+ uri = new UriRef(OWLUtils.guessOntologyIdentifier((OWLOntology) o).toString());
+ } else throw new UnsupportedOperationException("This ontology space implementation cannot handle "
+ + o.getClass() + " objects.");
+ // create/get the graph and add the triples.
+ MGraph mg;
+ try {
+ mg = tcManager.createMGraph(uri);
+ } catch (EntityAlreadyExistsException e) {
+ mg = tcManager.getMGraph(uri);
+ mg.clear();
+ }
+ if (o instanceof TripleCollection) mg.addAll((TripleCollection) o);
+ else if (o instanceof OWLOntology) {
+ // FIXME there must be a better angle than using converters...
+ mg.addAll(OWLAPIToClerezzaConverter.owlOntologyToClerezzaTriples((OWLOntology) o));
+ }
+
+ // add to index
+ managedOntologies.add(IRI.create(uri.getUnicodeString()));
+
+ // fire the event
+ fireOntologyAdded(uri);
+ }
+
+ @Override
+ public void clearListeners() {
+ listeners.clear();
+ }
+
+ /**
+ * Notifies all ontology space listeners that an ontology has been added to this space.
+ *
+ * @param ontologyIri
+ * the identifier of the ontology that was added to this space.
+ */
+ protected void fireOntologyAdded(IRI ontologyIri) {
+ for (OntologyCollectorListener listener : listeners)
+ listener.onOntologyAdded(IRI.create(namespace + _id), ontologyIri);
+ }
+
+ /**
+ * Notifies all ontology space listeners that an ontology has been added to this space.
+ *
+ * @param ontologyIri
+ * the identifier of the ontology that was added to this space.
+ */
+ protected void fireOntologyAdded(UriRef ontologyIri) {
+ fireOntologyAdded(IRI.create(ontologyIri.getUnicodeString()));
+ }
+
+ /**
+ * Notifies all ontology space listeners that an ontology has been removed from this space.
+ *
+ * @param ontologyIri
+ * the identifier of the ontology that was removed from this space.
+ */
+ protected void fireOntologyRemoved(IRI ontologyIri) {
+ for (OntologyCollectorListener listener : listeners)
+ listener.onOntologyRemoved(IRI.create(namespace + _id), ontologyIri);
+ }
+
+ protected void fireOntologyRemoved(UriRef ontologyIri) {
+ fireOntologyRemoved(IRI.create(ontologyIri.getUnicodeString()));
+ }
+
+ @Override
+ public String getID() {
+ return _id;
+ }
+
+ @Override
+ public Collection<OntologyCollectorListener> getListeners() {
+ return listeners;
+ }
+
+ @Override
+ public IRI getNamespace() {
+ return namespace;
+ }
+
+ /**
+ * FIXME not including closure yet.
+ *
+ * @see OntologySpace#getOntologies(boolean)
+ */
+ @Override
+ public Set<OWLOntology> getOntologies(boolean withClosure) {
+ Set<OWLOntology> ontologies = new HashSet<OWLOntology>();
+ for (IRI id : managedOntologies)
+ ontologies.add(getOntology(id));
+ return Collections.unmodifiableSet(ontologies);
+ }
+
+ @Override
+ public OWLOntology getOntology(IRI ontologyIri) {
+ if (!managedOntologies.contains(ontologyIri)) return null;
+ TripleCollection g = tcManager.getTriples(new UriRef(ontologyIri.toString()));
+ return OWLAPIToClerezzaConverter.clerezzaGraphToOWLOntology(g);
+ }
+
+ @Override
+ public Set<Class<?>> getSupportedTypes() {
+ return Collections.unmodifiableSet(supportedTypes);
+ }
+
+ public TcManager getTcManager() {
+ return tcManager;
+ }
+
+ @Override
+ public boolean hasOntology(IRI ontologyIri) {
+ return managedOntologies.contains(ontologyIri);
+ }
+
+ @Override
+ public boolean isLocked() {
+ return locked;
+ }
+
+ @Override
+ public void removeListener(OntologyCollectorListener listener) {
+ listeners.remove(listener);
+ }
+
+ @Override
+ public void removeOntology(IRI ontologyId) throws OntologyCollectorModificationException {
+ if (locked) throw new UnmodifiableOntologyCollectorException(this);
+ try {
+ managedOntologies.remove(ontologyId);
+ fireOntologyRemoved(ontologyId);
+ } catch (RuntimeException ex) {
+ throw new OntologyCollectorModificationException(this, ex);
+ }
+ }
+
+ protected abstract void setID(String id);
+
+ /**
+ * @param namespace
+ * The OntoNet namespace that will prefix the space ID in Web references. This implementation
+ * only allows non-null and non-empty IRIs, with no query or fragment. Hash URIs are not
+ * allowed, slash URIs are preferred. If neither, a slash will be concatenated and a warning
+ * will be logged.
+ *
+ * @see OntologySpace#setNamespace(IRI)
+ */
+ @Override
+ public void setNamespace(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.");
+ if (namespace.toURI().getFragment() != null) throw new IllegalArgumentException(
+ "URI Fragment is not allowed in OntoNet namespaces.");
+ if (namespace.toString().endsWith("#")) throw new IllegalArgumentException(
+ "OntoNet namespaces must not end with a hash ('#') character.");
+ if (!namespace.toString().endsWith("/")) {
+ log.warn("Namespace {} does not end with slash character ('/'). It will be added automatically.",
+ namespace);
+ namespace = IRI.create(namespace + "/");
+ }
+ this.namespace = namespace;
+ }
+
+ @Override
+ public void setUp() {
+ this.locked = true;
+ }
+
+ @Override
+ public void tearDown() {
+ this.locked = false;
+ }
+
+}
Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologySpaceImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologySpaceImpl.java?rev=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologySpaceImpl.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologySpaceImpl.java Mon Oct 17 07:46:10 2011
@@ -0,0 +1,152 @@
+/*
+ * 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.impl.clerezza;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OWLExportable;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.SpaceType;
+import org.apache.stanbol.owl.util.URIUtils;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.AddImport;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException;
+import org.semanticweb.owlapi.model.OWLOntologyChange;
+import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract Clerezza-native implementation of {@link OntologySpace}.
+ *
+ * @author alexdma
+ *
+ */
+public abstract class AbstractOntologySpaceImpl extends AbstractOntologyCollectorImpl implements
+ OntologySpace {
+
+ protected Logger log = LoggerFactory.getLogger(getClass());
+
+ protected boolean silent = false;
+
+ protected SpaceType type;
+
+ public AbstractOntologySpaceImpl(String spaceID, IRI namespace, SpaceType type, TcManager tcManager) {
+ super(spaceID, namespace, tcManager);
+ this.type = type;
+ }
+
+ @Override
+ public OWLOntology asOWLOntology() {
+ return this.asOWLOntology(false);
+ }
+
+ /**
+ * FIXME not merging yet
+ *
+ * @see OWLExportable#asOWLOntology(boolean)
+ */
+ @Override
+ public OWLOntology asOWLOntology(boolean merge) {
+ OWLOntology root;
+ OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
+ IRI iri = IRI.create(namespace + _id);
+ try {
+ root = ontologyManager.createOntology(iri);
+ } catch (OWLOntologyAlreadyExistsException e) {
+ ontologyManager.removeOntology(ontologyManager.getOntology(iri));
+ try {
+ root = ontologyManager.createOntology(iri);
+ } catch (OWLOntologyAlreadyExistsException e1) {
+ root = ontologyManager.getOntology(iri);
+ } catch (OWLOntologyCreationException e1) {
+ log.error("Failed to assemble root ontology for scope " + iri, e);
+ root = null;
+ }
+ } catch (OWLOntologyCreationException e) {
+ log.error("Failed to assemble root ontology for scope " + _id, e);
+ root = null;
+ }
+
+ // Add the import declarations for directly managed ontologies.
+ if (root != null) {
+ List<OWLOntologyChange> changes = new LinkedList<OWLOntologyChange>();
+ OWLDataFactory df = ontologyManager.getOWLDataFactory();
+ for (OWLOntology o : getOntologies(false)) {
+ if (o == null) continue;
+
+ String base = URIUtils.upOne(IRI.create(namespace + getID())) + "/";
+
+ IRI ontologyIri;
+
+ if (o.isAnonymous()) try {
+ ontologyIri = ontologyManager.getOntologyDocumentIRI(o);
+ } catch (Exception ex) {
+ ontologyIri = o.getOWLOntologyManager().getOntologyDocumentIRI(o);
+ }
+ else {
+ ontologyIri = o.getOntologyID().getDefaultDocumentIRI();
+ }
+
+ IRI physIRI = IRI.create(base + ontologyIri);
+
+ changes.add(new AddImport(root, df.getOWLImportsDeclaration(physIRI)));
+ }
+ ontologyManager.applyChanges(changes);
+ }
+ return root;
+ }
+
+ @Override
+ public boolean isSilentMissingOntologyHandling() {
+ return silent;
+ }
+
+ /**
+ *
+ * @param id
+ * The ontology space identifier. This implementation only allows non-null and non-empty
+ * alphanumeric sequences, case-sensitive and preferably separated by a single slash character,
+ * with optional dashes or underscores.
+ */
+ @Override
+ protected void setID(String id) {
+ if (id == null) throw new IllegalArgumentException("Space ID cannot be null.");
+ id = id.trim();
+ if (id.isEmpty()) throw new IllegalArgumentException("Space ID cannot be empty.");
+ if (id.matches("[\\w-]+")) log.warn(
+ "Space ID {} is a single alphanumeric sequence, with no separating slash."
+ + " This is legal but strongly discouraged. Please consider using"
+ + " space IDs of the form [scope_id]/[space_type], e.g. Users/core .", id);
+ else if (!id.matches("[\\w-]+/[\\w-]+")) throw new IllegalArgumentException(
+ "Illegal space ID " + id + " - Must be an alphanumeric sequence, (preferably two, "
+ + " slash-separated), with optional underscores or dashes.");
+ this._id = id;
+ }
+
+ @Override
+ public void setSilentMissingOntologyHandling(boolean silent) {
+ this.silent = silent;
+ }
+
+}
Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaUtils.java?rev=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaUtils.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaUtils.java Mon Oct 17 07:46:10 2011
@@ -0,0 +1,45 @@
+/*
+ * 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.impl.clerezza;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.ontologies.OWL;
+import org.apache.clerezza.rdf.ontologies.RDF;
+
+/**
+ * A set of utilities for handling OWL2 ontologies in Clerezza.
+ *
+ * @author alexdma
+ *
+ */
+public class ClerezzaUtils {
+
+ public static MGraph createOntology(String id, TcManager tcm) {
+ UriRef name = new UriRef(id);
+ MGraph ont = tcm.createMGraph(name);
+ ont.add(new TripleImpl(name, RDF.type, OWL.Ontology));
+ return ont;
+ }
+
+ public static MGraph createOntology(String id) {
+ return createOntology(id, TcManager.getInstance());
+ }
+
+}
Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CoreOntologySpaceImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CoreOntologySpaceImpl.java?rev=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CoreOntologySpaceImpl.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CoreOntologySpaceImpl.java Mon Oct 17 07:46:10 2011
@@ -0,0 +1,58 @@
+/*
+ * 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.impl.clerezza;
+
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.CoreOntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.SpaceType;
+import org.semanticweb.owlapi.model.IRI;
+
+/**
+ * Default implementation of core ontology space.
+ *
+ * @author alexdma
+ *
+ */
+public class CoreOntologySpaceImpl extends AbstractOntologySpaceImpl implements CoreOntologySpace {
+
+ public static final String SUFFIX = SpaceType.CORE.getIRISuffix();
+
+ protected static String buildId(String scopeID) {
+ return (scopeID != null ? scopeID : "") + "/" + SUFFIX;
+ }
+
+ public CoreOntologySpaceImpl(String scopeID, IRI namespace, TcManager tcManager) {
+ super(buildId(scopeID), namespace, SpaceType.CORE, tcManager);
+ }
+
+ /**
+ * When set up, a core space is write-locked.
+ */
+ @Override
+ public synchronized void setUp() {
+ locked = true;
+ }
+
+ /**
+ * When torn down, a core space releases its write-lock.
+ */
+ @Override
+ public synchronized void tearDown() {
+ locked = false;
+ }
+
+}
Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomOntologySpaceImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomOntologySpaceImpl.java?rev=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomOntologySpaceImpl.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/CustomOntologySpaceImpl.java Mon Oct 17 07:46:10 2011
@@ -0,0 +1,63 @@
+/*
+ * 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.impl.clerezza;
+
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.CoreOntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.CustomOntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.SpaceType;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.UnmodifiableOntologyCollectorException;
+import org.semanticweb.owlapi.model.IRI;
+
+/**
+ * Default implementation of custom ontology space.
+ *
+ * @author alexdma
+ *
+ */
+public class CustomOntologySpaceImpl extends AbstractOntologySpaceImpl implements CustomOntologySpace {
+
+ public static final String SUFFIX = SpaceType.CUSTOM.getIRISuffix();
+
+ protected static String buildId(String scopeID) {
+ return (scopeID != null ? scopeID : "") + "/" + SUFFIX;
+ }
+
+ public CustomOntologySpaceImpl(String scopeID, IRI namespace, TcManager tcManager) {
+ super(buildId(scopeID), namespace, SpaceType.CUSTOM, tcManager);
+ }
+
+ @Override
+ public void attachCoreSpace(CoreOntologySpace coreSpace, boolean skipRoot) throws UnmodifiableOntologyCollectorException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * Once it is set up, a custom space is write-locked.
+ */
+ @Override
+ public synchronized void setUp() {
+ locked = true;
+ }
+
+ @Override
+ public synchronized void tearDown() {
+ locked = false;
+ }
+
+}
Added: 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=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/OntologySpaceFactoryImpl.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/OntologySpaceFactoryImpl.java Mon Oct 17 07:46:10 2011
@@ -0,0 +1,138 @@
+/*
+ * 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.impl.clerezza;
+
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.OfflineConfiguration;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.CoreOntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.CustomOntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyScope;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologySpaceFactory;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyCollectorListener;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.ScopeRegistry;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.SessionOntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.SpaceType;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.UnmodifiableOntologyCollectorException;
+import org.semanticweb.owlapi.model.IRI;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implementation of {@link OntologySpaceFactory} based on Clerezza.
+ *
+ * @author alexdma
+ *
+ */
+public class OntologySpaceFactoryImpl implements OntologySpaceFactory {
+
+ protected Logger log = LoggerFactory.getLogger(getClass());
+
+ protected IRI namespace;
+
+ protected OfflineConfiguration offline;
+
+ protected ScopeRegistry registry;
+
+ protected TcManager tcManager;
+
+ public OntologySpaceFactoryImpl(ScopeRegistry registry,
+ TcManager tcManager,
+ OfflineConfiguration offline,
+ IRI namespace) {
+ this.registry = registry;
+ this.tcManager = tcManager;
+ this.offline = offline;
+ this.namespace = namespace;
+ }
+
+ /**
+ * Utility method for configuring ontology spaces after creating them.
+ *
+ * @param s
+ * @param scopeID
+ * @param rootSource
+ */
+ 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);
+
+ if (parentScope != null && parentScope instanceof OntologyCollectorListener) s
+ .addListener((OntologyCollectorListener) parentScope);
+ // Set the supplied ontology's parent as the root for this space.
+ if (ontologySources != null) try {
+ for (OntologyInputSource<?> src : ontologySources)
+ s.addOntology(src);
+ } catch (UnmodifiableOntologyCollectorException e) {
+ log.error("Ontology space " + s.getID() + " was found locked at creation time!", e);
+ }
+ // s.setUp();
+ }
+
+ @Override
+ public CoreOntologySpace createCoreOntologySpace(String scopeId, OntologyInputSource<?>... coreSources) {
+ CoreOntologySpace s = new CoreOntologySpaceImpl(scopeId, namespace, tcManager);
+ configureSpace(s, scopeId, coreSources);
+ return s;
+ }
+
+ @Override
+ public CustomOntologySpace createCustomOntologySpace(String scopeId,
+ OntologyInputSource<?>... customSources) {
+ CustomOntologySpace s = new CustomOntologySpaceImpl(scopeId, namespace, tcManager);
+ configureSpace(s, scopeId, customSources);
+ return s;
+ }
+
+ @Override
+ public OntologySpace createOntologySpace(String scopeId,
+ SpaceType type,
+ OntologyInputSource<?>... ontologySources) {
+ switch (type) {
+ case CORE:
+ return createCoreOntologySpace(scopeId, ontologySources);
+ case CUSTOM:
+ return createCustomOntologySpace(scopeId, ontologySources);
+ case SESSION:
+ // return createSessionOntologySpace(scopeId, ontologySources);
+ throw new IllegalArgumentException("Factory " + getClass()
+ + "cannot create obsolete session spaces.");
+ default:
+ return null;
+ }
+ }
+
+ @Override
+ public SessionOntologySpace createSessionOntologySpace(String scopeId,
+ OntologyInputSource<?>... sessionSources) {
+ throw new UnsupportedOperationException(
+ "Newer ontology space factory implementations such as " + getClass()
+ + " no longer allow the creation of session spaces. Please store data in sessions");
+ }
+
+ @Override
+ public IRI getNamespace() {
+ return this.namespace;
+ }
+
+ @Override
+ public void setNamespace(IRI namespace) {
+ this.namespace = namespace;
+ }
+
+}
Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/io/TestClerezzaInputSources.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/io/TestClerezzaInputSources.java?rev=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/io/TestClerezzaInputSources.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/io/TestClerezzaInputSources.java Mon Oct 17 07:46:10 2011
@@ -0,0 +1,77 @@
+/*
+ * 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.io;
+
+import static org.apache.stanbol.ontologymanager.ontonet.MockOsgiContext.*;
+import static org.junit.Assert.*;
+
+import java.io.InputStream;
+import java.util.Set;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.stanbol.ontologymanager.ontonet.Locations;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.GraphSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestClerezzaInputSources {
+
+ @BeforeClass
+ public static void loadGraphs() throws Exception {
+ reset();
+ UriRef uri = new UriRef(Locations.CHAR_ACTIVE.toString());
+ InputStream inputStream = TestClerezzaInputSources.class
+ .getResourceAsStream("/ontologies/characters_all.owl");
+ parser.parse(tcManager.createMGraph(uri), inputStream, "application/rdf+xml", uri);
+ uri = new UriRef(Locations.CHAR_MAIN.toString());
+ inputStream = TestClerezzaInputSources.class.getResourceAsStream("/ontologies/maincharacters.owl");
+ parser.parse(tcManager.createMGraph(uri), inputStream, "application/rdf+xml", uri);
+ uri = new UriRef(Locations.CHAR_MINOR.toString());
+ inputStream = TestClerezzaInputSources.class.getResourceAsStream("/ontologies/minorcharacters.owl");
+ parser.parse(tcManager.createMGraph(uri), inputStream, "application/rdf+xml", uri);
+
+ }
+
+ private OntologyInputSource<Graph> gis;
+
+ @Before
+ public void bind() throws Exception {
+
+ }
+
+ @After
+ public void cleanup() {
+ reset();
+ }
+
+ @Test
+ public void testGraphSource() throws Exception {
+ gis = new GraphSource(new UriRef(Locations.CHAR_ACTIVE.toString()));
+ assertNotNull(gis);
+ assertNotNull(gis.getRootOntology());
+ Set<Graph> imported = gis.getImports(false);
+ // Number of stored graphs minus the importing one = imported graphs
+ assertEquals(tcManager.listTripleCollections().size() - 1, imported.size());
+ for (Graph g : imported)
+ assertNotNull(g);
+ }
+
+}
Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestClerezzaSpaces.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestClerezzaSpaces.java?rev=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestClerezzaSpaces.java (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestClerezzaSpaces.java Mon Oct 17 07:46:10 2011
@@ -0,0 +1,295 @@
+/*
+ * 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.ontology;
+
+import static org.apache.stanbol.ontologymanager.ontonet.MockOsgiContext.parser;
+import static org.apache.stanbol.ontologymanager.ontonet.MockOsgiContext.reset;
+import static org.apache.stanbol.ontologymanager.ontonet.MockOsgiContext.tcManager;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Hashtable;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
+import org.apache.stanbol.ontologymanager.ontonet.Constants;
+import org.apache.stanbol.ontologymanager.ontonet.api.OfflineConfiguration;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.BlankOntologySource;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.GraphSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.ParentPathInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.RootOntologyIRISource;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.CoreOntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.CustomOntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologySpaceFactory;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.ScopeRegistry;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.SessionOntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.SpaceType;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.UnmodifiableOntologyCollectorException;
+import org.apache.stanbol.ontologymanager.ontonet.impl.OfflineConfigurationImpl;
+import org.apache.stanbol.ontologymanager.ontonet.impl.clerezza.ClerezzaUtils;
+import org.apache.stanbol.ontologymanager.ontonet.impl.clerezza.OntologySpaceFactoryImpl;
+import org.apache.stanbol.ontologymanager.ontonet.impl.ontology.ScopeRegistryImpl;
+import org.apache.stanbol.owl.OWLOntologyManagerFactory;
+import org.apache.stanbol.owl.util.OWLUtils;
+import org.apache.stanbol.owl.util.URIUtils;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLAxiom;
+import org.semanticweb.owlapi.model.OWLClass;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.semanticweb.owlapi.model.OWLIndividual;
+import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+
+public class TestClerezzaSpaces {
+
+ public static IRI baseIri = IRI.create(Constants.PEANUTS_MAIN_BASE), baseIri2 = IRI
+ .create(Constants.PEANUTS_MINOR_BASE);
+
+ private static OWLAxiom linusIsHuman = null;
+
+ private static OntologySpaceFactory factory;
+
+ private static OntologyInputSource<?> inMemorySrc, minorSrc, dropSrc, nonexSrc;
+
+ private static OfflineConfiguration offline;
+
+ private static OntologyInputSource<Graph> getLocalSource(String resourcePath) {
+ InputStream is = TestOntologySpaces.class.getResourceAsStream(resourcePath);
+ return new GraphSource(parser.parse(is, SupportedFormat.RDF_XML));
+ }
+
+ private static OntologyInputSource<?> getLocalSource(String resourcePath, OWLOntologyManager mgr) throws OWLOntologyCreationException,
+ URISyntaxException {
+ URL url = TestOntologySpaces.class.getResource(resourcePath);
+ File f = new File(url.toURI());
+ return new ParentPathInputSource(f, mgr != null ? mgr
+ : OWLOntologyManagerFactory.createOWLOntologyManager(offline.getOntologySourceLocations()
+ .toArray(new IRI[0])));
+ }
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ offline = new OfflineConfigurationImpl(new Hashtable<String,Object>());
+ ScopeRegistry reg = new ScopeRegistryImpl();
+
+ // This one is created from scratch
+ MGraph ont2 = ClerezzaUtils.createOntology(baseIri2.toString());
+ minorSrc = new GraphSource(ont2.getGraph());
+ dropSrc = getLocalSource("/ontologies/droppedcharacters.owl");
+ nonexSrc = getLocalSource("/ontologies/nonexistentcharacters.owl");
+ inMemorySrc = new RootOntologyIRISource(IRI.create(TestClerezzaSpaces.class
+ .getResource("/ontologies/maincharacters.owl")));
+
+ OWLDataFactory df = OWLManager.getOWLDataFactory();
+ OWLClass cHuman = df.getOWLClass(IRI.create(baseIri + "/" + Constants.humanBeing));
+ OWLIndividual iLinus = df.getOWLNamedIndividual(IRI.create(baseIri + "/" + Constants.linus));
+ linusIsHuman = df.getOWLClassAssertionAxiom(cHuman, iLinus);
+
+ factory = new OntologySpaceFactoryImpl(reg, tcManager, offline,
+ IRI.create("http://stanbol.apache.org/ontology/"));
+ }
+
+ String scopeId = "Comics";
+
+ @AfterClass
+ public static void cleanup() {
+ reset();
+ }
+
+ @Test
+ public void testAddOntology() throws Exception {
+ CustomOntologySpace space = null;
+ IRI logicalId = IRI.create(OWLUtils.guessOntologyIdentifier(nonexSrc.getRootOntology())
+ .getUnicodeString());
+
+ space = factory.createCustomOntologySpace(scopeId, dropSrc, minorSrc);
+ space.addOntology(minorSrc);
+ space.addOntology(nonexSrc);
+
+ assertTrue(space.hasOntology(logicalId));
+ logicalId = IRI
+ .create(OWLUtils.guessOntologyIdentifier(dropSrc.getRootOntology()).getUnicodeString());
+ assertTrue(space.hasOntology(logicalId));
+ }
+
+ @Test
+ public void testCoreLock() throws Exception {
+ CoreOntologySpace space = factory.createCoreOntologySpace(scopeId, inMemorySrc);
+ space.setUp();
+ try {
+ space.addOntology(minorSrc);
+ fail("Modification was permitted on locked ontology space.");
+ } catch (UnmodifiableOntologyCollectorException e) {
+ assertSame(space, e.getOntologyCollector());
+ }
+ }
+
+ @Test
+ public void testCreateSpace() throws Exception {
+ CustomOntologySpace space = factory.createCustomOntologySpace(scopeId, dropSrc);
+ IRI logicalId = IRI.create(OWLUtils.guessOntologyIdentifier(dropSrc.getRootOntology())
+ .getUnicodeString());
+ assertTrue(space.hasOntology(logicalId));
+ }
+
+ @Test
+ public void testCustomLock() throws Exception {
+ CustomOntologySpace space = factory.createCustomOntologySpace(scopeId, inMemorySrc);
+ space.setUp();
+ try {
+ space.addOntology(minorSrc);
+ fail("Modification was permitted on locked ontology space.");
+ } catch (UnmodifiableOntologyCollectorException e) {
+ assertSame(space, e.getOntologyCollector());
+ }
+ }
+
+ /**
+ * Checks whether attempting to create ontology spaces with invalid identifiers or namespaces results in
+ * the appropriate exceptions being thrown.
+ *
+ * @throws Exception
+ * if an unexpected error occurs.
+ */
+ @Test
+ public void testIdentifiers() throws Exception {
+ OntologySpace shouldBeNull = null, shouldBeNotNull = null;
+
+ /* First test space identifiers. */
+
+ // Null identifier (invalid).
+ try {
+ shouldBeNull = factory.createOntologySpace(null, SpaceType.CORE, new BlankOntologySource());
+ fail("Expected IllegalArgumentException not thrown despite null scope identifier.");
+ } catch (IllegalArgumentException ex) {}
+ assertNull(shouldBeNull);
+
+ // More than one slash in identifier (invalid).
+ try {
+ shouldBeNull = factory.createOntologySpace("Sc0/p3", SpaceType.CORE, new BlankOntologySource());
+ fail("Expected IllegalArgumentException not thrown despite null scope identifier.");
+ } catch (IllegalArgumentException ex) {}
+ assertNull(shouldBeNull);
+
+ /* Now test namespaces. */
+
+ // Null namespace (invalid).
+ factory.setNamespace(null);
+ try {
+ shouldBeNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE, new BlankOntologySource());
+ fail("Expected IllegalArgumentException not thrown despite null OntoNet namespace.");
+ } catch (IllegalArgumentException ex) {}
+ assertNull(shouldBeNull);
+
+ // Namespace with query (invalid).
+ factory.setNamespace(IRI.create("http://stanbol.apache.org/ontology/?query=true"));
+ try {
+ shouldBeNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE, new BlankOntologySource());
+ fail("Expected IllegalArgumentException not thrown despite query in OntoNet namespace.");
+ } catch (IllegalArgumentException ex) {}
+ assertNull(shouldBeNull);
+
+ // Namespace with fragment (invalid).
+ factory.setNamespace(IRI.create("http://stanbol.apache.org/ontology#fragment"));
+ try {
+ shouldBeNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE, new BlankOntologySource());
+ fail("Expected IllegalArgumentException not thrown despite fragment in OntoNet namespace.");
+ } catch (IllegalArgumentException ex) {}
+ assertNull(shouldBeNull);
+
+ // Namespace ending with hash (invalid).
+ factory.setNamespace(IRI.create("http://stanbol.apache.org/ontology#"));
+ try {
+ shouldBeNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE, new BlankOntologySource());
+ fail("Expected IllegalArgumentException not thrown despite fragment in OntoNet namespace.");
+ } catch (IllegalArgumentException ex) {}
+ assertNull(shouldBeNull);
+
+ // Namespace ending with neither (valid, should automatically add slash).
+ factory.setNamespace(IRI.create("http://stanbol.apache.org/ontology"));
+ shouldBeNotNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE, new BlankOntologySource());
+ assertNotNull(shouldBeNotNull);
+ assertTrue(shouldBeNotNull.getNamespace().toString().endsWith("/"));
+
+ shouldBeNotNull = null;
+
+ // Namespace ending with slash (valid).
+ factory.setNamespace(IRI.create("http://stanbol.apache.org/ontology/"));
+ shouldBeNotNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE, new BlankOntologySource());
+ assertNotNull(shouldBeNotNull);
+ }
+
+ @Test
+ public void testRemoveCustomOntology() throws Exception {
+ CustomOntologySpace space = null;
+ space = factory.createCustomOntologySpace(scopeId, dropSrc);
+ IRI dropId = URIUtils.createIRI(OWLUtils.guessOntologyIdentifier(dropSrc.getRootOntology()));
+ IRI nonexId = URIUtils.createIRI(OWLUtils.guessOntologyIdentifier(nonexSrc.getRootOntology()));
+
+ space.addOntology(inMemorySrc);
+ space.addOntology(nonexSrc);
+ // The other remote ontologies may change base IRI...
+ // baseIri is maincharacters
+ assertTrue(space.hasOntology(baseIri));
+ assertTrue(space.hasOntology(dropId));
+ assertTrue(space.hasOntology(nonexId));
+ space.removeOntology(dropId);
+ assertFalse(space.hasOntology(dropId));
+ space.removeOntology(nonexId);
+ assertFalse(space.hasOntology(nonexId));
+ // OntologyUtils.printOntology(space.getTopOntology(), System.err);
+
+ }
+
+// @Test
+ public void testSessionModification() throws Exception {
+ SessionOntologySpace space = factory.createSessionOntologySpace(scopeId);
+ space.setUp();
+ try {
+ // First add an in-memory ontology with a few axioms.
+ space.addOntology(inMemorySrc);
+ // Now add a real online ontology
+ space.addOntology(dropSrc);
+ // The in-memory ontology must be in the space.
+ assertTrue(space.hasOntology(baseIri));
+ // The in-memory ontology must still have its axioms.
+ assertTrue(space.getOntology(baseIri).containsAxiom(linusIsHuman));
+
+ // // The top ontology must still have axioms from in-memory
+ // // ontologies. NO LONGER
+ // assertTrue(space.getTopOntology().containsAxiom(linusIsHuman));
+ } catch (UnmodifiableOntologyCollectorException e) {
+ fail("Modification was denied on unlocked ontology space.");
+ }
+ }
+
+}
Added: incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/RegistryManagerResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/RegistryManagerResource.java?rev=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/RegistryManagerResource.java (added)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/RegistryManagerResource.java Mon Oct 17 07:46:10 2011
@@ -0,0 +1,76 @@
+package org.apache.stanbol.ontologymanager.web.resources;
+
+import static javax.ws.rs.core.MediaType.TEXT_HTML;
+import static org.apache.stanbol.commons.web.base.CorsHelper.addCORSOrigin;
+import static org.apache.stanbol.commons.web.base.CorsHelper.enableCORS;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.GET;
+import javax.ws.rs.OPTIONS;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+import org.apache.stanbol.commons.web.base.ContextHelper;
+import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
+import org.apache.stanbol.ontologymanager.registry.api.RegistryManager;
+import org.apache.stanbol.ontologymanager.registry.api.model.Library;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.sun.jersey.api.view.Viewable;
+
+@Path("/ontonet/registry")
+public class RegistryManagerResource extends BaseStanbolResource {
+
+ protected RegistryManager regMgr;
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ // bind the registry manager by looking it up from the servlet request context
+ public RegistryManagerResource(@Context ServletContext context, @Context UriInfo uriInfo) {
+ super();
+ regMgr = ContextHelper.getServiceFromContext(RegistryManager.class, context);
+ this.uriInfo = uriInfo;
+ }
+
+ public String getPath() {
+ return uriInfo.getPath().replaceAll("[\\/]*$", "");
+ }
+
+ @GET
+ @Produces(value = MediaType.TEXT_HTML)
+ public Response getHtmlInfo(@Context HttpHeaders headers) {
+ ResponseBuilder rb = Response.ok(new Viewable("index", this));
+ rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
+ addCORSOrigin(servletContext, rb, headers);
+ return rb.build();
+ }
+
+ @OPTIONS
+ public Response handleCorsPreflight(@Context HttpHeaders headers) {
+ ResponseBuilder rb = Response.ok();
+ enableCORS(servletContext, rb, headers);
+ return rb.build();
+ }
+
+ public List<Library> getLibraries() {
+ if (regMgr != null) {
+ log.debug("There are {} ontology libraries registered.", regMgr.getLibraries().size());
+ return new ArrayList<Library>(regMgr.getLibraries());
+ } else {
+ log.debug("There are no ontology libraries registered.");
+ return Collections.emptyList();
+ }
+ }
+
+}
Added: incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/RegistryManagerResource/index.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/RegistryManagerResource/index.ftl?rev=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/RegistryManagerResource/index.ftl (added)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/org/apache/stanbol/ontologymanager/web/resources/RegistryManagerResource/index.ftl Mon Oct 17 07:46:10 2011
@@ -0,0 +1,62 @@
+<#--
+ 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.
+-->
+<#import "/imports/common.ftl" as common>
+
+<#escape x as x?html>
+<@common.page title="Ontology Registry Manager" hasrestapi=false>
+
+ <div class="panel" id="webview">
+ <#if it.libraries?size == 0>
+ <p><em>There are no libraries registered. Administrators can populate libraries by adding ontology registries using the
+ <a href="/system/console/components" target="_blank">OSGi console</a>.</em></p>
+ <#else>
+ <!-- FIXME class names should be generic, and not bound to a specific functionality (here engines->reasoning services)-->
+ <div class="enginelisting">
+ <div class="collapsed">
+ <p class="collapseheader">There are currently
+ <strong>${it.libraries?size}</strong> ontology libraries.</p>
+ <div class="collapsable">
+
+ <ul>
+ <#list it.libraries as library>
+ <li>
+ <b><a href="${library.IRI}">${library.name}</a></b> : ${library.children?size} ontologies <i>(${library.loaded?string("cached", "not cached")})</i>
+ </li>
+ </#list>
+ </ul>
+
+ <p class="note">Administrators can enable, disable and deploy reasoning services using the <a href="/system/console/components" target="_blank">OSGi console</a>.</p>
+ </div>
+
+ </div>
+ </div>
+
+<script>
+$(".enginelisting p").click(function () {
+ $(this).parents("div").toggleClass("collapsed");
+});
+</script>
+ </#if>
+ </div>
+
+ <!-- We disable this at the moment -->
+ <!--div class="panel" id="restapi" style="display: none;">
+
+ </div -->
+
+</...@common.page>
+</#escape>
\ No newline at end of file
Added: incubator/stanbol/trunk/owl/src/test/java/org/apache/stanbol/owl/util/TestOWLUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/owl/src/test/java/org/apache/stanbol/owl/util/TestOWLUtils.java?rev=1185033&view=auto
==============================================================================
--- incubator/stanbol/trunk/owl/src/test/java/org/apache/stanbol/owl/util/TestOWLUtils.java (added)
+++ incubator/stanbol/trunk/owl/src/test/java/org/apache/stanbol/owl/util/TestOWLUtils.java Mon Oct 17 07:46:10 2011
@@ -0,0 +1,65 @@
+/*
+ * 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.owl.util;
+
+import static org.junit.Assert.*;
+
+import java.io.InputStream;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.clerezza.rdf.core.serializedform.ParsingProvider;
+import org.apache.clerezza.rdf.jena.parser.JenaParserProvider;
+import org.apache.clerezza.rdf.simple.storage.SimpleTcProvider;
+import org.junit.After;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestOWLUtils {
+
+ @BeforeClass
+ public static void setupTests() throws Exception {
+ TcManager.getInstance().addWeightedTcProvider(new SimpleTcProvider());
+ }
+
+ private ParsingProvider pp = new JenaParserProvider();
+
+ private UriRef uri = new UriRef("ontonet:http://stanbol.apache.org/prova");
+
+ @Test
+ public void namedUriRef() throws Exception {
+ InputStream inputStream = getClass().getResourceAsStream("/owl/maincharacters.owl");
+ MGraph mg = TcManager.getInstance().createMGraph(uri);
+ pp.parse(mg, inputStream, "application/rdf+xml", uri);
+ assertNotNull(OWLUtils.guessOntologyIdentifier(mg.getGraph()));
+ }
+
+ @Test
+ public void namelessUriRef() throws Exception {
+ InputStream inputStream = getClass().getResourceAsStream("/owl/nameless_ontology.owl");
+ MGraph mg = TcManager.getInstance().createMGraph(uri);
+ pp.parse(mg, inputStream, "application/rdf+xml", uri);
+ assertNull(OWLUtils.guessOntologyIdentifier(mg.getGraph()));
+ }
+
+ @After
+ public void reset() throws Exception {
+ TcManager.getInstance().deleteTripleCollection(uri);
+ }
+
+}