You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by an...@apache.org on 2013/09/27 05:04:31 UTC

[2/4] git commit: MARMOTTA-325 : Make io service more flexible wrt dynamic services

MARMOTTA-325 : Make io service more flexible wrt dynamic services

If parsers were loaded into the registry after startup, the current code
would not recognise them. In order to make it possible to do this for
marmotta, the io service needs to call the authoritative service
registry when asked about questions.

In addition, the list of accept types could contain duplicates if more
than one parser supports a given format, so filtering through a set.

Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/57272d71
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/57272d71
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/57272d71

Branch: refs/heads/develop
Commit: 57272d7129f35e7bb144d89b01f9c9d31e3b8061
Parents: 9b9f685
Author: Peter Ansell <p_...@yahoo.com>
Authored: Fri Sep 27 12:40:51 2013 +1000
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Fri Sep 27 12:40:51 2013 +1000

----------------------------------------------------------------------
 .../core/services/io/MarmottaIOServiceImpl.java | 42 ++++++++------------
 1 file changed, 17 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/57272d71/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/io/MarmottaIOServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/io/MarmottaIOServiceImpl.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/io/MarmottaIOServiceImpl.java
index 3c8d9b6..683b07c 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/io/MarmottaIOServiceImpl.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/io/MarmottaIOServiceImpl.java
@@ -21,6 +21,7 @@ import org.apache.marmotta.platform.core.api.io.MarmottaIOService;
 import org.openrdf.rio.RDFFormat;
 import org.openrdf.rio.RDFParserRegistry;
 import org.openrdf.rio.RDFWriterRegistry;
+import org.openrdf.rio.Rio;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -28,7 +29,9 @@ import javax.annotation.PostConstruct;
 import javax.enterprise.context.ApplicationScoped;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Set;
 
 /**
  * User: Thomas Kurz
@@ -40,31 +43,12 @@ public class MarmottaIOServiceImpl implements MarmottaIOService {
 
     private Logger log = LoggerFactory.getLogger(this.getClass());
 
-    private RDFParserRegistry parserRegistry;
-    private RDFWriterRegistry writerRegistry;
-
-    private List<String> acceptTypes;
-    private List<String> producedTypes;
-
     @PostConstruct
     public void initialise() {
         log.info("initialising Apache Marmotta I/O service ...");
 
-        parserRegistry = RDFParserRegistry.getInstance();
-
-        acceptTypes = new ArrayList<String>();
-        for(RDFFormat format : parserRegistry.getKeys()) {
-            acceptTypes.addAll(format.getMIMETypes());
-        }
-        log.info(" - available parsers: {}", Arrays.toString(acceptTypes.toArray()));
-
-        writerRegistry = RDFWriterRegistry.getInstance();
-
-        producedTypes = new ArrayList<String>();
-        for(RDFFormat format : writerRegistry.getKeys()) {
-            producedTypes.addAll(format.getMIMETypes());
-        }
-        log.info(" - available writers: {}", Arrays.toString(producedTypes.toArray()));
+        log.info(" - available parsers: {}", Arrays.toString(getAcceptTypes().toArray()));
+        log.info(" - available writers: {}", Arrays.toString(getProducedTypes().toArray()));
     }
 
 	/**
@@ -73,7 +57,11 @@ public class MarmottaIOServiceImpl implements MarmottaIOService {
 	 */
 	@Override
 	public List<String> getAcceptTypes() {
-		return acceptTypes;
+        Set<String> acceptTypes = new LinkedHashSet<String>();
+        for(RDFFormat format : RDFParserRegistry.getInstance().getKeys()) {
+            acceptTypes.addAll(format.getMIMETypes());
+        }
+        return new ArrayList<String>(acceptTypes);
 	}
 
 	/**
@@ -82,7 +70,11 @@ public class MarmottaIOServiceImpl implements MarmottaIOService {
 	 */
 	@Override
 	public List<String> getProducedTypes() {
-		return producedTypes;
+	    Set<String> producedTypes = new LinkedHashSet<String>();
+        for(RDFFormat format : RDFWriterRegistry.getInstance().getKeys()) {
+            producedTypes.addAll(format.getMIMETypes());
+        }
+        return new ArrayList<String>(producedTypes);
 	}
 
 	/**
@@ -92,7 +84,7 @@ public class MarmottaIOServiceImpl implements MarmottaIOService {
 	 */
 	@Override
 	public RDFFormat getSerializer(String mimetype) {
-		return writerRegistry.getFileFormatForMIMEType(mimetype);
+		return Rio.getWriterFormatForMIMEType(mimetype);
 	}
 
 	/**
@@ -102,7 +94,7 @@ public class MarmottaIOServiceImpl implements MarmottaIOService {
 	 */
 	@Override
 	public RDFFormat getParser(String mimetype) {
-		return parserRegistry.getFileFormatForMIMEType(mimetype);
+		return Rio.getParserFormatForMIMEType(mimetype);
 	}
 	
 }