jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1451772 - in /jena/trunk/jena-arq: src-examples/arq/examples/riot/ExRIOT_5.java src/main/java/org/apache/jena/riot/IO_Jena.java src/main/java/org/apache/jena/riot/RDFParserRegistry.java
Date Fri, 01 Mar 2013 23:31:32 GMT
Author: andy
Date: Fri Mar  1 23:31:32 2013
New Revision: 1451772

URL: http://svn.apache.org/r1451772
Log:
Tidy up registration.
Add to example of wiring into Jena.

Modified:
    jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_5.java
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/IO_Jena.java
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/RDFParserRegistry.java

Modified: jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_5.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_5.java?rev=1451772&r1=1451771&r2=1451772&view=diff
==============================================================================
--- jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_5.java (original)
+++ jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_5.java Fri Mar  1 23:31:32 2013
@@ -23,11 +23,13 @@ import java.util.Iterator ;
 
 import org.apache.jena.atlas.web.ContentType ;
 import org.apache.jena.riot.* ;
+import org.apache.jena.riot.adapters.RDFReaderRIOT ;
 import org.apache.jena.riot.system.StreamRDF ;
 
 import com.hp.hpl.jena.graph.Graph ;
 import com.hp.hpl.jena.graph.Triple ;
 import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
 import com.hp.hpl.jena.sparql.sse.Item ;
 import com.hp.hpl.jena.sparql.sse.SSE ;
 import com.hp.hpl.jena.sparql.sse.builders.BuilderGraph ;
@@ -46,9 +48,21 @@ public class ExRIOT_5
         ReaderRIOTFactory factory = new SSEReaderFactory() ;
         RDFParserRegistry.registerLangTriples(lang, factory) ;
         
+        // use it ...
         String filename = "data.rsse" ;
+        // model.read(filename) 
         Model model = RDFDataMgr.loadModel(filename) ;
+        
+        // print results.
         model.write(System.out, "TTL") ;
+        
+        // Optional extra:
+        // If needed to set or override the syntax, register the name explicitly ...
+        System.out.println("## --") ;
+        IO_Jena.registerForModelRead("SSE", RDFReaderSSE.class) ;
+        // and use read( , "SSE")
+        Model model2 = ModelFactory.createDefaultModel().read(filename, "SSE") ;
+        model2.write(System.out, "TTL") ;
     }
     
     static class SSEReaderFactory implements ReaderRIOTFactory
@@ -74,6 +88,9 @@ public class ExRIOT_5
         }
     }
     
