You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2014/03/02 18:39:53 UTC
git commit: CLEREZZA-881: system graph now backed by a file and thus
persistent
Repository: clerezza
Updated Branches:
refs/heads/master cf4ea9c4c -> a40724e70
CLEREZZA-881: system graph now backed by a file and thus persistent
Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/a40724e7
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/a40724e7
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/a40724e7
Branch: refs/heads/master
Commit: a40724e7018e30f2f99a4b240914f16ef5650298
Parents: cf4ea9c
Author: retobg <re...@apache.org>
Authored: Sun Mar 2 18:38:50 2014 +0100
Committer: retobg <re...@apache.org>
Committed: Sun Mar 2 18:38:50 2014 +0100
----------------------------------------------------------------------
platform.config/pom.xml | 5 +++
.../clerezza/platform/config/SystemConfig.java | 40 ++++++++++++++------
2 files changed, 34 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/clerezza/blob/a40724e7/platform.config/pom.xml
----------------------------------------------------------------------
diff --git a/platform.config/pom.xml b/platform.config/pom.xml
index 2975d32..3d5be3a 100644
--- a/platform.config/pom.xml
+++ b/platform.config/pom.xml
@@ -70,5 +70,10 @@
<artifactId>permissiondescriptions</artifactId>
<version>0.2-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.file.storage</artifactId>
+ <version>0.4-SNAPSHOT</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/clerezza/blob/a40724e7/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 ab103ac..285300d 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,6 +18,7 @@
*/
package org.apache.clerezza.platform.config;
+import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
@@ -35,11 +36,15 @@ import org.apache.clerezza.rdf.core.access.EntityUndeletableException;
import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.serializedform.Parser;
import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.clerezza.rdf.core.serializedform.ParsingProvider;
+import org.apache.clerezza.rdf.core.serializedform.Serializer;
+import org.apache.clerezza.rdf.file.storage.FileMGraph;
import org.apache.felix.scr.annotations.Service;
+import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Deactivate;
@@ -51,11 +56,12 @@ import org.osgi.service.component.annotations.Deactivate;
*
* @author mir
*/
-@Component
+@Component(immediate = true)
@Service(WeightedTcProvider.class)
public class SystemConfig implements WeightedTcProvider {
- public static final String CONFIG_FILE = "default-system-graph.rdf";
+ public static final String DEFAULT_SYSTEM_GRAPH = "default-system-graph.rdf";
+ private static final String DATA_FILE_SYSTEM_GRAPH = "system-graph.nt";
private final Logger logger = LoggerFactory.getLogger(getClass());
/**
*
@@ -70,27 +76,39 @@ public class SystemConfig implements WeightedTcProvider {
*/
public static final String SYSTEM_GRAPH_FILTER =
"(name=" + Constants.SYSTEM_GRAPH_URI_STRING + ")";
+
public static final String PARSER_FILTER =
- "(supportedFormat=" + SupportedFormat.RDF_XML + ")";
+ "(&("+SupportedFormat.supportedFormat+"=" + SupportedFormat.RDF_XML + ") "+
+ "("+SupportedFormat.supportedFormat+"=" + SupportedFormat.N_TRIPLE + "))";
@Reference(target = PARSER_FILTER)
- private ParsingProvider parser;
- private MGraph loadedFile;
+ private Parser parser;
+
+ public static final String SERIALIZER_FILTER =
+ "("+SupportedFormat.supportedFormat+"=" + SupportedFormat.N_TRIPLE + ")";
+ @Reference(target = SERIALIZER_FILTER)
+ private Serializer serializer;
+ private MGraph systemGraph;
@Activate
protected void activate(ComponentContext componentContext) {
+ final BundleContext bundleContext = componentContext.getBundleContext();
+ File systemGraphFile = bundleContext.getDataFile(DATA_FILE_SYSTEM_GRAPH);
+ boolean dataFileExisted = systemGraphFile.exists();
//yould be good to use IndexedMGraph to be faster
- loadedFile = new SimpleMGraph();
- readConfigGraphFile(loadedFile);
- logger.info("Add initial configuration to system graph");
+ systemGraph = new FileMGraph(systemGraphFile, parser, serializer);
+ if (!dataFileExisted) {
+ readConfigGraphFile(systemGraph);
+ logger.info("Add initial configuration to system graph");
+ }
}
@Deactivate
protected void deactivate(ComponentContext componentContext) {
- loadedFile = null;
+ systemGraph = null;
}
private void readConfigGraphFile(MGraph mGraph) {
- URL config = getClass().getResource(CONFIG_FILE);
+ URL config = getClass().getResource(DEFAULT_SYSTEM_GRAPH);
if (config == null) {
throw new RuntimeException("no config file found");
}
@@ -120,7 +138,7 @@ public class SystemConfig implements WeightedTcProvider {
@Override
public MGraph getMGraph(UriRef name) throws NoSuchEntityException {
if (name.equals(Constants.SYSTEM_GRAPH_URI)) {
- return loadedFile;
+ return systemGraph;
} else {
throw new NoSuchEntityException(name);
}