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/07/23 14:23:15 UTC

svn commit: r1150092 [3/5] - in /incubator/stanbol/trunk: ./ launchers/full/src/main/bundles/ launchers/kres/src/main/bundles/ ontologymanager/ ontologymanager/ontonet/ ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/ap...

Added: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/AbstractRegistryItem.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/AbstractRegistryItem.java?rev=1150092&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/AbstractRegistryItem.java (added)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/AbstractRegistryItem.java Sat Jul 23 12:22:56 2011
@@ -0,0 +1,202 @@
+/*
+ * 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.registry.impl.model;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.stanbol.ontologymanager.registry.api.IllegalRegistryCycleException;
+import org.apache.stanbol.ontologymanager.registry.api.RegistryContentException;
+import org.apache.stanbol.ontologymanager.registry.api.RegistryContentListener;
+import org.apache.stanbol.ontologymanager.registry.api.RegistryOperation;
+import org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem;
+import org.semanticweb.owlapi.model.IRI;
+
+public abstract class AbstractRegistryItem implements RegistryItem {
+
+    /* Two-way adjacency index TODO use maps instead? */
+    protected Map<IRI,RegistryItem> children = new HashMap<IRI,RegistryItem>(),
+            parents = new HashMap<IRI,RegistryItem>();
+
+    private IRI iri;
+
+    protected Set<RegistryContentListener> listeners = new HashSet<RegistryContentListener>();
+
+    private String name;
+
+    public AbstractRegistryItem(IRI iri) {
+        setIRI(iri);
+    }
+
+    public AbstractRegistryItem(IRI iri, String name) {
+        this(iri);
+        setName(name);
+    }
+
+    @Override
+    public void addChild(RegistryItem child) throws RegistryContentException {
+        if (this.equals(child) || parents.values().contains(child)) throw new IllegalRegistryCycleException(
+                this, child, RegistryOperation.ADD_CHILD);
+        if (!children.values().contains(child)) {
+            children.put(child.getIRI(), child);
+            try {
+                child.addParent(this);
+            } catch (RegistryContentException e) {
+                // Shouldn't happen. null is always legal.
+            }
+        }
+    }
+
+    @Override
+    public void addParent(RegistryItem parent) throws RegistryContentException {
+        if (this.equals(parent) || children.values().contains(parent)) throw new IllegalRegistryCycleException(
+                this, parent, RegistryOperation.ADD_PARENT);
+        if (!parents.values().contains(parent)) {
+            parents.put(parent.getIRI(), parent);
+            try {
+                parent.addChild(this);
+            } catch (RegistryContentException e) {
+                // Shouldn't happen. null is always legal.
+            }
+        }
+    }
+
+    @Override
+    public void addRegistryContentListener(RegistryContentListener listener) {
+        listeners.add(listener);
+    }
+
+    @Override
+    public void clearChildren() {
+        for (RegistryItem child : children.values())
+            removeChild(child);
+    }
+
+    @Override
+    public void clearParents() {
+        for (RegistryItem parent : parents.values())
+            removeParent(parent);
+    }
+
+    @Override
+    public void clearRegistryContentListeners() {
+        listeners.clear();
+    }
+
+    protected void fireContentRequested(RegistryItem item) {
+        for (RegistryContentListener listener : getRegistryContentListeners())
+            listener.registryContentRequested(item);
+    }
+
+    @Override
+    public RegistryItem getChild(IRI id) {
+        return children.get(id);
+    }
+
+    @Override
+    public RegistryItem[] getChildren() {
+        return children.values().toArray(new RegistryItem[children.size()]);
+    }
+
+    @Override
+    public IRI getIRI() {
+        return iri;
+    }
+
+    public String getName() {
+        return this.name;
+    }
+
+    @Override
+    public RegistryItem getParent(IRI id) {
+        return parents.get(id);
+    }
+
+    @Override
+    public RegistryItem[] getParents() {
+        return parents.values().toArray(new RegistryItem[parents.size()]);
+    }
+
+    @Override
+    public Set<RegistryContentListener> getRegistryContentListeners() {
+        return listeners;
+    }
+
+    @Override
+    public boolean hasChildren() {
+        return !children.isEmpty();
+    }
+
+    @Override
+    public boolean hasParents() {
+        return !parents.isEmpty();
+    }
+
+    @Override
+    public boolean isLibrary() {
+        return Type.LIBRARY.equals(getType());
+    }
+
+    @Override
+    public boolean isOntology() {
+        return Type.ONTOLOGY.equals(getType());
+    }
+
+    @Override
+    public void prune() {
+        clearChildren();
+        clearParents();
+    }
+
+    @Override
+    public void removeChild(RegistryItem child) {
+        if (children.values().contains(child)) {
+            children.remove(child.getIRI());
+            child.removeParent(this);
+        }
+    }
+
+    @Override
+    public void removeParent(RegistryItem parent) {
+        if (parents.values().contains(parent)) {
+            parents.remove(parent.getIRI());
+            parent.removeChild(this);
+        }
+    }
+
+    @Override
+    public void removeRegistryContentListener(RegistryContentListener listener) {
+        listeners.remove(listener);
+    }
+
+    @Override
+    public void setIRI(IRI iri) {
+        this.iri = iri;
+    }
+
+    @Override
+    public void setName(String string) {
+        this.name = string;
+    }
+
+    @Override
+    public String toString() {
+        return getName();
+    }
+}

Added: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/LibraryImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/LibraryImpl.java?rev=1150092&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/LibraryImpl.java (added)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/LibraryImpl.java Sat Jul 23 12:22:56 2011
@@ -0,0 +1,88 @@
+/*
+ * 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.registry.impl.model;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.stanbol.ontologymanager.registry.api.LibraryContentNotLoadedException;
+import org.apache.stanbol.ontologymanager.registry.api.RegistryContentException;
+import org.apache.stanbol.ontologymanager.registry.api.RegistryOntologyNotLoadedException;
+import org.apache.stanbol.ontologymanager.registry.api.model.Library;
+import org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem;
+import org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+
+
+/**
+ * Default implementation of the ontology library model.
+ */
+public class LibraryImpl extends AbstractRegistryItem implements Library {
+
+    private boolean loaded = false;
+
+    public LibraryImpl(IRI iri) {
+        super(iri);
+    }
+
+    public LibraryImpl(IRI iri, String name) {
+        super(iri, name);
+    }
+
+    @Override
+    public Set<OWLOntology> getOntologies() throws RegistryContentException {
+        /*
+         * Note that this implementation is not synchronized. Listeners may indefinitely be notified before or
+         * after the rest of this method is executed. If listeners call loadOntologies(), they could still get
+         * a RegistryContentException, which however they can catch by calling loadOntologies() and
+         * getOntologies() in sequence.
+         */
+        fireContentRequested(this);
+        if (!loaded) throw new LibraryContentNotLoadedException(this);
+        Set<OWLOntology> ontologies = new HashSet<OWLOntology>();
+        for (RegistryItem child : getChildren()) {
+            if (child instanceof RegistryOntology) {
+                OWLOntology o = ((RegistryOntology) child).asOWLOntology();
+                // Should never be null if the library was loaded correctly (an error should have already been
+                // thrown when loading it), but just in case.
+                if (o != null) ontologies.add(o);
+                else throw new RegistryOntologyNotLoadedException((RegistryOntology) child);
+            }
+        }
+        return ontologies;
+    }
+
+    @Override
+    public Type getType() {
+        return type;
+    }
+
+    @Override
+    public boolean isLoaded() {
+        return loaded;
+    }
+
+    @Override
+    public void loadOntologies(OWLOntologyManager mgr) {
+        if (mgr == null) throw new IllegalArgumentException("A null ontology manager is not allowed.");
+        // TODO Auto-generated method stub
+        loaded = true;
+    }
+
+}

