jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [6/8] jena git commit: JENA-1033 : Rework RDFReaderFImpl/RDFWriterFImpl and RIOT integration.
Date Mon, 21 Sep 2015 16:39:15 GMT
JENA-1033 : Rework RDFReaderFImpl/RDFWriterFImpl and RIOT integration.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/e214ba27
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/e214ba27
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/e214ba27

Branch: refs/heads/Jena-1029_subsystem
Commit: e214ba27f149ae49f0a0e767bda6be4945681a73
Parents: 852569a
Author: Andy Seaborne <andy@apache.org>
Authored: Mon Sep 21 17:12:40 2015 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Mon Sep 21 17:12:40 2015 +0100

----------------------------------------------------------------------
 .../arq/examples/riot/ExRIOT_5.java             |  22 +-
 .../arq/examples/riot/ExRIOT_out3.java          |  12 +-
 .../main/java/org/apache/jena/riot/IO_Jena.java |  31 +--
 .../org/apache/jena/riot/RDFWriterRegistry.java |  39 +++-
 .../jena/riot/adapters/JenaReadersWriters.java  |  50 -----
 .../riot/adapters/RDFReaderFactoryRIOT.java     |  53 ++---
 .../jena/riot/adapters/RDFReaderRIOT.java       |   2 +-
 .../jena/riot/adapters/RDFReaderRIOT_ARP.java   |  94 --------
 .../jena/riot/adapters/RDFReaderRIOT_CSV.java   |  62 ------
 .../jena/riot/adapters/RDFReaderRIOT_Web.java   |  99 ---------
 .../riot/adapters/RDFWriterFactoryRIOT.java     |  53 +++++
 .../jena/riot/adapters/RDFWriterRIOT.java       |  92 ++++----
 .../apache/jena/riot/system/IO_JenaReaders.java |  76 +++----
 .../apache/jena/riot/system/IO_JenaWriters.java | 122 ++--------
 .../jena/riot/system/TestIO_JenaReaders.java    |  97 ++++----
 .../jena/riot/system/TestIO_JenaWriters.java    | 111 ++++------
 .../jena/riot/writer/TestJenaWriters.java       |   6 +-
 .../apache/jena/rdf/model/impl/ModelCom.java    |   7 +-
 .../jena/rdf/model/impl/RDFReaderFImpl.java     | 218 +++++++++---------
 .../jena/rdf/model/impl/RDFWriterFImpl.java     | 222 ++++++++++---------
 20 files changed, 548 insertions(+), 920 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-arq/src-examples/arq/examples/riot/ExRIOT_5.java
----------------------------------------------------------------------
diff --git a/jena-arq/src-examples/arq/examples/riot/ExRIOT_5.java b/jena-arq/src-examples/arq/examples/riot/ExRIOT_5.java
index cdad38e..ed8095c 100644
--- a/jena-arq/src-examples/arq/examples/riot/ExRIOT_5.java
+++ b/jena-arq/src-examples/arq/examples/riot/ExRIOT_5.java
@@ -22,6 +22,7 @@ import java.io.InputStream ;
 import java.io.Reader ;
 import java.util.Iterator ;
 
+import org.apache.jena.atlas.logging.LogCtl ;
 import org.apache.jena.atlas.web.ContentType ;
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.graph.Triple ;
@@ -38,9 +39,11 @@ import org.apache.jena.sparql.sse.SSE ;
 import org.apache.jena.sparql.sse.builders.BuilderGraph ;
 import org.apache.jena.sparql.util.Context ;
 
