Package org.apache.stanbol.ontologymanager.ontonet.api.scope

Examples of org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologyScope


    @Override
    public void setScopeActive(String scopeID, boolean active) {
        if (!containsScope(scopeID)) throw new NoSuchScopeException(scopeID);
        // Prevent no-changes from firing events.
        boolean previousStatus = isScopeActive(scopeID);
        OntologyScope scope = getScope(scopeID);
        if (active == previousStatus) return;
        if (active) {
            scope.setUp();
            activeScopeIRIs.add(scopeID);
        } else {
            scope.tearDown();
            activeScopeIRIs.remove(scopeID);
        }
        fireScopeActivationChange(scopeID, active);
    }
View Full Code Here


        if (ontologyid != null && !ontologyid.equals("")) {
            // String scopeURI = uriInfo.getAbsolutePath().toString().replace(ontologyid, "");
            // IRI scopeIri = IRI.create(uriInfo.getBaseUri() + "ontology/" + scopeId);
            IRI ontIri = IRI.create(ontologyid);
            ScopeRegistry reg = onm.getScopeRegistry();
            OntologyScope scope = reg.getScope(scopeId);
            OntologySpace cs = scope.getCustomSpace();
            if (cs.hasOntology(ontIri)) {
                try {
                    reg.setScopeActive(scopeId, false);
                    cs.removeOntology(ontIri);
                    reg.setScopeActive(scopeId, true);
View Full Code Here

     * @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 {
View Full Code Here

                for (String s : customs) {
                    log.debug("\tCustom ontology " + s);
                }

                // Create the scope
                OntologyScope sc = null;
                sc = ontologyScopeFactory.createOntologyScope(scopeIRI, new BlankOntologySource());

                // Populate the core space
                if (cores.length > 0) {
                    OntologySpace corespc = sc.getCoreSpace();
                    corespc.tearDown();
                    for (int i = 0; i < cores.length; i++)
                        try {
                            corespc.addOntology(new RootOntologyIRISource(IRI.create(cores[i])));
                        } catch (Exception ex) {
                            log.warn("Failed to import ontology " + cores[i], ex);
                            continue;
                        }
                }

                sc.setUp();
                scopeRegistry.registerScope(sc);

                // getScopeHelper().createScope(scopeIRI);
                // getScopeHelper().addToCoreSpace(scopeIRI, cores);
                getScopeHelper().addToCustomSpace(scopeIRI, customs);
View Full Code Here

         *
         * @param scopeID
         * @param locationIri
         */
        public synchronized void addToCustomSpace(String scopeID, String[] locationIris) {
            OntologyScope scope = getScopeRegistry().getScope(scopeID);

            scope.getCustomSpace().tearDown();
            for (String locationIri : locationIris) {
                try {
                    scope.getCustomSpace().addOntology(createOntologyInputSource(locationIri));
                    log.debug("Added " + locationIri + " to scope " + scopeID + " in the custom space.", this);
                } catch (UnmodifiableOntologyCollectorException e) {
                    log.error("An error occurred while trying to add the ontology from location: "
                              + locationIri, e);
                }
            }
            scope.getCustomSpace().setUp();
        }
View Full Code Here

        ScopeRegistry reg = onm.getScopeRegistry();
        OntologyScopeFactory f = onm.getOntologyScopeFactory();

        log.debug("Request URI {}", uriInfo.getRequestUri());

        OntologyScope scope;
        OntologyInputSource<?,?> coreSrc = null, custSrc = null;

        // First thing, check the core source.
        if (coreRegistry != null && !coreRegistry.isEmpty()) try {
            coreSrc = new LibrarySource(IRI.create(coreRegistry.replace("%23", "#")), regMgr);
        } catch (Exception e1) {
            throw new WebApplicationException(e1, BAD_REQUEST);
            // Bad or not supplied core registry, try the ontology.
        }
        else if (coreOntology != null && !coreOntology.isEmpty()) try {
            coreSrc = new RootOntologyIRISource(IRI.create(coreOntology));
        } catch (Exception e2) {
            // If this fails too, throw a bad request.
            throw new WebApplicationException(e2, BAD_REQUEST);
        }

        // Don't bother if no custom was supplied at all...
        if (customRegistry != null && !customRegistry.isEmpty())
        // ...but if it was, be prepared to throw exceptions.
        try {
            coreSrc = new LibrarySource(IRI.create(customRegistry.replace("%23", "#")), regMgr);
        } catch (Exception e1) {
            throw new WebApplicationException(e1, BAD_REQUEST);
            // Bad or not supplied custom registry, try the ontology.
        }
        if (customOntology != null && !customOntology.isEmpty()) try {
            custSrc = new RootOntologyIRISource(IRI.create(customOntology));
        } catch (Exception e2) {
            // If this fails too, throw a bad request.
            throw new WebApplicationException(e2, BAD_REQUEST);
        }

        // Now the creation.
        try {
            // Expand core sources
            List<OntologyInputSource<?,?>> expanded = new ArrayList<OntologyInputSource<?,?>>();
            if (coreSrc != null) {
                if (coreSrc instanceof OntologySetInputSource) {
                    for (OWLOntology o : ((OntologySetInputSource) coreSrc).getOntologies()) {
                        expanded.add(new RootOntologySource(o));
                    }
                } else expanded.add(coreSrc);
            }
            if (custSrc != null) {
                if (custSrc instanceof OntologySetInputSource) for (OWLOntology o : ((OntologySetInputSource) custSrc)
                        .getOntologies())
                    expanded.add(new RootOntologySource(o));
                else expanded.add(custSrc);
            }
            // Invoke the appropriate factory method depending on the
            // availability of a custom source.
            // scope = (custSrc != null) ? f.createOntologyScope(scopeid, coreSrc, custSrc) : f
            // .createOntologyScope(scopeid, coreSrc);
            scope = f.createOntologyScope(scopeid, expanded.toArray(new OntologyInputSource[0]));
            // Setup and register the scope. If no custom space was set, it will
            // still be open for modification.
            scope.setUp();
            reg.registerScope(scope);
            reg.setScopeActive(scopeid, activate);
        } catch (DuplicateIDException e) {
            throw new WebApplicationException(e, CONFLICT);
        } catch (Exception ex) {
View Full Code Here

        return false;
    }

    private OWLOntology getFromOntonet() throws IOException {
        try {
            OntologyScope scope = null;
            synchronized (onManager) {
                scope = onManager.getScopeRegistry().getScope(this.scopeId);
            }
            if (scope == null) {
                log.error("Scope {} cannot be retrieved", this.scopeId);
                throw new IOException("Scope " + this.scopeId + " cannot be retrieved");
            }
            Session session = null;
            if (sessionManager != null) synchronized (sessionManager) {
                session = sessionManager.getSession(sessionId);
            }
            if (session == null) {
                log.warn("Session {} cannot be retrieved. Ignoring.", this.sessionId);
            }
            final Set<OWLOntology> set = new HashSet<OWLOntology>();
            set.add(scope.export(OWLOntology.class, true));
            if (session != null) {
                set.add(session.export(OWLOntology.class, true));
            }

            if (set.size() == 1) return set.iterator().next();
View Full Code Here

        }
    }

    @Test
    public void testCreateSessionSpaceManual() throws Exception {
        OntologyScope scope = null;
        try {
            // we don't register it
            scope = scopeFactory.createOntologyScope(scopeId1, src1, src2);
            scope.setUp();
        } catch (DuplicateIDException e) {
            fail("Unexpected DuplicateIDException was caught while testing scope " + e.getDuplicateID());
        }
        assertNotNull(scope);
        Session ses = sesmgr.createSession();
        assertTrue(scope.getSessionSpaces().isEmpty());
        // scope.addSessionSpace(spaceFactory.createSessionOntologySpace(scopeId1), ses.getID());
        // assertFalse(scope.getSessionSpaces().isEmpty());
    }
View Full Code Here

        // assertFalse(scope.getSessionSpaces().isEmpty());
    }

    @Test
    public void testCreateSessionSpaceAutomatic() throws Exception {
        OntologyScope scope1 = null, scope2 = null, scope3 = null;
        try {
            scope1 = scopeFactory.createOntologyScope(scopeId1, src1, src2);
            scopeRegistry.registerScope(scope1);
            scope2 = scopeFactory.createOntologyScope(scopeId2, src2, src1);
            scopeRegistry.registerScope(scope2);
View Full Code Here

TOP

Related Classes of org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologyScope

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.