Added: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryImpl.java?rev=1150092&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryImpl.java (added)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryImpl.java Sat Jul 23 12:22:56 2011
@@ -0,0 +1,87 @@
+/*
+ * 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.registry.impl.model;
+
+import org.apache.stanbol.ontologymanager.registry.api.model.Registry;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+
+public class RegistryImpl extends AbstractRegistryItem implements Registry {
+
+    private OWLOntologyManager cache;
+
+    private String message = "";
+
+    public RegistryImpl(IRI iri) {
+        this(iri, OWLManager.createOWLOntologyManager());
+    }
+
+    public RegistryImpl(IRI iri, OWLOntologyManager cache) {
+        super(iri);
+        setCache(cache);
+    }
+
+    public RegistryImpl(IRI iri, String name) {
+        this(iri, name, OWLManager.createOWLOntologyManager());
+    }
+
+    public RegistryImpl(IRI iri, String name, OWLOntologyManager cache) {
+        super(iri, name);
+        setCache(cache);
+    }
+
+    @Override
+    public OWLOntologyManager getCache() {
+        return cache;
+    }
+
+    public String getError() {
+        return this.message;
+    }
+
+    public String getName() {
+        return super.getName() + getError();
+    }
+
+    @Override
+    public Type getType() {
+        return type;
+    }
+
+    @Deprecated
+    public boolean isError() {
+        return !isOK();
+    }
+
+    @Deprecated
+    public boolean isOK() {
+        return this.getError().equals("");
+    }
+
+    @Override
+    public void setCache(OWLOntologyManager cache) {
+        // TODO use the ontology manager factory.
+        if (cache == null) cache = OWLManager.createOWLOntologyManager();
+        this.cache = cache;
+    }
+
+    @Deprecated
+    public void setError(String message) {
+        this.message = message;
+    }
+}

Added: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryOntologyImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryOntologyImpl.java?rev=1150092&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryOntologyImpl.java (added)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryOntologyImpl.java Sat Jul 23 12:22:56 2011
@@ -0,0 +1,52 @@
+/*
+ * 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.registry.impl.model;
+
+import org.apache.stanbol.ontologymanager.registry.api.RegistryOntologyNotLoadedException;
+import org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLOntology;
+
+public class RegistryOntologyImpl extends AbstractRegistryItem implements RegistryOntology {
+
+    private OWLOntology owl;
+
+    public RegistryOntologyImpl(IRI iri) {
+        super(iri);
+    }
+
+    public RegistryOntologyImpl(IRI iri, String name) {
+        super(iri, name);
+    }
+
+    @Override
+    public OWLOntology asOWLOntology() throws RegistryOntologyNotLoadedException {
+        fireContentRequested(this);
+        return owl;
+    }
+
+    @Override
+    public Type getType() {
+        return type;
+    }
+
+    @Override
+    public void setOWLOntology(OWLOntology owl) {
+        this.owl = owl;
+    }
+
+}

Added: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/util/RegistryUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/util/RegistryUtils.java?rev=1150092&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/util/RegistryUtils.java (added)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/util/RegistryUtils.java Sat Jul 23 12:22:56 2011
@@ -0,0 +1,154 @@
+/*
+ * 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.registry.impl.util;
+
+import java.util.Set;
+
+import org.apache.stanbol.ontologymanager.registry.api.model.Library;
+import org.apache.stanbol.ontologymanager.registry.api.model.Registry;
+import org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem;
+import org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem.Type;
+import org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology;
+import org.apache.stanbol.ontologymanager.registry.xd.vocabulary.CODOVocabulary;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLAxiom;
+import org.semanticweb.owlapi.model.OWLAxiomVisitor;
+import org.semanticweb.owlapi.model.OWLClass;
+import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
+import org.semanticweb.owlapi.model.OWLClassExpression;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.semanticweb.owlapi.model.OWLIndividual;
+import org.semanticweb.owlapi.model.OWLObjectProperty;
+import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
+import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.util.OWLAxiomVisitorAdapter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RegistryUtils {
+
+    private static final OWLClass cRegistryLibrary, cOntology;
+
+    private static final OWLObjectProperty hasPart, hasOntology, isPartOf, isOntologyOf;
+
+    @SuppressWarnings("unused")
+    private static Logger log = LoggerFactory.getLogger(RegistryUtils.class);
+
+    static {
+        OWLDataFactory factory = OWLManager.getOWLDataFactory();
+        cOntology = factory.getOWLClass(IRI.create(CODOVocabulary.CODK_Ontology));
+        cRegistryLibrary = factory.getOWLClass(IRI.create(CODOVocabulary.CODD_OntologyLibrary));
+        isPartOf = factory.getOWLObjectProperty(IRI.create(CODOVocabulary.PARTOF_IsPartOf));
+        isOntologyOf = factory.getOWLObjectProperty(IRI.create(CODOVocabulary.ODPM_IsOntologyOf));
+        hasPart = factory.getOWLObjectProperty(IRI.create(CODOVocabulary.PARTOF_HasPart));
+        hasOntology = factory.getOWLObjectProperty(IRI.create(CODOVocabulary.ODPM_HasOntology));
+    }
+
+    /**
+     * Utility method to recurse into registry items.
+     * 
+     * TODO: move this to main?
+     * 
+     * @param item
+     * @param ontologyId
+     * @return
+     */
+    public static boolean containsOntologyRecursive(RegistryItem item, IRI ontologyId) {
+
+        boolean result = false;
+        if (item instanceof RegistryOntology) {
+            // An Ontology MUST have a non-null URI.
+            try {
+                IRI iri = item.getIRI();
+                result |= iri.equals(ontologyId);
+            } catch (Exception e) {
+                return false;
+            }
+        } else if (item instanceof Library || item instanceof Registry)
+        // Inspect children
+        for (RegistryItem child : ((RegistryItem) item).getChildren()) {
+            result |= containsOntologyRecursive(child, ontologyId);
+            if (result) break;
+        }
+        return result;
+
+    }
+
+    @Deprecated
+    public static Type getType(final OWLIndividual ind, Set<OWLOntology> ontologies) {
+
+        // 0 is for library, 1 is for ontology (more in the future?)
+        final int[] pointsFor = new int[] {0, 0};
+        final int[] pointsAgainst = new int[] {0, 0};
+
+        OWLAxiomVisitor v = new OWLAxiomVisitorAdapter() {
+
+            @Override
+            public void visit(OWLClassAssertionAxiom axiom) {
+                if (ind.equals(axiom.getIndividual())) {
+                    OWLClassExpression type = axiom.getClassExpression();
+                    if (cRegistryLibrary.equals(type)) {
+                        pointsFor[0]++;
+                        pointsAgainst[1]++;
+                    } else if (cOntology.equals(type)) {
+                        pointsFor[1]++;
+                        pointsAgainst[0]++;
+                    }
+                }
+            }
+
+            @Override
+            public void visit(OWLObjectPropertyAssertionAxiom axiom) {
+                OWLObjectPropertyExpression prop = axiom.getProperty();
+                if (ind.equals(axiom.getSubject())) {
+
+                    if (hasOntology.equals(prop)) {
+                        pointsFor[0]++;
+                        pointsAgainst[1]++;
+                    } else if (isOntologyOf.equals(prop)) {
+                        pointsFor[1]++;
+                        pointsAgainst[0]++;
+                    }
+
+                } else if (ind.equals(axiom.getObject())) {
+                    if (isOntologyOf.equals(prop)) {
+                        pointsFor[0]++;
+                        pointsAgainst[1]++;
+                    } else if (hasOntology.equals(prop)) {
+                        pointsFor[1]++;
+                        pointsAgainst[0]++;
+                    }
+                }
+            }
+
+        };
+
+        // TODO use this strategy in the single pass algorithm for constructing the model.
+        for (OWLOntology o : ontologies)
+            for (OWLAxiom ax : o.getAxioms())
+                ax.accept(v);
+
+        if (pointsFor[0] > 0 && pointsAgainst[0] == 0) return Type.LIBRARY;
+        if (pointsFor[1] > 0 && pointsAgainst[1] == 0) return Type.ONTOLOGY;
+        // Cannot determine registries, since they have no associated individual.
+        return null;
+
+    }
+
+}

