Return-Path: X-Original-To: apmail-clerezza-commits-archive@www.apache.org Delivered-To: apmail-clerezza-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1CAAE10426 for ; Wed, 19 Feb 2014 17:17:15 +0000 (UTC) Received: (qmail 14106 invoked by uid 500); 19 Feb 2014 17:17:13 -0000 Delivered-To: apmail-clerezza-commits-archive@clerezza.apache.org Received: (qmail 14048 invoked by uid 500); 19 Feb 2014 17:17:13 -0000 Mailing-List: contact commits-help@clerezza.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@clerezza.apache.org Delivered-To: mailing list commits@clerezza.apache.org Received: (qmail 14033 invoked by uid 99); 19 Feb 2014 17:17:12 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Feb 2014 17:17:12 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 943098C3B47; Wed, 19 Feb 2014 17:17:12 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: reto@apache.org To: commits@clerezza.apache.org Date: Wed, 19 Feb 2014 17:17:13 -0000 Message-Id: <4f1262ac644c4b99b506b8a5e67711df@git.apache.org> In-Reply-To: <8d944bd99bfa446793472208c518a6b3@git.apache.org> References: <8d944bd99bfa446793472208c518a6b3@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] git commit: CLEREZZA-881:providing a TcProvider for the system garph to make sure it is only available when fully loaded CLEREZZA-881:providing a TcProvider for the system garph to make sure it is only available when fully loaded Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/13b6fe35 Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/13b6fe35 Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/13b6fe35 Branch: refs/heads/master Commit: 13b6fe35db41cfe5ee55af0644d9dc9585444515 Parents: bf9217a Author: retobg Authored: Wed Feb 19 18:16:50 2014 +0100 Committer: retobg Committed: Wed Feb 19 18:16:50 2014 +0100 ---------------------------------------------------------------------- .../clerezza/platform/config/SystemConfig.java | 129 ++++++++++++++----- 1 file changed, 98 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/clerezza/blob/13b6fe35/platform.config/src/main/java/org/apache/clerezza/platform/config/SystemConfig.java ---------------------------------------------------------------------- diff --git a/platform.config/src/main/java/org/apache/clerezza/platform/config/SystemConfig.java b/platform.config/src/main/java/org/apache/clerezza/platform/config/SystemConfig.java index a241976..ab103ac 100644 --- a/platform.config/src/main/java/org/apache/clerezza/platform/config/SystemConfig.java +++ b/platform.config/src/main/java/org/apache/clerezza/platform/config/SystemConfig.java @@ -18,70 +18,75 @@ */ package org.apache.clerezza.platform.config; - import java.io.IOException; import java.net.URL; +import java.util.Collections; +import java.util.Set; import org.apache.clerezza.platform.Constants; +import org.apache.clerezza.rdf.core.Graph; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Reference; import org.osgi.service.component.ComponentContext; import org.apache.clerezza.rdf.core.MGraph; +import org.apache.clerezza.rdf.core.TripleCollection; import org.apache.clerezza.rdf.core.UriRef; +import org.apache.clerezza.rdf.core.access.EntityAlreadyExistsException; +import org.apache.clerezza.rdf.core.access.EntityUndeletableException; import org.apache.clerezza.rdf.core.access.NoSuchEntityException; -import org.apache.clerezza.rdf.core.access.TcManager; +import org.apache.clerezza.rdf.core.access.WeightedTcProvider; import org.apache.clerezza.rdf.core.impl.SimpleMGraph; import org.apache.clerezza.rdf.core.serializedform.SupportedFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.clerezza.rdf.core.serializedform.ParsingProvider; - -/** - * When the SystemConfig component is activated it checks if the - * system graph exists, in case it does not exist then it creates the - * system graph and writes the default platform configuration into it. +import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Deactivate; +/** + * When the + * SystemConfig component is activated it checks if the system + * graph exists, in case it does not exist then it creates the system graph and + * writes the default platform configuration into it. + * * @author mir */ @Component -public class SystemConfig { +@Service(WeightedTcProvider.class) +public class SystemConfig implements WeightedTcProvider { + public static final String CONFIG_FILE = "default-system-graph.rdf"; - private final Logger logger = LoggerFactory.getLogger(getClass()); - /** * * @deprecated use org.apache.clerezza.platform.Contants instead */ @Deprecated public static final UriRef SYSTEM_GRAPH_URI = Constants.SYSTEM_GRAPH_URI; - /** - * A filter that can be used to get the system graph as OSGi service, - * that is provided by org.apache.clerezza.rdf.core.access.TcManager. + * A filter that can be used to get the system graph as OSGi service, that + * is provided by + * org.apache.clerezza.rdf.core.access.TcManager. */ public static final String SYSTEM_GRAPH_FILTER = - "(name="+ Constants.SYSTEM_GRAPH_URI_STRING +")"; + "(name=" + Constants.SYSTEM_GRAPH_URI_STRING + ")"; public static final String PARSER_FILTER = - "(supportedFormat=" + SupportedFormat.RDF_XML +")"; - - @Reference - private TcManager tcManager; - - @Reference(target=PARSER_FILTER) + "(supportedFormat=" + SupportedFormat.RDF_XML + ")"; + @Reference(target = PARSER_FILTER) private ParsingProvider parser; + private MGraph loadedFile; + @Activate protected void activate(ComponentContext componentContext) { - try { - tcManager.getMGraph(Constants.SYSTEM_GRAPH_URI); - } catch (NoSuchEntityException nsee) { - MGraph loadedFile = new SimpleMGraph(); - readConfigGraphFile(loadedFile); - MGraph systemGraph = tcManager.createMGraph(Constants.SYSTEM_GRAPH_URI); - systemGraph.addAll(loadedFile); - logger.info("Add initial configuration to system graph"); - - - } + //yould be good to use IndexedMGraph to be faster + loadedFile = new SimpleMGraph(); + readConfigGraphFile(loadedFile); + logger.info("Add initial configuration to system graph"); + } + + @Deactivate + protected void deactivate(ComponentContext componentContext) { + loadedFile = null; } private void readConfigGraphFile(MGraph mGraph) { @@ -98,4 +103,66 @@ public class SystemConfig { } } + /* + * Reason to be high: don't allow overwriting of system graph (by accident or as an attack) + * Reason to be low: avoid that TcManager always first tries to create TripleCollections using this provider + */ + @Override + public int getWeight() { + return Integer.MAX_VALUE; + } + + @Override + public Graph getGraph(UriRef name) throws NoSuchEntityException { + throw new NoSuchEntityException(name); + } + + @Override + public MGraph getMGraph(UriRef name) throws NoSuchEntityException { + if (name.equals(Constants.SYSTEM_GRAPH_URI)) { + return loadedFile; + } else { + throw new NoSuchEntityException(name); + } + } + + @Override + public TripleCollection getTriples(UriRef name) throws NoSuchEntityException { + return getMGraph(name); + } + + @Override + public Set listGraphs() { + return Collections.emptySet(); + } + + @Override + public Set listMGraphs() { + return Collections.singleton(Constants.SYSTEM_GRAPH_URI); + } + + @Override + public Set listTripleCollections() { + return listMGraphs(); + } + + @Override + public MGraph createMGraph(UriRef name) throws UnsupportedOperationException, EntityAlreadyExistsException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Graph createGraph(UriRef name, TripleCollection triples) throws UnsupportedOperationException, EntityAlreadyExistsException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void deleteTripleCollection(UriRef name) throws UnsupportedOperationException, NoSuchEntityException, EntityUndeletableException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Set getNames(Graph graph) { + return Collections.emptySet(); + } }