-/** Example of using RIOT : register a new language */
+/** Example of using RIOT : register a new input language */
 public class ExRIOT_5
 {
+    static { LogCtl.setCmdLogging(); }
+    
     public static void main(String... argv) {
         Lang lang = LangBuilder.create("SSE", "text/x-sse").addFileExtensions("rsse").build() ;
         // This just registers the name, not the parser.
@@ -51,21 +54,18 @@ public class ExRIOT_5
         RDFParserRegistry.registerLangTriples(lang, factory) ;
 
         // use it ...
-        String filename = "data.rsse" ;
+        String filename = "/home/afs/tmp/data.rsse" ;
         // model.read(filename)
+        System.out.println("## -- RDFDataMgr.loadModel") ;
         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")
+        RDFDataMgr.write(System.out, model, Lang.TTL) ;
+
+        System.out.println("## -- Model.read") ;
+        // Model.read( , "SSE")
         Model model2 = ModelFactory.createDefaultModel().read(filename, "SSE") ;
-        model2.write(System.out, "TTL") ;
+        RDFDataMgr.write(System.out, model2, Lang.TTL) ;
     }
 
     static class SSEReaderFactory implements ReaderRIOTFactory

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-arq/src-examples/arq/examples/riot/ExRIOT_out3.java
----------------------------------------------------------------------
diff --git a/jena-arq/src-examples/arq/examples/riot/ExRIOT_out3.java b/jena-arq/src-examples/arq/examples/riot/ExRIOT_out3.java
index 7c74cb9..ac7c26e 100644
--- a/jena-arq/src-examples/arq/examples/riot/ExRIOT_out3.java
+++ b/jena-arq/src-examples/arq/examples/riot/ExRIOT_out3.java
@@ -22,6 +22,7 @@ import java.io.OutputStream ;
 import java.io.Writer ;
 
 import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.atlas.logging.LogCtl ;
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.rdf.model.Model ;
 import org.apache.jena.riot.* ;
@@ -35,6 +36,8 @@ import org.apache.jena.sparql.util.Context ;
 /** Example of registering a new writer with RIOT */
 public class ExRIOT_out3
 {
+    static { LogCtl.setCmdLogging(); }
+    
     // See also ExRIOT_5
     public static void main(String[] args)
     {
@@ -55,7 +58,7 @@ public class ExRIOT_out3
         RDFWriterRegistry.register(format, new SSEWriterFactory()) ;
 
         // ---- Use the register writer
-        Model model = RDFDataMgr.loadModel("D.ttl") ;
+        Model model = RDFDataMgr.loadModel("/home/afs/tmp/D.ttl") ;
         // Write
         System.out.println("## Write by format") ;
         RDFDataMgr.write(System.out, model, format) ;
@@ -63,11 +66,8 @@ public class ExRIOT_out3
         System.out.println("## Write by language") ;
         RDFDataMgr.write(System.out, model, lang) ;
         
-        // ---- Register for use with Model.read
-        // because naming is explicit, need to register an adapter.  
-        IO_Jena.registerForModelWrite("SSE", RDFWriterSSE.class) ;
-        
-        // and use it
+        // ---- Or use Model.write
+        System.out.println("## Write by Model.write") ;
         model.write(System.out, "SSE") ;
     }
     

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-arq/src/main/java/org/apache/jena/riot/IO_Jena.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/IO_Jena.java b/jena-arq/src/main/java/org/apache/jena/riot/IO_Jena.java
index 4709b0c..e04e7e8 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/IO_Jena.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/IO_Jena.java
@@ -18,40 +18,25 @@
 
 package org.apache.jena.riot ;
 
-import org.apache.jena.riot.adapters.AdapterFileManager ;
 import org.apache.jena.riot.system.IO_JenaReaders ;
 import org.apache.jena.riot.system.IO_JenaWriters ;
-import org.apache.jena.sparql.util.Symbol ;
-import org.apache.jena.util.FileManager ;
+import org.apache.jena.system.JenaSystem ;
 
 public class IO_Jena
 {
-    private static String      riotBase               = "http://jena.apache.org/riot/" ;
-    private static String      streamManagerSymbolStr = riotBase + "streammanager" ;
-    public static Symbol       streamManagerSymbol    = Symbol.create(streamManagerSymbolStr) ;
-    private static FileManager coreFileManager        = null ;
+    static { JenaSystem.init(); }
+    
+//    private static String      riotBase               = "http://jena.apache.org/riot/" ;
+//    private static String      streamManagerSymbolStr = riotBase + "streammanager" ;
+//    public static Symbol       streamManagerSymbol    = Symbol.create(streamManagerSymbolStr) ;
 
     public static void wireIntoJena() {
-        FileManager.setGlobalFileManager(AdapterFileManager.get()) ;
-        IO_JenaReaders.wireIntoJena() ;
-        IO_JenaWriters.wireIntoJena() ;
+       IO_JenaReaders.wireIntoJena() ;
+       IO_JenaWriters.wireIntoJena() ;
     }
 
     public static void resetJena() {
-        // This forces reinitialization if ever used.
-        FileManager.setGlobalFileManager(null) ;
         IO_JenaReaders.resetJena() ;
         IO_JenaWriters.resetJena() ;
     }
-
-    /** Register for use with Model.read (old style compatibility) */
-    public static void registerForModelRead(String name, Class<? > cls) {
-        IO_JenaReaders.registerForModelRead(name, cls) ;
-    }
-
-    /** Register for use with Model.write (old style compatibility) */
-    public static void registerForModelWrite(String name, Class<? > cls) {
-        IO_JenaWriters.registerForModelWrite(name, cls) ;
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-arq/src/main/java/org/apache/jena/riot/RDFWriterRegistry.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/RDFWriterRegistry.java b/jena-arq/src/main/java/org/apache/jena/riot/RDFWriterRegistry.java
index 139c3fe..101b459 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/RDFWriterRegistry.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/RDFWriterRegistry.java
@@ -20,6 +20,7 @@ package org.apache.jena.riot;
 
 import java.util.* ;
 
+import org.apache.jena.n3.N3JenaWriter ;
 import org.apache.jena.riot.out.CharSpace ;
 import org.apache.jena.riot.out.JsonLDWriter ;
 import org.apache.jena.riot.system.RiotLib ;
@@ -36,10 +37,11 @@ public class RDFWriterRegistry
     // UTF-8 is universal - but UTF-8 is not the default in Java ("platform encoding" is).
     
     static { JenaSystem.init() ; }
-
+    
     private static Map<RDFFormat, WriterGraphRIOTFactory> registryGraph     = new HashMap<>() ;
     private static Map<RDFFormat, WriterDatasetRIOTFactory> registryDataset = new HashMap<>() ;
     private static Map<Lang, RDFFormat> langToFormat                        = new HashMap<>() ;
+    private static Map<String, RDFFormat> mapJenaNameToFormat               = new HashMap<>() ;
     
     // Writing a graph
     static WriterGraphRIOTFactory wgfactory = new WriterGraphRIOTFactory() {
@@ -208,6 +210,41 @@ public class RDFWriterRegistry
          register(RDFFormat.TRIX, wdsTriXFactory) ;
      }
     
+     // ---- Compatibility
+     
+     /** return the RDFFormat for the existing Jena writer name, or null */
+     public static RDFFormat getFormatForJenaWriter(String jenaName) {
+         return mapJenaNameToFormat.get(jenaName);
+     }
+
+     /** Register an RDFFormat for a Jena writer name */
+     private /*public*/ static void setFormatForJenaWriter(String jenaName, RDFFormat format) {
+         mapJenaNameToFormat.put(jenaName, format);
+     }
+
+     /** Return a collection of Jena writer names */
+     public static Collection<String> getJenaWriterNames() {
+         return mapJenaNameToFormat.keySet();
+     }
+
+     private static void setup() {
+         setFormatForJenaWriter("RDF/XML",                           RDFFormat.RDFXML_PLAIN) ;
+         setFormatForJenaWriter("RDF/XML-ABBREV",                    RDFFormat.RDFXML_ABBREV) ;
+         setFormatForJenaWriter("N-TRIPLE",                          RDFFormat.NTRIPLES) ;
+         setFormatForJenaWriter("NT",                                RDFFormat.NTRIPLES) ;
+         setFormatForJenaWriter("N-TRIPLES",                         RDFFormat.NTRIPLES) ;
+         setFormatForJenaWriter("N-Triples",                         RDFFormat.NTRIPLES) ;
+         setFormatForJenaWriter("N3",                                RDFFormat.TURTLE) ;
+         setFormatForJenaWriter(N3JenaWriter.n3WriterPrettyPrinter,  RDFFormat.TURTLE_PRETTY) ;
+         setFormatForJenaWriter(N3JenaWriter.n3WriterPlain,          RDFFormat.TURTLE_BLOCKS) ;
+         setFormatForJenaWriter(N3JenaWriter.n3WriterTriples,        RDFFormat.TURTLE_FLAT) ;
+         setFormatForJenaWriter(N3JenaWriter.n3WriterTriplesAlt,     RDFFormat.TURTLE_FLAT) ;
+         setFormatForJenaWriter(N3JenaWriter.turtleWriter,           RDFFormat.TURTLE) ;
+         setFormatForJenaWriter(N3JenaWriter.turtleWriterAlt1,       RDFFormat.TURTLE) ;
+         setFormatForJenaWriter(N3JenaWriter.turtleWriterAlt2,       RDFFormat.TURTLE) ;
+     }
+
+     
     /** Register the serialization for graphs and it's associated factory
      * @param serialization         RDFFormat for the output format.
      * @param graphWriterFactory    Source of writer engines

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-arq/src/main/java/org/apache/jena/riot/adapters/JenaReadersWriters.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/adapters/JenaReadersWriters.java b/jena-arq/src/main/java/org/apache/jena/riot/adapters/JenaReadersWriters.java
deleted file mode 100644
index c92b05a..0000000
--- a/jena-arq/src/main/java/org/apache/jena/riot/adapters/JenaReadersWriters.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.riot.adapters;
-
-import static org.apache.jena.riot.RDFLanguages.JSONLD ;
-import org.apache.jena.n3.N3JenaWriter ;
-
-public class JenaReadersWriters
-{
-    public static class RDFReaderRIOT_RDFXML        extends RDFReaderRIOT   { public RDFReaderRIOT_RDFXML()     { super("RDF/XML") ; } }
-    public static class RDFReaderRIOT_TTL           extends RDFReaderRIOT   { public RDFReaderRIOT_TTL()        { super("TTL") ; } }
-    public static class RDFReaderRIOT_NT            extends RDFReaderRIOT   { public RDFReaderRIOT_NT()         { super("N-TRIPLE") ; } }
-    public static class RDFReaderRIOT_JSONLD        extends RDFReaderRIOT   { public RDFReaderRIOT_JSONLD()  { super(JSONLD.getName()) ; } }
-    public static class RDFReaderRIOT_RDFJSON       extends RDFReaderRIOT   { public RDFReaderRIOT_RDFJSON()    { super("RDF/JSON") ; } }
-    
-    // Unused - we use the original RDF/XML writers directly to preserve property setting.  
-//    public static class RDFWriterRIOT_RDFXML        extends RDFWriterRIOT   { public RDFWriterRIOT_RDFXML()         { super("RDF/XML") ; } }
-//    public static class RDFWriterRIOT_RDFXMLAbbrev  extends RDFWriterRIOT   { public RDFWriterRIOT_RDFXMLAbbrev()   { super("RDF/XML-ABBREV") ; } }
-    public static class RDFWriterRIOT_NTriples      extends RDFWriterRIOT   { public RDFWriterRIOT_NTriples()       { super("N-TRIPLES") ; } }
-    public static class RDFWriterRIOT_N3            extends RDFWriterRIOT   { public RDFWriterRIOT_N3()             { super("N3") ; } }
-    public static class RDFWriterRIOT_N3_PP         extends RDFWriterRIOT   { public RDFWriterRIOT_N3_PP()          { super(N3JenaWriter.n3WriterPrettyPrinter) ; } }
-    public static class RDFWriterRIOT_N3Plain       extends RDFWriterRIOT   { public RDFWriterRIOT_N3Plain()        { super(N3JenaWriter.n3WriterPlain) ; } }
-    public static class RDFWriterRIOT_N3Triples     extends RDFWriterRIOT   { public RDFWriterRIOT_N3Triples()      { super(N3JenaWriter.n3WriterTriples) ; } }
-    public static class RDFWriterRIOT_N3TriplesAlt  extends RDFWriterRIOT   { public RDFWriterRIOT_N3TriplesAlt()   { super(N3JenaWriter.n3WriterTriplesAlt) ; } }
-    public static class RDFWriterRIOT_Turtle        extends RDFWriterRIOT   { public RDFWriterRIOT_Turtle()         { super(N3JenaWriter.turtleWriter) ; } }
-    public static class RDFWriterRIOT_Turtle1       extends RDFWriterRIOT   { public RDFWriterRIOT_Turtle1()        { super(N3JenaWriter.turtleWriterAlt1) ; } }
-    public static class RDFWriterRIOT_Turtle2       extends RDFWriterRIOT   { public RDFWriterRIOT_Turtle2()        { super(N3JenaWriter.turtleWriterAlt2) ; } }
-
-    public static class RDFWriterRIOT_JSONLD        extends RDFWriterRIOT   { public RDFWriterRIOT_JSONLD()         { super("JSON-LD") ; } }
-    public static class RDFWriterRIOT_JSONLDAlt     extends RDFWriterRIOT   { public RDFWriterRIOT_JSONLDAlt()      { super("JSONLD") ; } }
-    
-    public static class RDFWriterRIOT_RDFJSON       extends RDFWriterRIOT   { public RDFWriterRIOT_RDFJSON()        { super("RDF/JSON") ; } }
-}
-

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderFactoryRIOT.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderFactoryRIOT.java b/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderFactoryRIOT.java
index da73306..b49ee9c 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderFactoryRIOT.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderFactoryRIOT.java
@@ -18,48 +18,37 @@
 
 package org.apache.jena.riot.adapters;
 
-import org.apache.jena.rdf.model.RDFReader ;
-import org.apache.jena.rdf.model.RDFReaderF ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFLanguages ;
+import org.apache.jena.rdf.model.RDFReader;
+import org.apache.jena.rdf.model.RDFReaderF;
+import org.apache.jena.rdf.model.impl.RDFReaderFImpl;
 
-/** Adapter to old style Jena reader factory */ 
-public class RDFReaderFactoryRIOT implements RDFReaderF
-{
+/** Adapter to old style Jena reader factory */
+public class RDFReaderFactoryRIOT implements RDFReaderF {
     public RDFReaderFactoryRIOT() {}
-    
+
     @Override
-    public RDFReader getReader()
-    {
-        return new RDFReaderRIOT() ;
+    public RDFReader getReader() {
+        return getReader(RDFReaderFImpl.DEFAULTLANG);
     }
 
     @Override
-    public RDFReader getReader(String langname)
-    {
-        // If RDF/XML, then return an ARP 
-        
-        Lang lang = RDFLanguages.nameToLang(langname) ;
-        if ( RDFLanguages.RDFXML.equals(lang) )
-            return new RDFReaderRIOT_ARP() ;
-        return new RDFReaderRIOT(langname) ; 
+    public RDFReader getReader(String langname) {
+        // For RIOT, the language name is a hint.
+        return new RDFReaderRIOT(langname);
     }
 
     @Override
-    public String setReaderClassName(String lang, String className)
-    {
-        return null ;
+    public String setReaderClassName(String lang, String className) {
+        return null;
     }
 
-	@Override
-	public void resetRDFReaderF() {
-		// does nothing as the reader can not be modified.
-		
-	}
+    @Override
+    public void resetRDFReaderF() {
+        // does nothing as the reader can not be modified.
+    }
 
-	@Override
-	public String removeReader(String lang) throws IllegalArgumentException {
-		return null;
-	}
+    @Override
+    public String removeReader(String lang) throws IllegalArgumentException {
+        return null;
+    }
 }
-

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderRIOT.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderRIOT.java b/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderRIOT.java
index 9d34f0c..bf576da 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderRIOT.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderRIOT.java
@@ -45,7 +45,7 @@ public class RDFReaderRIOT implements RDFReader {
     }
 
     public RDFReaderRIOT(String lang) {
-        this(RDFLanguages.nameToLang(lang)) ;
+        this(lang != null ? RDFLanguages.nameToLang(lang) : null) ;
     }
 
     public RDFReaderRIOT(Lang hintlang) {

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderRIOT_ARP.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderRIOT_ARP.java b/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderRIOT_ARP.java
deleted file mode 100644
index 4cc726f..0000000
--- a/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderRIOT_ARP.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.riot.adapters;
-
-import java.io.InputStream ;
-import java.io.Reader ;
-
-import org.apache.jena.atlas.lib.IRILib ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.rdf.model.RDFErrorHandler ;
-import org.apache.jena.rdf.model.RDFReader ;
-import org.apache.jena.rdfxml.xmlinput.JenaReader ;
-import org.apache.jena.riot.SysRIOT ;
-import org.apache.jena.util.FileManager ;
-import org.apache.jena.util.FileUtils ;
-
-/** Adapter from Jena2 original style adapter for ARP - adds the file: */
-
-public class RDFReaderRIOT_ARP implements RDFReader
-{
-    // A FileManager sort out baseURIs for files.
-    static FileManager fileMgr = new FileManager() ;
-    static {
-        fileMgr.addLocatorFile() ;
-        fileMgr.addLocatorURL() ;
-    }
-    
-    JenaReader reader = new JenaReader() ;
-    
-    public RDFReaderRIOT_ARP() {}
-
-    @Override
-    public void read(Model model, Reader r, String base)
-    { reader.read(model, r, base) ; }
-
-    @Override
-    public void read(Model model, InputStream r, String base)
-    { reader.read(model, r, base) ; }
-    
-    @Override
-    public void read(Model model, String url)
-    {
-        url = fixupURL(url) ;
-        reader.read(model, url) ;
-    }
-
-    /** Sort out filename-like URLs: file:, X: and plain filename */ 
-    private static String fixupURL(String url)
-    {
-        String scheme = FileUtils.getScheme(url) ;
-
-        if ( scheme != null )
-        {
-            // Skip any scheme that is not file: and not a windows drive letter.
-            if ( ! scheme.equals("file") && ! isWindowsDrive(scheme) )
-                return url ;
-        }
-        return IRILib.filenameToIRI(url) ;
-    }
-    
-    private static boolean isWindowsDrive(String scheme)
-    {
-        return  (SysRIOT.isWindows && scheme.length() == 1) ;
-    }
-
-    @Override
-    public Object setProperty(String propName, Object propValue)
-    {
-        return reader.setProperty(propName, propValue) ;
-    }
-    
-    @Override
-    public RDFErrorHandler setErrorHandler(RDFErrorHandler errHandler)
-    {
-        return reader.setErrorHandler(errHandler) ;
-    }
-}
-

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderRIOT_CSV.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderRIOT_CSV.java b/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderRIOT_CSV.java
deleted file mode 100644
index 07fffde..0000000
--- a/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderRIOT_CSV.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.riot.adapters;
-
-import java.io.InputStream;
-import java.io.Reader;
-
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.rdf.model.RDFErrorHandler ;
-import org.apache.jena.rdf.model.RDFReader ;
-
-public class RDFReaderRIOT_CSV implements RDFReader{
-
-	private RDFReader reader ;
-	public RDFReaderRIOT_CSV(){
-		reader = new RDFReaderRIOT("CSV");
-	}
-
-	@Override
-	public void read(Model model, Reader r, String base) {
-		reader.read(model, r, base);
-		
-	}
-
-	@Override
-	public void read(Model model, InputStream r, String base) {
-		reader.read(model, r, base);
-		
-	}
-
-	@Override
-	public void read(Model model, String url) {
-		reader.read(model, url);
-		
-	}
-
-	@Override
-	public Object setProperty(String propName, Object propValue) {
-		return reader.setProperty(propName, propValue);
-	}
-
-	@Override
-	public RDFErrorHandler setErrorHandler(RDFErrorHandler errHandler) {
-		return reader.setErrorHandler(errHandler);
-	}
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderRIOT_Web.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderRIOT_Web.java b/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderRIOT_Web.java
deleted file mode 100644
index 6d58bf7..0000000
--- a/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFReaderRIOT_Web.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.riot.adapters;
-
-import java.io.InputStream ;
-import java.io.Reader ;
-import java.util.Objects;
-
-import org.apache.jena.atlas.web.TypedInputStream ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFDataMgr ;
-import org.apache.jena.riot.RDFLanguages ;
-import org.apache.jena.riot.WebContent ;
-import org.apache.jena.riot.system.stream.StreamManager ;
-import org.apache.jena.shared.NotFoundException ;
-
-/** This is a reader primarily for model.read(url)
- */ 
-public class RDFReaderRIOT_Web extends RDFReaderRIOT
-{
-    private static final String defaultSyntax = "RDF/XML" ;
-    
-    public RDFReaderRIOT_Web()
-    {
-        super(defaultSyntax) ;
-    }
-    
-    @SuppressWarnings("deprecation")
-    @Override
-    public void read(Model model, Reader r, String base)
-    { 
-        // model.read(Reader, baseURI)
-        startRead(model) ; 
-        RDFDataMgr.read(model, r, base, hintlang) ;
-        finishRead(model) ;
-    }
-
-    
-    @Override
-    public void read(Model model, InputStream r, String base)
-    {
-        // model.read(InputStream, baseURI)
-        startRead(model) ; 
-        RDFDataMgr.read(model, r, base, hintlang) ;
-        finishRead(model) ;
-    }
-    
-    @Override
-    public void read(Model model, String url)
-    {
-        // model.read(url)
-        TypedInputStream in = StreamManager.get().open(url) ;
-        if ( in == null )
-            throw new NotFoundException(url) ;
-        String contentType = in.getContentType() ;
-        
-        // Reading a URL, no hint language provided.
-        // Use the URL structure as the hint.
-        Lang lang = null ;
-        if ( ! Objects.equals(contentType, WebContent.contentTypeTextPlain) )
-            lang = RDFLanguages.contentTypeToLang(contentType) ; 
-        
-        if ( lang == null )
-            lang = RDFLanguages.filenameToLang(url) ;
-        
-        if ( lang == null )
-            lang = super.hintlang ;
-        
-        // Here, we want syntax determination to be:
-        // ctLang > fileExtLang > RDF/XML
-        //
-        // whereas RDFDataMgr.read(.. , lang) ;
-        // treats lang to override.
-                        
-        // ** 
-        
-        startRead(model) ;
-        RDFDataMgr.read(model, in, url, lang) ;
-        finishRead(model) ;
-    }
-}
-

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFWriterFactoryRIOT.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFWriterFactoryRIOT.java b/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFWriterFactoryRIOT.java
new file mode 100644
index 0000000..7d6a730
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFWriterFactoryRIOT.java
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.riot.adapters;
+
+import org.apache.jena.rdf.model.RDFWriter;
+import org.apache.jena.rdf.model.RDFWriterF;
+
+/** Adapter to old style Jena writer factory */
+public class RDFWriterFactoryRIOT implements RDFWriterF {
+    public RDFWriterFactoryRIOT() {}
+
+    @Override
+    public RDFWriter getWriter() {
+        return getWriter(null);
+    }
+
+    @Override
+    public RDFWriter getWriter(String langname) {
+        return new RDFWriterRIOT(langname);
+    }
+
+    @Override
+    public String setWriterClassName(String lang, String className) {
+        return null;
+    }
+
+    @Override
+    public void resetRDFWriterF() {
+        // does nothing as the reader can not be modified.
+
+    }
+
+    @Override
+    public String removeWriter(String lang) {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFWriterRIOT.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFWriterRIOT.java b/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFWriterRIOT.java
index f2b2340..3c9d53d 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFWriterRIOT.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/adapters/RDFWriterRIOT.java
@@ -28,7 +28,6 @@ import org.apache.jena.rdf.model.RDFErrorHandler ;
 import org.apache.jena.rdf.model.RDFWriter ;
 import org.apache.jena.rdf.model.impl.RDFDefaultErrorHandler ;
 import org.apache.jena.riot.* ;
-import org.apache.jena.riot.system.IO_JenaWriters ;
 import org.apache.jena.riot.system.RiotLib ;
 import org.apache.jena.sparql.util.Context ;
 import org.apache.jena.sparql.util.Symbol ;
@@ -36,6 +35,7 @@ import org.apache.jena.sparql.util.Symbol ;
 /** Adapter from RIOT to old style Jena RDFWriter. */
 public class RDFWriterRIOT implements RDFWriter 
 {
+    // ---- Compatibility
     private final String basename ; 
     private final String jenaName ; 
     private Context context = new Context() ;
@@ -48,71 +48,63 @@ public class RDFWriterRIOT implements RDFWriter
 //        writer = writer() ;
 //    }
     
-    public RDFWriterRIOT(String jenaName)
-    { 
-        this.basename = "org.apache.jena.riot.writer."+jenaName.toLowerCase(Locale.ROOT) ;
-        this.jenaName = jenaName ;
+    public RDFWriterRIOT(String jenaName) {
+        this.basename = "org.apache.jena.riot.writer." + jenaName.toLowerCase(Locale.ROOT);
+        this.jenaName = jenaName;
     }
-    
-    //Initialize late to avoid confusing exceptions during newInstance. 
-    private WriterGraphRIOT writer()
-    {
-        if ( writer != null ) 
-            return writer ;
+
+    // Initialize late to avoid confusing exceptions during newInstance.
+    private WriterGraphRIOT writer() {
+        if ( writer != null )
+            return writer;
         if ( jenaName == null )
-            throw new IllegalArgumentException("Jena writer name is null") ;
-        writer = setWriter() ;
-        return writer ;
+            throw new IllegalArgumentException("Jena writer name is null");
+        writer = setWriter();
+        return writer;
     }
-    
-    // Delayed lookup (avoid problems in newInstance). 
-    private WriterGraphRIOT setWriter()
-    {
-        if ( writer != null ) 
-            return writer ;
+
+    private WriterGraphRIOT setWriter() {
+        if ( writer != null )
+            return writer;
         if ( jenaName == null )
-            throw new IllegalArgumentException("Jena writer name is null") ;
-        RDFFormat format = IO_JenaWriters.getFormatForJenaWriter(jenaName) ;
+            throw new IllegalArgumentException("Jena writer name is null");
+        // For writing via model.write(), use the old names for jena writers.
+        RDFFormat format = RDFWriterRegistry.getFormatForJenaWriter(jenaName) ;
         if ( format != null )
             return RDFDataMgr.createGraphWriter(format) ;
-        // Try lang instead.
-        Lang lang = RDFLanguages.nameToLang(jenaName) ;
+        Lang lang = RDFLanguages.nameToLang(jenaName);
         if ( lang != null )
-            return RDFDataMgr.createGraphWriter(lang) ;
-        throw new RiotException("No graph writer for '"+jenaName+"'") ;
+            return RDFDataMgr.createGraphWriter(lang);
+        throw new RiotException("No graph writer for '" + jenaName + "'");
     }
-    
+
     @Override
-    public void write(Model model, Writer out, String base)
-    {
-        if (  base != null && base.equals("") )
-            base = null ;
-        Graph graph = model.getGraph() ;
-        writer().write(out, graph, RiotLib.prefixMap(graph), base, context) ;
+    public void write(Model model, Writer out, String base) {
+        if ( base != null && base.equals("") )
+            base = null;
+        Graph graph = model.getGraph();
+        writer().write(out, graph, RiotLib.prefixMap(graph), base, context);
     }
-
+    
     @Override
-    public void write(Model model, OutputStream out, String base)
-    {
+    public void write(Model model, OutputStream out, String base) {
         if ( base != null && base.equals("") )
-            base = null ;
-        Graph graph = model.getGraph() ;
-        writer().write(out, graph, RiotLib.prefixMap(graph), base, context) ;
+            base = null;
+        Graph graph = model.getGraph();
+        writer().write(out, graph, RiotLib.prefixMap(graph), base, context);
     }
 
     @Override
-    public Object setProperty(String propName, Object propValue)
-    {
-        Symbol sym = Symbol.create(basename+propName) ;
-        Object oldObj = context.get(sym) ;
-        return oldObj ;
+    public Object setProperty(String propName, Object propValue) {
+        Symbol sym = Symbol.create(basename + propName);
+        Object oldObj = context.get(sym);
+        return oldObj;
     }
-    
+
     @Override
-    public RDFErrorHandler setErrorHandler(RDFErrorHandler errHandler)
-    {
-        RDFErrorHandler old = errorHandler ;
-        errorHandler = errHandler ;
-        return old ;
+    public RDFErrorHandler setErrorHandler(RDFErrorHandler errHandler) {
+        RDFErrorHandler old = errorHandler;
+        errorHandler = errHandler;
+        return old;
     }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-arq/src/main/java/org/apache/jena/riot/system/IO_JenaReaders.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/system/IO_JenaReaders.java b/jena-arq/src/main/java/org/apache/jena/riot/system/IO_JenaReaders.java
index 0b5c3a0..5372539 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/system/IO_JenaReaders.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/system/IO_JenaReaders.java
@@ -19,63 +19,41 @@
 package org.apache.jena.riot.system;
 
 import org.apache.jena.rdf.model.impl.RDFReaderFImpl ;
-import org.apache.jena.riot.adapters.JenaReadersWriters ;
-import org.apache.jena.riot.adapters.RDFReaderRIOT_Web ;
-import org.apache.jena.sparql.util.Symbol ;
+import org.apache.jena.riot.adapters.AdapterFileManager ;
+import org.apache.jena.riot.adapters.RDFReaderFactoryRIOT ;
+import org.apache.jena.util.FileManager ;
 
 public class IO_JenaReaders
 {
-    private static String riotBase = "http://jena.apache.org/riot/" ; 
-    private static String streamManagerSymbolStr = riotBase+"streammanager" ; 
-    public static Symbol streamManagerSymbol = Symbol.create(streamManagerSymbolStr) ; 
+//    private static String riotBase = "http://jena.apache.org/riot/" ; 
+//    private static String streamManagerSymbolStr = riotBase+"streammanager" ; 
+//    public static Symbol streamManagerSymbol = Symbol.create(streamManagerSymbolStr) ; 
 
+    private static FileManager coreFileManager = null;
+    private static boolean     isWiredIn       = false;
+    
     public static void wireIntoJena() {
-        registerForModelRead("RDF",             RDFReaderRIOT_Web.class) ; // Default
-        registerForModelRead("RDF/XML",         JenaReadersWriters.RDFReaderRIOT_RDFXML.class) ;
-        registerForModelRead("RDF/XML-ABBREV",  JenaReadersWriters.RDFReaderRIOT_RDFXML.class) ;
-
-        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("JSON-LD",         JenaReadersWriters.RDFReaderRIOT_JSONLD.class) ;
-        registerForModelRead("JSONLD",          JenaReadersWriters.RDFReaderRIOT_JSONLD.class) ;
-        registerForModelRead("RDF/JSON",        JenaReadersWriters.RDFReaderRIOT_RDFJSON.class) ;
+        if ( isWiredIn )
+            return ;
+        isWiredIn = true ;
+        if ( coreFileManager == null )
+            coreFileManager = FileManager.get();
+        FileManager.setGlobalFileManager(AdapterFileManager.get());
+        RDFReaderFImpl.alternative(new RDFReaderFactoryRIOT());
     }
-    
-    static String jenaNTriplesReader = org.apache.jena.rdf.model.impl.NTripleReader.class.getName(); 
-    static String jenaTurtleReader = org.apache.jena.n3.turtle.TurtleReader.class.getName();
-    static String jenaN3Reader = jenaTurtleReader ;
-    static String jenaRDFReader = org.apache.jena.rdfxml.xmlinput.JenaReader.class.getName(); 
-    
-    public static void resetJena() {
-        RDFReaderFImpl.setBaseReaderClassName("RDF", jenaRDFReader) ;
-        RDFReaderFImpl.setBaseReaderClassName("RDF/XML", jenaRDFReader) ;
-        RDFReaderFImpl.setBaseReaderClassName("RDF/XML-ABBREV", jenaRDFReader) ;
-
-        RDFReaderFImpl.setBaseReaderClassName("N-TRIPLES", jenaNTriplesReader) ;
-        RDFReaderFImpl.setBaseReaderClassName("N-Triples", jenaNTriplesReader) ;
-        RDFReaderFImpl.setBaseReaderClassName("N-TRIPLE", jenaNTriplesReader) ;
 
-        RDFReaderFImpl.setBaseReaderClassName("N3", jenaTurtleReader) ;
-        RDFReaderFImpl.setBaseReaderClassName("TURTLE", jenaTurtleReader) ;
-        RDFReaderFImpl.setBaseReaderClassName("Turtle", jenaTurtleReader) ;
-        RDFReaderFImpl.setBaseReaderClassName("TTL", jenaTurtleReader) ;
-
-        RDFReaderFImpl.setBaseReaderClassName("JSON-LD", "") ;
-        RDFReaderFImpl.setBaseReaderClassName("JSONLD", "") ;
-
-        RDFReaderFImpl.setBaseReaderClassName("RDF/JSON", "") ;
-        RDFReaderFImpl.setBaseReaderClassName("RDFJSON", "") ;
+    public static void resetJena() {
+        if ( ! isWiredIn )
+            return ;
+        isWiredIn = false ;
+        RDFReaderFImpl.alternative(null);
+        // Or set to null - this forces reinitialization if ever used.
+        FileManager.setGlobalFileManager(coreFileManager) ;
     }
-    
+
     /** Register for use with Model.read (old style compatibility) */ 
-    public static void registerForModelRead(String name, Class<?> cls)
-    {
-        RDFReaderFImpl.setBaseReaderClassName(name, cls.getName()) ;
+    @Deprecated
+    public static void registerForModelRead(String name, Class<? > cls) {
+        RDFReaderFImpl.setBaseReaderClassName(name, cls.getName());
     }
 }
-

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-arq/src/main/java/org/apache/jena/riot/system/IO_JenaWriters.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/system/IO_JenaWriters.java b/jena-arq/src/main/java/org/apache/jena/riot/system/IO_JenaWriters.java
index e369abb..e8e287f 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/system/IO_JenaWriters.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/system/IO_JenaWriters.java
@@ -18,118 +18,30 @@
 
 package org.apache.jena.riot.system;
 
-import java.util.Collection ;
-import java.util.HashMap ;
-import java.util.Map ;
-
-import org.apache.jena.n3.N3JenaWriter ;
 import org.apache.jena.rdf.model.impl.RDFWriterFImpl ;
-import org.apache.jena.riot.RDFFormat ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_JSONLD ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_N3 ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_N3Plain ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_N3Triples ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_N3TriplesAlt ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_N3_PP ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_NTriples ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_RDFJSON ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_Turtle ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_Turtle1 ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_Turtle2 ;
+import org.apache.jena.riot.adapters.RDFWriterFactoryRIOT ;
 
 public class IO_JenaWriters
-{
-    private static Map<String, RDFFormat> mapJenaNameToFormat               = new HashMap<>() ;
-
-    /** return the RDFFormat for the existing Jena writer name, or null */ 
-    public static RDFFormat getFormatForJenaWriter(String jenaName) { return mapJenaNameToFormat.get(jenaName) ; }
-
-    /** Register an RDFFormat for a Jena writer name */ 
-    public static void setFormatForJenaWriter(String jenaName, RDFFormat format) { mapJenaNameToFormat.put(jenaName, format) ; }
-
-    /** Return a collection of jena writer names */ 
-    public static Collection<String> getJenaWriterNames() { return mapJenaNameToFormat.keySet() ; }
+{ 
+    // Do once.
+    private static boolean isWiredIn = false ;
     
-    public static void wireIntoJena()
-    {
-        setFormatForJenaWriter("RDF/XML",                           RDFFormat.RDFXML_PLAIN) ;
-        setFormatForJenaWriter("RDF/XML-ABBREV",                    RDFFormat.RDFXML_ABBREV) ;
-        setFormatForJenaWriter("N-TRIPLE",                          RDFFormat.NTRIPLES) ;
-        setFormatForJenaWriter("NT",                                RDFFormat.NTRIPLES) ;
-        setFormatForJenaWriter("N-TRIPLES",                         RDFFormat.NTRIPLES) ;
-        setFormatForJenaWriter("N-Triples",                         RDFFormat.NTRIPLES) ;
-        setFormatForJenaWriter("N3",                                RDFFormat.TURTLE) ;
-        setFormatForJenaWriter(N3JenaWriter.n3WriterPrettyPrinter,  RDFFormat.TURTLE_PRETTY) ;
-        setFormatForJenaWriter(N3JenaWriter.n3WriterPlain,          RDFFormat.TURTLE_BLOCKS) ;
-        setFormatForJenaWriter(N3JenaWriter.n3WriterTriples,        RDFFormat.TURTLE_FLAT) ;
-        setFormatForJenaWriter(N3JenaWriter.n3WriterTriplesAlt,     RDFFormat.TURTLE_FLAT) ;
-        setFormatForJenaWriter(N3JenaWriter.turtleWriter,           RDFFormat.TURTLE) ;
-        setFormatForJenaWriter(N3JenaWriter.turtleWriterAlt1,       RDFFormat.TURTLE) ;
-        setFormatForJenaWriter(N3JenaWriter.turtleWriterAlt2,       RDFFormat.TURTLE) ;
-
-        setFormatForJenaWriter("JSON-LD",                           RDFFormat.JSONLD) ; 
-        setFormatForJenaWriter("JSONLD",                            RDFFormat.JSONLD) ; 
-        
-        setFormatForJenaWriter("RDF/JSON",                          RDFFormat.RDFJSON) ;
-        setFormatForJenaWriter("RDFJSON",                           RDFFormat.RDFJSON) ;
-        
-        //registerForModelWrite("RDF/XML",                            RDFWriterRIOT_RDFXML.class) ;
-        //registerForModelWrite("RDF/XML-ABBREV",                     RDFWriterRIOT_RDFXMLAbbrev.class) ;
-        
-        // Use the original classes so that setting properties works transparently.
-        registerForModelWrite("RDF/XML",                            org.apache.jena.rdfxml.xmloutput.impl.Basic.class) ;
-        registerForModelWrite("RDF/XML-ABBREV",                     org.apache.jena.rdfxml.xmloutput.impl.Abbreviated.class) ;
-        
-        registerForModelWrite("N-TRIPLE",                           RDFWriterRIOT_NTriples.class) ;
-        registerForModelWrite("N-TRIPLES",                          RDFWriterRIOT_NTriples.class) ;
-        registerForModelWrite("N-Triples",                          RDFWriterRIOT_NTriples.class) ;
-        registerForModelWrite("NT",                                 RDFWriterRIOT_NTriples.class) ;
-        registerForModelWrite("N3",                                 RDFWriterRIOT_N3.class) ;
-        
-        registerForModelWrite(N3JenaWriter.n3WriterPrettyPrinter,   RDFWriterRIOT_N3_PP.class) ;
-        registerForModelWrite(N3JenaWriter.n3WriterPlain,           RDFWriterRIOT_N3Plain.class) ;
-        registerForModelWrite(N3JenaWriter.n3WriterTriples,         RDFWriterRIOT_N3Triples.class) ;
-        registerForModelWrite(N3JenaWriter.n3WriterTriplesAlt,      RDFWriterRIOT_N3TriplesAlt.class) ;
-        
-        registerForModelWrite(N3JenaWriter.turtleWriter,            RDFWriterRIOT_Turtle.class) ;
-        registerForModelWrite(N3JenaWriter.turtleWriterAlt1,        RDFWriterRIOT_Turtle1.class) ;
-        registerForModelWrite(N3JenaWriter.turtleWriterAlt2,        RDFWriterRIOT_Turtle2.class) ;
-
-        registerForModelWrite("JSON-LD",                            RDFWriterRIOT_JSONLD.class) ;
-        registerForModelWrite("JSONLD",                             RDFWriterRIOT_JSONLD.class) ;
-        
-        registerForModelWrite("RDF/JSON",                           RDFWriterRIOT_RDFJSON.class) ;
-        registerForModelWrite("RDFJSON",                            RDFWriterRIOT_RDFJSON.class) ;
+    public static void wireIntoJena() {
+        if ( isWiredIn )
+            return ;
+        isWiredIn = true ;
+        RDFWriterFImpl.alternative(new RDFWriterFactoryRIOT());
     }
     
-    public static void resetJena()
-    {
-        // This is the old Jena configuration (bugs and all) 
-        RDFWriterFImpl.setBaseWriterClassName("RDF/XML",        org.apache.jena.rdfxml.xmloutput.impl.Basic.class.getName()) ;
-        RDFWriterFImpl.setBaseWriterClassName("RDF/XML-ABBREV", org.apache.jena.rdfxml.xmloutput.impl.Abbreviated.class.getName()) ;
-
-        RDFWriterFImpl.setBaseWriterClassName("N-TRIPLE",       org.apache.jena.rdf.model.impl.NTripleWriter.class.getName()) ;
-        RDFWriterFImpl.setBaseWriterClassName("NT",             "") ;
-        RDFWriterFImpl.setBaseWriterClassName("N-TRIPLES",      org.apache.jena.rdf.model.impl.NTripleWriter.class.getName()) ;
-        RDFWriterFImpl.setBaseWriterClassName("N-Triples",      org.apache.jena.rdf.model.impl.NTripleWriter.class.getName()) ;
-
-        RDFWriterFImpl.setBaseWriterClassName("N3",             org.apache.jena.n3.N3JenaWriter.class.getName()) ;         
-        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.n3WriterPrettyPrinter,    org.apache.jena.n3.N3JenaWriterPP.class.getName()) ;
-        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.n3WriterPlain,           org.apache.jena.n3.N3TurtleJenaWriter.class.getName()) ;
-        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.n3WriterTriples,         org.apache.jena.n3.N3TurtleJenaWriter.class.getName()) ;
-        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.n3WriterTriplesAlt,      org.apache.jena.n3.N3JenaWriterTriples.class.getName()) ;
-        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.turtleWriter,            org.apache.jena.n3.N3TurtleJenaWriter.class.getName()) ;
-        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.turtleWriterAlt1,        org.apache.jena.n3.N3TurtleJenaWriter.class.getName()) ;
-        RDFWriterFImpl.setBaseWriterClassName(N3JenaWriter.turtleWriterAlt2,        org.apache.jena.n3.N3TurtleJenaWriter.class.getName()) ;
-        
-        RDFWriterFImpl.setBaseWriterClassName("JSON-LD",    "");
-        RDFWriterFImpl.setBaseWriterClassName("JSON",       "");
-
-        RDFWriterFImpl.setBaseWriterClassName("RDF/JSON",   "");
-        RDFWriterFImpl.setBaseWriterClassName("RDFJSON",    "");
+    public static void resetJena() {
+        if ( ! isWiredIn )
+            return ;
+        isWiredIn = false ;
+        RDFWriterFImpl.alternative(null);
     }
-    
-    /** Register for use with Model.write  (old style compatibility) */ 
+
+    /** Register for use with Model.write  (old style compatibility) */
+    @Deprecated
     public static void registerForModelWrite(String name, Class<?> cls)
     {
         RDFWriterFImpl.setBaseWriterClassName(name, cls.getName()) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-arq/src/test/java/org/apache/jena/riot/system/TestIO_JenaReaders.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/riot/system/TestIO_JenaReaders.java b/jena-arq/src/test/java/org/apache/jena/riot/system/TestIO_JenaReaders.java
index d3424b9..a3b5d19 100644
--- a/jena-arq/src/test/java/org/apache/jena/riot/system/TestIO_JenaReaders.java
+++ b/jena-arq/src/test/java/org/apache/jena/riot/system/TestIO_JenaReaders.java
@@ -18,20 +18,14 @@
 package org.apache.jena.riot.system;
 
 import static org.junit.Assert.assertEquals ;
-import static org.junit.Assert.assertFalse ;
-
-import java.util.LinkedHashMap ;
-import java.util.Map ;
-import java.util.Properties ;
+import static org.junit.Assert.assertNotEquals ;
+import static org.junit.Assert.fail ;
 
+import org.apache.jena.rdf.model.RDFReaderF ;
 import org.apache.jena.rdf.model.impl.RDFReaderFImpl ;
 import org.apache.jena.riot.IO_Jena ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFReaderRIOT_NT ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFReaderRIOT_RDFJSON ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFReaderRIOT_JSONLD ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFReaderRIOT_RDFXML ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFReaderRIOT_TTL ;
-import org.apache.jena.riot.adapters.* ;
+import org.apache.jena.riot.adapters.RDFReaderRIOT ;
+import org.apache.jena.shared.NoReaderForLangException ;
 import org.junit.AfterClass ;
 import org.junit.BeforeClass ;
 import org.junit.Test ;
@@ -40,59 +34,48 @@ public class TestIO_JenaReaders {
     @BeforeClass public static void beforeClass() { } 
     @AfterClass public static void afterClass()   { IO_Jena.wireIntoJena(); }
     
-    private final class RDFReaderFImplExposingProtected extends RDFReaderFImpl {
-        public Map<String, String> defaultReaders() {
-            Map<String,String> defaults = new LinkedHashMap<>();
-            for (int i=0; i<LANGS.length; i++) {
-                defaults.put(LANGS[i], DEFAULTREADERS[i]);
-            }
-            return defaults;
-        }
-        public Properties getLangToClassName() {
-            return langToClassName;
-        }
-    }
-
     @Test
     public void wireIntoJena() {
-        IO_JenaReaders.wireIntoJena();
-        RDFReaderFImpl readerF = new RDFReaderFImpl();
-        assertEquals(RDFReaderRIOT_Web.class,       readerF.getReader().getClass());
-        assertEquals(RDFReaderRIOT_RDFXML.class,    readerF.getReader("RDF/XML").getClass());
-        assertEquals(RDFReaderRIOT_RDFXML.class,    readerF.getReader("RDF/XML-ABBREV").getClass());
-        assertEquals(RDFReaderRIOT_NT.class,        readerF.getReader("N-TRIPLES").getClass());
-        assertEquals(RDFReaderRIOT_NT.class,        readerF.getReader("N-Triples").getClass());
-        assertEquals(RDFReaderRIOT_NT.class,        readerF.getReader("N-TRIPLE").getClass());
-        assertEquals(RDFReaderRIOT_TTL.class,       readerF.getReader("N3").getClass());
-        assertEquals(RDFReaderRIOT_TTL.class,       readerF.getReader("TURTLE").getClass());
-        assertEquals(RDFReaderRIOT_TTL.class,       readerF.getReader("Turtle").getClass());
-        assertEquals(RDFReaderRIOT_TTL.class,       readerF.getReader("TTL").getClass());
-        assertEquals(RDFReaderRIOT_JSONLD.class,    readerF.getReader("JSON-LD").getClass());
-        assertEquals(RDFReaderRIOT_JSONLD.class,    readerF.getReader("JSONLD").getClass());
-        assertEquals(RDFReaderRIOT_RDFJSON.class,   readerF.getReader("RDF/JSON").getClass());
-        
+        IO_Jena.wireIntoJena();
+        RDFReaderF readerF = new RDFReaderFImpl();
+
+        assertEquals(RDFReaderRIOT.class, readerF.getReader().getClass());
+        assertEquals(RDFReaderRIOT.class, readerF.getReader("RDF/XML").getClass());
+        assertEquals(RDFReaderRIOT.class, readerF.getReader("RDF/XML-ABBREV").getClass());
+        assertEquals(RDFReaderRIOT.class, readerF.getReader("N-TRIPLES").getClass());
+        assertEquals(RDFReaderRIOT.class, readerF.getReader("N-Triples").getClass());
+        assertEquals(RDFReaderRIOT.class, readerF.getReader("N-TRIPLE").getClass());
+        assertEquals(RDFReaderRIOT.class, readerF.getReader("N3").getClass());
+        assertEquals(RDFReaderRIOT.class, readerF.getReader("TURTLE").getClass());
+        assertEquals(RDFReaderRIOT.class, readerF.getReader("Turtle").getClass());
+        assertEquals(RDFReaderRIOT.class, readerF.getReader("TTL").getClass());
+        assertEquals(RDFReaderRIOT.class, readerF.getReader("JSON-LD").getClass());
+        assertEquals(RDFReaderRIOT.class, readerF.getReader("JSONLD").getClass());
+        assertEquals(RDFReaderRIOT.class, readerF.getReader("RDF/JSON").getClass());
     }
     
     @Test
     public void resetJena() {
-        IO_JenaReaders.wireIntoJena();
-        IO_JenaReaders.resetJena();
-        RDFReaderFImplExposingProtected readerF = new RDFReaderFImplExposingProtected();
-        Map<String, String> defaults = readerF.defaultReaders();
-        assertFalse(defaults.isEmpty());
-        for (String lang : defaults.keySet()) {
-            assertEquals(defaults.get(lang), readerF.getLangToClassName().get(lang));
-            if (lang.equals("GRDDL")) {
-                // Can't load
-                continue;
-            }
-            assertEquals(defaults.get(lang), readerF.getReader(lang).getClass().getName());
-        }
+        IO_Jena.wireIntoJena();
+        IO_Jena.resetJena();
+        RDFReaderF readerF = new RDFReaderFImpl();
+        
+        assertNotEquals(RDFReaderRIOT.class, readerF.getReader().getClass());
+        assertNotEquals(RDFReaderRIOT.class, readerF.getReader("RDF/XML").getClass());
+        assertNotEquals(RDFReaderRIOT.class, readerF.getReader("RDF/XML-ABBREV").getClass());
+        assertNotEquals(RDFReaderRIOT.class, readerF.getReader("N-TRIPLES").getClass());
+        assertNotEquals(RDFReaderRIOT.class, readerF.getReader("N-Triples").getClass());
+        assertNotEquals(RDFReaderRIOT.class, readerF.getReader("N-TRIPLE").getClass());
+        assertNotEquals(RDFReaderRIOT.class, readerF.getReader("N3").getClass());
+        assertNotEquals(RDFReaderRIOT.class, readerF.getReader("TURTLE").getClass());
+        assertNotEquals(RDFReaderRIOT.class, readerF.getReader("Turtle").getClass());
+        assertNotEquals(RDFReaderRIOT.class, readerF.getReader("TTL").getClass());
+        
+        try { readerF.getReader("NT")      ; fail("Exception expected") ; } catch (NoReaderForLangException e) {}
+        try { readerF.getReader("JSON_LD") ; fail("Exception expected") ; } catch (NoReaderForLangException e) {}
+        try { readerF.getReader("RDF/JSON"); fail("Exception expected") ; } catch (NoReaderForLangException e) {}
         
-        // And unregistered our additional langs
-        assertEquals("", readerF.getLangToClassName().get("JSON-LD"));
-        assertEquals("", readerF.getLangToClassName().get("RDF/JSON"));
-        IO_JenaReaders.wireIntoJena();
+        IO_Jena.wireIntoJena();
     }
 
     

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-arq/src/test/java/org/apache/jena/riot/system/TestIO_JenaWriters.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/riot/system/TestIO_JenaWriters.java b/jena-arq/src/test/java/org/apache/jena/riot/system/TestIO_JenaWriters.java
index b7c71a3..f835b3b 100644
--- a/jena-arq/src/test/java/org/apache/jena/riot/system/TestIO_JenaWriters.java
+++ b/jena-arq/src/test/java/org/apache/jena/riot/system/TestIO_JenaWriters.java
@@ -18,27 +18,15 @@
 package org.apache.jena.riot.system;
 
 import static org.junit.Assert.assertEquals ;
-import static org.junit.Assert.assertFalse ;
-
-import java.util.LinkedHashMap ;
-import java.util.Map ;
-import java.util.Properties ;
+import static org.junit.Assert.assertNotEquals ;
+import static org.junit.Assert.fail ;
 
 import org.apache.jena.n3.N3JenaWriter ;
+import org.apache.jena.rdf.model.RDFWriterF ;
 import org.apache.jena.rdf.model.impl.RDFWriterFImpl ;
-import org.apache.jena.rdfxml.xmloutput.impl.Abbreviated ;
-import org.apache.jena.rdfxml.xmloutput.impl.Basic ;
 import org.apache.jena.riot.IO_Jena ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_N3 ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_N3Plain ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_N3Triples ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_N3TriplesAlt ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_N3_PP ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_NTriples ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_RDFJSON ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_Turtle ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_Turtle1 ;
-import org.apache.jena.riot.adapters.JenaReadersWriters.RDFWriterRIOT_Turtle2 ;
+import org.apache.jena.riot.adapters.RDFWriterRIOT ;
+import org.apache.jena.shared.NoWriterForLangException ;
 import org.junit.AfterClass ;
 import org.junit.BeforeClass ;
 import org.junit.Test ;
@@ -48,62 +36,59 @@ public class TestIO_JenaWriters {
     @BeforeClass public static void beforeClass() { } 
     @AfterClass public static void afterClass()   { IO_Jena.wireIntoJena(); }
     
-    private final class RDFWriterFImplExposingProtected extends RDFWriterFImpl {
-        public Map<String, String> defaultWriters() {
-            Map<String,String> defaults = new LinkedHashMap<>();
-            for (int i=0; i<LANGS.length; i++) {
-                defaults.put(LANGS[i], DEFAULTWRITERS[i]);
-            }
-            return defaults;
-        }
-        public Properties getLangToClassName() {
-            return langToClassName;
-        }
-    }
-
     @Test
     public void testWireIntoJena() {
-        IO_JenaWriters.wireIntoJena();
-        RDFWriterFImpl writerF = new RDFWriterFImpl();
-        assertEquals(Basic.class, writerF.getWriter().getClass());
-        assertEquals(Basic.class, writerF.getWriter("RDF/XML").getClass());
-        assertEquals(Abbreviated.class, writerF.getWriter("RDF/XML-ABBREV").getClass());
-        assertEquals(RDFWriterRIOT_NTriples.class, writerF.getWriter("N-TRIPLE").getClass());
-        assertEquals(RDFWriterRIOT_NTriples.class, writerF.getWriter("N-Triples").getClass());
-        assertEquals(RDFWriterRIOT_NTriples.class, writerF.getWriter("N-TRIPLE").getClass());
-        assertEquals(RDFWriterRIOT_NTriples.class, writerF.getWriter("NT").getClass());
+        IO_Jena.wireIntoJena();
+        RDFWriterF writerF = new RDFWriterFImpl();
+        assertEquals(RDFWriterRIOT.class, writerF.getWriter().getClass());
+        assertEquals(RDFWriterRIOT.class, writerF.getWriter("RDF/XML").getClass());
+        assertEquals(RDFWriterRIOT.class, writerF.getWriter("RDF/XML-ABBREV").getClass());
+        assertEquals(RDFWriterRIOT.class, writerF.getWriter("N-TRIPLE").getClass());
+        assertEquals(RDFWriterRIOT.class, writerF.getWriter("N-Triples").getClass());
+        assertEquals(RDFWriterRIOT.class, writerF.getWriter("N-TRIPLE").getClass());
+        assertEquals(RDFWriterRIOT.class, writerF.getWriter("NT").getClass());
 
-        assertEquals(RDFWriterRIOT_N3.class, writerF.getWriter("N3").getClass());
-        assertEquals(RDFWriterRIOT_N3_PP.class, writerF.getWriter(N3JenaWriter.n3WriterPrettyPrinter).getClass());
-        assertEquals(RDFWriterRIOT_N3Plain.class, writerF.getWriter(N3JenaWriter.n3WriterPlain).getClass());
-        assertEquals(RDFWriterRIOT_N3Triples.class, writerF.getWriter(N3JenaWriter.n3WriterTriples).getClass());
-        assertEquals(RDFWriterRIOT_N3TriplesAlt.class, writerF.getWriter(N3JenaWriter.n3WriterTriplesAlt).getClass());
+        assertEquals(RDFWriterRIOT.class, writerF.getWriter("N3").getClass());
+        assertEquals(RDFWriterRIOT.class, writerF.getWriter(N3JenaWriter.n3WriterPrettyPrinter).getClass());
+        assertEquals(RDFWriterRIOT.class, writerF.getWriter(N3JenaWriter.n3WriterPlain).getClass());
+        assertEquals(RDFWriterRIOT.class, writerF.getWriter(N3JenaWriter.n3WriterTriples).getClass());
+        assertEquals(RDFWriterRIOT.class, writerF.getWriter(N3JenaWriter.n3WriterTriplesAlt).getClass());
         
-        assertEquals(RDFWriterRIOT_Turtle.class, writerF.getWriter(N3JenaWriter.turtleWriter).getClass());
-        assertEquals(RDFWriterRIOT_Turtle1.class, writerF.getWriter(N3JenaWriter.turtleWriterAlt1).getClass());
-        assertEquals(RDFWriterRIOT_Turtle2.class, writerF.getWriter(N3JenaWriter.turtleWriterAlt2).getClass());
+        assertEquals(RDFWriterRIOT.class, writerF.getWriter(N3JenaWriter.turtleWriter).getClass());
+        assertEquals(RDFWriterRIOT.class, writerF.getWriter(N3JenaWriter.turtleWriterAlt1).getClass());
+        assertEquals(RDFWriterRIOT.class, writerF.getWriter(N3JenaWriter.turtleWriterAlt2).getClass());
 
-        assertEquals(RDFWriterRIOT_RDFJSON.class, writerF.getWriter("RDF/JSON").getClass());
-        assertEquals(RDFWriterRIOT_RDFJSON.class, writerF.getWriter("RDFJSON").getClass());
+        assertEquals(RDFWriterRIOT.class, writerF.getWriter("RDF/JSON").getClass());
+        assertEquals(RDFWriterRIOT.class, writerF.getWriter("RDFJSON").getClass());
     }
     
     @Test
     public void testResetJena() {
-        IO_JenaWriters.wireIntoJena();
-        IO_JenaWriters.resetJena();
-        RDFWriterFImplExposingProtected writerF = new RDFWriterFImplExposingProtected();
-        Map<String, String> defaults = writerF.defaultWriters();
-        assertFalse(defaults.isEmpty());
-        for (String lang : defaults.keySet()) {
-            assertEquals(defaults.get(lang), writerF.getLangToClassName().get(lang));
-            assertEquals(defaults.get(lang), writerF.getWriter(lang).getClass().getName());
-        }
+        IO_Jena.wireIntoJena();
+        IO_Jena.resetJena();
+        RDFWriterF writerF = new RDFWriterFImpl();
         
-        // And unregistered our additional langs
-        assertEquals("", writerF.getLangToClassName().get("NT"));
-        assertEquals("", writerF.getLangToClassName().get("RDF/JSON"));
-        assertEquals("", writerF.getLangToClassName().get("RDFJSON"));
-        IO_JenaWriters.wireIntoJena();
+        assertNotEquals(RDFWriterRIOT.class, writerF.getWriter().getClass());
+        assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("RDF/XML").getClass());
+        assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("RDF/XML-ABBREV").getClass());
+        assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("N-TRIPLE").getClass());
+        assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("N-Triples").getClass());
+        assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("N-TRIPLE").getClass());
+
+        assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("N3").getClass());
+        assertNotEquals(RDFWriterRIOT.class, writerF.getWriter(N3JenaWriter.n3WriterPrettyPrinter).getClass());
+        assertNotEquals(RDFWriterRIOT.class, writerF.getWriter(N3JenaWriter.n3WriterPlain).getClass());
+        assertNotEquals(RDFWriterRIOT.class, writerF.getWriter(N3JenaWriter.n3WriterTriples).getClass());
+        assertNotEquals(RDFWriterRIOT.class, writerF.getWriter(N3JenaWriter.n3WriterTriplesAlt).getClass());
+        
+        assertNotEquals(RDFWriterRIOT.class, writerF.getWriter(N3JenaWriter.turtleWriter).getClass());
+        assertNotEquals(RDFWriterRIOT.class, writerF.getWriter(N3JenaWriter.turtleWriterAlt1).getClass());
+        assertNotEquals(RDFWriterRIOT.class, writerF.getWriter(N3JenaWriter.turtleWriterAlt2).getClass());
+
+        try { writerF.getWriter("NT"); fail("Exception expected") ; } catch (NoWriterForLangException ex) {}
+        try { writerF.getWriter("RDF/JSON") ; fail("Exception expected") ; } catch (NoWriterForLangException ex) {}
+        try { writerF.getWriter("RDFJSON"); fail("Exception expected") ; } catch (NoWriterForLangException ex) {}
+        IO_Jena.wireIntoJena();
     }
 
     

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-arq/src/test/java/org/apache/jena/riot/writer/TestJenaWriters.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/riot/writer/TestJenaWriters.java b/jena-arq/src/test/java/org/apache/jena/riot/writer/TestJenaWriters.java
index 3f0d5f0..5bfcca2 100644
--- a/jena-arq/src/test/java/org/apache/jena/riot/writer/TestJenaWriters.java
+++ b/jena-arq/src/test/java/org/apache/jena/riot/writer/TestJenaWriters.java
@@ -25,7 +25,7 @@ import java.util.List ;
 import org.apache.jena.atlas.lib.Bytes ;
 import org.apache.jena.rdf.model.Model ;
 import org.apache.jena.riot.RDFDataMgr ;
-import org.apache.jena.riot.system.IO_JenaWriters ;
+import org.apache.jena.riot.RDFWriterRegistry ;
 import org.junit.Test ;
 import org.junit.runner.RunWith ;
 import org.junit.runners.Parameterized ;
@@ -37,7 +37,7 @@ public class TestJenaWriters extends AbstractWriterTest
     @Parameters(name = "{index}: {0}")
     public static Iterable<Object[]> data() {
         List<Object[]> x = new ArrayList<>() ;
-        for ( String wname : IO_JenaWriters.getJenaWriterNames() )
+        for ( String wname :  RDFWriterRegistry.getJenaWriterNames())
             x.add(new Object[]{wname}) ;
         return x ; 
     }
@@ -58,7 +58,7 @@ public class TestJenaWriters extends AbstractWriterTest
     private void test(String filename) {
         Model m = readModel(filename) ;
         ByteArrayOutputStream out2 = new ByteArrayOutputStream() ;
-        RDFDataMgr.write(out2, m, IO_JenaWriters.getFormatForJenaWriter(jenaFormatName)) ;
+        RDFDataMgr.write(out2, m, RDFWriterRegistry.getFormatForJenaWriter(jenaFormatName)) ;
 
         ByteArrayOutputStream out1 = new ByteArrayOutputStream() ;
         m.write(out1, jenaFormatName) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ModelCom.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ModelCom.java b/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ModelCom.java
index ff93f69..8e48855 100644
--- a/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ModelCom.java
+++ b/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ModelCom.java
@@ -50,7 +50,6 @@ import org.apache.jena.vocabulary.RDF ;
 public class ModelCom extends EnhGraph
 implements Model, PrefixMapping, Lock
 {
-
     private static final RDFReaderF readerFactory = new RDFReaderFImpl();
     private static final RDFWriterF writerFactory = new RDFWriterFImpl();
     private Lock modelLock = null ;
@@ -58,7 +57,7 @@ implements Model, PrefixMapping, Lock
 
     static {
         // This forces RIOT (in ARQ) to initialize but after Jena readers/writers
-        // have cleanly initialized from the calls of  RDFReaderFImpl and RDFWriterFImpl
+        // have cleanly initialized from the calls of RDFReaderFImpl and RDFWriterFImpl
         // above.  RIOT initialization happens before model.read can be called.
         JenaSystem.init() ;
     }
@@ -213,6 +212,8 @@ implements Model, PrefixMapping, Lock
         return readerFactory.getReader(lang);
     }
 
+    /** @deprecated Use {@code org.apache.jena.riot.RDFParserRegistry.register}
+     */
     @Override
     @Deprecated
     public String setReaderClassName(String lang, String className) {
@@ -300,6 +301,8 @@ implements Model, PrefixMapping, Lock
     }
 
 
+    /** @deprecated Use {@code org.apache.jena.riot.RDFWriterRegistry.register}
+     */
     @Override
     @Deprecated
     public String setWriterClassName(String lang, String className) {

http://git-wip-us.apache.org/repos/asf/jena/blob/e214ba27/jena-core/src/main/java/org/apache/jena/rdf/model/impl/RDFReaderFImpl.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/rdf/model/impl/RDFReaderFImpl.java b/jena-core/src/main/java/org/apache/jena/rdf/model/impl/RDFReaderFImpl.java
index 7dd1aa2..4c3eaff 100644
--- a/jena-core/src/main/java/org/apache/jena/rdf/model/impl/RDFReaderFImpl.java
+++ b/jena-core/src/main/java/org/apache/jena/rdf/model/impl/RDFReaderFImpl.java
@@ -18,134 +18,144 @@
 
 package org.apache.jena.rdf.model.impl;
 
-import java.util.Arrays;
-import java.util.Properties;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
-import org.apache.jena.* ;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.shared.* ;
+import org.apache.jena.atlas.logging.Log ;
+import org.apache.jena.rdf.model.RDFReader;
+import org.apache.jena.rdf.model.RDFReaderF;
+import org.apache.jena.shared.ConfigException;
+import org.apache.jena.shared.JenaException;
+import org.apache.jena.shared.NoReaderForLangException;
 
-/**
- */
 public class RDFReaderFImpl extends Object implements RDFReaderF {
-    // ** The setting in this class are overrided by RIOT **
-    private static final String TURTLEREADER = org.apache.jena.n3.turtle.TurtleReader.class.getName() ;
-    
-	protected static Properties langToClassName = null;
-
-    // predefined languages - these should probably go in a properties file
-
-    protected static final String LANGS[] = { "RDF" ,
-                                              "RDF/XML",
-                                              "RDF/XML-ABBREV",
-                                              "N-TRIPLE",
-                                              "N-TRIPLES",
-                                              "N-Triples",
-                                              "N3",
-                                              "TURTLE",
-                                              "Turtle",
-                                              "TTL",
-                                              "CSV"};
-    // default readers for each language
-
-    protected static final String DEFAULTREADERS[] = {
-        org.apache.jena.rdfxml.xmlinput.JenaReader.class.getName(),
-        org.apache.jena.rdfxml.xmlinput.JenaReader.class.getName(),
-        org.apache.jena.rdfxml.xmlinput.JenaReader.class.getName(),
-        org.apache.jena.rdf.model.impl.NTripleReader.class.getName(),
-        org.apache.jena.rdf.model.impl.NTripleReader.class.getName(),
-        org.apache.jena.rdf.model.impl.NTripleReader.class.getName(),
-        TURTLEREADER,  // N3 replaced by a Turtle-based parser 
-        TURTLEREADER,
-        TURTLEREADER,
-        TURTLEREADER,
-        "org.apache.jena.riot.adapters.RDFReaderRIOT_CSV",
-        
-    };
-
-    protected static final String DEFAULTLANG = LANGS[0];
-
-    protected static final String PROPNAMEBASE = Jena.PATH + ".reader.";
-
-    static { // static initializer - set default readers
-        reset();
+    public static final String DEFAULTLANG = "RDF/XML" ;
+    private static Map<String, Class<? extends RDFReader>> custom = new LinkedHashMap<>();
+    private static RDFReaderF rewiredAlternative = null ;
+    /** Rewire to use an external RDFReaderF (typically, RIOT).
+     * Set to null to use old jena-core setup.
+     * @param other
+     */
+    public static void alternative(RDFReaderF other) {
+        rewiredAlternative = other ;
     }
     
-    private static void reset()
-    {
-    	Properties newLangToClassName = new Properties();
-        for (int i = 0; i<LANGS.length; i++) {
-        	newLangToClassName.setProperty(
-                               LANGS[i],
-                               JenaRuntime.getSystemProperty(PROPNAMEBASE + LANGS[i],
-                                                  DEFAULTREADERS[i]));
-        }
-        // reset all at once
-        langToClassName = newLangToClassName;
-    }
-
-    private static String remove(String lang )
-    {
-    	if (Arrays.asList( LANGS ).contains(lang))
-		{
-			throw new IllegalArgumentException( lang+" is an initial language and may not be removed");
-		}
-		Object prev = langToClassName.remove(lang);
-		return prev==null?null:prev.toString();
-    }
-
     /** Creates new RDFReaderFImpl */
-    public  RDFReaderFImpl() {
-    }
-
+    public RDFReaderFImpl() {}
+    
     @Override
     public RDFReader getReader()  {
-        return getReader(DEFAULTLANG);
+        return getReader(null);
     }
-
+    
     @Override
-    public RDFReader getReader(String lang)  {
+    public RDFReader getReader(String lang) {
+        // Jena model.read rule for defaulting.
+        if (lang==null || lang.equals(""))
+            lang = DEFAULTLANG ;
+        // if RIOT ->
+        if ( rewiredAlternative != null )
+            return rewiredAlternative.getReader(lang) ;
+        Class<? extends RDFReader> c = custom.get(lang);
+        if ( c == null )
+            throw new NoReaderForLangException("Reader not found: " + lang);
 
-        // setup default language
-        if (lang==null || lang.equals("")) {
-            lang = LANGS[0];
+        try {
+            return c.newInstance();
         }
-
-        String className = langToClassName.getProperty(lang);
-        if (className == null || className.equals("")) {
-            throw new NoReaderForLangException( lang );
+        catch (InstantiationException | IllegalAccessException e) {
+            throw new JenaException(e);
         }
+    }
+
+    /**
+     * Use RIOT to add custom RDF parsers. See
+     * {@code RDFParserRegistry.registerLangTriples} and
+     * {@code RDFParserRegistry.registerLangQuads}
+     * 
+     * @deprecated Register with RIOT.
+     */
+    @Override
+    @Deprecated
+    public String setReaderClassName(String lang, String className) {
+        return setBaseReaderClassName(lang, className);
+    }
+
+    /**
+     * Use RIOT to add custom RDF parsers. See
+     * {@code RDFParserRegistry.registerLang}
+     * 
+     * @deprecated Register with RIOT.
+     */
+    @Deprecated
+    public static String setBaseReaderClassName(String lang, String className) {
+        if ( rewiredAlternative != null )
+            Log.fatal(RDFReaderFImpl.class, "Rewired RDFReaderFImpl - configuration changes have no effect on reading");
+            
+        String oldClassName = currentEntry(lang);
         try {
-          return (RDFReader) Class.forName(className)
-                                  .newInstance();
-        } catch (ClassNotFoundException e) {
-        	throw new ConfigException("Reader not found on classpath",e);
-        } catch (Exception e) {
+            @SuppressWarnings("unchecked")
+            Class<? extends RDFReader> newClass = (Class<? extends RDFReader>)Class.forName(className, false,
+                                                                                            Thread.currentThread().getContextClassLoader());
+            custom.put(lang, newClass);
+            return oldClassName;
+        }
+        catch (ClassNotFoundException e) {
+            throw new ConfigException("Reader not found on classpath", e);
+        }
+        catch (Exception e) {
             throw new JenaException(e);
         }
     }
 
+    @Override
+    public void resetRDFReaderF() {
+        reset();
+    }
 
     @Override
-    public String setReaderClassName( String lang,String className ) {
-        return setBaseReaderClassName( lang, className );
+    public String removeReader(String lang) throws IllegalArgumentException {
+        return remove(lang);
     }
-    
-    public static String setBaseReaderClassName( String lang, String className ) {
-        String oldClassName = langToClassName.getProperty(lang);
-        langToClassName.setProperty(lang, className);
-        return oldClassName;
+
+    static { 
+        // static initializer - set default readers
+        reset();
     }
 
+    private static void reset() {
+        Class<? extends RDFReader> rdfxmlReader = org.apache.jena.rdfxml.xmlinput.JenaReader.class;
+        Class<? extends RDFReader> ntReader = org.apache.jena.rdf.model.impl.NTripleReader.class;
+        Class<? extends RDFReader> turtleReader = org.apache.jena.n3.turtle.TurtleReader.class;
 
-	@Override
-	public void resetRDFReaderF() {
-		reset();
-	}
+        custom.put("RDF", rdfxmlReader);
+        custom.put("RDF/XML", rdfxmlReader);
+        custom.put("RDF/XML-ABBREV", rdfxmlReader);
 
+        custom.put("N-TRIPLE", ntReader);
+        custom.put("N-TRIPLES", ntReader);
+        custom.put("N-Triples", ntReader);
 
-	@Override
-	public String removeReader(String lang) throws IllegalArgumentException {
-		return remove( lang );
-	}
+        custom.put("N3", turtleReader);
+        custom.put("TURTLE", turtleReader);
+        custom.put("Turtle", turtleReader);
+        custom.put("TTL", turtleReader);
+    }
+
+    private static String currentEntry(String lang) {
+        Class<? extends RDFReader> oldClass = custom.get(lang);
+        if ( oldClass != null )
+            return oldClass.getName();
+        else
+            return null;
+    }
+
+    private static String remove(String lang) {
+        if ( rewiredAlternative != null )
+            Log.fatal(RDFReaderFImpl.class, "Rewired RDFReaderFImpl - configuration changes have no effect on reading");
+
+        String oldClassName = currentEntry(lang);
+        custom.remove(lang);
+        return oldClassName;
+    }
 }


Mime
View raw message