Added: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/LibrarySource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/LibrarySource.java?rev=1150092&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/LibrarySource.java (added)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/LibrarySource.java Sat Jul 23 12:22:56 2011
@@ -0,0 +1,251 @@
+/*
+ * 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.registry.io;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.stanbol.ontologymanager.ontonet.api.io.AbstractOntologyInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.impl.util.OntologyUtils;
+import org.apache.stanbol.ontologymanager.registry.api.RegistryLoader;
+import org.apache.stanbol.ontologymanager.registry.api.model.Registry;
+import org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem;
+import org.apache.stanbol.ontologymanager.registry.impl.model.LibraryImpl;
+import org.apache.stanbol.owl.util.URIUtils;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException;
+import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * An ontology input source that loads all the ontologies in a given library and attaches them to a parent
+ * ontology, either new or supplied by the developer. This input source can either accept an already built
+ * {@link LibraryImpl} object, or parse a library OWL file from its logical URI.
+ */
+public class LibrarySource extends AbstractOntologyInputSource {
+
+    private IRI libraryID;
+
+    private Logger log = LoggerFactory.getLogger(getClass());
+
+    /**
+     * Creates a new ontology source from a library. The physical registry location is assumed to be the
+     * parent URL of <code>libraryID</code>. <br/>
+     * <br/>
+     * Example : if <code>libraryID</code> is <tt>http://foo.bar.baz/registry#library</tt>, the registry
+     * location will be <tt>http://foo.bar.baz/registry</tt>. Same goes for slash-URIs.
+     * 
+     * @param libraryID
+     *            the identifier of the ontology library.
+     */
+    public LibrarySource(IRI libraryID) {
+        this(libraryID, URIUtils.upOne(libraryID));
+    }
+
+    /**
+     * Creates a new ontology source from a library.
+     * 
+     * @param libraryID
+     * @param registryLocation
+     */
+    public LibrarySource(IRI libraryID, IRI registryLocation) {
+        this(libraryID, registryLocation, null);
+    }
+
+    /**
+     * Creates a new ontology source from a library.
+     * 
+     * @param libraryID
+     *            the identifier of the ontology library.
+     * @param registryLocation
+     * @param ontologyManager
+     * @param loader
+     */
+    public LibrarySource(IRI libraryID,
+                         IRI registryLocation,
+                         OWLOntologyManager ontologyManager,
+                         RegistryLoader loader) {
+        this(libraryID, registryLocation, ontologyManager, loader, null);
+    }
+
+    /**
+     * Creates a new ontology source from a library.
+     * 
+     * @param libraryID
+     *            the identifier of the ontology library.
+     * @param registryLocation
+     * @param ontologyManager
+     * @param loader
+     * @param parentSrc
+     *            the source of the ontology that will import all the ontologies in the registry. If null, a
+     *            new blank ontology will be used.
+     */
+    public LibrarySource(IRI libraryID,
+                         IRI registryLocation,
+                         OWLOntologyManager ontologyManager,
+                         RegistryLoader loader,
+                         OntologyInputSource parentSrc) {
+        this.libraryID = libraryID;
+
+        // The ontology that imports the whole network is created in-memory, therefore it has no physical IRI.
+        bindPhysicalIri(null);
+
+        Set<OWLOntology> subtrees = new HashSet<OWLOntology>();
+        Registry reg = loader.loadLibrary(registryLocation, libraryID);
+        for (RegistryItem ri : reg.getChildren()) {
+            if (ri.isLibrary()) try {
+                Set<OWLOntology> adds = loader.gatherOntologies(ri, ontologyManager, true);
+                subtrees.addAll(adds);
+            } catch (OWLOntologyAlreadyExistsException e) {
+                // Chettefreca
+                continue;
+            } catch (OWLOntologyCreationException e) {
+                log.warn("Failed to load ontology library " + ri.getName() + ". Skipping.", e);
+                // If we can't load this library at all, scrap it.
+                // TODO : not entirely convinced of this step.
+                continue;
+            }
+        }
+
+        // We always construct a new root now, even if there's just one subtree.
+
+        // Set<OWLOntology> subtrees = mgr.getOntologies();
+        // if (subtrees.size() == 1)
+        // rootOntology = subtrees.iterator().next();
+        // else
+        try {
+            if (parentSrc != null) bindRootOntology(OntologyUtils.buildImportTree(parentSrc, subtrees,
+                ontologyManager));
+            else bindRootOntology(OntologyUtils.buildImportTree(subtrees, ontologyManager));
+        } catch (OWLOntologyCreationException e) {
+            log.error("Failed to build import tree for registry source " + registryLocation, e);
+        }
+    }
+
+    /**
+     * Creates a new ontology source from a library.
+     * 
+     * @param libraryID
+     *            the identifier of the ontology library.
+     * @param registryLocation
+     * @param loader
+     */
+    public LibrarySource(IRI libraryID, IRI registryLocation, RegistryLoader loader) {
+        this(libraryID, registryLocation, OWLManager.createOWLOntologyManager(), loader);
+    }
+
+    /**
+     * Creates a new ontology source from a library.
+     * 
+     * @param libraryID
+     *            the identifier of the ontology library.
+     * @param registryLocation
+     * @param loader
+     * @param parentSrc
+     *            the source of the ontology that will import all the ontologies in the registry. If null, a
+     *            new blank ontology will be used.
+     */
+    public LibrarySource(IRI libraryID,
+                         IRI registryLocation,
+                         RegistryLoader loader,
+                         OntologyInputSource parentSrc) {
+        this(libraryID, registryLocation, OWLManager.createOWLOntologyManager(), loader, parentSrc);
+    }
+
+    /**
+     * Creates a new ontology source from a library. The physical registry location is assumed to be the
+     * parent URL of <code>libraryID</code>. <br/>
+     * <br/>
+     * Example : if <code>libraryID</code> is <tt>http://foo.bar.baz/registry#library</tt>, the registry
+     * location will be <tt>http://foo.bar.baz/registry</tt>. Same goes for slash-URIs.
+     * 
+     * @param libraryID
+     *            the identifier of the ontology library.
+     * @param ontologyManager
+     * @param loader
+     */
+    public LibrarySource(IRI libraryID, OWLOntologyManager ontologyManager, RegistryLoader loader) {
+        this(libraryID, URIUtils.upOne(libraryID), ontologyManager, loader);
+    }
+
+    /**
+     * Creates a new ontology source from a library. The physical registry location is assumed to be the
+     * parent URL of <code>libraryID</code>. <br/>
+     * <br/>
+     * Example : if <code>libraryID</code> is <tt>http://foo.bar.baz/registry#library</tt>, the registry
+     * location will be <tt>http://foo.bar.baz/registry</tt>. Same goes for slash-URIs.
+     * 
+     * @param libraryID
+     *            the identifier of the ontology library.
+     * @param ontologyManager
+     * @param loader
+     * @param parentSrc
+     *            the source of the ontology that will import all the ontologies in the registry. If null, a
+     *            new blank ontology will be used.
+     */
+    public LibrarySource(IRI libraryID,
+                         OWLOntologyManager ontologyManager,
+                         RegistryLoader loader,
+                         OntologyInputSource parentSrc) {
+        this(libraryID, URIUtils.upOne(libraryID), ontologyManager, loader, parentSrc);
+    }
+
+    /**
+     * Creates a new ontology source from a library. The physical registry location is assumed to be the
+     * parent URL of <code>libraryID</code>. <br/>
+     * <br/>
+     * Example : if <code>libraryID</code> is <tt>http://foo.bar.baz/registry#library</tt>, the registry
+     * location will be <tt>http://foo.bar.baz/registry</tt>. Same goes for slash-URIs.
+     * 
+     * @param libraryID
+     *            the identifier of the ontology library.
+     * @param loader
+     */
+    public LibrarySource(IRI libraryID, RegistryLoader loader) {
+        this(libraryID, URIUtils.upOne(libraryID), loader);
+    }
+
+    /**
+     * Creates a new ontology source from a library. The physical registry location is assumed to be the
+     * parent URL of <code>libraryID</code>. <br/>
+     * <br/>
+     * Example : if <code>libraryID</code> is <tt>http://foo.bar.baz/registry#library</tt>, the registry
+     * location will be <tt>http://foo.bar.baz/registry</tt>. Same goes for slash-URIs.
+     * 
+     * @param libraryID
+     *            the identifier of the ontology library.
+     * @param loader
+     * @param parentSrc
+     *            the source of the ontology that will import all the ontologies in the registry. If null, a
+     *            new blank ontology will be used.
+     */
+    public LibrarySource(IRI libraryID, RegistryLoader loader, OntologyInputSource parentSrc) {
+        this(libraryID, URIUtils.upOne(libraryID), OWLManager.createOWLOntologyManager(), loader, parentSrc);
+    }
+
+    @Override
+    public String toString() {
+        return "LIBRARY<" + libraryID + ">";
+    }
+
+}