+    // Model.read adapter - must be public.
+    public static class RDFReaderSSE extends RDFReaderRIOT { public RDFReaderSSE() { super("SSE")
; } } 
+    
     /* data.rsse :
      * (graph
      *   (<s> <p1> 123)

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/IO_Jena.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/IO_Jena.java?rev=1451772&r1=1451771&r2=1451772&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/IO_Jena.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/IO_Jena.java Fri Mar  1 23:31:32
2013
@@ -38,32 +38,33 @@ public class IO_Jena
     public static void wireIntoJena()
     {
 //        // Wire in generic 
-//        String readerRDF = RDFReaderRIOT.class.getName() ;
-//        RDFReaderFImpl.setBaseReaderClassName("RDF/XML",    readerRDF) ;           // And
default
-//        RDFReaderFImpl.setBaseReaderClassName("RDF/XML-ABBREV", readerRDF) ;
+//        Class<?> readerRDF = RDFReaderRIOT.class ;
+//        registerForModelRead("RDF/XML",    readerRDF) ;
+//        registerForModelRead("RDF/XML-ABBREV", readerRDF) ;
 //
-//        RDFReaderFImpl.setBaseReaderClassName("N-TRIPLES",  readerRDF) ;
-//        RDFReaderFImpl.setBaseReaderClassName("N-Triples",  readerRDF) ;
-//        RDFReaderFImpl.setBaseReaderClassName("N-TRIPLE",   readerRDF) ;
-//        RDFReaderFImpl.setBaseReaderClassName("N3",         readerRDF) ;
-//        RDFReaderFImpl.setBaseReaderClassName("TURTLE",     readerRDF) ;
-//        RDFReaderFImpl.setBaseReaderClassName("Turtle",     readerRDF) ;
-//        RDFReaderFImpl.setBaseReaderClassName("TTL",        readerRDF) ;
-//        RDFReaderFImpl.setBaseReaderClassName("RDF/JSON",   readerRDF) ;
+//        registerForModelRead("N-TRIPLES",  readerRDF) ;
+//        registerForModelRead("N-Triples",  readerRDF) ;
+//        registerForModelRead("N-TRIPLE",   readerRDF) ;
+//        registerForModelRead("N3",         readerRDF) ;
+//        registerForModelRead("TURTLE",     readerRDF) ;
+//        registerForModelRead("Turtle",     readerRDF) ;
+//        registerForModelRead("TTL",        readerRDF) ;
+//        registerForModelRead("RDF/JSON",   readerRDF) ;
         
-      RDFReaderFImpl.setBaseReaderClassName("RDF/XML",    JenaReadersWriters.RDFReaderRIOT_RDFXML.class.getName())
;           // And default
-      RDFReaderFImpl.setBaseReaderClassName("RDF/XML-ABBREV", JenaReadersWriters.RDFReaderRIOT_RDFXML.class.getName())
;
+      registerForModelRead("RDF/XML",    JenaReadersWriters.RDFReaderRIOT_RDFXML.class) ;
          // And default
+      registerForModelRead("RDF/XML-ABBREV", JenaReadersWriters.RDFReaderRIOT_RDFXML.class)
;
 
-      RDFReaderFImpl.setBaseReaderClassName("N-TRIPLES",  JenaReadersWriters.RDFReaderRIOT_NT.class.getName())
;
-      RDFReaderFImpl.setBaseReaderClassName("N-Triples",  JenaReadersWriters.RDFReaderRIOT_NT.class.getName())
;
-      RDFReaderFImpl.setBaseReaderClassName("N-TRIPLE",   JenaReadersWriters.RDFReaderRIOT_NT.class.getName())
;
-      RDFReaderFImpl.setBaseReaderClassName("N3",         JenaReadersWriters.RDFReaderRIOT_TTL.class.getName())
;
-      RDFReaderFImpl.setBaseReaderClassName("TURTLE",     JenaReadersWriters.RDFReaderRIOT_TTL.class.getName())
;
-      RDFReaderFImpl.setBaseReaderClassName("Turtle",     JenaReadersWriters.RDFReaderRIOT_TTL.class.getName())
;
-      RDFReaderFImpl.setBaseReaderClassName("TTL",        JenaReadersWriters.RDFReaderRIOT_TTL.class.getName())
;
-      RDFReaderFImpl.setBaseReaderClassName("RDF/JSON",   JenaReadersWriters.RDFReaderRIOT_RDFJSON.class.getName())
;
+      registerForModelRead("N-TRIPLES",  JenaReadersWriters.RDFReaderRIOT_NT.class) ;
+      registerForModelRead("N-Triples",  JenaReadersWriters.RDFReaderRIOT_NT.class) ;
+      registerForModelRead("N-TRIPLE",   JenaReadersWriters.RDFReaderRIOT_NT.class) ;
+      registerForModelRead("N3",         JenaReadersWriters.RDFReaderRIOT_TTL.class) ;
+      registerForModelRead("TURTLE",     JenaReadersWriters.RDFReaderRIOT_TTL.class) ;
+      registerForModelRead("Turtle",     JenaReadersWriters.RDFReaderRIOT_TTL.class) ;
+      registerForModelRead("TTL",        JenaReadersWriters.RDFReaderRIOT_TTL.class) ;
+      registerForModelRead("RDF/JSON",   JenaReadersWriters.RDFReaderRIOT_RDFJSON.class)
;
       
       // Old style Jena writers.
+      // TODO Remove when riot-output arrives.
       String writerRdfJson = JenaWriterRdfJson.class.getName() ;
       RDFWriterFImpl.setBaseWriterClassName("RDF/JSON", writerRdfJson) ;
     }
@@ -85,7 +86,19 @@ public class IO_Jena
 
         RDFReaderFImpl.setBaseReaderClassName("RDF/JSON", "") ;
         RDFWriterFImpl.setBaseWriterClassName("RDF/JSON", "") ;
-
     }
+    
+    /** Register for use with Model.read **/ 
+    public static void registerForModelRead(String name, Class<?> cls)
+    {
+        RDFReaderFImpl.setBaseReaderClassName(name, cls.getName()) ;
+    }
+    
+    /** Register for use with Model.write **/ 
+    public static void registerForModelWrite(String name, Class<?> cls)
+    {
+        RDFWriterFImpl.setBaseWriterClassName(name, cls.getName()) ;
+    }
+
 }
 

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/RDFParserRegistry.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/RDFParserRegistry.java?rev=1451772&r1=1451771&r2=1451772&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/RDFParserRegistry.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/RDFParserRegistry.java Fri Mar
 1 23:31:32 2013
@@ -18,13 +18,7 @@
 
 package org.apache.jena.riot;
 
-import static org.apache.jena.riot.RDFLanguages.NQUADS ;
-import static org.apache.jena.riot.RDFLanguages.NTRIPLES ;
-import static org.apache.jena.riot.RDFLanguages.RDFJSON ;
-import static org.apache.jena.riot.RDFLanguages.RDFXML ;
-import static org.apache.jena.riot.RDFLanguages.TRIG ;
-import static org.apache.jena.riot.RDFLanguages.N3 ;
-import static org.apache.jena.riot.RDFLanguages.TURTLE ;
+import static org.apache.jena.riot.RDFLanguages.* ;
 
 import java.io.InputStream ;
 import java.util.Map ;



Mime
View raw message