Added: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/RegistryIRISource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/RegistryIRISource.java?rev=1150092&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/RegistryIRISource.java (added)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/RegistryIRISource.java Sat Jul 23 12:22:56 2011
@@ -0,0 +1,124 @@
+/*
+ * 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.registry.io;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.stanbol.ontologymanager.ontonet.api.io.AbstractOntologyInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.impl.util.OntologyUtils;
+import org.apache.stanbol.ontologymanager.registry.api.RegistryLoader;
+import org.apache.stanbol.ontologymanager.registry.api.model.Registry;
+import org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException;
+import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * An input source that provides a single ontology that imports all the imported ontology libraries found in
+ * the ontology registry obtained by dereferencing a supplied IRI.
+ * 
+ */
+public class RegistryIRISource extends AbstractOntologyInputSource {
+
+    private Logger log = LoggerFactory.getLogger(getClass());
+
+    protected IRI registryIRI = null;
+
+    /**
+     * @param registryIRI
+     * @param ontologyManager
+     * @param loader
+     */
+    public RegistryIRISource(IRI registryIRI, OWLOntologyManager ontologyManager, RegistryLoader loader) {
+        this(registryIRI, ontologyManager, loader, null);
+    }
+
+    /**
+     * Creates a new ontology input source by providing a new root ontology that imports the entire network
+     * addressed by the ontology registry at the supplied IRI.
+     * 
+     * @param registryIRI
+     */
+    public RegistryIRISource(IRI registryIRI,
+                             OWLOntologyManager ontologyManager,
+                             RegistryLoader loader,
+                             OntologyInputSource parentSrc) {
+
+        this.registryIRI = registryIRI;
+
+        // The ontology that imports the whole network is created in-memory, therefore it has no physical IRI.
+        bindPhysicalIri(null);
+
+        Set<OWLOntology> subtrees = new HashSet<OWLOntology>();
+        Registry reg = loader.loadRegistry(registryIRI, ontologyManager);
+        // for (Registry reg : loader.loadRegistriesEager(registryIRI)) {
+        for (RegistryItem ri : reg.getChildren()) {
+            if (ri.isLibrary()) try {
+                Set<OWLOntology> adds = loader.gatherOntologies(ri, ontologyManager, true);
+                subtrees.addAll(adds);
+            } catch (OWLOntologyAlreadyExistsException e) {
+                // Chettefreca
+                continue;
+            } catch (OWLOntologyCreationException e) {
+                log.warn("Failed to load ontology library " + ri.getName() + ". Skipping.", e);
+                // If we can't load this library at all, scrap it.
+                // TODO : not entirely convinced of this step.
+                continue;
+            }
+        }
+        // }
+        // We always construct a new root now, even if there's just one subtree.
+
+        // Set<OWLOntology> subtrees = mgr.getOntologies();
+        // if (subtrees.size() == 1)
+        // rootOntology = subtrees.iterator().next();
+        // else
+        try {
+            if (parentSrc != null) bindRootOntology(OntologyUtils.buildImportTree(parentSrc, subtrees,
+                ontologyManager));
+            else bindRootOntology(OntologyUtils.buildImportTree(subtrees, ontologyManager));
+        } catch (OWLOntologyCreationException e) {
+            log.error("Failed to build import tree for registry source " + registryIRI, e);
+        }
+    }
+
+    public RegistryIRISource(IRI registryIRI, RegistryLoader loader) {
+        this(registryIRI, OWLManager.createOWLOntologyManager(), loader, null);
+    }
+
+    public RegistryIRISource(IRI registryIRI, RegistryLoader loader, OntologyInputSource parentSrc) {
+        this(registryIRI, OWLManager.createOWLOntologyManager(), loader, parentSrc);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.stanbol.ontologymanager.ontonet.api.io.AbstractOntologyInputSource#toString()
+     */
+    @Override
+    public String toString() {
+        return "REGISTRY_IRI<" + registryIRI + ">";
+    }
+
+}

Added: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/lang/Language.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/lang/Language.java?rev=1150092&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/lang/Language.java (added)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/lang/Language.java Sat Jul 23 12:22:56 2011
@@ -0,0 +1,66 @@
+/*
+* 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.registry.xd.lang;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Enrico Daga
+ * 
+ */
+public enum Language {
+    EN("en"), IT("it"), FR("fr"), DE("de"), ES("es");
+    private String value = "";
+
+    Language(String s) {
+	this.value = s;
+    }
+
+    public String getValue() {
+	return this.value;
+    }
+
+    @Override
+    public String toString() {
+	return this.value;
+    }
+
+    public String toValue() {
+	return this.value;
+    }
+
+    public static String[] allValues() {
+	List<String> str = new ArrayList<String>();
+	for (Language l : Language.values()) {
+	    str.add(l.getValue());
+	}
+	return str.toArray(new String[str.size()]);
+    }
+
+    public static Language getInstance(String xx) {
+	return Language.valueOf(xx.toUpperCase());
+    }
+
+    public static Language getDefault() {
+	return EN;
+    }
+    
+}

Added: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/util/RDFSLabelGetter.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/util/RDFSLabelGetter.java?rev=1150092&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/util/RDFSLabelGetter.java (added)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/util/RDFSLabelGetter.java Sat Jul 23 12:22:56 2011
@@ -0,0 +1,107 @@
+/*
+* 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.registry.xd.util;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.apache.stanbol.ontologymanager.registry.xd.lang.Language;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom;
+import org.semanticweb.owlapi.model.OWLAnnotationValue;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.semanticweb.owlapi.model.OWLLiteral;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;
+
+
+/**
+ * Extracts rdfs:label(s) for entity
+ * 
+ * @author Enrico Daga
+ * 
+ */
+public class RDFSLabelGetter {
+	private Map<String, String> allLabels;
+	private IRI subject;
+	private boolean strict;
+	private OWLDataFactory owlFactory = OWLManager.getOWLDataFactory();
+
+	public RDFSLabelGetter(OWLOntology ontology, IRI subject, boolean strict) {
+		this.subject = subject;
+		this.strict = strict;
+		Set<OWLAnnotationAssertionAxiom> individualAnnotations = ontology
+				.getAnnotationAssertionAxioms(subject);
+		allLabels = new HashMap<String, String>();
+		for (OWLAnnotationAssertionAxiom annotation : individualAnnotations) {
+			if (annotation.getProperty().equals(
+					owlFactory
+							.getOWLAnnotationProperty(
+									OWLRDFVocabulary.RDFS_LABEL.getIRI()))) {
+				OWLAnnotationValue value = annotation.getValue();
+				if (value instanceof IRI) {
+					IRI asIRI = (IRI) value;
+					allLabels.put(asIRI.toQuotedString(), null);
+				} else if (value instanceof OWLLiteral) {
+					OWLLiteral sLiteral = (OWLLiteral) value;
+					allLabels.put(sLiteral.getLiteral(), sLiteral.getLang());
+				}
+			}
+		}
+	}
+
+	public String getPreferred() {
+		String[] s = getForLang(Language.EN.getValue());
+		return (s.length == 0) ? "" : s[0];
+	}
+
+	public String[] getForLang(String lang) {
+		if (lang == null)
+			lang = "";
+		List<String> forLang = new ArrayList<String>();
+		for (Entry<String, String> entry : allLabels.entrySet()) {
+			if (lang.equals(entry.getValue())) {
+				forLang.add(entry.getKey());
+			}
+		}
+
+		if (forLang.isEmpty() && allLabels.isEmpty()) {
+			// This entity has no labels at all:(
+			// If we are not in strict mode, we must return something!
+			// If it has a fragment we assume it is human readable
+			if (!strict) {
+				if (subject.toURI().getFragment() != null
+						&& (!"".equals(subject.toURI().getFragment()))) {
+					forLang.add(subject.toURI().getFragment());
+				} else
+					forLang.add(subject.toQuotedString());
+			}
+		} else {
+			for (Entry<String, String> entry : allLabels.entrySet()) {
+				forLang.add(entry.getKey());
+				break;
+			}
+		}
+		return forLang.toArray(new String[forLang.size()]);
+
+	}
+}

Added: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/util/XDAction.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/util/XDAction.java?rev=1150092&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/util/XDAction.java (added)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/util/XDAction.java Sat Jul 23 12:22:56 2011
@@ -0,0 +1,21 @@
+/*
+* 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.registry.xd.util;
+
+public enum XDAction {
+	SPECIALIZATION, ANNOTATION, IMPORT, REFRESH_REPOSITORY, FIND_PATTERNS, STOP, CLEAR, QUICK_SEARCH, FILTER
+}

Added: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/vocabulary/CODOVocabulary.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/vocabulary/CODOVocabulary.java?rev=1150092&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/vocabulary/CODOVocabulary.java (added)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/vocabulary/CODOVocabulary.java Sat Jul 23 12:22:56 2011
@@ -0,0 +1,67 @@
+/*
+ * 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.registry.xd.vocabulary;
+
+/**
+ * @author Enrico Daga
+ * 
+ */
+public class CODOVocabulary {
+
+    public static final String CODD_hasLogicalLanguage = Vocabulary.CODD.uri + "#hasLogicalLanguage";
+    public static final String CODD_hasVersion = Vocabulary.CODD.uri + "#hasVersion";
+    public static final String CODD_imports = Vocabulary.CODD.uri + "#imports";
+    public static final String CODD_isImportedBy = Vocabulary.CODD.uri + "#isImportedBy";
+    public static final String CODD_isVersionOf = Vocabulary.CODD.uri + "#isVersionOf";
+    public static final String CODD_OntologyLibrary = Vocabulary.CODD.uri + "#OntologyLibrary";
+    public static final String CODD_relatedToOntology = Vocabulary.CODD.uri + "#relatedToOntology";
+    public static final String CODK_isReusedBy = Vocabulary.CODK.uri + "#isReusedBy";
+    public static final String CODK_Ontology = Vocabulary.CODK.uri + "#Ontology";
+    public static final String CODP_isIntendedOutputOf = Vocabulary.CODP.uri + "#isIntendedOutputOf";
+    public static final String CODT_isInputDataFor = Vocabulary.CODT.uri + "#isInputDataFor";
+    public static final String CODT_isOutputDataFor = Vocabulary.CODT.uri + "#isOutputDataFor";
+    public static final String CODW_isInvolvedInDesignOperationsBy = Vocabulary.CODW.uri
+                                                                     + "#isInvolvedInDesignOperationsBy";
+    public static final String DESCASIT_isDescribedBy = Vocabulary.DESCASIT.uri + "#isDescribedBy";
+    public static final String INTEXT_expresses = Vocabulary.INTEXT.uri + "#expresses";
+    public static final String INTEXT_isAbout = Vocabulary.INTEXT.uri + "#isAbout";
+    public static final String ODP_ONTOLOGY_LOCATION = Vocabulary.ODP.uri;
+    public static final String ODPM_HasOntology = Vocabulary.ODPM.uri + "#hasOntology";
+    public static final String ODPM_IsOntologyOf = Vocabulary.ODPM.uri + "#isOntologyOf";
+    public static final String ODPM_ODPRepository = Vocabulary.ODPM.uri + "#ODPRepository";
+    public static final String PARTOF_HasPart = Vocabulary.PARTOF.uri + "#hasPart";
+    public static final String PARTOF_IsPartOf = Vocabulary.PARTOF.uri + "#isPartOf";
+    public static final String REPOSITORY_MERGED_ONTOLOGY = "http://xd-repository/temporary/merged/ontology";
+    public static final String REPRESENTATION_hasRepresentationLanguage = Vocabulary.REPRESENTATION.uri
+                                                                          + "#hasRepresentationLanguage";
+    public static final String[] ONTOLOGY_ANNOTATION_PROPERTIES = {
+                                                                   CODOVocabulary.CODD_hasLogicalLanguage,
+                                                                   CODOVocabulary.CODD_hasVersion,
+                                                                   CODOVocabulary.CODD_imports,
+                                                                   CODOVocabulary.CODD_isImportedBy,
+                                                                   CODOVocabulary.CODD_isVersionOf,
+                                                                   CODOVocabulary.CODD_relatedToOntology,
+                                                                   CODOVocabulary.CODK_isReusedBy,
+                                                                   CODOVocabulary.CODP_isIntendedOutputOf,
+                                                                   CODOVocabulary.CODT_isInputDataFor,
+                                                                   CODOVocabulary.CODT_isOutputDataFor,
+                                                                   CODOVocabulary.CODW_isInvolvedInDesignOperationsBy,
+                                                                   CODOVocabulary.DESCASIT_isDescribedBy,
+                                                                   CODOVocabulary.INTEXT_expresses,
+                                                                   CODOVocabulary.INTEXT_isAbout,
+                                                                   CODOVocabulary.REPRESENTATION_hasRepresentationLanguage};
+}

Added: incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/vocabulary/Vocabulary.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/vocabulary/Vocabulary.java?rev=1150092&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/vocabulary/Vocabulary.java (added)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/xd/vocabulary/Vocabulary.java Sat Jul 23 12:22:56 2011
@@ -0,0 +1,239 @@
+/*
+* 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.registry.xd.vocabulary;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+
+import org.semanticweb.owlapi.model.IRI;
+
+/**
+ * Class Vocabulary
+ * 
+ * @author Enrico Daga
+ * 
+ */
+public enum Vocabulary {
+
+	ODP("odp", "http://www.ontologydesignpatterns.org/schemas/repository.owl",
+			""), XD_QUERY("xdq",
+			"http://www.ontologydesignpatterns.org/xd/selection/query.owl", ""),
+	/**
+	 * Ontology Design Patterns Metadata Vocabulary
+	 */
+	ODPM("odpm", "http://www.ontologydesignpatterns.org/schemas/meta.owl", ""),
+	/**
+	 * Ontology Metadata Vocabulary
+	 */
+	OMV("omv", "http://omv.ontoware.org/2005/05/ontology", ""),
+	/**
+	 * Friend-Of-A-Friend
+	 */
+	FOAF("foaf", "http://xmlns.com/foaf/0.1/", ""),
+	/**
+	 * The Web Ontology Language
+	 */
+	OWL("owl", "http://www.w3.org/2002/07/owl", ""),
+	/**
+	 * Simple Knowledge Organization System
+	 */
+	SKOS("skos", "http://www.w3.org/2008/05/skos", ""),
+	/**
+	 * eXtensible Markup Language
+	 */
+	XML("xml", "http://www.w3.org/XML/1998/namespace", ""),
+	/**
+	 * XML Schema Definition
+	 */
+	XSD("xsd", "http://www.w3.org/2001/XMLSchema", ""),
+	/**
+	 * Resource Description Framework
+	 */
+	RDF("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns", ""),
+	/**
+	 * RDF Schema
+	 */
+	RDFs("rdfs", "http://www.w3.org/2000/01/rdf-schema", ""),
+	/**
+	 * Dublin Core
+	 */
+	DC("dc", "http://purl.org/dc/elements/1.1/", ""),
+	/**
+	 * DC Terms
+	 */
+	DT("dterm", "http://purl.org/dc/terms/", ""),
+	/**
+	 * Content Pattern Annotation Schema
+	 */
+	CPA(
+			"cpa",
+			"http://www.ontologydesignpatterns.org/schemas/cpannotationschema.owl",
+			""),
+	/**
+	 * C-ODO core module
+	 */
+	CODK("codkernel",
+			"http://www.ontologydesignpatterns.org/cpont/codo/codkernel.owl",
+			""),
+	/**
+	 * C-ODO Data module
+	 */
+	CODD("coddata",
+			"http://www.ontologydesignpatterns.org/cpont/codo/coddata.owl", ""),
+	/**
+	 * C-ODO Solutions module
+	 */
+	CODS(
+			"cods",
+			"http://www.ontologydesignpatterns.org/cpont/codo/codsolutions.owl",
+			""),
+	/**
+	 * C-ODO Light root
+	 */
+	CODL("codlight",
+			"http://www.ontologydesignpatterns.org/cpont/codo/codolight.owl",
+			""),
+	/**
+	 * C-ODO Projects module
+	 */
+	CODP("codprojects",
+			"http://www.ontologydesignpatterns.org/cpont/codo/codprojects.owl",
+			""),
+	/**
+	 * C-ODO Tools module
+	 */
+	CODT("codtools",
+			"http://www.ontologydesignpatterns.org/cpont/codo/codtools.owl", ""),
+	/**
+	 * C-ODO Workflows module
+	 */
+	CODW(
+			"codworkflows",
+			"http://www.ontologydesignpatterns.org/cpont/codo/codworkflows.owl",
+			""),
+	/**
+	 * Part-Of content pattern
+	 */
+	PARTOF("partof", "http://www.ontologydesignpatterns.org/cp/owl/partof.owl",
+			""),
+	/**
+	 * Descriptions and Situations content pattern
+	 */
+	DESCASIT(
+			"descriptionandsituation",
+			"http://www.ontologydesignpatterns.org/cp/owl/descriptionandsituation.owl",
+			""),
+	/**
+	 * Intension/Extension content pattern
+	 */
+	INTEXT(
+			"intensionextension",
+			"http://www.ontologydesignpatterns.org/cp/owl/intensionextension.owl",
+			""),
+
+	/**
+	 * Information Objects and Representation Languages content pattern
+	 */
+	REPRESENTATION(
+			"representation",
+			"http://www.ontologydesignpatterns.org/cp/owl/informationobjectsandrepresentationlanguages.owl",
+			"");
+
+	// This is the preferred prefix
+	public final String prefix;
+	// This is the standard URI
+	public final String uri;
+	// This is the location
+	public final String url;
+
+	/**
+	 * 
+	 * @param prefix
+	 * @param sUri
+	 * @param sUrl
+	 */
+	Vocabulary(String prefix, String sUri, String sUrl) {
+		this.prefix = prefix;
+		this.uri = sUri;
+		this.url = sUrl.equals("") ? sUri : sUrl;
+	}
+
+	/**
+	 * 
+	 * @return URL
+	 */
+	public URL getURL() {
+		try {
+			if (this.url.equals(""))
+				return new URL(this.uri);
+			return new URL(this.url);
+		} catch (MalformedURLException e) {
+			// This cannot happen!
+			return null;
+		}
+	}
+
+	/**
+	 * 
+	 * @return URI
+	 */
+	public URI getURI() {
+		return URI.create(this.uri);
+	}
+
+	/**
+	 * Default separator is '#'
+	 * 
+	 * @return URI
+	 */
+	public URI getURIWithElement(String element) {
+		return URI.create(this.uri + "#" + element);
+	}
+
+	@Override
+	public String toString() {
+		return this.prefix;
+	}
+
+	/**
+	 * 
+	 * @param uri
+	 * @return String
+	 */
+	public static String getPrefix(URI uri) {
+		for (Vocabulary vocabulary : Vocabulary.values()) {
+			if (vocabulary.getURI().equals(uri))
+				return vocabulary.toString();
+		}
+		return "";
+	}
+
+	public IRI getIRI() {
+		return IRI.create(this.uri);
+	}
+
+	/**
+	 * @param string
+	 * @return
+	 */
+	public IRI getIRIWithElement(String element) {
+		// TODO Auto-generated method stub
+		return IRI.create(this.uri + "#" + element);
+	}
+
+}

Added: incubator/stanbol/trunk/ontologymanager/registry/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1150092&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/main/resources/OSGI-INF/metatype/metatype.properties (added)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/main/resources/OSGI-INF/metatype/metatype.properties Sat Jul 23 12:22:56 2011
@@ -0,0 +1,31 @@
+# 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.
+
+#===============================================================================
+#Properties defined by the Registry Manager
+#===============================================================================
+org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl.name = Apache Stanbol Ontology Registry Manager
+org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl.description = Manages the loading and indexing of ontology registries and libraries.
+
+org.apache.stanbol.ontologymanager.registry.cachingPolicy.name = Caching policy
+org.apache.stanbol.ontologymanager.registry.cachingPolicy.description = Specifies if ontology caching should spread across all registries or maintained separate for each registry.
+org.apache.stanbol.ontologymanager.registry.cachingPolicy.option.registry = Per Registry
+org.apache.stanbol.ontologymanager.registry.cachingPolicy.option.all = All Registries
+
+org.apache.stanbol.ontologymanager.registry.laziness.name = Lazy ontology loading
+org.apache.stanbol.ontologymanager.registry.laziness.description = If set, the ontologies referenced in a library will not be loaded until the library is requested.
+
+org.apache.stanbol.ontologymanager.registry.locations.name = Registry locations
+org.apache.stanbol.ontologymanager.registry.locations.description = The physical URLs of the ontology registry OWL files.
\ No newline at end of file

Added: incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/Locations.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/Locations.java?rev=1150092&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/Locations.java (added)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/Locations.java Sat Jul 23 12:22:56 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.registry;
+
+import org.semanticweb.owlapi.model.IRI;
+
+/**
+ * Physical and logical IRIs for unit tests.
+ */
+public class Locations {
+
+    /**
+     * Default namespace of Stanbol ontologies.
+     */
+    public static final IRI __STANBOL_ONT_NAMESPACE = IRI.create("http://stanbol.apache.org/ontologies/");
+
+    /**
+     * Default physical location of the ontology registry for testing.
+     */
+    public static final IRI _REGISTRY_TEST = IRI.create(__STANBOL_ONT_NAMESPACE + "registries/onmtest.owl");
+
+    /**
+     * Default physical location of the ontology registry for testing.
+     */
+    public static final IRI _REGISTRY_TEST_ADDITIONS = IRI.create(__STANBOL_ONT_NAMESPACE
+                                                                  + "registries/onmtest_additions.owl");
+
+    /**
+     * An ontology in test library 1 but not in test library 2.
+     */
+    public static final IRI CHAR_ACTIVE = IRI.create(__STANBOL_ONT_NAMESPACE + "pcomics/characters_all.owl");
+
+    /**
+     * An ontology in test library 2 but not in test library 1.
+     */
+    public static final IRI CHAR_DROPPED = IRI.create(__STANBOL_ONT_NAMESPACE
+                                                      + "pcomics/droppedcharacters.owl");
+
+    /**
+     * An ontology in test libraries 1 and 2.
+     */
+    public static final IRI CHAR_MAIN = IRI.create(__STANBOL_ONT_NAMESPACE + "pcomics/maincharacters.owl");
+
+    /**
+     * Identifier of test ontology library 1.
+     */
+    public static final IRI LIBRARY_TEST1 = IRI.create(_REGISTRY_TEST + "#Library1");
+
+    /**
+     * Identifier of test ontology library 2.
+     */
+    public static final IRI LIBRARY_TEST2 = IRI.create(_REGISTRY_TEST + "#Library2");
+
+    /**
+     * Identifier of test ontology library 1.
+     */
+    public static final IRI ONT_TEST1 = IRI.create(__STANBOL_ONT_NAMESPACE + "test1.owl");
+
+}

Added: incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyLibrary.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyLibrary.java?rev=1150092&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyLibrary.java (added)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyLibrary.java Sat Jul 23 12:22:56 2011
@@ -0,0 +1,151 @@
+/*
+ * 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.registry;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerConfigurationImpl;
+import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
+import org.apache.stanbol.ontologymanager.registry.api.RegistryLoader;
+import org.apache.stanbol.ontologymanager.registry.api.RegistryManager;
+import org.apache.stanbol.ontologymanager.registry.api.model.Library;
+import org.apache.stanbol.ontologymanager.registry.api.model.Registry;
+import org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem;
+import org.apache.stanbol.ontologymanager.registry.impl.RegistryLoaderImpl;
+import org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl;
+import org.apache.stanbol.ontologymanager.registry.impl.util.RegistryUtils;
+import org.apache.stanbol.ontologymanager.registry.io.LibrarySource;
+import org.junit.Before;
+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.OWLImportsDeclaration;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.semanticweb.owlapi.util.AutoIRIMapper;
+
+/**
+ * This class tests the correct loading of ontology libraries from an OWL repository. It also checks that
+ * ontologies referred to only by other libraries in the same repository are not loaded.
+ */
+public class TestOntologyLibrary {
+
+    private String registryResource = "/ontologies/registry/onmtest.owl";
+
+    private static ONManager onm;
+
+    private static RegistryLoader loader;
+
+    private OWLOntologyManager virginOntologyManager;
+
+    /**
+     * Sets the ontology network manager and registry loader before running the tests.
+     */
+    @BeforeClass
+    public static void setupTest() throws Exception {
+        final Dictionary<String,Object> emptyConfig = new Hashtable<String,Object>();
+        RegistryManager regman = new RegistryManagerImpl(emptyConfig);
+        // An ONManagerImpl with no store and default settings
+        onm = new ONManagerImpl(null, null, new ONManagerConfigurationImpl(emptyConfig), emptyConfig);
+        loader = new RegistryLoaderImpl(regman, onm);
+    }
+
+    /**
+     * Resets the {@link OWLOntologyManager} used for tests, since caching phenomena across tests could bias
+     * the results.
+     * 
+     * @throws Exception
+     *             if any error occurs;
+     */
+    @Before
+    public void resetOntologyManager() throws Exception {
+        virginOntologyManager = OWLManager.createOWLOntologyManager();
+        URL url = getClass().getResource("/ontologies");
+        virginOntologyManager.addIRIMapper(new AutoIRIMapper(new File(url.toURI()), true));
+        url = getClass().getResource("/ontologies/registry");
+        virginOntologyManager.addIRIMapper(new AutoIRIMapper(new File(url.toURI()), true));
+
+        // *Not* adding mappers to empty resource directories.
+        // It seems the Maven surefire plugin won't copy them.
+        // url = getClass().getResource("/ontologies/odp");
+        // virginOntologyManager.addIRIMapper(new AutoIRIMapper(new File(url.toURI()), true));
+    }
+
+    /**
+     * Uses a plain {@link RegistryLoader} to load a single ontology library and checks for its expected hits
+     * and misses.
+     * 
+     * @throws Exception
+     */
+    @Test
+    public void testLibraryLoad() throws Exception {
+        IRI localTestRegistry = IRI.create(getClass().getResource(registryResource));
+        Registry reg = loader.loadRegistry(localTestRegistry, virginOntologyManager);
+        assertTrue(reg.hasChildren());
+        Library lib = null;
+        // Look for test #Library2
+        for (RegistryItem item : reg.getChildren()) {
+            if (Locations.LIBRARY_TEST2.equals(item.getIRI())) {
+                lib = (Library) item;
+                break;
+            }
+        }
+        assertNotNull(lib);
+        // Should be in the library.
+        boolean hasShould = RegistryUtils.containsOntologyRecursive(lib, Locations.CHAR_DROPPED);
+        // Should NOT be in the library (belongs to another library in the same registry).
+        boolean hasShouldNot = RegistryUtils.containsOntologyRecursive(lib, Locations.CHAR_ACTIVE);
+        assertTrue(hasShould);
+        assertFalse(hasShouldNot);
+    }
+
+    /**
+     * Tests the creation of an ontology input source from a single library. Because the test is run offline,
+     * import statements might be file URIs, so tests should not fail on this.
+     * 
+     * @throws Exception
+     */
+    @Test
+    public void testLibrarySourceCreation() throws Exception {
+        IRI localTestRegistry = IRI.create(getClass().getResource(registryResource));
+        OntologyInputSource src = new LibrarySource(Locations.LIBRARY_TEST1, localTestRegistry,
+                virginOntologyManager, loader);
+        OWLOntology o = src.getRootOntology();
+        boolean hasImporting = false, hasImported = false;
+        for (OWLImportsDeclaration ax : o.getImportsDeclarations()) {
+            // Since we added a local IRI mapping, import statements might be using file: IRIs instead of
+            // HTTP, in which case IRI equality would fail. So it is enough here to just check the filename.
+            String tmpstr = ax.getIRI().toString();
+            if (!hasImporting && tmpstr.endsWith("characters_all.owl")) hasImporting = true;
+            else if (!hasImported && tmpstr.endsWith("maincharacters.owl")) hasImported = true;
+            if (hasImporting && hasImported) break;
+        }
+        assertTrue(hasImporting);
+        assertTrue(hasImported);
+    }
+
+}

Added: incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java?rev=1150092&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java (added)
+++ incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java Sat Jul 23 12:22:56 2011
@@ -0,0 +1,199 @@
+/*
+ * 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.registry;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Set;
+
+import org.apache.stanbol.ontologymanager.ontonet.api.DuplicateIDException;
+import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.ONManagerConfiguration;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.CoreOntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyScope;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.SessionOntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.UnmodifiableOntologySpaceException;
+import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerConfigurationImpl;
+import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
+import org.apache.stanbol.ontologymanager.registry.api.RegistryManager;
+import org.apache.stanbol.ontologymanager.registry.api.model.Registry;
+import org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem;
+import org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology;
+import org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl;
+import org.apache.stanbol.ontologymanager.registry.io.RegistryIRISource;
+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.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.semanticweb.owlapi.util.AutoIRIMapper;
+
+public class TestOntologyRegistry {
+
+    private static RegistryIRISource ontologySource;
+    private static ONManagerConfiguration configuration;
+    private static ONManager onm;
+    private static RegistryManager regman;
+
+    @BeforeClass
+    public static void setup() {
+        final Dictionary<String,Object> emptyConfig = new Hashtable<String,Object>();
+        configuration = new ONManagerConfigurationImpl(emptyConfig);
+        regman = new RegistryManagerImpl(emptyConfig);
+        // An ONManagerImpl with no store and default settings
+        onm = new ONManagerImpl(null, null, configuration, emptyConfig);
+    }
+
+    // private static boolean mapperIsSet = false;
+    //
+    // public void setupOfflineMapper() {
+    // if (mapperIsSet) {} else {
+    // ontologySource = new OntologyRegistryIRISource(testRegistryIri, ontologyManager, loader);
+    // mapperIsSet = true;
+    // }
+    // }
+
+    @Test
+    public void testPopulateRegistry() throws Exception {
+        OWLOntologyManager virginOntologyManager = OWLManager.createOWLOntologyManager();
+        URL url = getClass().getResource("/ontologies/registry");
+        assertNotNull(url);
+        virginOntologyManager.addIRIMapper(new AutoIRIMapper(new File(url.toURI()), true));
+        // Population is lazy; no need to add other mappers.
+
+        OWLOntology oReg = virginOntologyManager.loadOntology(Locations._REGISTRY_TEST);
+        Set<Registry> rs = regman.createModel(Collections.singleton(oReg));
+
+        assertEquals(1, rs.size());
+        Registry r = rs.iterator().next();
+        assertTrue(r.hasChildren());
+        // The nonexistent library should also be included, if using the more powerful algorithm.
+        int count = 3; // set to 2 if using the less powerful algorithm.
+        assertEquals(count, r.getChildren().length);
+
+        for (RegistryItem ri : r.getChildren())
+            assertTrue(ri.hasChildren());
+    }
+
+    /**
+     * Verify that, when loading multiple registries that add library information to each other, the overall
+     * model reflects the union of these registries.
+     * 
+     * @throws Exception
+     */
+    @Test
+    public void testRegistryUnion() throws Exception {
+        OWLOntologyManager virginOntologyManager = OWLManager.createOWLOntologyManager();
+        URL url = getClass().getResource("/ontologies/registry");
+        assertNotNull(url);
+        virginOntologyManager.addIRIMapper(new AutoIRIMapper(new File(url.toURI()), true));
+        // Population is lazy; no need to add other mappers.
+
+        // Create the model from two overlapping registries.
+        Set<OWLOntology> regs = new HashSet<OWLOntology>();
+        regs.add(virginOntologyManager.loadOntology(Locations._REGISTRY_TEST));
+        regs.add(virginOntologyManager.loadOntology(Locations._REGISTRY_TEST_ADDITIONS));
+        Set<Registry> rs = regman.createModel(regs);
+
+        for (Registry r : rs) {
+            // The nonexistent library should also be included, if using the more powerful algorithm.
+            if (Locations._REGISTRY_TEST.equals(r.getIRI())) assertEquals(3, r.getChildren().length); // set
+                                                                                                      // to 2
+                                                                                                      // if
+                                                                                                      // using
+                                                                                                      // the
+                                                                                                      // less
+                                                                                                      // powerful
+                                                                                                      // algorithm.
+            else if (Locations._REGISTRY_TEST_ADDITIONS.equals(r.getIRI())) assertEquals(1,
+                r.getChildren().length);
+            // check
+            for (RegistryItem lib : r.getChildren()) {
+                if (Locations.LIBRARY_TEST1.equals(lib.getIRI())) {
+                    boolean found = false;
+                    for (RegistryItem child : lib.getChildren()) {
+                        if (child instanceof RegistryOntology && Locations.ONT_TEST1.equals(child.getIRI())) {
+                            found = true;
+                            break;
+                        }
+                    }
+                    assertTrue(found);
+                    break;
+                }
+
+            }
+        }
+    }
+
+    @Test
+    public void testAddRegistryToSessionSpace() throws Exception {
+        // setupOfflineMapper();
+        IRI scopeIri = IRI.create("http://fise.iks-project.eu/scopone");
+        SessionOntologySpace space = null;
+        space = onm.getOntologySpaceFactory().createSessionOntologySpace(scopeIri);
+        space.setUp();
+        try {
+            // space.addOntology(new
+            // OntologyRegistryIRISource(testRegistryIri,onm.getOwlCacheManager(),onm.getRegistryLoader()));
+            space.addOntology(ontologySource);
+        } catch (UnmodifiableOntologySpaceException e) {
+            fail("Adding libraries to session space failed. "
+                 + "This should not happen for active session spaces.");
+        }
+
+        assertTrue(space.getTopOntology() != null);
+        assertTrue(space.getOntologies().contains(space.getTopOntology()));
+    }
+
+    @Test
+    public void testScopeCreationWithRegistry() {
+        // setupOfflineMapper();
+        IRI scopeIri = IRI.create("http://fise.iks-project.eu/scopone");
+        OntologyScope scope = null;
+        // The factory call also invokes loadRegistriesEager() and
+        // gatherOntologies() so no need to test them individually.
+        try {
+            scope = onm.getOntologyScopeFactory().createOntologyScope(scopeIri, ontologySource);
+        } catch (DuplicateIDException e) {
+            fail("DuplicateID exception caught when creating test scope.");
+        }
+
+        assertTrue(scope != null && scope.getCoreSpace().getTopOntology() != null);
+    }
+
+    @Test
+    public void testSpaceCreationWithRegistry() {
+        // setupOfflineMapper();
+        IRI scopeIri = IRI.create("http://fise.iks-project.eu/scopone");
+        CoreOntologySpace space = null;
+        // The factory call also invokes loadRegistriesEager() and
+        // gatherOntologies() so no need to test them individually.
+        space = onm.getOntologySpaceFactory().createCoreOntologySpace(scopeIri, ontologySource);
+        assertTrue(space != null && space.getTopOntology() != null);
+    }
+
+}