You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2016/01/05 13:45:55 UTC

[01/20] jena git commit: Invoke utility

Repository: jena
Updated Branches:
  refs/heads/master eb9eec043 -> 216209190


Invoke utility

Can be used to call commands in a later-in-build module


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

Branch: refs/heads/master
Commit: ff7f3613563f89daf521cd8e49da6d15ab63e443
Parents: cda5c7c
Author: Andy Seaborne <an...@apache.org>
Authored: Mon Jan 4 14:28:56 2016 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Jan 5 12:31:35 2016 +0000

----------------------------------------------------------------------
 jena-cmds/src/main/java/jena/cmd/Invoke.java | 66 +++++++++++++++++++++++
 1 file changed, 66 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/ff7f3613/jena-cmds/src/main/java/jena/cmd/Invoke.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/Invoke.java b/jena-cmds/src/main/java/jena/cmd/Invoke.java
new file mode 100644
index 0000000..df27ec2
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/Invoke.java
@@ -0,0 +1,66 @@
+/*
+ * 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 jena.cmd;
+
+import java.lang.reflect.InvocationTargetException ;
+import java.lang.reflect.Method ;
+
+/** Helper code to invoke a main method buy reflection
+ *  This means coomand can be invoked from this module even
+ *  if their implementation resides in a module later
+ *  in the build sequence.
+ */
+public class Invoke {
+    public static void invokeCmd(String className, String[] args) {
+        Class<? > cmd = null;
+        try {
+            cmd = Class.forName(className);
+        }
+        catch (ClassNotFoundException ex) {
+            System.err.println("Class '" + className + "' not found");
+            System.exit(1);
+        }
+
+        Method method = null;
+        try {
+            method = cmd.getMethod("main", new Class[]{String[].class});
+        }
+        catch (NoSuchMethodException ex) {
+            System.err.println("'main' not found but the class '" + className + "' was");
+            System.exit(1);
+        }
+
+        try {
+            method.invoke(null, new Object[]{args});
+            return;
+        }
+        catch (IllegalArgumentException ex) {
+            System.err.println("IllegalArgumentException exception: " + ex.getMessage());
+            System.exit(7);
+        }
+        catch (IllegalAccessException ex) {
+            System.err.println("IllegalAccessException exception: " + ex.getMessage());
+            System.exit(8);
+        }
+        catch (InvocationTargetException ex) {
+            System.err.println("InvocationTargetException exception: " + ex.getMessage());
+            System.exit(9);
+        }
+    }
+}


[08/20] jena git commit: JENA-1108 : jena-cmds module

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/test/java/jena/cmd/Test_schemagen.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/test/java/jena/cmd/Test_schemagen.java b/jena-cmds/src/test/java/jena/cmd/Test_schemagen.java
new file mode 100644
index 0000000..c31ba20
--- /dev/null
+++ b/jena-cmds/src/test/java/jena/cmd/Test_schemagen.java
@@ -0,0 +1,848 @@
+/*
+ * 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
+///////////////
+package jena.cmd;
+
+
+// Imports
+///////////////
+import java.io.*;
+import java.lang.reflect.Method;
+import java.util.*;
+import java.util.regex.Pattern;
+
+import jena.schemagen;
+import jena.schemagen.SchemagenOptionsImpl;
+import junit.framework.TestCase;
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.util.FileUtils ;
+import org.junit.Test ;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * <p>
+ * Unit tests for schemagen
+ * </p>
+ */
+public class Test_schemagen
+    extends TestCase
+{
+    // Constants
+    //////////////////////////////////
+
+    String PREFIX = "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n" +
+            "@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n" +
+            "@prefix owl: <http://www.w3.org/2002/07/owl#> .\n" +
+            "@prefix ex: <http://example.com/sg#> .\n";
+
+    // Static variables
+    //////////////////////////////////
+
+    private static Logger log = LoggerFactory.getLogger( Test_schemagen.class );
+
+    // Instance variables
+    //////////////////////////////////
+
+    // Constructors
+    //////////////////////////////////
+
+    // External signature methods
+    //////////////////////////////////
+
+    /** This test used to fail with an abort, but we now guess the NS based on prevalence */
+    @Test
+    public void testNoBaseURI0() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {},
+                             new String[] {".*public static final Resource A =.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testClass0() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl"},
+                             new String[] {".*public static final Resource A.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testClass1() throws Exception {
+        String SOURCE = PREFIX + "ex:A a rdfs:Class .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl"},
+                             new String[] {},
+                             new String[] {".*public static final Resource A.*"} );
+    }
+
+    @Test
+    public void testClass2() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--rdfs"},
+                             new String[] {},
+                             new String[] {".*public static final Resource A.*"} );
+    }
+
+    @Test
+    public void testClass3() throws Exception {
+        String SOURCE = PREFIX + "ex:A a rdfs:Class .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--rdfs"},
+                             new String[] {".*public static final Resource A.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testProperty0() throws Exception {
+        String SOURCE = PREFIX + "ex:p a owl:ObjectProperty .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl"},
+                             new String[] {".*public static final Property p.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testProperty1() throws Exception {
+        String SOURCE = PREFIX + "ex:p a rdf:Property .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl"},
+                             // in OWL mode we permit rdf:properties
+                             new String[] {".*public static final Property p.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testProperty2() throws Exception {
+        String SOURCE = PREFIX + "ex:p a owl:ObjectProperty .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--rdfs"},
+                             new String[] {},
+                             new String[] {".*public static final Property p.*"} );
+    }
+
+    @Test
+    public void testProperty3() throws Exception {
+        String SOURCE = PREFIX + "ex:p a rdf:Property .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--rdfs"},
+                             new String[] {".*public static final Property p.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testInstance0() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl"},
+                             new String[] {".*public static final Resource i.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testInstance1() throws Exception {
+        String SOURCE = PREFIX + "ex:A a rdfs:Class . ex:i a ex:A .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl"},
+                             new String[] {".*public static final Resource i.*"},
+                             new String[] {} );
+    }
+
+    /* TODO this test fails, because the isInstance check in schemagen is quite weak.
+     * Consider whether to fix the test or the code... *
+    public void testInstance2() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--rdfs"},
+                             new String[] {},
+                             new String[] {".*public static final Resource i.*"} );
+    }
+    */
+
+    @Test
+    public void testInstance3() throws Exception {
+        String SOURCE = PREFIX + "ex:A a rdfs:Class . ex:i a ex:A .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--rdfs"},
+                             new String[] {".*public static final Resource i.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testInstance4() throws Exception {
+        String SOURCE = PREFIX + "@prefix ex2: <http://example.org/otherNS#>. ex2:A a rdfs:Class . ex:i a ex2:A .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--rdfs"},
+                             new String[] {".*public static final Resource i.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testInstance5() throws Exception {
+        String SOURCE = "@prefix :        <http://ontology.earthster.org/eco/impact#> .\n" +
+                "@prefix core:    <http://ontology.earthster.org/eco/core#> .\n" +
+                "@prefix ecoinvent:  <http://ontology.earthster.org/eco/ecoinvent#> .\n" +
+                "@prefix owl:     <http://www.w3.org/2002/07/owl#> .\n" +
+                "@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n" +
+                "@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .\n" +
+                "@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .\n" +
+                "\n" +
+                "<http://ontology.earthster.org/eco/impact>\n" +
+                "      rdf:type owl:Ontology ;\n" +
+                "      owl:imports <http://ontology.earthster.org/eco/ecoinvent> , <http://ontology.earthster.org/eco/core> ;\n" +
+                "      owl:versionInfo \"Created with TopBraid Composer\"^^xsd:string .\n" +
+                "\n" +
+                ":CD-CML2001-AbioticDepletion\n" +
+                "      rdf:type core:ImpactAssessmentMethodCategoryDescription ;\n" +
+                "      rdfs:label \"abiotic resource depletion\"^^xsd:string ;\n" +
+                "      core:hasImpactCategory\n" +
+                "              :abioticDepletion .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"--owl", "--inference"},
+                             new String[] {".*public static final Resource CD_CML2001_AbioticDepletion.*"},
+                             new String[] {".*valtype.*"} );
+    }
+
+    @Test
+    public void testDatatype0() throws Exception {
+        String SOURCE = PREFIX + "ex:d a rdfs:Datatype . ex:d rdfs:comment \"custom datatype\" .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl"},
+                             new String[] {".*public static final Resource d.*"},
+                             new String[] {} );
+    }
+    
+    @Test
+    public void testDatatype1() throws Exception {
+        String SOURCE = PREFIX + "ex:d a rdfs:Datatype . ex:d rdfs:comment \"custom datatype\" .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl", "--nodatatypes"},
+                             new String[] {},
+                             new String[] {".*public static final Resource d.*"} );
+    }
+    
+    @Test
+    public void testRC0() throws Exception {
+        String SOURCE = PREFIX + "ex:class a owl:Class .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl"},
+                             new String[] {},
+                             new String[] {".*public static final Resource class .*"} );
+    }
+
+
+    @Test
+    public void testComment0() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class ; rdfs:comment \"commentcomment\" .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl"},
+                             new String[] {" */\\*\\* <p>commentcomment</p> \\*/ *"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testComment1() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class ; rdfs:comment \"commentcomment\" .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl", "--nocomments"},
+                             new String[] {},
+                             new String[] {" */\\*\\* <p>commentcomment</p> \\*/ *"} );
+    }
+
+    @Test
+    public void testComment2() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class ; rdfs:comment \"commentcomment\" .";
+
+        // we don't want the input fixed to be http://example.com/sg
+        SchemaGenAux sga = new SchemaGenAux() {
+            @Override
+            protected void go( String[] args ) {
+                go( new SchemagenOptionsImpl( args ) );
+            }
+        };
+        testSchemagenOutput( SOURCE, sga,
+                             new String[] {"-a", "http://example.com/sg#", "--owl", "-i", "file:\\\\C:\\Users\\fubar/vocabs/test.ttl"},
+                             new String[] {".*Vocabulary definitions from file:\\\\\\\\C:\\\\Users\\\\fubar/vocabs/test.ttl.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testComment3() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class ; rdfs:comment \"commentcomment\" .";
+
+        // we don't want the input fixed to be http://example.com/sg
+        SchemaGenAux sga = new SchemaGenAux() {
+            @Override
+            protected void go( String[] args ) {
+                go( new SchemagenOptionsImpl( args ) );
+            }
+        };
+        testSchemagenOutput( SOURCE, sga,
+                             new String[] {"-a", "http://example.com/sg#", "--owl", "-i", "C:\\Users\\fubar/vocabs/test.ttl"},
+                             new String[] {".*Vocabulary definitions from C:\\\\Users\\\\fubar/vocabs/test.ttl.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testOntClass0() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl", "--ontology"},
+                             new String[] {".*public static final OntClass A.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testOntClass1() throws Exception {
+        String SOURCE = PREFIX + "ex:A a rdfs:Class .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl", "--ontology"},
+                             new String[] {},
+                             new String[] {".*public static final OntClass A.*"} );
+    }
+
+    @Test
+    public void testOntClass2() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--rdfs", "--ontology"},
+                             new String[] {},
+                             new String[] {".*public static final OntClass A.*"} );
+    }
+
+    @Test
+    public void testOntClass3() throws Exception {
+        String SOURCE = PREFIX + "ex:A a rdfs:Class .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--rdfs", "--ontology"},
+                             new String[] {".*public static final OntClass A.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testOntProperty0() throws Exception {
+        String SOURCE = PREFIX + "ex:p a owl:ObjectProperty .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl", "--ontology"},
+                             new String[] {".*public static final ObjectProperty p.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testOntProperty1() throws Exception {
+        String SOURCE = PREFIX + "ex:p a rdf:Property .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl", "--ontology"},
+                             // in OWL mode we permit rdf:properties
+                             new String[] {".*public static final OntProperty p.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testOntProperty2() throws Exception {
+        String SOURCE = PREFIX + "ex:p a owl:ObjectProperty .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--rdfs", "--ontology"},
+                             new String[] {},
+                             new String[] {".*public static final ObjectProperty p.*"} );
+    }
+
+    @Test
+    public void testOntProperty3() throws Exception {
+        String SOURCE = PREFIX + "ex:p a rdf:Property .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--rdfs", "--ontology"},
+                             new String[] {".*public static final OntProperty p.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testHeader() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--ontology", "--header", "/* header */\n%package%\n%imports%\n"},
+                             new String[] {"/\\* header \\*/"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testFooter() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--ontology", "--footer", "/* footer */"},
+                             new String[] {"/\\* footer \\*/"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testPackage() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--ontology", "--package", "test.test"},
+                             new String[] {"package test.test;\\s*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testClassname() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class .";
+        SchemaGenAux fixture = new SchemaGenAux() {
+            @Override
+            protected void go( String[] args ) {
+                SchemagenOptionsFixture sgf = new SchemagenOptionsFixture( args ) {
+                    @Override
+                    public Resource getInputOption() {
+                        return ResourceFactory.createResource( "http://example.org/soggy" );
+                    }
+                };
+                go( sgf );
+            }
+        };
+
+        testSchemagenOutput( SOURCE, fixture,
+                             new String[] {"-a", "http://example.com/soggy#", "--ontology", "--package", "test.test", "-n", "Sg"},
+                             new String[] {},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testClassdec() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--ontology", "--classdec", "\n    implements java.lang.Cloneable\n"},
+                             new String[] {"\\s*implements java.lang.Cloneable\\s*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testDeclarations() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--ontology", "--declarations", "protected String m_gnole = \"Fungle\";;\n"},
+                             new String[] {".*Fungle.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testNoClasses() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--ontology", "--noclasses"},
+                             new String[] {},
+                             new String[] {".*OntClass A.*"} );
+    }
+
+    @Test
+    public void testNoProperties() throws Exception {
+        String SOURCE = PREFIX + "ex:p a owl:ObjectProperty .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl", "--ontology", "--noproperties"},
+                             new String[] {},
+                             new String[] {".*Property p.*"} );
+    }
+
+    @Test
+    public void testNoIndividuals() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl", "--noindividuals"},
+                             new String[] {".*Resource A.*"},
+                             new String[] {".*Resource i.*"} );
+    }
+
+    @Test
+    public void testNoHeader() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl", "--noheader"},
+                             new String[] {},
+                             new String[] {"/\\*\\*.*"} );
+    }
+
+    @Test
+    public void testUCNames() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl", "--uppercase"},
+                             new String[] {".*Resource A.*",".*Resource I.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testInference0() throws Exception {
+        String SOURCE = PREFIX + "ex:p rdfs:domain ex:A .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl"},
+                             new String[] {},
+                             new String[] {".*Resource A.*",".*Property p.*"} );
+    }
+
+    @Test
+    public void testInference1() throws Exception {
+        String SOURCE = PREFIX + "ex:p rdfs:domain ex:A .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl", "--inference"},
+                             new String[] {".*Resource A.*",".*Property p.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testInference2() throws Exception {
+        String SOURCE = PREFIX + "ex:p rdfs:domain ex:A .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--rdfs", "--inference"},
+                             new String[] {".*Resource A.*",".*Property p.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testStrictIndividuals0() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A . <http://example.com/different#j> a ex:A .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--rdfs"},
+                             new String[] {".*Resource i.*",".*Resource j.*"},
+                             new String[] {} );
+    }
+
+    @Test
+    public void testStrictIndividuals1() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A . <http://example.com/different#j> a ex:A .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--rdfs", "--strictIndividuals"},
+                             new String[] {".*Resource i.*"},
+                             new String[] {".*Resource j.*"} );
+    }
+
+    @Test
+    public void testLineEnd0() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A . ex:p a rdf:Property .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--rdfs", "--strictIndividuals"},
+                             new String[] {},
+                             new String[] {".*\r.*"} );
+    }
+
+    @Test
+    public void testLineEnd1() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A . ex:p a rdf:Property .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--rdfs", "--dos"},
+                             new String[] {".*\\r"},
+                             new String[] {".*[^\r]"} );
+    }
+
+    @Test
+    public void testIncludeSource0() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A . ex:p a owl:ObjectProperty .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl", "--includeSource"},
+                             new String[] {".*private static final String SOURCE.*",
+        ".*ex:A *(a|rdf:type) *owl:Class.*"} ,
+                             new String[] {} );
+    }
+
+    @Test
+    public void testIncludeSource1() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class ; rdfs:comment \"comment\".";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl", "--includeSource"},
+                             new String[] {".*\\\\\"comment\\\\\".*\""},
+                             new String[] {} );
+    }
+
+
+    @Test
+    public void testIncludeSource2() throws Exception {
+        // had a report of the following not compiling ....
+        String SOURCE = PREFIX + "@prefix skos: <http://www.w3.org/2004/02/skos/core#>.\n" +
+            " <http://purl.org/dc/elements/1.1/relation> skos:note \"\"\"A second property with the same name as this property has been declared in the dcterms: namespace (http://purl.org/dc/terms/).  See the Introduction to the document \"DCMI Metadata Terms\" (http://dublincore.org/documents/dcmi-terms/) for an explanation.\"\"\".";
+
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--owl", "--includeSource"},
+                             new String[] {},
+                             new String[] {} );
+
+    }
+
+    @Test
+    public void testIncludeSource3() throws Exception {
+        // multiple literals on one line can cause double-quote issues
+        String SOURCE = PREFIX +
+            " ex:foo a ex:Foo; rdfs:label \"thing called foo\"@en, \"le foo\"@fr, \"das foo\"@de. ";
+
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-a", "http://example.com/sg#", "--rdfs", "--includeSource"},
+                             new String[] {},
+                             new String[] {} );
+
+    }
+
+    @Test
+    public void testConfigFile() throws Exception {
+        String SOURCE = PREFIX + "ex:A a owl:Class .";
+        testSchemagenOutput( SOURCE, null,
+                             new String[] {"-c", "testing/cmd/sg-test-config.rdf"},
+                             new String[] {".*OntClass.*"}, // if config is not processed, we will not get --ontology output
+                             new String[] {} );
+
+    }
+
+    // Internal implementation methods
+    //////////////////////////////////
+
+    /**
+     * Test the output from schemagen by saving the output to a string,
+     * then ensuring that every positive regex matches at least one line, and
+     * every negative regex matches at most no lines. Also checks that
+     * compiling the file does not cause any errors.
+     *
+     * @param source String defining the model, using N3
+     * @param sg The schemagen object to test, or null for a default
+     * @param args list of args to pass to SG
+     * @param posPatterns array of regexps that must match at least once in the output
+     * @param negPatterns arrays of regexps that must not match the output
+     * @return The string defining the java class
+     */
+    protected String testSchemagenOutput( String source, SchemaGenAux sg, String[] args,
+                                          String[] posPatterns, String[] negPatterns )
+        throws Exception
+    {
+        Model m = ModelFactory.createDefaultModel();
+        m.read(  new StringReader( source ), "http://example.com/sg#", "N3" );
+        return testSchemagenOutput( m, sg, args, posPatterns, negPatterns );
+    }
+
+    /**
+     * Test the output from schemagen by saving the output to a string,
+     * then ensuring that every positive regex matches at least one line, and
+     * every negative regex matches at most no lines. Also checks that
+     * compiling the file does not cause any errors.
+     *
+     * @param m Source model to read from
+     * @param sg The schemagen object to test, or null for a default
+     * @param args list of args to pass to SG
+     * @param posPatterns array of regexps that must match at least once in the output
+     * @param negPatterns arrays of regexps that must not match the output
+     * @return The string defining the java class
+     */
+    protected String testSchemagenOutput( Model m, SchemaGenAux sg, String[] args,
+                                          String[] posPatterns, String[] negPatterns )
+        throws Exception
+    {
+        sg = (sg == null) ? new SchemaGenAux() : sg;
+        sg.setSource( m );
+
+        ByteArrayOutputStream buf = new ByteArrayOutputStream();
+        sg.setOutput( new PrintStream( buf ) );
+
+        // run schemagen
+        sg.testGo( args );
+
+        // now run the test pattern over the lines in the file
+        String result = buf.toString();
+//        if (log.isDebugEnabled()) {
+//            log.debug(  result );
+//        }
+        StringTokenizer tokens = new StringTokenizer( result, "\n" );
+
+        boolean[] foundPos = new boolean[posPatterns.length];
+
+        // look for any line that matches the patterns
+        while (tokens.hasMoreTokens()) {
+            String line = tokens.nextToken();
+
+            // try each positive pattern
+            for (int i = 0; i < posPatterns.length; i++) {
+                Pattern pat = Pattern.compile( posPatterns[i] );
+                foundPos[i] |= pat.matcher( line ).matches();
+            }
+
+            // try each negative pattern
+            for ( String negPattern : negPatterns )
+            {
+                Pattern pat = Pattern.compile( negPattern );
+                assertFalse( "negative match pattern ||" + negPattern + "|| matched on line: " + line,
+                             pat.matcher( line ).matches() );
+            }
+        }
+
+        for (int i = 0; i < posPatterns.length; i++) {
+            String msg = "Expecting a positive match to pattern: ||" + posPatterns[i] + "||";
+            assertTrue( msg + " in:\n" + result, foundPos[i] );
+        }
+
+        // check that the file compiles with javac
+        testCompile( result, "Sg" );
+
+        return result;
+    }
+
+    /**
+     * Test the compilability of the generated output string by saving it to a
+     * class file, and invoking javac on that file.
+     * @param source
+     * @param className
+     * @throws Exception
+     */
+    protected void testCompile( String source, String defaultClassName )
+        throws Exception
+    {
+        String className = defaultClassName;
+
+        // ensure we use the right class name for the temp file
+        // should do this with a regex, but java Pattern & Matcher is borked
+        String key = "public class ";
+        int i = source.indexOf( key );
+        if (i > 0) {
+            i += key.length();
+            className = source.substring( i, source.indexOf( " ", i ) );
+        }
+
+        // first write the source file to a temp dir
+        File tmpDir = FileUtils.getScratchDirectory( "schemagen" );
+        File srcFile = new File( tmpDir, className + ".java" );
+        try ( FileWriter out = new FileWriter( srcFile ) ) {
+            out.write( source );
+        }
+
+        // now get ready to invoke javac using the new javax.tools package
+        try {
+            Class<?> tp = Class.forName(  "javax.tools.ToolProvider" );
+
+            // static method to get the Java compiler tool
+            Method gsjc = tp.getMethod( "getSystemJavaCompiler" );
+            Object sjc = gsjc.invoke( null );
+
+            // get the run method for the Java compiler tool
+            Class<?> jc = Class.forName( "javax.tools.JavaCompiler" );
+            Method jcRun = jc.getMethod( "run", new Class[] {InputStream.class, OutputStream.class, OutputStream.class, String[].class} );
+
+            if (sjc != null && jcRun != null) {
+                // build the args list for javac
+                String[] args = new String[] {"-classpath", getClassPath( tmpDir ), "-d", tmpDir.getPath(), srcFile.getPath()};
+
+                int success = (Integer) jcRun.invoke( sjc, null, null, null, args );
+                assertEquals( "Errors reported from compilation of schemagen output", 0, success );
+            }
+            else {
+                log.debug( "Could not resolve javax.tools.JavaCompiler.run() method. Is the CLASSPATH defined correctly?" );
+            }
+        }
+        catch (ClassNotFoundException nf) {
+            log.debug( "javax.tools not found (no tools.jar on classpath?). schemagen compilation test skipped." );
+        }
+        catch (Exception e) {
+            log.debug( e.getMessage(), e );
+            fail( e.getMessage() );
+        }
+
+        // clean up
+        List<File> toClean = new ArrayList<>();
+        toClean.add( tmpDir );
+
+        while (!toClean.isEmpty()) {
+            File f = toClean.remove( 0 );
+            f.deleteOnExit();
+
+            if (f.isDirectory()) {
+                for (File g: f.listFiles()) {toClean.add( g );}
+            }
+        }
+    }
+
+    /**
+     * Return the classpath we can use to compile the sg output files
+     * @param tmpDir
+     * @return
+     */
+    protected String getClassPath( File tmpDir ) {
+        Properties pp = System.getProperties();
+        // if we're running under maven, use Special Secret Knowledge to identify the class path
+        // otherwise, default to the CP that Java thinks it's using
+        return pp.getProperty( "surefire.test.class.path", pp.getProperty( "java.class.path" ) );
+    }
+
+    //==============================================================================
+    // Inner class definitions
+    //==============================================================================
+
+    /**
+     * An extension to standard schemagen to create a test fixture; we override the
+     * input and output methods.
+     */
+    static class SchemaGenAux
+        extends schemagen
+    {
+        protected PrintStream m_auxOutput;
+        protected Model m_auxSource;
+        public void setOutput( PrintStream out ) {
+            m_auxOutput = out;
+        }
+        public void setSource( Model m ) {
+            m_auxSource = m;
+        }
+
+        // override the behaviours from schemagen
+        @Override
+        protected void selectInput() {
+            m_source.add( m_auxSource );
+            m_source.setNsPrefixes( m_auxSource );
+        }
+        @Override
+        protected void selectOutput() {
+            // call super to allow option processing
+            super.selectOutput();
+            // then override the result
+            m_output = m_auxOutput;
+        }
+
+        public void testGo( String[] args ) {
+            go( args );
+        }
+
+        @Override
+        protected void go( String[] args ) {
+            go( new SchemagenOptionsFixture( args ) );
+        }
+
+        @Override
+        protected void abort( String msg, Exception e ) {
+            throw new RuntimeException( msg, e );
+        }
+    }
+
+    static class SchemagenOptionsFixture
+        extends SchemagenOptionsImpl
+    {
+
+        public SchemagenOptionsFixture( String[] args ) {
+            super( args );
+        }
+
+        @Override
+        public Resource getInputOption() {
+            return ResourceFactory.createResource( "http://example.org/sg" );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/test/java/jena/cmd/qtest.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/test/java/jena/cmd/qtest.java b/jena-cmds/src/test/java/jena/cmd/qtest.java
new file mode 100644
index 0000000..82abd1d
--- /dev/null
+++ b/jena-cmds/src/test/java/jena/cmd/qtest.java
@@ -0,0 +1,274 @@
+/*
+ * 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 jena.cmd;
+
+import java.io.File ;
+
+import arq.cmdline.CmdARQ ;
+import arq.cmdline.ModEngine ;
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException;
+import jena.cmd.TerminationException;
+import junit.framework.TestSuite ;
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.query.ARQ ;
+import org.apache.jena.rdf.model.Literal ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.rdf.model.Resource ;
+import org.apache.jena.sparql.ARQTestSuite ;
+import org.apache.jena.sparql.expr.E_Function ;
+import org.apache.jena.sparql.expr.NodeValue ;
+import org.apache.jena.sparql.junit.EarlReport ;
+import org.apache.jena.sparql.junit.ScriptTestSuiteFactory ;
+import org.apache.jena.sparql.junit.SimpleTestRunner ;
+import org.apache.jena.sparql.util.NodeFactoryExtra ;
+import org.apache.jena.sparql.vocabulary.DOAP ;
+import org.apache.jena.sparql.vocabulary.FOAF ;
+import org.apache.jena.sparql.vocabulary.TestManifest ;
+import org.apache.jena.vocabulary.DC ;
+import org.apache.jena.vocabulary.DCTerms ;
+import org.apache.jena.vocabulary.RDF ;
+import org.apache.jena.vocabulary.XSD ;
+
+
+/** A program to execute query test suites
+ * 
+ * <pre>
+ * Usage: 
+ *   [--all]
+ *   [--dawg]
+ *   <i>testManifest</i>
+ *   [ --query <i>query</i> --data <i>data</i> --result <i>result</i> ] -- run one test
+ * </pre>
+ */
+
+public class qtest extends CmdARQ
+{
+    protected ArgDecl allDecl =    new ArgDecl(ArgDecl.NoValue, "all") ;
+    protected ArgDecl wgDecl =     new ArgDecl(ArgDecl.NoValue, "wg", "dawg") ;
+    protected ArgDecl queryDecl =  new ArgDecl(ArgDecl.HasValue, "query") ;
+    protected ArgDecl dataDecl =   new ArgDecl(ArgDecl.HasValue, "data") ;
+    protected ArgDecl resultDecl = new ArgDecl(ArgDecl.HasValue, "result") ;
+    protected ArgDecl earlDecl =   new ArgDecl(ArgDecl.NoValue, "earl") ;
+    
+    protected ModEngine modEngine = null ;
+    
+    protected TestSuite suite = null;
+    protected boolean execAllTests = false;
+    protected boolean execDAWGTests = false;
+    protected String testfile = null;
+    protected boolean createEarlReport = false;
+    
+    public static void main (String... argv)
+    {
+        try {
+            new qtest(argv).mainRun() ;
+        }
+        catch (TerminationException ex) { System.exit(ex.getCode()) ; }
+    }
+    
+    public qtest(String[] argv)
+    {
+        super(argv) ;
+        
+        modEngine = setModEngine() ;
+        addModule(modEngine) ;
+        
+        getUsage().startCategory("Tests (single query)") ;
+        add(queryDecl, "--query", "run the given query") ;
+        add(dataDecl, "--data", "data file to be queried") ;
+        add(resultDecl, "--result", "file that specifies the expected result") ;
+        
+        getUsage().startCategory("Tests (built-in tests)") ;
+        add(allDecl, "--all", "run all built-in tests") ;
+        add(wgDecl, "--dawg", "run working group tests") ;
+        
+        getUsage().startCategory("Tests (execute test manifest)") ;
+        getUsage().addUsage("<manifest>", "run the tests specified in the given manifest") ;
+        add(earlDecl, "--earl", "create EARL report") ;
+    }
+    
+    protected ModEngine setModEngine()
+    {
+        return new ModEngine() ;
+    }
+    
+    @Override
+    protected String getCommandName() { return Lib.className(this) ; }
+    
+    @Override
+    protected String getSummary() { return getCommandName()+" [ --data=<file> --query=<query> --result=<results> ] | --all | --dawg | <manifest>" ; }
+    
+    @Override
+    protected void processModulesAndArgs()
+    {
+        super.processModulesAndArgs() ;
+        
+        if ( contains(queryDecl) || contains(dataDecl) || contains(resultDecl) )
+        {
+            if ( ! ( contains(queryDecl) && contains(dataDecl) && contains(resultDecl) ) )
+                throw new CmdException("Must give query, data and result to run a single test") ;
+            
+            String query = getValue(queryDecl) ;
+            String data = getValue(dataDecl) ;
+            String result = getValue(resultDecl) ;
+            
+            suite = ScriptTestSuiteFactory.make(query, data, result) ;
+        }
+        else if ( contains(allDecl) )
+        {
+            execAllTests = true ;
+        }
+        else if ( contains(wgDecl) )
+        {
+            execDAWGTests = true ;
+        }
+        else
+        {
+            // OK - running a manifest
+            
+            if ( ! hasPositional() )
+                throw new CmdException("No manifest file") ;
+
+            testfile = getPositionalArg(0) ;
+            createEarlReport = contains(earlDecl) ;
+        }
+    }
+    
+    @Override
+    protected void exec()
+    {
+        if ( cmdStrictMode )
+            ARQ.setStrictMode() ;
+        
+        if ( suite != null )
+            SimpleTestRunner.runAndReport(suite) ;
+        else if ( execAllTests )
+            allTests() ;
+        else if ( execDAWGTests )
+            dawgTests() ;
+        else
+        {
+            // running a manifest
+            
+            NodeValue.VerboseWarnings = false ;
+            E_Function.WarnOnUnknownFunction = false ;
+            
+            if ( createEarlReport )
+                oneManifestEarl(testfile) ;
+            else
+                oneManifest(testfile) ;
+        }
+    }
+    
+    static void oneManifest(String testManifest)
+    {
+        TestSuite suite = ScriptTestSuiteFactory.make(testManifest) ;
+
+        //junit.textui.TestRunner.run(suite) ;
+        SimpleTestRunner.runAndReport(suite) ;
+    }
+    
+    static void oneManifestEarl(String testManifest)
+    {
+        String name =  "ARQ" ;
+        String releaseName =  "ARQ" ;
+        String version = "2.9.1" ;
+        String homepage = "http://jena.apache.org/" ;
+        String systemURI = "http://jena.apache.org/#arq" ;  // Null for bNode.
+        
+        // Include information later.
+        EarlReport report = new EarlReport(systemURI, name, version, homepage) ;
+        ScriptTestSuiteFactory.results = report ;
+        
+        Model model = report.getModel() ;
+        model.setNsPrefix("dawg", TestManifest.getURI()) ;
+        
+        // Update the EARL report. 
+        Resource jena = model.createResource()
+                    .addProperty(FOAF.homepage, model.createResource("http://jena.apache.org/")) ;
+        
+        // ARQ is part fo Jena.
+        Resource arq = report.getSystem()
+                        .addProperty(DCTerms.isPartOf, jena) ;
+        
+        // Andy wrote the test software (updates the thing being tested as well as they are the same). 
+        Resource who = model.createResource(FOAF.Person)
+                                .addProperty(FOAF.name, "Andy Seaborne")
+                                .addProperty(FOAF.homepage, 
+                                             model.createResource("http://people.apache.org/~andy")) ;
+        
+        Resource reporter = report.getReporter() ;
+        reporter.addProperty(DC.creator, who) ;
+
+        model.setNsPrefix("doap", DOAP.getURI()) ; 
+        model.setNsPrefix("xsd", XSD.getURI()) ;
+        
+        // DAWG specific stuff.
+        Resource system = report.getSystem() ;
+        system.addProperty(RDF.type, DOAP.Project) ;
+        system.addProperty(DOAP.name, name) ;
+        system.addProperty(DOAP.homepage, homepage) ;
+        system.addProperty(DOAP.maintainer, who) ;
+        
+        Resource release = model.createResource(DOAP.Version) ;
+        system.addProperty(DOAP.release, release) ;
+        
+        Node today_node = NodeFactoryExtra.todayAsDate() ;
+        Literal today = model.createTypedLiteral(today_node.getLiteralLexicalForm(), today_node.getLiteralDatatype()) ;
+        release.addProperty(DOAP.created, today) ;
+        release.addProperty(DOAP.name, releaseName) ;      // Again
+        
+        TestSuite suite = ScriptTestSuiteFactory.make(testManifest) ;
+        SimpleTestRunner.runSilent(suite) ;
+        
+        ScriptTestSuiteFactory.results.getModel().write(System.out, "TTL") ;
+        
+    }
+    
+    static void allTests()
+    {
+        // This should load all the built in tests.
+        // Check to see if expected directories are present or not.
+        
+        ensureDirExists("testing") ;
+        ensureDirExists("testing/ARQ") ;
+        ensureDirExists("testing/DAWG") ;
+        
+        TestSuite ts = ARQTestSuite.suite() ;
+        junit.textui.TestRunner.run(ts) ;
+        //SimpleTestRunner.runAndReport(ts) ;
+    }
+
+    static void dawgTests()
+    {
+        System.err.println("DAWG tests not packaged up yet") ;
+    }
+    
+    static void ensureDirExists(String dirname)
+    {
+        File f = new File(dirname) ;
+        if ( ! f.exists() || !f.isDirectory() )
+        {
+            System.err.println("Can't find required directory: '"+dirname+"'") ;
+            throw new TerminationException(8) ;
+        }
+    }
+ }

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/test/java/riotcmd/rdflangtest.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/test/java/riotcmd/rdflangtest.java b/jena-cmds/src/test/java/riotcmd/rdflangtest.java
new file mode 100644
index 0000000..1f5af3b
--- /dev/null
+++ b/jena-cmds/src/test/java/riotcmd/rdflangtest.java
@@ -0,0 +1,213 @@
+/*
+ * 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 riotcmd;
+
+import arq.cmdline.ModEngine ;
+import arq.cmdline.ModContext ;
+import jena.cmd.ArgDecl ;
+import jena.cmd.CmdException ;
+import jena.cmd.CmdGeneral ;
+import jena.cmd.TerminationException ;
+import junit.framework.TestSuite ;
+import org.apache.jena.atlas.legacy.BaseTest2 ;
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.query.ARQ ;
+import org.apache.jena.rdf.model.Literal ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.rdf.model.Resource ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFDataMgr ;
+import org.apache.jena.riot.langsuite.FactoryTestRiot ;
+import org.apache.jena.riot.langsuite.VocabLangRDF ;
+import org.apache.jena.sparql.expr.E_Function ;
+import org.apache.jena.sparql.expr.NodeValue ;
+import org.apache.jena.sparql.junit.EarlReport ;
+import org.apache.jena.sparql.junit.SimpleTestRunner ;
+import org.apache.jena.sparql.util.NodeFactoryExtra ;
+import org.apache.jena.sparql.vocabulary.DOAP ;
+import org.apache.jena.sparql.vocabulary.FOAF ;
+import org.apache.jena.system.JenaSystem ;
+import org.apache.jena.vocabulary.DC ;
+import org.apache.jena.vocabulary.DCTerms ;
+import org.apache.jena.vocabulary.RDF ;
+
+/** A program to execute RDF language test suites
+ * 
+ * <pre>
+ * Usage: 
+ *   [--all]
+ *   <i>testManifest</i>
+ *   [ --query <i>query</i> --data <i>data</i> --result <i>result</i> ] -- run one test
+ * </pre>
+ */
+
+public class rdflangtest extends CmdGeneral
+{
+    static { JenaSystem.init() ; }
+    protected ModContext modContext     = new ModContext() ;
+    protected ArgDecl  strictDecl       = new ArgDecl(ArgDecl.NoValue, "strict") ;
+    protected boolean  cmdStrictMode    = false ; 
+
+    //protected ArgDecl allDecl =    new ArgDecl(ArgDecl.NoValue, "all") ;
+    protected ArgDecl earlDecl          = new ArgDecl(ArgDecl.NoValue, "earl") ;
+    
+    protected boolean createEarlReport = false;
+    
+    public static void main (String... argv)
+    {
+        try { new rdflangtest(argv).mainRun() ; }
+        catch (TerminationException ex) { System.exit(ex.getCode()) ; }
+    }
+    
+    public rdflangtest(String[] argv)
+    {
+        super(argv) ;
+        super.add(strictDecl, "--strict", "Operate in strict mode (no extensions of any kind)") ;
+        super.modVersion.addClass(ARQ.class) ;
+        //add(allDecl, "--all", "run all tests") ;
+        getUsage().startCategory("Tests (execute test manifest)") ;
+        getUsage().addUsage("<manifest>", "run the tests specified in the given manifest") ;
+        add(earlDecl, "--earl", "create EARL report") ;
+        addModule(modContext) ;
+    }
+    
+    protected ModEngine setModEngine()
+    {
+        return new ModEngine() ;
+    }
+    
+    @Override
+    protected String getCommandName() { return Lib.className(this) ; }
+    
+    @Override
+    protected String getSummary() { return getCommandName()+" <manifest>" ; }
+    
+    @Override
+    protected void processModulesAndArgs()
+    {
+        if ( ! hasPositional() )
+            throw new CmdException("No manifest file") ;
+        createEarlReport = contains(earlDecl) ;
+    }
+    
+    @Override
+    protected void exec()
+    {
+        // Paradoxical naming - the boolean is a visibility flag.
+        BaseTest2.setTestLogging() ;
+        
+//        if ( contains(strictDecl) ) {
+//            // Always done in test setups.
+//            cmdStrictMode = true ;
+//            // Which will apply to reading the manifest!
+//            ARQ.setStrictMode() ;
+//            SysRIOT.setStrictMode(true) ;
+//        }
+        
+        NodeValue.VerboseWarnings = false ;
+        E_Function.WarnOnUnknownFunction = false ;
+        
+        for ( String fn : getPositional() )
+            exec1(fn) ;
+    }
+    
+    protected void exec1(String manifest)
+    {
+        if ( createEarlReport )
+            oneManifestEarl(manifest) ;
+        else
+            oneManifest(manifest) ;
+    }
+
+    static void oneManifest(String testManifest)
+    {
+        TestSuite suite = FactoryTestRiot.make(testManifest, null, null) ;
+
+        //junit.textui.TestRunner.run(suite) ;
+        SimpleTestRunner.runAndReport(suite) ;
+    }
+    
+    static String name =  "Apache Jena RIOT" ;
+    static String releaseName =  "RIOT" ;
+    //static String version = RIOT.getVersion() ;  // Can be "development"
+    static String version = null ;
+    static String homepage = "http://jena.apache.org/" ;
+    static String systemURI = "http://jena.apache.org/#riot" ;  // Null for bNode.
+
+    static void oneManifestEarl(String testManifest)
+    {
+        EarlReport report = new EarlReport(systemURI, name, version, homepage) ;
+        FactoryTestRiot.report = report ;
+        TestSuite suite = FactoryTestRiot.make(testManifest, null, null) ;
+        SimpleTestRunner.runSilent(suite) ;
+
+        Model model = report.getModel() ;
+        model.setNsPrefix("rdft", VocabLangRDF.getURI()) ;
+        model.setNsPrefix("turtletest", "http://www.w3.org/2013/TurtleTests/manifest.ttl#") ;
+        insertMetaOld(report) ;
+        RDFDataMgr.write(System.out, model, Lang.TURTLE) ;
+    }
+    
+    static void insertMeta(EarlReport report) {
+        Model model = report.getModel() ;
+        // We add the meta by hand separatly for better layout later 
+    }
+    
+    //OLD meta.
+    static void insertMetaOld(EarlReport report) {
+        Model model = report.getModel() ;
+        /*
+        <> foaf:primaryTopic <http://jena.apache.org/#riot> ;
+            dc:issued "..."^^xsd:dateTime;
+            foaf:maker who.
+        */
+        
+        // Update the EARL report. 
+        Resource jena = model.createResource()
+                    .addProperty(FOAF.homepage, model.createResource("http://jena.apache.org/")) ;
+        
+        // ARQ is part of Jena.
+        Resource arq = report.getSystem()
+                        .addProperty(DCTerms.isPartOf, jena) ;
+        
+        // Andy wrote the test software (updates the thing being tested as well as they are the same). 
+        Resource who = model.createResource(FOAF.Person)
+                                .addProperty(FOAF.name, "Andy Seaborne")
+                                .addProperty(FOAF.homepage, 
+                                             model.createResource("http://people.apache.org/~andy")) ;
+        
+        Resource reporter = report.getReporter() ;
+        reporter.addProperty(DC.creator, who) ;
+
+        Resource system = report.getSystem() ;
+        system.addProperty(RDF.type, DOAP.Project) ;
+        system.addProperty(DOAP.name, name) ;
+        system.addProperty(DOAP.homepage, homepage) ;
+        system.addProperty(DOAP.maintainer, who) ;
+        
+        Resource release = model.createResource(DOAP.Version) ;
+        system.addProperty(DOAP.release, release) ;
+        
+        Node today_node = NodeFactoryExtra.todayAsDate() ;
+        Literal today = model.createTypedLiteral(today_node.getLiteralLexicalForm(), today_node.getLiteralDatatype()) ;
+        release.addProperty(DOAP.created, today) ;
+        release.addProperty(DOAP.name, releaseName) ;      // Again
+    }
+ }

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/testing/cmd/README_LICENSE
----------------------------------------------------------------------
diff --git a/jena-cmds/testing/cmd/README_LICENSE b/jena-cmds/testing/cmd/README_LICENSE
new file mode 100644
index 0000000..bb80806
--- /dev/null
+++ b/jena-cmds/testing/cmd/README_LICENSE
@@ -0,0 +1,16 @@
+The following statement applied to all files in this directory unless otherwise noted:
+
+   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.

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/testing/cmd/rdfcat.n3
----------------------------------------------------------------------
diff --git a/jena-cmds/testing/cmd/rdfcat.n3 b/jena-cmds/testing/cmd/rdfcat.n3
new file mode 100644
index 0000000..e3ae5fb
--- /dev/null
+++ b/jena-cmds/testing/cmd/rdfcat.n3
@@ -0,0 +1,18 @@
+@prefix rdf:        <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs:	    <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix jms:        <http://jena.hpl.hp.com/2003/08/jms#> .
+@prefix dc:         <http://purl.org/dc/elements/1.1/> .
+
+jms:MakerSpec           rdf:type     rdfs:Class .
+jms:FileMakerSpec       rdf:type     rdfs:Class .
+jms:MemMakerSpec        rdf:type     rdfs:Class .
+jms:RDBMakerSpec        rdf:type     rdfs:Class .
+jms:ModelSpec           rdf:type     rdfs:Class .
+jms:PlainModelSpec      rdf:type     rdfs:Class .
+jms:InfModelSpec        rdf:type     rdfs:Class .
+jms:OntModelSpec        rdf:type     rdfs:Class .
+
+jms:MemMakerSpec        rdfs:subClassOf     jms:MakerSpec .
+jms:FileMakerSpec       rdfs:subClassOf     jms:MakerSpec .
+jms:RDBMakerSpec        rdfs:subClassOf     jms:MakerSpec .
+        

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/testing/cmd/rdfcat.nt
----------------------------------------------------------------------
diff --git a/jena-cmds/testing/cmd/rdfcat.nt b/jena-cmds/testing/cmd/rdfcat.nt
new file mode 100644
index 0000000..39d1562
--- /dev/null
+++ b/jena-cmds/testing/cmd/rdfcat.nt
@@ -0,0 +1,11 @@
+<http://jena.hpl.hp.com/2003/08/jms#MemMakerSpec> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
+<http://jena.hpl.hp.com/2003/08/jms#MemMakerSpec> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://jena.hpl.hp.com/2003/08/jms#MakerSpec> .
+<http://jena.hpl.hp.com/2003/08/jms#FileMakerSpec> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
+<http://jena.hpl.hp.com/2003/08/jms#FileMakerSpec> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://jena.hpl.hp.com/2003/08/jms#MakerSpec> .
+<http://jena.hpl.hp.com/2003/08/jms#PlainModelSpec> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
+<http://jena.hpl.hp.com/2003/08/jms#OntModelSpec> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
+<http://jena.hpl.hp.com/2003/08/jms#ModelSpec> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
+<http://jena.hpl.hp.com/2003/08/jms#MakerSpec> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
+<http://jena.hpl.hp.com/2003/08/jms#InfModelSpec> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
+<http://jena.hpl.hp.com/2003/08/jms#RDBMakerSpec> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
+<http://jena.hpl.hp.com/2003/08/jms#RDBMakerSpec> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://jena.hpl.hp.com/2003/08/jms#MakerSpec> .

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/testing/cmd/rdfcat.xml
----------------------------------------------------------------------
diff --git a/jena-cmds/testing/cmd/rdfcat.xml b/jena-cmds/testing/cmd/rdfcat.xml
new file mode 100644
index 0000000..15fe7b2
--- /dev/null
+++ b/jena-cmds/testing/cmd/rdfcat.xml
@@ -0,0 +1,20 @@
+<rdf:RDF
+    xmlns:jms="http://jena.hpl.hp.com/2003/08/jms#"
+    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+    xmlns:dc="http://purl.org/dc/elements/1.1/">
+  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#InfModelSpec"/>
+  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#OntModelSpec"/>
+  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#PlainModelSpec"/>
+  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#MakerSpec"/>
+  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#RDBMakerSpec">
+    <rdfs:subClassOf rdf:resource="http://jena.hpl.hp.com/2003/08/jms#MakerSpec"/>
+  </rdfs:Class>
+  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#FileMakerSpec">
+    <rdfs:subClassOf rdf:resource="http://jena.hpl.hp.com/2003/08/jms#MakerSpec"/>
+  </rdfs:Class>
+  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#ModelSpec"/>
+  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#MemMakerSpec">
+    <rdfs:subClassOf rdf:resource="http://jena.hpl.hp.com/2003/08/jms#MakerSpec"/>
+  </rdfs:Class>
+</rdf:RDF>

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/testing/cmd/rdfcat_1.xml
----------------------------------------------------------------------
diff --git a/jena-cmds/testing/cmd/rdfcat_1.xml b/jena-cmds/testing/cmd/rdfcat_1.xml
new file mode 100644
index 0000000..8cf143f
--- /dev/null
+++ b/jena-cmds/testing/cmd/rdfcat_1.xml
@@ -0,0 +1,10 @@
+<rdf:RDF
+    xmlns:jms="http://jena.hpl.hp.com/2003/08/jms#"
+    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+    xmlns:dc="http://purl.org/dc/elements/1.1/">
+  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#InfModelSpec"/>
+  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#OntModelSpec"/>
+  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#PlainModelSpec"/>
+  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#MakerSpec"/>
+</rdf:RDF>

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/testing/cmd/rdfcat_1_n3
----------------------------------------------------------------------
diff --git a/jena-cmds/testing/cmd/rdfcat_1_n3 b/jena-cmds/testing/cmd/rdfcat_1_n3
new file mode 100644
index 0000000..bc9ccc9
--- /dev/null
+++ b/jena-cmds/testing/cmd/rdfcat_1_n3
@@ -0,0 +1,17 @@
+@prefix dc:      <http://purl.org/dc/elements/1.1/> .
+@prefix jms:     <http://jena.hpl.hp.com/2003/08/jms#> .
+@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix :        <#> .
+
+jms:InfModelSpec
+      a       rdfs:Class .
+
+jms:OntModelSpec
+      a       rdfs:Class .
+
+jms:MakerSpec
+      a       rdfs:Class .
+
+jms:PlainModelSpec
+      a       rdfs:Class .

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/testing/cmd/rdfcat_2.xml
----------------------------------------------------------------------
diff --git a/jena-cmds/testing/cmd/rdfcat_2.xml b/jena-cmds/testing/cmd/rdfcat_2.xml
new file mode 100644
index 0000000..137c092
--- /dev/null
+++ b/jena-cmds/testing/cmd/rdfcat_2.xml
@@ -0,0 +1,16 @@
+<rdf:RDF
+    xmlns:jms="http://jena.hpl.hp.com/2003/08/jms#"
+    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+    xmlns:dc="http://purl.org/dc/elements/1.1/">
+  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#RDBMakerSpec">
+    <rdfs:subClassOf rdf:resource="http://jena.hpl.hp.com/2003/08/jms#MakerSpec"/>
+  </rdfs:Class>
+  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#FileMakerSpec">
+    <rdfs:subClassOf rdf:resource="http://jena.hpl.hp.com/2003/08/jms#MakerSpec"/>
+  </rdfs:Class>
+  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#ModelSpec"/>
+  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#MemMakerSpec">
+    <rdfs:subClassOf rdf:resource="http://jena.hpl.hp.com/2003/08/jms#MakerSpec"/>
+  </rdfs:Class>
+</rdf:RDF>

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/testing/cmd/rdfcat_2_n3
----------------------------------------------------------------------
diff --git a/jena-cmds/testing/cmd/rdfcat_2_n3 b/jena-cmds/testing/cmd/rdfcat_2_n3
new file mode 100644
index 0000000..fc284d2
--- /dev/null
+++ b/jena-cmds/testing/cmd/rdfcat_2_n3
@@ -0,0 +1,20 @@
+@prefix dc:      <http://purl.org/dc/elements/1.1/> .
+@prefix jms:     <http://jena.hpl.hp.com/2003/08/jms#> .
+@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix :        <#> .
+
+jms:RDBMakerSpec
+      a       rdfs:Class ;
+      rdfs:subClassOf jms:MakerSpec .
+
+jms:FileMakerSpec
+      a       rdfs:Class ;
+      rdfs:subClassOf jms:MakerSpec .
+
+jms:ModelSpec
+      a       rdfs:Class .
+
+jms:MemMakerSpec
+      a       rdfs:Class ;
+      rdfs:subClassOf jms:MakerSpec .

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/testing/cmd/sg-test-config.rdf
----------------------------------------------------------------------
diff --git a/jena-cmds/testing/cmd/sg-test-config.rdf b/jena-cmds/testing/cmd/sg-test-config.rdf
new file mode 100644
index 0000000..df7adb7
--- /dev/null
+++ b/jena-cmds/testing/cmd/sg-test-config.rdf
@@ -0,0 +1,23 @@
+<?xml version='1.0'?>
+
+<!DOCTYPE rdf:RDF [
+    <!ENTITY jena    'http://jena.hpl.hp.com/'>
+
+    <!ENTITY rdf     'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
+    <!ENTITY rdfs    'http://www.w3.org/2000/01/rdf-schema#'>
+    <!ENTITY owl     'http://www.w3.org/2002/07/owl#'>
+    <!ENTITY xsd     'http://www.w3.org/2001/XMLSchema#'>
+    <!ENTITY base    '&jena;2003/04/schemagen'>
+    <!ENTITY sgen    '&base;#'>
+]>
+
+<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:owl="http://www.w3.org/2002/07/owl#"
+  xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:sgen="http://jena.hpl.hp.com/2003/04/schemagen#">
+
+  <sgen:Config>
+    <!-- specifies that the source document uses OWL -->
+    <sgen:owl rdf:datatype="&xsd;boolean">true</sgen:owl>
+    <!-- specifies that we want the generated vocab to use OntClass, OntProperty, etc, not Resource and Property -->
+    <sgen:ontology rdf:datatype="&xsd;boolean">true</sgen:ontology>
+  </sgen:Config>
+</rdf:RDF>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/main/java/jena/InvokingUtil.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/jena/InvokingUtil.java b/jena-core/src/main/java/jena/InvokingUtil.java
deleted file mode 100644
index 85b5ca8..0000000
--- a/jena-core/src/main/java/jena/InvokingUtil.java
+++ /dev/null
@@ -1,66 +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 jena;
-
-import java.lang.reflect.InvocationTargetException ;
-import java.lang.reflect.Method ;
-
-public class InvokingUtil
-{
-    public static void invokeCmd(String className, String[] args)
-    {
-        Class<?> cmd = null ;
-        try { cmd = Class.forName(className) ; }
-        catch (ClassNotFoundException ex)
-        {
-            System.err.println("Class '"+className+"' not found") ;
-            System.exit(1) ;
-        }
-        
-        Method method = null ;
-        try { method = cmd.getMethod("main", new Class[]{String[].class}) ; }
-        catch (NoSuchMethodException ex)
-        {
-            System.err.println("'main' not found but the class '"+className+"' was") ;
-            System.exit(1) ;
-        }
-        
-        try 
-        {
-            method.invoke(null, new Object[]{args}) ;
-            return ;
-        } catch (IllegalArgumentException ex)
-        {
-            System.err.println("IllegalArgumentException exception: "+ex.getMessage());
-            System.exit(7) ;
-        } catch (IllegalAccessException ex)
-        {
-            System.err.println("IllegalAccessException exception: "+ex.getMessage());
-            System.exit(8) ;
-        } catch (InvocationTargetException ex)
-        {
-            System.err.println("InvocationTargetException exception: "+ex.getMessage());
-            System.exit(9) ;
-        }
-
-        
-        //arq.query.main(args) ;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/main/java/jena/RuleMap.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/jena/RuleMap.java b/jena-core/src/main/java/jena/RuleMap.java
deleted file mode 100644
index 111f44b..0000000
--- a/jena-core/src/main/java/jena/RuleMap.java
+++ /dev/null
@@ -1,196 +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 jena;
-
-
-import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
-
-import java.util.*;
-import java.io.*;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.DefaultParser;
-import org.apache.commons.cli.Options;
-import org.apache.jena.graph.* ;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.reasoner.Reasoner ;
-import org.apache.jena.reasoner.rulesys.* ;
-import org.apache.jena.reasoner.rulesys.builtins.BaseBuiltin ;
-import org.apache.jena.util.FileManager ;
-import org.apache.jena.util.FileUtils ;
-
-/**
- * General command line utility to process one RDF file into another
- * by application of a set of forward chaining rules.
- * <pre>
- * Usage:  RuleMap [-il inlang] [-ol outlang] [-d] rulefile infile
- * </pre>
- * The resulting RDF data is written to stdout in format <code>outlang</code>
- * (default N3). If <code>-d</code> is given then only the deductions
- * generated by the rules are output. Otherwise all data including any input
- * data (other than any removed triples) is output.
- * <p>
- * Rules are permitted an additional action "deduce" which forces triples
- * to be added to the deductions graph even if they are already known (for use
- * in deductions only mode). 
- * </p>
- */
-public class RuleMap {
-    static { setCmdLogging() ; }
-    
-    /**
-     * Load a set of rule definitions including processing of
-     * comment lines and any initial prefix definition lines.
-     * Also notes the prefix definitions for adding to a later inf model.
-     */
-    public static List<Rule> loadRules(String filename, Map<String, String> prefixes) {
-        String fname = filename;
-        if (fname.startsWith("file:///")) {
-            fname = File.separator + fname.substring(8);
-        } else if (fname.startsWith("file:/")) {
-            fname = File.separator + fname.substring(6);
-        } else if (fname.startsWith("file:")) {
-            fname = fname.substring(5);
-        }
-
-        BufferedReader src = FileUtils.openResourceFile(fname);
-        return loadRules(src, prefixes);
-    }
-    
-    /**
-     * Load a set of rule definitions including processing of
-     * comment lines and any initial prefix definition lines.
-     * Also notes the prefix definitions for adding to a later inf model.
-     */
-    public static List<Rule> loadRules(BufferedReader src, Map<String, String> prefixes) {
-        Rule.Parser parser = Rule.rulesParserFromReader(src);
-        List<Rule> rules = Rule.parseRules(parser);
-        prefixes.putAll(parser.getPrefixMap());
-        return rules;
-    }
-    
-    /**
-     * Internal implementation of the "deduce" primitve.
-     * This takes the form <code> ... -> deduce(s, p, o)</code>
-     */
-    static class Deduce extends BaseBuiltin {
-
-        /**
-         * Return a name for this builtin, normally this will be the name of the 
-         * functor that will be used to invoke it.
-         */
-        @Override
-        public String getName() {
-            return "deduce";
-        }    
-   
-        /**
-         * Return the expected number of arguments for this functor or 0 if the number is flexible.
-         */
-        @Override
-        public int getArgLength() {
-            return 3;
-        }
-
-        /**
-         * This method is invoked when the builtin is called in a rule head.
-         * Such a use is only valid in a forward rule.
-         * @param args the array of argument values for the builtin, this is an array 
-         * of Nodes.
-         * @param length the length of the argument list, may be less than the length of the args array
-         * for some rule engines
-         * @param context an execution context giving access to other relevant data
-         */
-        @Override
-        public void headAction(Node[] args, int length, RuleContext context) {
-            if (context.getGraph() instanceof FBRuleInfGraph) {
-                Triple t = new Triple(args[0], args[1], args[2]);
-                ((FBRuleInfGraph)context.getGraph()).addDeduction(t);
-            } else {
-                throw new BuiltinException(this, context, "Only usable in FBrule graphs");
-            }
-        }
-    }
-    
-    /**
-     * General command line utility to process one RDF file into another
-     * by application of a set of forward chaining rules. 
-     * <pre>
-     * Usage:  RuleMap [-il inlang] [-ol outlang] -d infile rulefile
-     * </pre>
-     */
-    public static void main(String[] args) {
-    	try {
-
-            // Parse the command line
-            String usage = "Usage:  RuleMap [-il inlang] [-ol outlang] [-d] rulefile infile (- for stdin)"; 
-            final CommandLineParser parser = new DefaultParser();
-			Options options = new Options().addOption("il", "inputLang", true, "input language")
-					.addOption("ol", "outputLang", true, "output language").addOption("d", "Deductions only?");
-			CommandLine cl = parser.parse(options, args);
-			final List<String> filenameArgs = cl.getArgList();
-            if (filenameArgs.size() != 2) {
-                System.err.println(usage);
-                System.exit(1);
-            }
-            
-            String inLang = cl.getOptionValue("inputLang");
-            String fname = filenameArgs.get(1);
-            Model inModel = null;
-            if (fname.equals("-")) {
-                inModel = ModelFactory.createDefaultModel();
-                inModel.read(System.in, null, inLang);
-            } else {
-                inModel = FileManager.get().loadModel(fname, inLang);
-            }
-            
-            String outLang = cl.hasOption("outputLang") ? cl.getOptionValue("outputLang") : "N3";            
-            
-            boolean deductionsOnly = cl.hasOption('d');
-            
-            // Fetch the rule set and create the reasoner
-            BuiltinRegistry.theRegistry.register(new Deduce());
-            Map<String, String> prefixes = new HashMap<>();
-            List<Rule> rules = loadRules(filenameArgs.get(0), prefixes);
-            Reasoner reasoner = new GenericRuleReasoner(rules);
-            
-            // Process
-            InfModel infModel = ModelFactory.createInfModel(reasoner, inModel);
-            infModel.prepare();
-            infModel.setNsPrefixes(prefixes);
-            
-            // Output
-            try ( PrintWriter writer = new PrintWriter(System.out) ) {
-                if (deductionsOnly) {
-                    Model deductions = infModel.getDeductionsModel();
-                    deductions.setNsPrefixes(prefixes);
-                    deductions.setNsPrefixes(inModel);
-                    deductions.write(writer, outLang);
-                } else {
-                    infModel.write(writer, outLang);
-                }
-            }
-        } catch (Throwable t) {
-            System.err.println("An error occured: \n" + t);
-            t.printStackTrace();
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/main/java/jena/package.html
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/jena/package.html b/jena-core/src/main/java/jena/package.html
deleted file mode 100644
index b0db285..0000000
--- a/jena-core/src/main/java/jena/package.html
+++ /dev/null
@@ -1,34 +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.
--->
-
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
-<head>
-</head>
- <body>
-<p>A package for some Jena command-line programs, including
-<ul>
-<li>copying RDF data with representation conversion, eg XML to N3
-<li>comparing two RDF files for isomorphism (extended equality)
-<li>an interface to the ARP RDF parser
-<li>access to the RDQL interpreter
-<li>a schema-to-Java generator
-</ul>
-</p>
-</body>
-</html>

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/main/java/jena/qtest.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/jena/qtest.java b/jena-core/src/main/java/jena/qtest.java
deleted file mode 100644
index 5d5137b..0000000
--- a/jena-core/src/main/java/jena/qtest.java
+++ /dev/null
@@ -1,29 +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 jena;
-
-
-public class qtest
-{
-    // Call-through to arq command line application
-    public static void main(String[] args)
-    {
-        InvokingUtil.invokeCmd("arq.qtest",args) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/main/java/jena/query.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/jena/query.java b/jena-core/src/main/java/jena/query.java
deleted file mode 100644
index 1d0c431..0000000
--- a/jena-core/src/main/java/jena/query.java
+++ /dev/null
@@ -1,33 +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 jena;
-
-
-
-public class query
-{
-    // Call-through to arq command line application
-    public static void main(String... args)
-    {
-        // Do this by reflection so it is not assumed that ARQ is available
-        // at compile time.
-        
-        InvokingUtil.invokeCmd("arq.query", args) ;
-    }
-}


[10/20] jena git commit: JENA-1108 : jena-cmds module

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/turtle.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/turtle.java b/jena-cmds/src/main/java/jena/turtle.java
new file mode 100644
index 0000000..8f3935b
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/turtle.java
@@ -0,0 +1,25 @@
+/*
+ * 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 jena;
+
+public class turtle {
+    public static void main(String... args) {
+        riotcmd.turtle.main(args);
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/version.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/version.java b/jena-cmds/src/main/java/jena/version.java
new file mode 100644
index 0000000..ea47d66
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/version.java
@@ -0,0 +1,49 @@
+/*
+ * 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 jena;
+
+import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
+
+import java.lang.reflect.*;
+
+import org.apache.jena.Jena ;
+
+/**
+ * jena.version
+ * Print out jena version information and exit.
+ */
+public class version implements Jena {
+
+    static { setCmdLogging(); }
+
+    /**
+	 * Print out jena version information and exit.
+	 * @param args
+	 * @throws IllegalAccessException 
+	 * @throws IllegalArgumentException 
+	 */
+	public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException {
+		Field f[] = Jena.class.getDeclaredFields();
+        for ( Field aF : f )
+        {
+            System.out.println( aF.getName() + ": " + aF.get( null ) );
+        }
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/riotcmd/CmdLangParse.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/riotcmd/CmdLangParse.java b/jena-cmds/src/main/java/riotcmd/CmdLangParse.java
new file mode 100644
index 0000000..61f3b96
--- /dev/null
+++ b/jena-cmds/src/main/java/riotcmd/CmdLangParse.java
@@ -0,0 +1,361 @@
+/*
+ * 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 riotcmd;
+
+import java.io.IOException ;
+import java.io.InputStream ;
+import java.io.OutputStream ;
+import java.util.zip.GZIPOutputStream ;
+
+import arq.cmdline.ModLangOutput ;
+import arq.cmdline.ModLangParse ;
+import arq.cmdline.ModContext ;
+import arq.cmdline.ModTime ;
+import jena.cmd.ArgDecl ;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral ;
+import org.apache.jena.Jena ;
+import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.lib.InternalErrorException ;
+import org.apache.jena.atlas.lib.Pair ;
+import org.apache.jena.atlas.web.ContentType ;
+import org.apache.jena.atlas.web.TypedInputStream ;
+import org.apache.jena.query.ARQ ;
+import org.apache.jena.riot.* ;
+import org.apache.jena.riot.lang.LabelToNode ;
+import org.apache.jena.riot.lang.StreamRDFCounting ;
+import org.apache.jena.riot.out.NodeToLabel ;
+import org.apache.jena.riot.process.inf.InfFactory ;
+import org.apache.jena.riot.process.inf.InferenceSetupRDFS ;
+import org.apache.jena.riot.system.* ;
+import org.apache.jena.riot.tokens.Tokenizer ;
+import org.apache.jena.riot.tokens.TokenizerFactory ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.sparql.core.DatasetGraphFactory ;
+import org.apache.jena.system.JenaSystem ;
+
+/** Common framework for running RIOT parsers */
+public abstract class CmdLangParse extends CmdGeneral
+{
+    static { JenaSystem.init(); }
+    protected ModTime modTime                   = new ModTime() ;
+    protected ModLangParse modLangParse         = new ModLangParse() ;
+    protected ModLangOutput modLangOutput       = new ModLangOutput() ;
+    protected InferenceSetupRDFS setup          = null ; 
+    protected ModContext modContext             = new ModContext() ;
+    protected ArgDecl strictDecl                = new ArgDecl(ArgDecl.NoValue, "strict") ;
+
+    protected boolean cmdStrictMode = false ; 
+    
+    interface LangHandler {
+        String getItemsName() ;
+        String getRateName() ;
+    }
+
+    static LangHandler langHandlerQuads = new LangHandler() {
+        @Override
+        public String getItemsName()        { return "quads" ; }
+        @Override
+        public String getRateName()         { return "QPS" ; }
+    } ;
+    static LangHandler langHandlerTriples = new LangHandler() {
+        @Override
+        public String getItemsName()        { return "triples" ; }
+        @Override
+        public String getRateName()         { return "TPS" ; }
+    } ;
+    static LangHandler langHandlerAny = new LangHandler() {
+        @Override
+        public String getItemsName()        { return "tuples" ; }
+        @Override
+        public String getRateName()         { return "TPS" ; }
+    } ;
+    
+    protected LangHandler langHandlerOverall = null ;
+
+    protected CmdLangParse(String[] argv)
+    {
+        super(argv) ;
+        addModule(modContext) ;
+        addModule(modTime) ;
+        addModule(modLangOutput) ;
+        addModule(modLangParse) ;
+        
+        super.modVersion.addClass(Jena.class) ;
+        // Force - sometimes initialization does not cause these
+        // to initialized early enough for reflection.
+        String x1 = ARQ.VERSION ;
+        String x2 = ARQ.BUILD_DATE ;
+        super.modVersion.addClass(RIOT.class) ;
+        
+    }
+
+    @Override
+    protected String getSummary() {
+        return getCommandName()+" [--time] [--check|--noCheck] [--sink] [--base=IRI] [--out=FORMAT] [--compress] file ..." ;
+    }
+
+    protected long totalMillis = 0 ; 
+    protected long totalTuples = 0 ; 
+    
+    OutputStream output = System.out ;
+    StreamRDF outputStream = null ;
+
+    @Override
+    protected void processModulesAndArgs() {
+        cmdStrictMode = super.contains(strictDecl) ;
+    }
+    
+    protected interface PostParseHandler { void postParse(); }
+    
+    @Override
+    protected void exec() {
+        boolean oldStrictValue = SysRIOT.isStrictMode() ;
+        if ( modLangParse.strictMode() )
+            SysRIOT.setStrictMode(true) ;
+        try { exec$() ; }
+        finally { SysRIOT.setStrictMode(oldStrictValue) ; } 
+    }
+    
+    protected void exec$() {
+        
+        if ( modLangParse.getRDFSVocab() != null )
+            setup = new InferenceSetupRDFS(modLangParse.getRDFSVocab()) ;
+     
+        if ( modLangOutput.compressedOutput() ) {
+            try { output = new GZIPOutputStream(output, true) ; }
+            catch (IOException e) { IO.exception(e);}
+        }
+            
+        outputStream = null ;
+        PostParseHandler postParse = null ;
+
+        outputStream = createStreamSink() ;
+        if ( outputStream == null ) {
+            Pair<StreamRDF, PostParseHandler> p = createAccumulateSink() ;
+            outputStream = p.getLeft() ;
+            postParse = p.getRight();
+        }
+        
+        try {
+            if ( super.getPositional().isEmpty() )
+                parseFile("-");
+            else {
+                boolean b = super.getPositional().size() > 1;
+                for ( String fn : super.getPositional() ) {
+                    if ( b && !super.isQuiet() )
+                        SysRIOT.getLogger().info("File: " + fn);
+                    parseFile(fn);
+                }
+            }
+            if ( postParse != null )
+                postParse.postParse();
+            if ( super.getPositional().size() > 1 && modTime.timingEnabled() )
+                output("Total", totalTuples, totalMillis, langHandlerOverall) ;
+        } finally {
+            if ( output != System.out )
+                IO.close(output) ;
+            else
+                IO.flush(output);    
+            System.err.flush() ;
+        }
+    }
+    
+    public void parseFile(String filename) {
+        TypedInputStream in = null ;
+        if ( filename.equals("-") ) {
+            in = new TypedInputStream(System.in) ;
+            parseFile("http://base/", "stdin", in) ;
+        } else {
+            try {
+                in = RDFDataMgr.open(filename) ;
+            } catch (Exception ex) {
+                System.err.println("Can't open '"+filename+"' "+ex.getMessage()) ;
+                return ;
+            }
+            parseFile(null, filename, in) ;
+            IO.close(in) ;
+            
+        }
+    }
+
+    public void parseFile(String defaultBaseURI, String filename, TypedInputStream in) {   
+        String baseURI = modLangParse.getBaseIRI() ;
+        if ( baseURI == null )
+            baseURI = defaultBaseURI ;
+        parseRIOT(baseURI, filename, in) ;
+    }
+    
+    protected abstract Lang selectLang(String filename, ContentType contentType, Lang dftLang  ) ;
+
+    protected void parseRIOT(String baseURI, String filename, TypedInputStream in) {
+        ContentType ct = in.getMediaType() ;
+        
+        baseURI = SysRIOT.chooseBaseIRI(baseURI, filename) ;
+        
+        boolean checking = true ;
+        if ( modLangParse.explicitChecking() )  checking = true ;
+        if ( modLangParse.explicitNoChecking() ) checking = false ;
+        
+        ErrorHandler errHandler = null ;
+        if ( checking )
+        {
+            if ( modLangParse.stopOnBadTerm() )
+                errHandler = ErrorHandlerFactory.errorHandlerStd  ;
+            else
+                // Try to go on if possible.  This is the default behaviour.
+                errHandler = ErrorHandlerFactory.errorHandlerWarn ;
+        }
+        
+        if ( modLangParse.skipOnBadTerm() )
+        {
+            // TODO skipOnBadterm
+        }
+        
+        Lang lang = selectLang(filename, ct, RDFLanguages.NQUADS) ;  
+        LangHandler handler = null ;
+        if ( RDFLanguages.isQuads(lang) )
+            handler = langHandlerQuads ;
+        else if ( RDFLanguages.isTriples(lang) )
+            handler = langHandlerTriples ;
+        else 
+            throw new CmdException("Undefined language: "+lang) ; 
+        
+        // If multiple files, choose the overall labels. 
+        if ( langHandlerOverall == null )
+            langHandlerOverall = handler ;
+        else
+        {
+            if ( langHandlerOverall != langHandlerAny )
+            {
+                if ( langHandlerOverall != handler )
+                    langHandlerOverall = langHandlerAny ;
+            }
+        }
+        
+        // Make a flag.
+        // Input and output subflags.
+        // If input is "label, then output using NodeToLabel.createBNodeByLabelRaw() ;
+        // else use NodeToLabel.createBNodeByLabel() ;
+        // Also, as URI.
+        final boolean labelsAsGiven = false ;
+
+        NodeToLabel labels = SyntaxLabels.createNodeToLabel() ;
+        if ( labelsAsGiven )
+            labels = NodeToLabel.createBNodeByLabelEncoded() ;
+        
+        StreamRDF s = outputStream ; 
+        if ( setup != null )
+            s = InfFactory.inf(s, setup) ;
+        StreamRDFCounting sink = StreamRDFLib.count(s) ;
+        s = null ;
+        
+        ReaderRIOT reader = RDFDataMgr.createReader(lang) ;
+        try {
+            if ( checking ) {
+                if ( lang == RDFLanguages.NTRIPLES || lang == RDFLanguages.NQUADS )
+                    reader.setParserProfile(RiotLib.profile(baseURI, false, true, errHandler)) ;
+                else
+                    reader.setParserProfile(RiotLib.profile(baseURI, true, true, errHandler)) ;
+            } else
+                reader.setParserProfile(RiotLib.profile(baseURI, false, false, errHandler)) ;
+
+            if ( labelsAsGiven )
+                reader.getParserProfile().setLabelToNode(LabelToNode.createUseLabelAsGiven()) ;
+            modTime.startTimer() ;
+            sink.start() ;
+            reader.read(in, baseURI, ct, sink, null) ;
+            sink.finish() ;
+        } catch (RiotException ex) {
+            // Should have handled the exception and logged a message by now.
+            // System.err.println("++++"+ex.getMessage());
+            if ( modLangParse.stopOnBadTerm() )
+                return ;
+        } finally {
+            // Not close the output - we may write again to the underlying output stream in another call to parse a file.  
+            IO.close(in) ;
+        }
+        long x = modTime.endTimer() ;
+        long n = sink.countTriples()+sink.countQuads() ;
+
+        if ( modTime.timingEnabled() )
+            output(filename, n, x, handler) ;
+        
+        totalMillis += x ;
+        totalTuples += n ;
+    }
+    
+    /** Create a streaming output sink if possible */
+    protected StreamRDF createStreamSink() {
+        if ( modLangParse.toBitBucket() )
+            return StreamRDFLib.sinkNull() ;
+        
+        RDFFormat fmt = modLangOutput.getOutputStreamFormat() ;
+        if ( fmt == null )
+            return null ;
+        /** Create an accumulating output stream for later pretty printing */        
+        return StreamRDFWriter.getWriterStream(output, fmt) ;
+    }
+    
+    /** Create an accumulating output stream for later pretty printing */
+    protected Pair<StreamRDF, PostParseHandler> createAccumulateSink() {
+        final DatasetGraph dsg = DatasetGraphFactory.create() ;
+        StreamRDF sink = StreamRDFLib.dataset(dsg) ;
+        final RDFFormat fmt = modLangOutput.getOutputFormatted() ;
+        PostParseHandler handler = new PostParseHandler() {
+            @Override
+            public void postParse() {
+                // Try as dataset, then as graph.
+                WriterDatasetRIOTFactory w = RDFWriterRegistry.getWriterDatasetFactory(fmt) ;
+                if ( w != null ) {
+                    RDFDataMgr.write(output, dsg, fmt) ;
+                    return ;
+                }
+                WriterGraphRIOTFactory wg = RDFWriterRegistry.getWriterGraphFactory(fmt) ;
+                if ( wg != null ) {
+                    RDFDataMgr.write(System.out, dsg.getDefaultGraph(), fmt) ;
+                    return ;
+                }
+                throw new InternalErrorException("failed to find the writer: "+fmt) ;  
+            }
+        } ;
+        return Pair.create(sink, handler) ;
+    }
+    
+    protected Tokenizer makeTokenizer(InputStream in) {
+        Tokenizer tokenizer = TokenizerFactory.makeTokenizerUTF8(in) ;
+        return tokenizer ;
+    }
+    
+    protected void output(String label, long numberTriples, long timeMillis, LangHandler handler) {
+        double timeSec = timeMillis/1000.0 ;
+        
+        System.out.flush() ;
+        System.err.printf("%s : %,5.2f sec  %,d %s  %,.2f %s\n",
+                          label,
+                          timeMillis/1000.0, numberTriples,
+                          handler.getItemsName(),
+                          timeSec == 0 ? 0.0 : numberTriples/timeSec,
+                          handler.getRateName()) ;
+    }
+    
+    protected void output(String label) {
+        System.err.printf("%s : \n", label) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/riotcmd/CmdTokens.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/riotcmd/CmdTokens.java b/jena-cmds/src/main/java/riotcmd/CmdTokens.java
new file mode 100644
index 0000000..d7c1340
--- /dev/null
+++ b/jena-cmds/src/main/java/riotcmd/CmdTokens.java
@@ -0,0 +1,75 @@
+/*
+ * 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 riotcmd;
+
+import java.io.InputStream ;
+
+import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.lib.Timer ;
+import org.apache.jena.riot.tokens.Token ;
+import org.apache.jena.riot.tokens.Tokenizer ;
+import org.apache.jena.riot.tokens.TokenizerFactory ;
+
+public class CmdTokens
+{
+    
+    public static void tokens(final boolean print, final boolean timing, String...args)
+    {
+        // Turn the node cache off.
+        //com.hp.hpl.jena.graph.Node.cache(false) ;
+
+        if ( args.length == 0 )
+            args = new String[] {"-"} ;
+
+        String arg = args[0] ;
+
+        if ( arg.equals("--help") || arg.equals("-help") || arg.equals("-h") || arg.equals("--h") ) 
+        {
+            System.err.println("Usage: stdin | FILE ...") ;
+            System.exit(1) ;
+        }
+        for ( String filename : args )
+        {
+            InputStream in = IO.openFile(filename) ;
+            Tokenizer tokenize = TokenizerFactory.makeTokenizerUTF8(in) ;
+            Timer timer = new Timer() ;
+            long count = 0 ; 
+            timer.startTimer() ;
+            for ( ; tokenize.hasNext() ; )
+            {
+                Token t = tokenize.next() ;
+                if ( print )
+                    System.out.println(t) ;
+                count++ ;
+            }
+            tokenize.close();
+            long millis = timer.endTimer() ;
+            if ( timing )
+            {
+                if ( millis == 0 )
+                    System.out.printf("Tokens=%,d : Time=0.00s\n", count) ;
+                else
+                {
+                    double seconds = millis/1000.0 ;
+                    System.out.printf("Tokens=%,d : Time=%,.2fs : Rate=%,.2f\n", count, seconds, count/seconds) ;
+                }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/riotcmd/dumpthrift.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/riotcmd/dumpthrift.java b/jena-cmds/src/main/java/riotcmd/dumpthrift.java
new file mode 100644
index 0000000..cfadd38
--- /dev/null
+++ b/jena-cmds/src/main/java/riotcmd/dumpthrift.java
@@ -0,0 +1,51 @@
+/**
+ * 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 riotcmd;
+
+import java.io.InputStream ;
+
+import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.riot.thrift.BinRDF ;
+import org.apache.jena.system.JenaSystem ;
+
+/** Dump an rdf-thrift file to show structure */ 
+public class dumpthrift {
+    static { LogCtl.setCmdLogging(); }
+    static { JenaSystem.init() ; }
+    
+    public static void main(String[] args) {
+        if ( args.length == 0 ) {
+            args = new String[] {"-"} ;
+        }
+        
+        if ( args.length != 1 ) {
+            System.err.println("Usage: "+Lib.classShortName(dumpthrift.class)+" FILE") ;
+            System.exit(2) ;
+        }
+        
+        // Leave a general loop ...
+        for ( String fn : args ) {
+            InputStream in = IO.openFile(fn) ; 
+            BinRDF.dump(System.out, in) ;
+        }
+    }
+}    
+

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/riotcmd/infer.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/riotcmd/infer.java b/jena-cmds/src/main/java/riotcmd/infer.java
new file mode 100644
index 0000000..d9a2983
--- /dev/null
+++ b/jena-cmds/src/main/java/riotcmd/infer.java
@@ -0,0 +1,154 @@
+/*
+ * 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 riotcmd;
+
+import java.util.List ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral;
+
+import org.apache.jena.atlas.io.IO ;
+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.process.inf.InfFactory ;
+import org.apache.jena.riot.system.StreamRDF ;
+import org.apache.jena.riot.system.StreamRDFLib ;
+import org.apache.jena.util.FileManager ;
+
+/*
+ * TDB Infer
+ *   RDFS
+ *   owl:sameAs (in T-Box, not A-Box)
+ *   owl:equivalentClass, owl:equivalentProperty
+ *   owl:TransitiveProperty, owl:SymmetricProperty
+ *
+ * OWLprime - Oracle
+- rdfs:domain
+- rdfs:range
+- rdfs:subClassOf
+- rdfs:subPropertyOf
+- owl:equivalentClass
+- owl:equivalentProperty
+- owl:sameAs
+- owl:inverseOf
+- owl:TransitiveProperty
+- owl:SymmetricProperty
+- owl:FunctionalProperty
+- owl:InverseFunctionalProperty
+
+ JimH: RDFS3:
+ #
+    * equivalentClass
+    * equivalentProperty
+    * sameAs
+    * differentFrom (and allDifferent) 
+
+# Property Characteristics:
+
+    * inverseOf
+    * TransitiveProperty
+    * SymmetricProperty
+    * FunctionalProperty
+    * InverseFunctionalProperty
+    * ObjectProperty
+    * DatatypeProperty
+    * disjointWith 
+
+AllegroGraph RDFS++
+    * rdf:type
+    * rdfs:subClassOf
+    * rdfs:domain and rdfs:range
+    * rdfs:subPropertyOf
+    * owl:sameAs
+    * owl:inverseOf
+    * owl:TransitiveProperty
+ */
+public class infer extends CmdGeneral
+{
+    static final ArgDecl argRDFS = new ArgDecl(ArgDecl.HasValue, "rdfs") ;
+    private Model vocab ;
+    
+    public static void main(String... argv)
+    {
+        new infer(argv).mainRun() ;
+    }        
+
+    protected infer(String[] argv)
+    {
+        super(argv) ;
+        super.add(argRDFS) ;
+    }
+
+//    public static void expand(String filename, Model vocab)
+//    {
+//        Sink<Triple> sink = new SinkTripleOutput(System.out) ;
+//        sink = new InferenceExpanderRDFS(sink, vocab) ;
+//        RiotReader.parseTriples(filename, sink) ;
+//        IO.flush(System.out); 
+//    }
+
+    @Override
+    protected String getSummary()
+    {
+        return "infer --rdfs=vocab FILE ..." ;
+    }
+
+    @Override
+    protected void processModulesAndArgs()
+    {
+        if ( ! contains(argRDFS) )
+            throw new CmdException("Required argument missing: --"+argRDFS.getKeyName()) ;
+        String fn = getValue(argRDFS) ;
+        vocab = FileManager.get().loadModel(fn) ;
+    }
+
+    @Override
+    protected void exec()
+    {
+        StreamRDF sink = StreamRDFLib.writer(System.out) ;
+        sink = InfFactory.inf(sink, vocab) ;
+        
+        List<String> files = getPositionalOrStdin() ;
+        if ( files.isEmpty() )
+            files.add("-") ;
+            
+        for ( String fn : files )
+            processFile(fn, sink) ;
+        IO.flush(System.out); 
+    }
+
+    private void processFile(String filename, StreamRDF sink)
+    {
+        Lang lang = filename.equals("-") ? RDFLanguages.NQUADS : RDFLanguages.filenameToLang(filename, RDFLanguages.NQUADS) ;
+
+        if ( filename.equals("-") )
+            RDFDataMgr.parse(sink, System.in, null, RDFLanguages.NQUADS, null) ;
+        else
+            RDFDataMgr.parse(sink, filename) ;
+    }
+
+    @Override
+    protected String getCommandName()
+    {
+        return "infer" ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/riotcmd/json.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/riotcmd/json.java b/jena-cmds/src/main/java/riotcmd/json.java
new file mode 100644
index 0000000..1c77073
--- /dev/null
+++ b/jena-cmds/src/main/java/riotcmd/json.java
@@ -0,0 +1,52 @@
+/*
+ * 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 riotcmd;
+
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.atlas.json.JSON ;
+import org.apache.jena.atlas.json.JsonParseException ;
+import org.apache.jena.atlas.json.JsonValue ;
+
+/** Command to read and print JSON */
+public class json
+{
+    public static void main(String... args)
+    {
+        if ( args.length == 0 )
+            args = new String[] {"-"} ;
+
+        try {
+            for ( String fn : args )
+            {
+                JsonValue json =null ;
+                try {
+                 json = JSON.readAny(fn) ;
+                } catch (JsonParseException ex)
+                {
+                    String name = fn.equals("-") ? "<stdin>" : fn ; 
+                    System.err.println(name+": "+JsonParseException.formatMessage(ex.getMessage(), ex.getLine(), ex.getColumn())) ;
+                    continue ;
+                }
+                JSON.write(IndentedWriter.stdout, json) ;
+                IndentedWriter.stdout.ensureStartOfLine() ;
+            }
+        } finally { IndentedWriter.stdout.flush() ; }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/riotcmd/nquads.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/riotcmd/nquads.java b/jena-cmds/src/main/java/riotcmd/nquads.java
new file mode 100644
index 0000000..d76cf96
--- /dev/null
+++ b/jena-cmds/src/main/java/riotcmd/nquads.java
@@ -0,0 +1,48 @@
+/*
+ * 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 riotcmd;
+
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.web.ContentType ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFLanguages ;
+
+/** Run the N-Quads parser - and produce N-Quads */
+public class nquads extends CmdLangParse
+{
+    public static void main(String... argv)
+    {
+        new nquads(argv).mainRun() ;
+    }    
+    
+    protected nquads(String[] argv)
+    {
+        super(argv) ;
+    }
+
+    @Override
+    protected String getCommandName()
+    {
+        return Lib.classShortName(nquads.class) ;
+    }
+    
+    @Override
+    protected Lang selectLang(String filename  , ContentType contentType  , Lang lang  ) 
+    { return RDFLanguages.NQUADS ; }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/riotcmd/ntriples.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/riotcmd/ntriples.java b/jena-cmds/src/main/java/riotcmd/ntriples.java
new file mode 100644
index 0000000..dd20e82
--- /dev/null
+++ b/jena-cmds/src/main/java/riotcmd/ntriples.java
@@ -0,0 +1,48 @@
+/*
+ * 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 riotcmd;
+
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.web.ContentType ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFLanguages ;
+
+/** Run the N-triples parser - and produce N-triples */
+public class ntriples extends CmdLangParse
+{
+    public static void main(String... argv)
+    {
+        new ntriples(argv).mainRun() ;
+    }        
+
+    protected ntriples(String[] argv)
+    {
+        super(argv) ;
+    }
+    
+    @Override
+    protected String getCommandName()
+    {
+        return Lib.classShortName(ntriples.class) ;
+    }
+    
+    @Override
+    protected Lang selectLang(String filename  , ContentType contentType  , Lang lang  ) 
+    { return RDFLanguages.NTRIPLES ; }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/riotcmd/perftokens.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/riotcmd/perftokens.java b/jena-cmds/src/main/java/riotcmd/perftokens.java
new file mode 100644
index 0000000..8da571e
--- /dev/null
+++ b/jena-cmds/src/main/java/riotcmd/perftokens.java
@@ -0,0 +1,28 @@
+/*
+ * 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 riotcmd;
+
+
+public class perftokens
+{
+    public static void main(String...args)
+    {
+        CmdTokens.tokens(false, true, args) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/riotcmd/printtokens.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/riotcmd/printtokens.java b/jena-cmds/src/main/java/riotcmd/printtokens.java
new file mode 100644
index 0000000..4be74bb
--- /dev/null
+++ b/jena-cmds/src/main/java/riotcmd/printtokens.java
@@ -0,0 +1,28 @@
+/*
+ * 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 riotcmd;
+
+
+public class printtokens
+{
+    public static void main(String...args)
+    {
+        CmdTokens.tokens(true, false, args) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/riotcmd/rdfxml.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/riotcmd/rdfxml.java b/jena-cmds/src/main/java/riotcmd/rdfxml.java
new file mode 100644
index 0000000..d4346da
--- /dev/null
+++ b/jena-cmds/src/main/java/riotcmd/rdfxml.java
@@ -0,0 +1,48 @@
+/*
+ * 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 riotcmd;
+
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.web.ContentType ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFLanguages ;
+
+/** Run the RDf/XML parser - and produce triples */
+public class rdfxml extends CmdLangParse
+{
+    public static void main(String... argv)
+    {
+        new rdfxml(argv).mainRun() ;
+    }    
+    
+    protected rdfxml(String[] argv)
+    {
+        super(argv) ;
+    }
+
+    @Override
+    protected String getCommandName()
+    {
+        return Lib.classShortName(rdfxml.class) ;
+    }
+    
+    @Override
+    protected Lang selectLang(String filename  , ContentType contentType  , Lang lang  ) 
+    { return RDFLanguages.RDFXML ; }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/riotcmd/riot.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/riotcmd/riot.java b/jena-cmds/src/main/java/riotcmd/riot.java
new file mode 100644
index 0000000..1bf8cf6
--- /dev/null
+++ b/jena-cmds/src/main/java/riotcmd/riot.java
@@ -0,0 +1,62 @@
+/*
+ * 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 riotcmd;
+
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.web.ContentType ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFLanguages ;
+import org.apache.jena.riot.WebContent ;
+
+/**
+ * Guess the syntax from the filename. 
+ */
+public class riot extends CmdLangParse
+{
+    public static void main(String... argv)
+    {
+        new riot(argv).mainRun() ;
+    }        
+
+    protected riot(String[] argv)
+    {
+        super(argv) ;
+    }
+    
+    @Override
+    protected Lang selectLang(String filename, ContentType contentType, Lang dftLang)
+    {
+        if ( modLangParse.getLang() != null )
+            return modLangParse.getLang() ;
+        
+        if ( contentType != null && ! WebContent.matchContentType(WebContent.ctTextPlain, contentType) )
+            return RDFLanguages.contentTypeToLang(contentType) ;
+
+        Lang lang =  RDFLanguages.filenameToLang(filename) ;
+        if ( lang == null )
+            lang = dftLang ;
+        return lang ;
+    }
+
+    @Override
+    protected String getCommandName()
+    {
+        return Lib.classShortName(riot.class) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/riotcmd/trig.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/riotcmd/trig.java b/jena-cmds/src/main/java/riotcmd/trig.java
new file mode 100644
index 0000000..08a24df
--- /dev/null
+++ b/jena-cmds/src/main/java/riotcmd/trig.java
@@ -0,0 +1,48 @@
+/*
+ * 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 riotcmd;
+
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.web.ContentType ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFLanguages ;
+
+/** Run the TriG parser - and produce N-Quads */
+public class trig extends CmdLangParse
+{
+    public static void main(String... argv)
+    {
+        new trig(argv).mainRun() ;
+    }    
+    
+    protected trig(String[] argv)
+    {
+        super(argv) ;
+    }
+
+    @Override
+    protected String getCommandName()
+    {
+        return Lib.classShortName(trig.class) ;
+    }
+
+    @Override
+    protected Lang selectLang(String filename  , ContentType contentType  , Lang lang  ) 
+    { return RDFLanguages.TRIG ; }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/riotcmd/turtle.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/riotcmd/turtle.java b/jena-cmds/src/main/java/riotcmd/turtle.java
new file mode 100644
index 0000000..776803b
--- /dev/null
+++ b/jena-cmds/src/main/java/riotcmd/turtle.java
@@ -0,0 +1,48 @@
+/*
+ * 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 riotcmd;
+
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.web.ContentType ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFLanguages ;
+
+/** Run the Turtle parser - and produce N-triples */
+public class turtle extends CmdLangParse
+{
+    public static void main(String... argv)
+    {
+        new turtle(argv).mainRun() ;
+    }    
+    
+    protected turtle(String[] argv)
+    {
+        super(argv) ;
+    }
+
+    @Override
+    protected String getCommandName()
+    {
+        return Lib.classShortName(turtle.class) ;
+    }
+
+    @Override
+    protected Lang selectLang(String filename  , ContentType contentType  , Lang dftLang  ) 
+    { return RDFLanguages.TURTLE ; }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/riotcmd/utf8.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/riotcmd/utf8.java b/jena-cmds/src/main/java/riotcmd/utf8.java
new file mode 100644
index 0000000..1fa5598
--- /dev/null
+++ b/jena-cmds/src/main/java/riotcmd/utf8.java
@@ -0,0 +1,75 @@
+/*
+ * 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 riotcmd;
+
+import java.io.InputStream ;
+
+import org.apache.jena.atlas.AtlasException ;
+import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.io.InStreamUTF8 ;
+import org.apache.jena.atlas.io.InputStreamBuffered ;
+
+public class utf8
+{
+    /** Simple program to help hunt down bad UTF-8 encoded characters */
+    public static void main(String[] args) {
+        long INIT_LINE = 1 ;
+        long INIT_COL = 1 ;
+
+        if ( args.length == 0 )
+            args = new String[]{"-"} ;
+
+        String label = "" ;
+        for ( String fn : args ) {
+            if ( args.length > 1 )
+                label = fn + ": " ;
+            InputStream in = IO.openFile(fn) ;
+            in = new InputStreamBuffered(in) ;
+
+            long charCount = 0 ;
+            long lineNum = INIT_LINE ;
+            long colNum = INIT_COL ;
+
+            InStreamUTF8 utf8 = null ;
+            try {
+                utf8 = new InStreamUTF8(in) ;
+                for ( ; ; ) {
+                    int ch = utf8.read() ;
+                    if ( ch == -1 )
+                        break ;
+                    charCount++ ;
+                    if ( ch == '\n' ) {
+                        lineNum++ ;
+                        colNum = INIT_COL ;
+                    } else
+                        colNum++ ;
+                    if ( !Character.isDefined(ch) )
+                        throw new AtlasException(String.format("No such codepoint: 0x%04X", ch)) ;
+                }
+                System.out.printf("%s: chars = %d , lines = %d\n", fn, charCount, lineNum) ;
+            }
+            catch (AtlasException ex) {
+                System.out.printf(label + "[line=%d, col=%d] %s\n", lineNum, colNum, ex.getMessage()) ;
+            }
+            finally {
+                IO.close(utf8) ;
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/CmdNodeTableBuilder.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/CmdNodeTableBuilder.java b/jena-cmds/src/main/java/tdb/CmdNodeTableBuilder.java
new file mode 100644
index 0000000..5dc0371
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/CmdNodeTableBuilder.java
@@ -0,0 +1,132 @@
+/*
+ * 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 tdb;
+
+import java.util.Arrays ;
+import java.util.List ;
+import java.util.Objects ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral;
+import org.apache.jena.atlas.lib.FileOps ;
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFLanguages ;
+import org.apache.jena.system.JenaSystem ;
+import org.apache.jena.tdb.base.file.Location ;
+import org.apache.jena.tdb.setup.DatasetBuilderStd ;
+import org.apache.jena.tdb.store.bulkloader2.ProcNodeTableBuilder ;
+import tdb.cmdline.CmdTDB ;
+
+/** Build node table - write triples/quads as text file */
+public class CmdNodeTableBuilder extends CmdGeneral
+{
+    static { LogCtl.setLog4j() ; }
+    static { JenaSystem.init(); }
+    
+
+    private static ArgDecl argLocation      = new ArgDecl(ArgDecl.HasValue, "loc", "location") ;
+    private static ArgDecl argTriplesOut    = new ArgDecl(ArgDecl.HasValue, "triples") ;
+    private static ArgDecl argQuadsOut      = new ArgDecl(ArgDecl.HasValue, "quads") ;
+    private static ArgDecl argNoStats       = new ArgDecl(ArgDecl.NoValue, "nostats") ;
+    
+    private String locationString ;
+    private String dataFileTriples ;
+    private String dataFileQuads ;
+    private List<String> datafiles ;
+    private Location location ;
+    private boolean collectStats = true ;
+    
+    public static void main(String...argv)
+    {
+        System.err.println("CmdNodeTableBuilder");
+        CmdTDB.init() ;
+        DatasetBuilderStd.setOptimizerWarningFlag(false) ;
+        new CmdNodeTableBuilder(argv).mainRun() ;
+    }
+    
+    public CmdNodeTableBuilder(String...argv)
+    {
+        super(argv) ;
+        super.add(argLocation,      "--loc",        "Location") ;
+        super.add(argTriplesOut,    "--triples",    "Output file for triples") ;
+        super.add(argQuadsOut,      "--quads",      "Output file for quads") ;
+        super.add(argNoStats,       "--nostats",    "Don't collect stats") ;
+    }
+        
+    @Override
+    protected void processModulesAndArgs()
+    {
+        if ( !super.contains(argLocation) ) throw new CmdException("Required: --loc DIR") ;
+//        if ( !super.contains(argTriplesOut) ) throw new CmdException("Required: --triples FILE") ;
+//        if ( !super.contains(argQuadsOut) ) throw new CmdException("Required: --quads FILE") ;
+        
+        locationString   = super.getValue(argLocation) ;
+        location = Location.create(locationString) ;
+
+        dataFileTriples  = super.getValue(argTriplesOut) ;
+        if ( dataFileTriples == null )
+            dataFileTriples = location.getPath("triples", "tmp") ;
+        
+        dataFileQuads    = super.getValue(argQuadsOut) ;
+        if ( dataFileQuads == null )
+            dataFileQuads = location.getPath("quads", "tmp") ;
+        
+        if ( Objects.equals(dataFileTriples, dataFileQuads) )
+            cmdError("Triples and Quads work files are the same") ;
+        
+        if ( super.contains(argNoStats) )
+            collectStats = false ;
+        
+        //datafiles  = getPositionalOrStdin() ;
+        datafiles  = getPositional() ;
+        if ( datafiles.isEmpty() )
+            datafiles = Arrays.asList("-") ;
+        
+        // ---- Checking.
+        for( String filename : datafiles)
+        {
+            Lang lang = RDFLanguages.filenameToLang(filename, RDFLanguages.NQUADS) ;
+            if ( lang == null )
+                // Does not happen due to default above.
+                cmdError("File suffix not recognized: " +filename) ;
+            if ( ! filename.equals("-") && ! FileOps.exists(filename) )
+                cmdError("File does not exist: "+filename) ;
+        }
+    }
+    
+    @Override
+    protected void exec()
+    {
+        ProcNodeTableBuilder.execInner(location, dataFileTriples, dataFileQuads, datafiles, collectStats); 
+    }
+    
+ @Override
+    protected String getSummary()
+    {
+        return getCommandName()+" --loc=DIR [--triples=tmpFile1] [--quads=tmpFile2] FILE ..." ;
+    }
+
+    @Override
+    protected String getCommandName()
+    {
+        return this.getClass().getName() ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/CmdRewriteIndex.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/CmdRewriteIndex.java b/jena-cmds/src/main/java/tdb/CmdRewriteIndex.java
new file mode 100644
index 0000000..0c4a6fa
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/CmdRewriteIndex.java
@@ -0,0 +1,147 @@
+/*
+ * 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 tdb;
+
+import java.util.Iterator ;
+
+import org.apache.jena.atlas.lib.FileOps ;
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.tdb.base.block.BlockMgr ;
+import org.apache.jena.tdb.base.block.BlockMgrFactory ;
+import org.apache.jena.tdb.base.file.FileSet ;
+import org.apache.jena.tdb.base.file.Location ;
+import org.apache.jena.tdb.base.record.Record ;
+import org.apache.jena.tdb.base.record.RecordFactory ;
+import org.apache.jena.tdb.index.RangeIndex ;
+import org.apache.jena.tdb.index.SetupIndex ;
+import org.apache.jena.tdb.index.bplustree.BPlusTree ;
+import org.apache.jena.tdb.index.bplustree.BPlusTreeParams ;
+import org.apache.jena.tdb.index.bplustree.BPlusTreeRewriter ;
+import org.apache.jena.tdb.sys.Names ;
+import org.apache.jena.tdb.sys.SystemTDB ;
+
+/** Rewrite one index */
+public class CmdRewriteIndex
+{
+    public static void main(String...argv)
+    {
+        // Usage: srcLocation dstLocation indexName
+        if ( argv.length != 3 )
+        {
+            System.err.println("Usage: "+Lib.classShortName(CmdRewriteIndex.class)+" SrcLocation DstLocation IndexName") ;
+            System.exit(1) ;
+        }
+        
+        Location srcLoc = Location.create(argv[0]) ;
+        Location dstLoc = Location.create(argv[1]) ;
+        String indexName = argv[2] ;
+        
+        if ( ! FileOps.exists(argv[1]) )
+        {
+            System.err.println("Destination directory does not exist") ;
+            System.exit(1) ;
+        }
+        
+        if ( FileOps.exists(dstLoc.getPath(indexName, Names.bptExtTree)) )
+        {
+            System.err.println("Destination contains an index of that name") ;
+            System.exit(1) ;
+        }
+        
+        // To current directory ....
+        FileSet destination = new FileSet(dstLoc, indexName) ;
+        // Check existance
+        
+//        FileOps.deleteSilent(destination.filename(Names.bptExt1)) ;
+//        FileOps.deleteSilent(destination.filename(Names.bptExt2)) ;
+        //FileSet destination = new FileSet(Location.mem(), destIndex) ;
+        
+        int readCacheSize = 0 ;
+        int writeCacheSize = -1 ;
+        
+        int dftKeyLength ;
+        int dftValueLength ;
+        
+        if ( indexName.length() == 3 )
+        {
+            dftKeyLength = SystemTDB.LenIndexTripleRecord ;
+            dftValueLength = 0 ;
+        }
+        else if ( indexName.length() == 4 )
+        {
+            dftKeyLength = SystemTDB.LenIndexQuadRecord ;
+            dftValueLength = 0 ;
+        }
+//        else if ( srcIndex.equals("node2id") )
+//        { }
+//      java -cp "$CP" -server -Xmx1000M bpt.CmdRewriteIndex "$@"  else if ( srcIndex.equals("prefixIdx") )
+//        {}
+//        else if ( srcIndex.equals("prefix2id") )
+//        {}
+        else
+        {
+            System.err.printf("Can't determine record size for %s\n",indexName) ;
+            return ;
+        }
+        
+        RecordFactory recordFactory = null ;
+        BPlusTreeParams bptParams = null ;
+        BlockMgr blkMgrNodes ;
+        BlockMgr blkMgrRecords ;
+        int blockSize = SystemTDB.BlockSize ;
+        
+        RangeIndex rangeIndex = SetupIndex.makeRangeIndex(srcLoc, indexName, blockSize, dftKeyLength, dftValueLength, readCacheSize, writeCacheSize) ;
+        BPlusTree bpt = (BPlusTree)rangeIndex ;
+        bptParams = bpt.getParams() ;
+        recordFactory = bpt.getRecordFactory() ;
+
+        int blockSizeNodes = blockSize ;
+        int blockSizeRecords = blockSize ;
+
+        blkMgrNodes = BlockMgrFactory.create(destination, Names.bptExtTree, blockSizeNodes, readCacheSize, writeCacheSize) ;
+        blkMgrRecords = BlockMgrFactory.create(destination, Names.bptExtRecords, blockSizeRecords, readCacheSize, writeCacheSize) ;
+
+        Iterator<Record>  iterator = bpt.iterator() ;
+            
+//            // Fakery.
+//            blkMgrNodes = BlockMgrFactory.create(destination, Names.bptExt1, blockSize, readCacheSize, writeCacheSize) ;
+//            blkMgrRecords = BlockMgrFactory.create(destination, Names.bptExt2, blockSize, readCacheSize, writeCacheSize) ;
+//            recordFactory = new RecordFactory(dftKeyLength, dftValueLength) ;
+//            bptParams = new BPlusTreeParams(3, recordFactory) ;
+//            List<Record> data = TestBPlusTreeRewriter.createData(10, recordFactory) ;
+//            iterator = data.iterator() ;
+        
+        //System.out.println("Rewrite: "+srcLoc+" "+indexName+" --> "+destination) ;
+        
+        BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(iterator, 
+                                                             bptParams, recordFactory,
+                                                             blkMgrNodes, blkMgrRecords) ;
+        if ( bpt2 == null )
+            return ;
+//        
+//        Iterator<Record> iter = bpt2.iterator() ;
+//        for ( ; iter.hasNext() ; )
+//        {
+//            Record r = iter.next() ;
+//            System.out.println(r) ;
+//        }
+
+        bpt2.close() ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/cmdline/CmdSub.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/cmdline/CmdSub.java b/jena-cmds/src/main/java/tdb/cmdline/CmdSub.java
new file mode 100644
index 0000000..fb7bbd0
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/cmdline/CmdSub.java
@@ -0,0 +1,77 @@
+/*
+ * 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 tdb.cmdline;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import jena.cmd.CmdException;
+
+
+public class CmdSub
+{
+    public interface Exec { public void exec(String[] argv) ; }
+    Map<String, Exec> dispatch = new HashMap<>() ;
+    
+    String subCmd ;
+    String args[] ;
+    
+    public CmdSub(String ...argv)
+    {
+        subCmd = subCommand(argv) ;
+        args = cmdline(argv) ;
+    }
+    
+    protected void exec()
+    {
+        Exec exec = dispatch.get(subCmd) ;
+        if ( exec == null )
+            throw new CmdException("No subcommand: "+subCmd) ;
+        exec.exec(args) ;
+    }
+
+    protected static String[] cmdline(String ... argv)
+    {
+        String [] a = new String[argv.length-1] ;
+        System.arraycopy(argv, 1, a, 0, argv.length-1) ;
+        return a ; 
+    }
+
+    protected static String subCommand(String ... argv)
+    {
+        if ( argv.length == 0 )
+            throw new CmdException("Missing subcommand") ;
+
+        String subCmd = argv[0] ;
+        if ( subCmd.startsWith("-") )
+            throw new CmdException("Argument found where subcommand expected") ;
+        return subCmd ;
+    }
+    
+    protected void addSubCommand(String subCmdName, Exec exec)
+    {
+        dispatch.put(subCmdName, exec) ;
+    }
+    
+    protected Collection<String> subCommandNames()
+    {
+        return dispatch.keySet() ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/cmdline/CmdTDB.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/cmdline/CmdTDB.java b/jena-cmds/src/main/java/tdb/cmdline/CmdTDB.java
new file mode 100644
index 0000000..8082308
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/cmdline/CmdTDB.java
@@ -0,0 +1,87 @@
+/*
+ * 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 tdb.cmdline;
+
+import arq.cmdline.CmdARQ ;
+import org.apache.jena.Jena ;
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.query.ARQ ;
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.system.JenaSystem ;
+import org.apache.jena.tdb.TDB ;
+import org.apache.jena.tdb.base.file.Location ;
+import org.apache.jena.tdb.setup.DatasetBuilderStd ;
+import org.apache.jena.tdb.store.DatasetGraphTDB ;
+import org.apache.jena.tdb.sys.TDBInternal ;
+
+public abstract class CmdTDB extends CmdARQ
+{
+    protected final ModTDBDataset tdbDatasetAssembler   = new ModTDBDataset() ;
+
+    private static boolean initialized = false ;
+    
+    protected CmdTDB(String[] argv) {
+        super(argv) ;
+        init() ;
+        super.addModule(tdbDatasetAssembler) ;
+        super.modVersion.addClass(Jena.class) ;
+        super.modVersion.addClass(ARQ.class) ;
+        super.modVersion.addClass(TDB.class) ;
+    }
+
+    public static synchronized void init() {
+        // In case called from elsewhere.
+        JenaSystem.init() ;
+        if (initialized)
+            return ;
+        // attempt once.
+        initialized = true ;
+        LogCtl.setCmdLogging() ;
+        DatasetBuilderStd.setOptimizerWarningFlag(false) ;
+    }
+
+    @Override
+    protected void processModulesAndArgs() {
+        super.processModulesAndArgs() ;
+    }
+
+    protected Location getLocation() {
+        return tdbDatasetAssembler.getLocation() ;
+    }
+
+    protected DatasetGraph getDatasetGraph() {
+        return getDataset().asDatasetGraph() ;
+    }
+
+    protected DatasetGraphTDB getDatasetGraphTDB() {
+        DatasetGraph dsg = getDatasetGraph() ;
+        return TDBInternal.getBaseDatasetGraphTDB(dsg) ;
+    }
+
+    protected Dataset getDataset() {
+        return tdbDatasetAssembler.getDataset() ;
+    }
+
+    @Override
+    protected String getCommandName() {
+        return Lib.className(this) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/cmdline/CmdTDBGraph.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/cmdline/CmdTDBGraph.java b/jena-cmds/src/main/java/tdb/cmdline/CmdTDBGraph.java
new file mode 100644
index 0000000..c261831
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/cmdline/CmdTDBGraph.java
@@ -0,0 +1,81 @@
+/*
+ * 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 tdb.cmdline;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException;
+
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.tdb.store.GraphTDB ;
+
+public abstract class CmdTDBGraph extends CmdTDB
+{
+    private static final ArgDecl argNamedGraph          = new ArgDecl(ArgDecl.HasValue, "graph") ;
+    protected String graphName = null ;
+    
+    protected CmdTDBGraph(String[] argv)
+    {
+        super(argv) ;
+        super.add(argNamedGraph, "--graph=IRI", "Act on a named graph") ;
+    }
+    
+    @Override
+    protected void processModulesAndArgs()
+    {
+        super.processModulesAndArgs() ;
+        if ( contains(argNamedGraph) )
+            graphName = getValue(argNamedGraph) ; 
+    }
+    
+    protected Model getModel()
+    {
+        Dataset ds = tdbDatasetAssembler.getDataset() ;
+        
+        if ( graphName != null )
+        {
+            Model m = ds.getNamedModel(graphName) ;
+            if ( m == null )
+                throw new CmdException("No such named graph (is this a TDB dataset?)") ;
+            return m ;
+        }
+        else
+            return ds.getDefaultModel() ;
+    }
+    
+    public Node getGraphName()  { return graphName == null ? null : NodeFactory.createURI(graphName) ; } 
+    
+    protected GraphTDB getGraph()
+    {
+        if ( graphName != null )
+            return (GraphTDB)tdbDatasetAssembler.getDataset().getNamedModel(graphName).getGraph() ;
+        else
+            return (GraphTDB)tdbDatasetAssembler.getDataset().getDefaultModel().getGraph() ;
+    }
+    
+    @Override
+    protected String getCommandName()
+    {
+        return Lib.className(this) ;
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/cmdline/ModLocation.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/cmdline/ModLocation.java b/jena-cmds/src/main/java/tdb/cmdline/ModLocation.java
new file mode 100644
index 0000000..387dba0
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/cmdline/ModLocation.java
@@ -0,0 +1,56 @@
+/*
+ * 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 tdb.cmdline;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.tdb.base.file.Location ;
+
+public class ModLocation extends ModBase
+{
+    public ModLocation() {}
+    
+    protected final ArgDecl locationDecl = new ArgDecl(ArgDecl.HasValue, "location", "loc") ;
+    protected Location location = null ;
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Location") ;
+        cmdLine.add(locationDecl, "--loc=DIR", "Location (a directory)") ;
+    }
+    
+    public void checkCommandLine(CmdArgModule cmdLine)
+    {}
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        if ( cmdLine.contains(locationDecl) )
+        {
+            String dir = cmdLine.getValue(locationDecl) ;
+            location = Location.create(dir) ;
+        }
+    }
+    
+    public Location getLocation() { return location ; }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/cmdline/ModModel.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/cmdline/ModModel.java b/jena-cmds/src/main/java/tdb/cmdline/ModModel.java
new file mode 100644
index 0000000..4b04471
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/cmdline/ModModel.java
@@ -0,0 +1,66 @@
+/*
+ * 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 tdb.cmdline;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.util.FileManager ;
+
+/** Name a model */
+public class ModModel extends ModBase
+{
+    protected ArgDecl modelArgDecl = null ;
+    private Model model = null ;
+    
+    //public ModModel() { this("model") ; }
+    public ModModel(String argName, String ... altNames)
+    {
+        modelArgDecl = new ArgDecl(ArgDecl.HasValue, argName) ;
+        for ( String x : altNames )
+            modelArgDecl.addName(x) ;
+    }
+
+    public ArgDecl getArg() 
+    {
+        return modelArgDecl ;
+    }
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.add(modelArgDecl, "--"+modelArgDecl.getKeyName()+"=filename", "Filename for a model") ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        if ( cmdLine.contains(modelArgDecl) )
+        {
+            String filename = cmdLine.getValue(modelArgDecl) ;
+            model = FileManager.get().loadModel(filename) ;
+        }
+    }
+    
+    public Model getModel() { return model ; }
+    
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/cmdline/ModTDBAssembler.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/cmdline/ModTDBAssembler.java b/jena-cmds/src/main/java/tdb/cmdline/ModTDBAssembler.java
new file mode 100644
index 0000000..a4cb52a
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/cmdline/ModTDBAssembler.java
@@ -0,0 +1,90 @@
+/*
+ * 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 tdb.cmdline;
+
+import java.io.File;
+
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral;
+
+import org.apache.jena.tdb.base.file.Location ;
+
+import arq.cmdline.ModAssembler;
+
+/**  Extends ModAssembler to include --tdb.
+ *   Defaulting to "tdb.ttl" is done in ModTDBDataset because it interacts
+ *   with --location
+ */  
+public class ModTDBAssembler extends ModAssembler
+{
+    private ModLocation modLocation     =  new ModLocation() ;
+
+    public static final String defaultAssemblerFile = "tdb.ttl" ;
+    protected boolean useDefaultAssemblerFile = false ;
+    
+    public ModTDBAssembler()
+    { 
+        super() ;
+        ModAssembler.assemblerDescDecl.addName("tdb") ;
+    }
+    
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        int count = 0 ;
+
+        modLocation.processArgs(cmdLine) ;
+        super.processArgs(cmdLine) ;
+        if ( super.getAssemblerFile() != null ) count++ ;
+        if ( modLocation.getLocation() != null ) count++ ;    
+        
+        if ( count == 0 )
+        {
+            useDefaultAssemblerFile = true ;
+            // throw new CmdException("No assembler file and no location") ;
+        }
+            
+        if ( count > 1 )
+            throw new CmdException("Only one of an assembler file and a location") ;
+    }
+   
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        super.registerWith(cmdLine) ;
+        cmdLine.addModule(modLocation) ;
+        //cmdLine.getUsage().startCategory("Dataset") ;
+        cmdLine.getUsage().addUsage("--tdb=", "Assembler description file") ;
+    }
+ 
+    public Location getLocation() { return modLocation.getLocation() ; }
+    
+    @Override
+    public String getAssemblerFile()
+    {
+        if ( useDefaultAssemblerFile )
+        {
+            File f = new File(defaultAssemblerFile) ;
+            if ( f.exists() )
+                return defaultAssemblerFile ; 
+        }
+        return super.getAssemblerFile() ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/cmdline/ModTDBDataset.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/cmdline/ModTDBDataset.java b/jena-cmds/src/main/java/tdb/cmdline/ModTDBDataset.java
new file mode 100644
index 0000000..5255fce
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/cmdline/ModTDBDataset.java
@@ -0,0 +1,139 @@
+/*
+ * 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 tdb.cmdline;
+
+import java.util.ArrayList ;
+import java.util.List ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral;
+
+import org.apache.jena.atlas.logging.Log ;
+import org.apache.jena.query.* ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.riot.RDFDataMgr ;
+import org.apache.jena.shared.JenaException ;
+import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
+import org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab ;
+import org.apache.jena.tdb.TDBFactory ;
+import org.apache.jena.tdb.assembler.VocabTDB ;
+import org.apache.jena.tdb.base.file.Location ;
+import org.apache.jena.tdb.transaction.DatasetGraphTransaction ;
+import org.apache.jena.util.FileManager ;
+
+import arq.cmdline.ModDataset ;
+
+public class ModTDBDataset extends ModDataset
+{
+    // Mixes assembler, location and "tdb"
+    // Can make a single model or a dataset
+    
+    private ArgDecl argMem                  = new ArgDecl(ArgDecl.HasValue, "mem", "data") ;
+    private ModTDBAssembler modAssembler    = new ModTDBAssembler() ;
+    private String inMemFile                = null ;
+    
+    public ModTDBDataset() {}
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.add(argMem, "--mem=FILE", "Execute on an in-memory TDB database (for testing)") ;
+        cmdLine.addModule(modAssembler) ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        inMemFile = cmdLine.getValue(argMem) ;
+        modAssembler.processArgs(cmdLine) ;
+    }        
+
+    @Override
+    public Dataset createDataset()
+    {
+        if ( inMemFile != null )
+        {
+            Dataset ds = TDBFactory.createDataset() ;
+            RDFDataMgr.read(ds, inMemFile) ;
+            return ds ;
+            
+        }
+        
+        if (  modAssembler.getAssemblerFile() != null )
+        {
+            Dataset thing = null ;
+            // Two variants: plain dataset with a TDB graph or a TDB dataset.
+            try {
+                thing = (Dataset)AssemblerUtils.build( modAssembler.getAssemblerFile(), VocabTDB.tDatasetTDB) ;
+                if ( thing != null && ! ( thing.asDatasetGraph() instanceof DatasetGraphTransaction ) )
+                        Log.warn(this, "Unexpected: Not a TDB dataset for type DatasetTDB");
+                
+                if ( thing == null )
+                    // Should use assembler inheritance but how do we assert the subclass relationship in a program?
+                    thing = (Dataset)AssemblerUtils.build( modAssembler.getAssemblerFile(), DatasetAssemblerVocab.tDataset) ;
+            }
+            catch (JenaException ex)    { throw ex ; }
+            catch (Exception ex)
+            { throw new CmdException("Error creating", ex) ; }
+            return thing ;
+        }
+        
+        if ( modAssembler.getLocation() == null )
+            throw new CmdException("No assembler file nor location provided") ;
+        
+        // No assembler - use location to find a database.
+        Dataset ds = TDBFactory.createDataset(modAssembler.getLocation()) ;
+        return ds ;
+    }
+    
+    public Location getLocation()
+    {
+        List<String> x = locations() ;
+        if ( x.size() == 0 )
+            return null ;
+        return Location.create(x.get(0)) ;
+    }
+    
+    public List<String> locations()
+    {
+        List<String> locations = new ArrayList<>() ;
+        
+        if ( modAssembler.getLocation() != null )
+            locations.add(modAssembler.getLocation().getDirectoryPath()) ;
+
+        // Extract the location from the assember file.
+        if ( modAssembler.getAssemblerFile() != null )
+        {
+            // Find and clear all locations
+            Model m = FileManager.get().loadModel(modAssembler.getAssemblerFile()) ;
+            Query query = QueryFactory.create("PREFIX tdb:     <http://jena.hpl.hp.com/2008/tdb#> SELECT ?dir { [] tdb:location ?dir FILTER (isURI(?dir)) }") ;
+            try(QueryExecution qExec = QueryExecutionFactory.create(query, m)) {
+                for (ResultSet rs = qExec.execSelect() ; rs.hasNext() ; )
+                {
+                    String x = rs.nextSolution().getResource("dir").getURI() ;
+                    locations.add(x) ;
+                }
+            }
+        }
+        
+        return locations ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/tdbbackup.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/tdbbackup.java b/jena-cmds/src/main/java/tdb/tdbbackup.java
new file mode 100644
index 0000000..06724d9
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/tdbbackup.java
@@ -0,0 +1,49 @@
+/**
+ * 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 tdb;
+
+import org.apache.jena.tdb.TDBBackup ;
+import tdb.cmdline.CmdTDB ;
+
+public class tdbbackup extends CmdTDB
+{
+    static public void main(String... argv)
+    { 
+        CmdTDB.init() ;
+        new tdbdump(argv).mainRun() ;
+    }
+
+    protected tdbbackup(String[] argv)
+    {
+        super(argv) ;
+    }
+    
+    @Override
+    protected String getSummary()
+    {
+        return getCommandName()+" : Write N-Quads to stdout" ;
+    }
+
+    @Override
+    protected void exec()
+    {
+        TDBBackup.backup(getLocation(), System.out) ;
+    }
+}
+


[14/20] jena git commit: JENA-1108 : jena-cmds module

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/query.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/query.java b/jena-cmds/src/main/java/arq/query.java
new file mode 100644
index 0000000..9a9ed5f
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/query.java
@@ -0,0 +1,257 @@
+/*
+ * 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 arq;
+
+import arq.cmdline.* ;
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException;
+import jena.cmd.TerminationException;
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.query.* ;
+import org.apache.jena.riot.RiotException ;
+import org.apache.jena.riot.RiotNotFoundException ;
+import org.apache.jena.riot.SysRIOT ;
+import org.apache.jena.shared.JenaException ;
+import org.apache.jena.sparql.ARQInternalErrorException ;
+import org.apache.jena.sparql.mgt.Explain ;
+import org.apache.jena.sparql.resultset.ResultSetException ;
+import org.apache.jena.sparql.resultset.ResultsFormat ;
+import org.apache.jena.sparql.util.QueryExecUtils ;
+
+public class query extends CmdARQ
+{
+    private ArgDecl argRepeat   = new ArgDecl(ArgDecl.HasValue, "repeat") ;
+    private ArgDecl argExplain  = new ArgDecl(ArgDecl.NoValue, "explain") ;
+    private ArgDecl argOptimize = new ArgDecl(ArgDecl.HasValue, "opt", "optimize") ;
+
+    protected int repeatCount = 1 ; 
+    protected int warmupCount = 0 ;
+    protected boolean queryOptimization = true ;
+    
+    protected ModTime       modTime =     new ModTime() ;
+    protected ModQueryIn    modQuery =    null;
+    protected ModDataset    modDataset =  null ;
+    protected ModResultsOut modResults =  new ModResultsOut() ;
+    protected ModEngine     modEngine =   new ModEngine() ;
+    
+    public static void main (String... argv)
+    {
+        new query(argv).mainRun() ;
+    }
+    
+    public query(String[] argv)
+    {
+        super(argv) ;
+        modQuery = new ModQueryIn(getDefaultSyntax()) ; 
+        modDataset = setModDataset() ;
+       
+        super.addModule(modQuery) ;
+        super.addModule(modResults) ;
+        super.addModule(modDataset) ;
+        super.addModule(modEngine) ;
+        super.addModule(modTime) ;
+
+        super.getUsage().startCategory("Control") ;
+        super.add(argExplain,  "--explain", "Explain and log query execution") ;
+        super.add(argRepeat,   "--repeat=N or N,M", "Do N times or N warmup and then M times (use for timing to overcome start up costs of Java)");
+        super.add(argOptimize, "--optimize=", "Turn the query optimizer on or off (default: on)") ;
+    }
+
+    /** Default syntax used when the syntax can not be determined from the command name or file extension
+     *  The order of determination is:
+     *  <ul>
+     *  <li>Explicitly given --syntax</li>
+     *  <li>File extension</li>
+     *  <li>Command default</li>
+     *  <li>System default</li>
+     *  </ul>
+     *  
+     */
+    protected Syntax getDefaultSyntax()     { return Syntax.defaultQuerySyntax ; }
+
+    @Override
+    protected void processModulesAndArgs()
+    {
+        super.processModulesAndArgs() ;
+        if ( contains(argRepeat) )
+        {
+            String[] x = getValue(argRepeat).split(",") ;
+            if ( x.length == 1 )
+            {
+                try { repeatCount = Integer.parseInt(x[0]) ; }
+                catch (NumberFormatException ex)
+                { throw new CmdException("Can't parse "+x[0]+" in arg "+getValue(argRepeat)+" as an integer") ; }
+                
+            }
+            else if ( x.length == 2 )
+            {
+                try { warmupCount = Integer.parseInt(x[0]) ; }
+                catch (NumberFormatException ex)
+                { throw new CmdException("Can't parse "+x[0]+" in arg "+getValue(argRepeat)+" as an integer") ; }
+                try { repeatCount = Integer.parseInt(x[1]) ; }
+                catch (NumberFormatException ex)
+                { throw new CmdException("Can't parse "+x[1]+" in arg "+getValue(argRepeat)+" as an integer") ; }
+            }
+            else
+                throw new CmdException("Wrong format for repeat count: "+getValue(argRepeat)) ;
+        }
+        if ( isVerbose() )
+            ARQ.getContext().setTrue(ARQ.symLogExec) ;
+        
+        if ( hasArg(argExplain) )
+            ARQ.setExecutionLogging(Explain.InfoLevel.ALL) ;
+        
+        if ( hasArg(argOptimize) )
+        {
+            String x1 = getValue(argOptimize) ;
+            if ( hasValueOfTrue(argOptimize) || x1.equalsIgnoreCase("on") || x1.equalsIgnoreCase("yes") ) 
+                queryOptimization = true ;
+            else if ( hasValueOfFalse(argOptimize) || x1.equalsIgnoreCase("off") || x1.equalsIgnoreCase("no") )
+                queryOptimization = false ;
+            else throw new CmdException("Optimization flag must be true/false/on/off/yes/no. Found: "+getValue(argOptimize)) ;
+        }
+    }
+    
+    protected ModDataset setModDataset()
+    {
+        return new ModDatasetGeneralAssembler() ;
+    }
+    
+    @Override
+    protected void exec()
+    {
+        if ( ! queryOptimization )
+            ARQ.getContext().setFalse(ARQ.optimization) ;
+        if ( cmdStrictMode )
+            ARQ.getContext().setFalse(ARQ.optimization) ;
+        
+        // Warm up.
+        for ( int i = 0 ; i < warmupCount ; i++ )
+        {
+            queryExec(false, ResultsFormat.FMT_NONE) ;
+        }
+        
+        for ( int i = 0 ; i < repeatCount ; i++ )
+            queryExec(modTime.timingEnabled(),  modResults.getResultsFormat()) ;
+        
+        if ( modTime.timingEnabled() && repeatCount > 1 )
+        {
+            long avg = totalTime/repeatCount ;
+            String avgStr = modTime.timeStr(avg) ;
+            System.err.println("Total time: "+modTime.timeStr(totalTime)+" sec for repeat count of "+repeatCount+ " : average: "+avgStr) ;
+        }
+    }
+
+    @Override
+    protected String getCommandName() { return Lib.className(this) ; }
+    
+    @Override
+    protected String getSummary() { return getCommandName()+" --data=<file> --query=<query>" ; }
+    
+    protected Dataset getDataset()  { 
+        try {
+            Dataset ds = modDataset.getDataset();
+            if ( ds == null )
+                ds = dealWithNoDataset();
+            return ds;
+        }
+        catch (RiotNotFoundException ex) {
+            System.err.println("Failed to load data: " + ex.getMessage());
+            throw new TerminationException(1);
+        }
+        catch (RiotException ex) {
+            System.err.println("Failed to load data");
+            throw new TerminationException(1);
+        }
+    }
+    
+    protected Dataset dealWithNoDataset()  {
+        return DatasetFactory.create() ;
+        //throw new CmdException("No dataset provided") ; 
+    }
+    
+    protected long totalTime = 0 ;
+    protected void queryExec(boolean timed, ResultsFormat fmt)
+    {
+        try{
+            Query query = modQuery.getQuery() ;
+            if ( isVerbose() )
+            {
+                IndentedWriter out = new IndentedWriter(System.out, true) ;
+                query.serialize(out) ;
+                out.flush() ;
+                System.out.println();
+            }
+            
+            if ( isQuiet() )
+                LogCtl.setError(SysRIOT.riotLoggerName) ;
+            Dataset dataset = getDataset() ;
+            modTime.startTimer() ;
+            QueryExecution qe = QueryExecutionFactory.create(query, dataset) ;
+            // Check there is a dataset
+            
+            if ( dataset == null && ! query.hasDatasetDescription() )
+            {
+                System.err.println("Dataset not specified in query nor provided on command line.");
+                throw new TerminationException(1) ;
+            }
+            try { QueryExecUtils.executeQuery(query, qe, fmt) ; } 
+            catch (QueryCancelledException ex) { 
+                System.out.flush() ;
+                System.err.println("Query timed out") ;
+            }
+            
+            long time = modTime.endTimer() ;
+            if ( timed )
+            {
+                totalTime += time ;
+                System.err.println("Time: "+modTime.timeStr(time)+" sec") ;
+            }
+            qe.close() ;
+        }
+        catch (ARQInternalErrorException intEx)
+        {
+            System.err.println(intEx.getMessage()) ;
+            if ( intEx.getCause() != null )
+            {
+                System.err.println("Cause:") ;
+                intEx.getCause().printStackTrace(System.err) ;
+                System.err.println() ;
+            }
+            intEx.printStackTrace(System.err) ;
+        }
+        catch (ResultSetException ex)
+        {
+            System.err.println(ex.getMessage()) ;
+            ex.printStackTrace(System.err) ;
+        }
+        catch (QueryException qEx)
+        {
+            //System.err.println(qEx.getMessage()) ;
+            throw new CmdException("Query Exeception", qEx) ;
+        }
+        catch (JenaException | CmdException ex) { throw ex ; }
+        catch (Exception ex)
+        {
+            throw new CmdException("Exception", ex) ;
+        }
+    }    
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/rdfdiff.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/rdfdiff.java b/jena-cmds/src/main/java/arq/rdfdiff.java
new file mode 100644
index 0000000..78a51bb
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/rdfdiff.java
@@ -0,0 +1,312 @@
+/*
+ * 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 arq;
+
+import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.io.FileInputStream;
+
+import org.apache.jena.rdf.model.*;
+import org.apache.jena.sparql.util.Closure;
+
+/**
+ * A program which read two RDF models and provides a basic triple level diff
+ *
+ * <p>
+ * This program will read two RDF models, in a variety of languages, and compare
+ * them providing a basic triple level diff output. Since blank nodes are a
+ * complicating factor diffs for blank node containing portions of the graph are
+ * reported in terms of sub-graphs rather than individual triples.
+ * </p>
+ * <p>
+ * Input can be read either from a URL or from a file. The program writes its
+ * results to the standard output stream and sets its exit code to 0 if the
+ * models are equal, to 1 if they are not and to -1 if it encounters an error.
+ * </p>
+ *
+ * <p>
+ * </p>
+ *
+ * <pre>
+ * java jena.rdfcompare model1 model2 [lang1 [lang2]]
+ *
+ *       model1 and model2 can be file names or URL's
+ *       lang1 and lang2 specify the language of the input and can be:
+ *           RDF/XML
+ *           N-TRIPLE
+ *           N3
+ * </pre>
+ */
+public class rdfdiff extends java.lang.Object {
+
+    static {
+        setCmdLogging();
+    }
+
+    /**
+     * @param args
+     *            the command line arguments
+     */
+    public static void main(String... args) {
+        if (args.length < 2 || args.length > 6) {
+            usage();
+            System.exit(-1);
+        }
+
+        String in1 = args[0];
+        String in2 = args[1];
+        String lang1 = "RDF/XML";
+        if (args.length >= 3) {
+            lang1 = args[2];
+        }
+        String lang2 = "N-TRIPLE";
+        if (args.length >= 4) {
+            lang2 = args[3];
+        }
+        String base1 = null;
+        if (args.length >= 5) {
+            base1 = args[4];
+        }
+        String base2 = base1;
+        if (args.length >= 6) {
+            base2 = args[5];
+        }
+
+        System.out.println(in1 + " " + in2 + " " + lang1 + " " + lang2 + " " + base1 + " " + base2);
+        try {
+            Model m1 = ModelFactory.createDefaultModel();
+            Model m2 = ModelFactory.createDefaultModel();
+
+            read(m1, in1, lang1, base1);
+            read(m2, in2, lang2, base2);
+
+            if (m1.isIsomorphicWith(m2)) {
+                System.out.println("models are equal");
+                System.out.println();
+                System.exit(0);
+            } else {
+                System.out.println("models are unequal");
+                System.out.println();
+
+                if (m1.size() != m2.size()) {
+                    System.out.println(String.format("< %,d triples", m1.size()));
+                    System.out.println(String.format("> %,d triples", m2.size()));
+                }
+
+                // Calculate differences
+                Map<AnonId, Model> m1SubGraphs = new HashMap<>();
+                StmtIterator iter = m1.listStatements();
+                while (iter.hasNext()) {
+                    Statement stmt = iter.next();
+                    if (stmt.asTriple().isConcrete()) {
+                        if (!m2.contains(stmt)) {
+                            System.out.print("< ");
+                            System.out.println(stmt.toString());
+                        }
+                    } else {
+                        // Handle blank nodes via sub-graphs
+                        addToSubGraph(stmt, m1SubGraphs);
+                    }
+                }
+
+                Map<AnonId, Model> m2SubGraphs = new HashMap<>();
+                iter = m2.listStatements();
+                while (iter.hasNext()) {
+                    Statement stmt = iter.next();
+                    if (stmt.asTriple().isConcrete()) {
+                        if (!m1.contains(stmt)) {
+                            System.out.print("> ");
+                            System.out.println(stmt.toString());
+                        }
+                    } else {
+                        // Handle blank nodes via sub-graphs
+                        addToSubGraph(stmt, m2SubGraphs);
+                    }
+                }
+
+                // Compute sub-graph differences
+
+                // Reduce to sets
+                Set<Model> m1SubGraphSet = new TreeSet<>(new ModelReferenceComparator());
+                m1SubGraphSet.addAll(m1SubGraphs.values());
+                Set<Model> m2SubGraphSet = new TreeSet<>(new ModelReferenceComparator());
+                m2SubGraphSet.addAll(m2SubGraphs.values());
+
+                if (m1SubGraphSet.size() != m2SubGraphSet.size()) {
+                    System.out.println("< " + m1SubGraphs.size() + " sub-graphs");
+                    System.out.println("> " + m2SubGraphs.size() + " sub-graphs");
+                }
+                if (m1SubGraphSet.size() > 0) {
+                    diffSubGraphs(m1SubGraphSet, m2SubGraphSet, "< ");
+                }
+                if (m2SubGraphSet.size() > 0) {
+                    diffSubGraphs(m2SubGraphSet, m1SubGraphSet, "> ");
+                }
+
+                System.exit(1);
+            }
+        } catch (Exception e) {
+            System.err.println("Unhandled exception:");
+            System.err.println("    " + e.toString());
+            System.exit(-1);
+        }
+    }
+
+    private static void diffSubGraphs(Set<Model> m1SubGraphSet, Set<Model> m2SubGraphSet, String prefix) {
+        for (Model subGraph : m1SubGraphSet) {
+            // Find candidate matches
+            List<Model> candidates = new ArrayList<>();
+            for (Model subGraphCandidate : m2SubGraphSet) {
+                if (subGraph.size() == subGraphCandidate.size()) {
+                    candidates.add(subGraph);
+                }
+            }
+
+            if (candidates.size() == 0) {
+                // No match
+                printNonMatchingSubGraph(prefix, subGraph);
+            } else if (candidates.size() == 1) {
+                // Precisely 1 candidate
+                if (!subGraph.isIsomorphicWith(candidates.get(0))) {
+                    printNonMatchingSubGraph(prefix, subGraph);
+                } else {
+                    m2SubGraphSet.remove(candidates.get(0));
+                }
+            } else {
+                // Multiple candidates
+                boolean matched = false;
+                for (Model subGraphCandidate : candidates) {
+                    if (subGraph.isIsomorphicWith(subGraphCandidate)) {
+                        // Found a match
+                        matched = true;
+                        m2SubGraphSet.remove(subGraphCandidate);
+                        break;
+                    }
+                }
+
+                if (!matched) {
+                    // Didn't find a match
+                    printNonMatchingSubGraph(prefix, subGraph);
+                }
+            }
+        }
+    }
+
+    private static void printNonMatchingSubGraph(String prefix, Model subGraph) {
+        StmtIterator sIter = subGraph.listStatements();
+        while (sIter.hasNext()) {
+            System.out.print(prefix);
+            System.out.println(sIter.next().toString());
+        }
+    }
+
+    private static void addToSubGraph(Statement stmt, Map<AnonId, Model> subGraphs) {
+        Set<AnonId> ids = new HashSet<>();
+
+        addToIdList(stmt, ids);
+
+        // Here we take a copy of the IDs
+        Model subGraph = null;
+        for (AnonId id : ids) {
+            if (!subGraphs.containsKey(id)) {
+                subGraph = Closure.closure(stmt);
+                subGraph.add(stmt);
+                break;
+            }
+        }
+
+        // May already have built the sub-graph that includes this statement
+        if (subGraph == null)
+            return;
+
+        // Find any further IDs that occur in the sub-graph
+        StmtIterator sIter = subGraph.listStatements();
+        while (sIter.hasNext()) {
+            addToIdList(sIter.next(), ids);
+        }
+
+        // Associate the sub-graph with all mentioned blank node IDs
+        for (AnonId id : ids) {
+            if (subGraphs.containsKey(id))
+                throw new IllegalStateException(String.format("ID %s occurs in multiple sub-graphs", id));
+            subGraphs.put(id, subGraph);
+        }
+    }
+
+    private static void addToIdList(Statement stmt, Set<AnonId> ids) {
+        if (stmt.getSubject().isAnon()) {
+            ids.add(stmt.getSubject().getId());
+        }
+        if (stmt.getObject().isAnon()) {
+            ids.add(stmt.getObject().asResource().getId());
+        }
+    }
+
+    protected static void usage() {
+        System.err.println("usage:");
+        System.err.println("    java jena.rdfdiff source1 source2 [lang1 [lang2 [base1 [base2]]]]");
+        System.err.println();
+        System.err.println("    source1 and source2 can be URL's or filenames");
+        System.err.println("    lang1 and lang2 can take values:");
+        System.err.println("      RDF/XML");
+        System.err.println("      N-TRIPLE");
+        System.err.println("      N3");
+        System.err.println("    lang1 defaults to RDF/XML, lang2 to N-TRIPLE");
+        System.err.println("    base1 and base2 are URIs");
+        System.err.println("    base1 defaults to null");
+        System.err.println("    base2 defaults to base1");
+        System.err.println("    If no base URIs are specified Jena determines the base URI based on the input source");
+
+        System.err.println();
+    }
+
+    protected static void read(Model model, String in, String lang, String base) throws java.io.FileNotFoundException {
+        try {
+            URL url = new URL(in);
+            model.read(in, base, lang);
+        } catch (java.net.MalformedURLException e) {
+            model.read(new FileInputStream(in), base, lang);
+        }
+    }
+
+    private static class ModelReferenceComparator implements Comparator<Model> {
+
+        @Override
+        public int compare(Model o1, Model o2) {
+            if (o1 == o2)
+                return 0;
+            int h1 = System.identityHashCode(o1);
+            int h2 = System.identityHashCode(o2);
+
+            if (h1 == h2)
+                return 0;
+            return h1 < h2 ? -1 : 1;
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/rset.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/rset.java b/jena-cmds/src/main/java/arq/rset.java
new file mode 100644
index 0000000..b1cbc3e
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/rset.java
@@ -0,0 +1,73 @@
+/*
+ * 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 arq;
+
+import org.apache.jena.query.ResultSet ;
+import arq.cmdline.CmdARQ ;
+import arq.cmdline.ModResultsIn ;
+import arq.cmdline.ModResultsOut ;
+
+/** Read and write result sets */
+
+public class rset extends CmdARQ
+{
+    ModResultsIn modInput    = new ModResultsIn() ;
+    ModResultsOut modOutput  = new ModResultsOut() ;
+    
+    static String usage = rset.class.getName()+
+            " [--in syntax] [--out syntax] [--file FILE | FILE ]" ; 
+
+    public static void main(String... argv)
+    {
+        new rset(argv).mainRun() ;
+    }
+
+    public rset(String[] argv)
+    {
+        super(argv) ;
+        super.addModule(modInput) ;
+        super.addModule(modOutput) ;
+    }
+            
+    @Override
+    protected void processModulesAndArgs()
+    {
+        super.processModulesAndArgs() ;
+    }
+
+    @Override
+    protected String getSummary()
+    {
+        return usage ;
+    }
+
+    @Override
+    protected void exec()
+    {
+        ResultSet rs = modInput.getResultSet() ;
+        modOutput.printResultSet(rs, null) ;
+    }
+
+    @Override
+    protected String getCommandName()
+    {
+        return "rset" ;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/rsparql.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/rsparql.java b/jena-cmds/src/main/java/arq/rsparql.java
new file mode 100644
index 0000000..bf87dfd
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/rsparql.java
@@ -0,0 +1,95 @@
+/*
+ * 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 arq;
+
+import jena.cmd.CmdException;
+
+import org.apache.jena.query.Query ;
+import org.apache.jena.query.QueryExecution ;
+import org.apache.jena.query.QueryExecutionFactory ;
+import org.apache.jena.query.Syntax ;
+import org.apache.jena.sparql.engine.http.HttpQuery ;
+import org.apache.jena.sparql.engine.http.QueryExceptionHTTP ;
+import org.apache.jena.sparql.util.QueryExecUtils ;
+
+import arq.cmdline.CmdARQ ;
+import arq.cmdline.ModQueryIn ;
+import arq.cmdline.ModRemote ;
+import arq.cmdline.ModResultsOut ;
+
+public class rsparql extends CmdARQ
+{
+    protected ModQueryIn    modQuery =      new ModQueryIn(Syntax.syntaxSPARQL_11) ;
+    protected ModRemote     modRemote =     new ModRemote() ;
+    protected ModResultsOut modResults =    new ModResultsOut() ;
+
+    public static void main (String... argv)
+    {
+        new rsparql(argv).mainRun() ;
+    }
+
+
+    public rsparql(String[] argv)
+    {
+        super(argv) ;
+        super.addModule(modRemote) ;
+        super.addModule(modQuery) ;
+        super.addModule(modResults) ;
+    }
+    
+    
+    @Override
+    protected void processModulesAndArgs()
+    {
+        super.processModulesAndArgs() ;
+        if ( modRemote.getServiceURL() == null )
+            throw new CmdException("No SPARQL endpoint specificied") ;
+    }
+    
+    @Override
+    protected void exec()
+    {
+        Query query = modQuery.getQuery() ;
+
+        try {
+            String serviceURL = modRemote.getServiceURL() ;
+            QueryExecution qe = QueryExecutionFactory.sparqlService(serviceURL, query) ;
+            if ( modRemote.usePost() )
+                HttpQuery.urlLimit = 0 ;
+
+            QueryExecUtils.executeQuery(query, qe, modResults.getResultsFormat()) ;
+        } catch (QueryExceptionHTTP ex)
+        {
+            throw new CmdException("HTTP Exeception", ex) ;
+        }
+        catch (Exception ex)
+        {
+            System.out.flush() ;
+            ex.printStackTrace(System.err) ;
+        }
+    }
+
+
+    @Override
+    protected String getSummary()
+    {
+        return null ;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/rupdate.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/rupdate.java b/jena-cmds/src/main/java/arq/rupdate.java
new file mode 100644
index 0000000..8ef988c
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/rupdate.java
@@ -0,0 +1,98 @@
+/**
+ * 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 arq;
+
+import java.util.List ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException;
+
+import org.apache.jena.update.UpdateExecutionFactory ;
+import org.apache.jena.update.UpdateFactory ;
+import org.apache.jena.update.UpdateProcessor ;
+import org.apache.jena.update.UpdateRequest ;
+
+import arq.cmdline.CmdARQ ;
+import arq.cmdline.ModRemote ;
+
+public class rupdate extends CmdARQ
+{
+    static final ArgDecl updateArg = new ArgDecl(ArgDecl.HasValue, "update", "file") ;
+    
+    protected ModRemote     modRemote =     new ModRemote() ;
+
+    List<String> requestFiles = null ;
+
+    public static void main(String[] argv)
+    {
+        new rupdate(argv).mainRun() ;
+    }
+
+    protected rupdate(String[] argv)
+    {
+        super(argv) ;
+        super.add(updateArg, "--update=FILE", "Update commands to execute") ;
+        super.addModule(modRemote) ;
+    }
+
+    @Override
+    protected void processModulesAndArgs()
+    {
+        requestFiles = getValues(updateArg) ;   // ????
+        super.processModulesAndArgs() ;
+    }
+    
+    
+    @Override
+    protected String getSummary()
+    {
+        return getCommandName()+" --service=URL --update=<request file>" ;
+    }
+
+    @Override
+    protected void exec()
+    {
+        if ( modRemote.getServiceURL() == null )
+        {
+            throw new CmdException("No endpoint given") ;
+        }
+        String endpoint = modRemote.getServiceURL() ;
+
+        for ( String filename : requestFiles )
+        {
+            UpdateRequest req = UpdateFactory.read( filename );
+            exec( endpoint, req );
+        }
+
+        for ( String requestString : super.getPositional() )
+        {
+            requestString = indirect( requestString );
+            UpdateRequest req = UpdateFactory.create( requestString );
+            exec( endpoint, req );
+        }
+    }
+
+    private void exec(String endpoint, UpdateRequest req) 
+    {
+        UpdateProcessor proc = UpdateExecutionFactory.createRemote(req, endpoint) ;
+        proc.execute() ;
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/sparql.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/sparql.java b/jena-cmds/src/main/java/arq/sparql.java
new file mode 100644
index 0000000..d42ba7f
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/sparql.java
@@ -0,0 +1,37 @@
+/*
+ * 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 arq;
+
+import org.apache.jena.query.Syntax ;
+
+/** A program to execute queries from the command line in SPARQL mode. */
+
+public class sparql extends query
+{
+    public static void main (String... argv) {
+        new sparql(argv).mainRun() ;
+    }
+    
+    public sparql(String[] argv) {
+        super(argv) ; 
+    }
+
+    @Override
+    protected Syntax getDefaultSyntax()     { return Syntax.syntaxSPARQL_11 ; } 
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/sse.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/sse.java b/jena-cmds/src/main/java/arq/sse.java
new file mode 100644
index 0000000..95a769e
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/sse.java
@@ -0,0 +1,108 @@
+/*
+ * 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 arq;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.TerminationException;
+
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.sparql.serializer.SerializationContext ;
+import org.apache.jena.sparql.sse.Item ;
+import org.apache.jena.sparql.sse.ItemWriter ;
+import org.apache.jena.sparql.sse.SSE ;
+
+import arq.cmdline.CmdARQ_SSE ;
+
+public class sse extends CmdARQ_SSE
+{
+    protected final ArgDecl numberDecl      = new ArgDecl(ArgDecl.HasValue, "num", "number") ;
+    protected final ArgDecl noPrintDecl     = new ArgDecl(ArgDecl.NoValue, "n") ;
+    protected final ArgDecl noResolveDecl   = new ArgDecl(ArgDecl.NoValue, "raw") ;
+
+    private boolean         print       = true ;
+    private boolean         structural  = true ;
+    private boolean         lineNumbers = false ;
+
+    public static void main (String... argv)
+    {
+        new sse(argv).mainRun() ;
+    }
+
+    public sse(String[] argv)
+    {
+        super(argv) ;
+        super.add(noPrintDecl,      "-n",               "Don't print the expression") ;
+        super.add(numberDecl,       "--num [on|off]",   "Numbers") ;
+        super.add(noResolveDecl,    "--raw", "Don't handle base or prefix names specially") ;
+    }
+
+    @Override
+    protected void processModulesAndArgs()
+    {
+        super.processModulesAndArgs() ;
+        print = !contains(noPrintDecl) ;
+        if ( contains(numberDecl) )
+            lineNumbers = getValue(numberDecl).equalsIgnoreCase("on") ;
+        
+        if ( contains(noResolveDecl) )
+            SSE.setUseResolver(false) ;
+    }
+
+    @Override
+    protected String getCommandName() { return Lib.className(this) ; }
+
+    @Override
+    protected String getSummary() { return getCommandName() ; }
+
+    static final String divider = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" ;
+    //static final String divider = "" ;
+
+    boolean needDivider = false ;
+    private void divider()
+    {
+        if ( needDivider ) System.out.println(divider) ;
+        needDivider = true ;
+    }
+
+    @Override
+    protected void exec(Item item)
+    {
+        if ( ! print )
+            return ;
+        
+        if ( item == null )
+        {
+            System.err.println("No expression") ;
+            throw new TerminationException(9) ;
+        }
+        divider() ;
+        IndentedWriter out = new IndentedWriter(System.out, lineNumbers) ;
+        
+        // Need to check if used.
+        //PrefixMapping pmap = SSE.getDefaultPrefixMapWrite() ;
+        PrefixMapping pmap = null ;
+        SerializationContext sCxt = new SerializationContext(pmap) ;
+        ItemWriter.write(out, item, sCxt) ;
+        //item.output(out) ;
+        out.ensureStartOfLine() ;
+        out.flush();
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/sse_exec.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/sse_exec.java b/jena-cmds/src/main/java/arq/sse_exec.java
new file mode 100644
index 0000000..3b5f49c
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/sse_exec.java
@@ -0,0 +1,50 @@
+/*
+ * 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 arq;
+
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.sparql.sse.Item ;
+import org.apache.jena.sparql.sse.builders.BuilderExec ;
+import arq.cmdline.CmdARQ_SSE ;
+
+public class sse_exec extends CmdARQ_SSE
+{
+    
+    public static void main (String... argv)
+    {
+        new sse_exec(argv).mainRun() ;
+    }
+    
+    public sse_exec(String[] argv)
+    {
+        super(argv) ;
+    }
+    
+    @Override
+    protected String getCommandName() { return Lib.className(this) ; }
+    
+    @Override
+    protected String getSummary() { return getCommandName()+" [--file<file> | string]" ; }
+
+    @Override
+    protected void exec(Item item)
+    {
+        BuilderExec.exec(item) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/sse_expr.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/sse_expr.java b/jena-cmds/src/main/java/arq/sse_expr.java
new file mode 100644
index 0000000..9339d53
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/sse_expr.java
@@ -0,0 +1,24 @@
+/*
+ * 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 arq;
+
+public class sse_expr
+{
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/sse_query.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/sse_query.java b/jena-cmds/src/main/java/arq/sse_query.java
new file mode 100644
index 0000000..c5d8c7f
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/sse_query.java
@@ -0,0 +1,162 @@
+/*
+ * 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 arq;
+
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException;
+import jena.cmd.TerminationException;
+
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.query.DatasetFactory ;
+import org.apache.jena.sparql.algebra.Algebra ;
+import org.apache.jena.sparql.algebra.Op ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.sparql.engine.Plan ;
+import org.apache.jena.sparql.engine.PlanOp ;
+import org.apache.jena.sparql.engine.QueryIterator ;
+import org.apache.jena.sparql.util.QueryExecUtils ;
+
+import arq.cmdline.CmdARQ ;
+import arq.cmdline.ModAlgebra ;
+import arq.cmdline.ModDataset ;
+import arq.cmdline.ModDatasetGeneralAssembler ;
+import arq.cmdline.ModEngine ;
+import arq.cmdline.ModResultsOut ;
+import arq.cmdline.ModTime ;
+
+public class sse_query extends CmdARQ
+{
+    // Merging with qparse/sparql
+    // 1 - split those two into Query and QueryExecution parts
+    // 2 - This is then calls on the QueryExecution parts
+    // 3 - Printing plan - uses a verbose prefix setting.  Scan to see what's in use.
+    //      WriterOp.reducePrologue(prologue, op) => prologue.
+    
+    protected final ArgDecl printDecl  = new ArgDecl(ArgDecl.HasValue, "print") ;
+    
+    ModAlgebra    modAlgebra =  new ModAlgebra() ;
+    ModDataset    modDataset =  new ModDatasetGeneralAssembler() ;
+    ModResultsOut modResults =  new ModResultsOut() ;
+    ModTime       modTime =     new ModTime() ;
+    ModEngine     modEngine =   new ModEngine() ;
+
+    boolean printOp      = false ;
+    boolean printPlan    = false ;
+    
+    public static void main (String... argv)
+    {
+        new sse_query(argv).mainRun() ;
+    }
+    
+    public sse_query(String[] argv)
+    {
+        super(argv) ;
+        super.add(printDecl, "--print=op/plan",  "Print details") ;
+        super.addModule(modAlgebra) ;
+        super.addModule(modResults) ;
+        super.addModule(modDataset) ;
+        super.addModule(modTime) ;
+        super.addModule(modEngine) ;
+    }
+
+    @Override
+    protected void processModulesAndArgs()
+    {
+        super.processModulesAndArgs() ;
+
+        for (String arg : getValues(printDecl))
+        {
+            if ( arg.equalsIgnoreCase("op") ||
+                      arg.equalsIgnoreCase("alg") || 
+                      arg.equalsIgnoreCase("algebra") ) { printOp = true ; }
+            else if ( arg.equalsIgnoreCase("plan"))     { printPlan = true ; }
+            else
+                throw new CmdException("Not a recognized print form: "+arg+" : Choices are: query, op, quad") ;
+        }
+        
+    }
+    
+    @Override
+    protected String getCommandName() { return Lib.className(this) ; }
+    
+    @Override
+    protected String getSummary() { return getCommandName()+" --data=<file> --query=<query>" ; }
+
+    static final String divider = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" ;
+    //static final String divider = "" ;
+    boolean needDivider = false ;
+    private void divider()
+    {
+        if ( needDivider ) System.out.println(divider) ;
+        needDivider = true ;
+    }
+    
+    @Override
+    protected void exec()
+    {
+        Op op = modAlgebra.getOp() ;
+
+        if ( op == null )
+        {
+            System.err.println("No query expression to execute") ;
+            throw new TerminationException(9) ;
+        }
+
+        Dataset dataset = modDataset.getDataset() ;
+        // Check there is a dataset.
+        if ( dataset == null )
+            dataset = DatasetFactory.createGeneral() ;
+
+        modTime.startTimer() ;
+        DatasetGraph dsg = dataset.asDatasetGraph() ;
+
+        if ( printOp || printPlan )
+        {
+            if ( printOp )
+            {
+                divider() ;
+                IndentedWriter out = new IndentedWriter(System.out, true) ;
+                op.output(out) ;
+                out.flush();
+            }
+
+            if ( printPlan )
+            {
+                QueryIterator qIter = Algebra.exec(op, dsg) ;
+                Plan plan = new PlanOp(op, null, qIter) ;
+                divider() ;
+                IndentedWriter out = new IndentedWriter(System.out, false) ;
+                plan.output(out) ;
+                out.flush();
+            }
+            //return ;
+        }
+
+        // Do not optimize.  Execute as-is.
+        QueryExecUtils.execute(op, dsg, modResults.getResultsFormat()) ;
+
+        long time = modTime.endTimer() ;
+        if ( modTime.timingEnabled() )
+            System.out.println("Time: "+modTime.timeStr(time)) ;
+    }    
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/tokens.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/tokens.java b/jena-cmds/src/main/java/arq/tokens.java
new file mode 100644
index 0000000..a7cbbd2
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/tokens.java
@@ -0,0 +1,24 @@
+/*
+ * 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 arq;
+
+public class tokens
+{
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/uparse.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/uparse.java b/jena-cmds/src/main/java/arq/uparse.java
new file mode 100644
index 0000000..83d44cb
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/uparse.java
@@ -0,0 +1,187 @@
+/*
+ * 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 arq;
+
+import java.io.IOException ;
+import java.util.List ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException;
+
+import org.apache.jena.atlas.io.IndentedLineBuffer ;
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.query.QueryParseException ;
+import org.apache.jena.query.Syntax ;
+import org.apache.jena.sparql.modify.request.UpdateWriter ;
+import org.apache.jena.update.UpdateFactory ;
+import org.apache.jena.update.UpdateRequest ;
+import org.apache.jena.util.FileUtils ;
+
+import arq.cmdline.CmdARQ ;
+
+public class uparse extends CmdARQ
+{
+    protected static final ArgDecl fileArg          = new ArgDecl(ArgDecl.HasValue, "file", "update") ;
+    protected static final ArgDecl syntaxArg        = new ArgDecl(ArgDecl.HasValue, "syntax", "syn") ;
+    protected static final ArgDecl argDeclPrint     = new ArgDecl(ArgDecl.HasValue, "print") ;
+    List<String> requestFiles = null ;
+    protected Syntax updateSyntax = null ;
+    private boolean printUpdate = false ;
+    private boolean printNone  = false ;
+    
+    public static void main (String... argv)
+    { new uparse(argv).mainRun() ; }
+    
+    protected uparse(String[] argv)
+    {
+        super(argv) ;
+        super.add(fileArg, "--file=FILE",  "Update commands to parse") ;
+        super.add(syntaxArg, "--syntax=name", "Update syntax") ;
+        super.add(argDeclPrint, "--print", "Print in various forms [update, none]") ;
+    }
+
+    @Override
+    protected void processModulesAndArgs()
+    {
+        requestFiles = getValues(fileArg) ;
+        super.processModulesAndArgs() ;
+        if ( super.cmdStrictMode )
+            updateSyntax = Syntax.syntaxSPARQL_11 ;
+
+        // Set syntax
+        if ( super.contains(syntaxArg) ) {
+            // short name
+            String s = super.getValue(syntaxArg) ;
+            Syntax syn = Syntax.lookup(s) ;
+            if ( syn == null )
+                super.cmdError("Unrecognized syntax: " + s) ;
+            updateSyntax = syn ;
+        }
+        
+        for ( String arg : getValues( argDeclPrint ) )
+        {
+            if ( arg.equalsIgnoreCase( "query" ) )
+                printUpdate = true;
+            else if ( arg.equalsIgnoreCase( "none" ) )
+                printNone = true;
+            else
+                throw new CmdException("Not a recognized print form: " + arg + " : Choices are: update, none" );
+        }
+        
+        if ( !printUpdate && ! printNone )
+            printUpdate = true ;
+        
+    }
+    
+    @Override
+    protected String getCommandName() { return Lib.className(this) ; }
+    
+    @Override
+    protected String getSummary() { return getCommandName()+" --file=<request file> | <update string>" ; }
+
+    @Override
+    protected void exec()
+    {
+        for ( String filename : requestFiles )
+        {
+            Syntax syntax = updateSyntax ;
+            if ( syntax == null )
+                syntax = Syntax.guessUpdateFileSyntax(filename) ;
+            String x = oneFile( filename );
+            if ( x != null )
+                execOne( x, syntax );
+        }
+
+        
+        
+        
+        for ( String x : super.positionals ) {
+            Syntax syntax = updateSyntax ;    
+            if ( matchesIndirect(x) ) {
+                if ( syntax == null )
+                    syntax = Syntax.guessUpdateFileSyntax(x) ;
+                x = indirect( x );
+            }
+            if ( syntax == null )
+                syntax = Syntax.defaultUpdateSyntax ;
+            execOne( x, syntax );
+        }
+
+    }
+    
+    private String oneFile(String filename)
+    {
+        divider() ;
+        try
+        {
+            return FileUtils.readWholeFileAsUTF8(filename) ;
+        } catch (IOException ex)
+        {
+            System.err.println("No such file: "+filename) ;
+            return null ;
+        }
+    }
+    
+    private void execOne(String updateString, Syntax syntax)
+    {
+        UpdateRequest req ; 
+        try {
+            req = UpdateFactory.create(updateString, syntax) ;
+        } catch (QueryParseException ex)
+        {
+            System.err.print("Parse error: ") ;
+            System.err.println(ex.getMessage()) ;
+            return ; 
+        }
+        //req.output(IndentedWriter.stderr) ;
+        if ( printUpdate )
+            System.out.print(req) ;
+        
+        if ( printNone )
+            return ;
+        
+        // And some checking.
+        IndentedLineBuffer w = new IndentedLineBuffer() ;
+        UpdateWriter.output(req, w) ;
+        String updateString2 = w.asString() ;
+        UpdateRequest req2 = null ;
+        try {
+            req2 = UpdateFactory.create(updateString2, syntax) ;
+        } catch (QueryParseException ex)
+        {
+            System.err.println("Can not reparse update after serialization") ;
+            System.err.println(updateString2) ; 
+        }
+
+        if ( ! req.equalTo(req2) )
+            System.err.println("Reparsed update does not .equalTo original parsed request") ;
+        
+        
+    }
+    
+    static final String divider = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" ;
+    //static final String divider = "" ;
+    static boolean needDivider = false ;
+    private static void divider()
+    {
+        if ( needDivider ) System.out.println(divider) ;
+        needDivider = true ;
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/update.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/update.java b/jena-cmds/src/main/java/arq/update.java
new file mode 100644
index 0000000..333d41a
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/update.java
@@ -0,0 +1,128 @@
+/*
+ * 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 arq;
+
+import java.util.List ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException;
+
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFDataMgr ;
+import org.apache.jena.sparql.SystemARQ ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.sparql.core.DatasetGraphFactory ;
+import org.apache.jena.sparql.core.Transactional ;
+import org.apache.jena.sparql.core.TransactionalNull ;
+import org.apache.jena.update.UpdateExecutionFactory ;
+import org.apache.jena.update.UpdateFactory ;
+import org.apache.jena.update.UpdateRequest ;
+
+import arq.cmdline.CmdUpdate ;
+
+public class update extends CmdUpdate
+{
+    static final ArgDecl updateArg = new ArgDecl(ArgDecl.HasValue, "update", "file") ;
+    static final ArgDecl dumpArg = new ArgDecl(ArgDecl.NoValue, "dump") ;       // Write the result to stdout.
+    
+    List<String> requestFiles = null ;
+    boolean dump = false ;
+    
+    public static void main (String... argv)
+    { new update(argv).mainRun() ; }
+    
+    protected update(String[] argv) {
+        super(argv) ;
+        super.add(updateArg, "--update=FILE", "Update commands to execute") ;
+        super.add(dumpArg, "--dump", "Dump the resulting graph store") ;
+    }
+
+    @Override
+    protected void processModulesAndArgs() {
+        requestFiles = getValues(updateArg) ; // ????
+        dump = contains(dumpArg) ;
+        super.processModulesAndArgs() ;
+    }
+
+    @Override
+    protected String getCommandName() { return Lib.className(this) ; }
+    
+    @Override
+    protected String getSummary() { return getCommandName()+" --desc=assembler [--dump] --update=<request file>" ; }
+
+    // Subclass for specialised commands making common updates more convenient
+    @Override
+    protected void execUpdate(DatasetGraph graphStore) {
+        if ( requestFiles.size() == 0 && getPositional().size() == 0 )
+            throw new CmdException("Nothing to do") ;
+
+        Transactional transactional = (graphStore instanceof Transactional) ? (Transactional)graphStore : new TransactionalNull() ;
+
+        for ( String filename : requestFiles ) {
+            try {
+                transactional.begin(ReadWrite.WRITE) ;
+                execOneFile(filename, graphStore) ;
+                transactional.commit() ;
+            }
+            catch (Throwable ex) { 
+                try { transactional.abort() ; } catch (Exception ex2) {}
+                throw ex ;
+            }
+            finally { transactional.end() ; }
+        }
+
+        for ( String requestString : super.getPositional() ) {
+            requestString = indirect(requestString) ;
+
+            try {
+                transactional.begin(ReadWrite.WRITE) ;
+                execOne(requestString, graphStore) ;
+                transactional.commit() ;
+            }
+            catch (Throwable ex) { 
+                try { transactional.abort() ; } catch (Exception ex2) {}
+                throw ex ;
+            }
+            finally { transactional.end() ; }
+        }
+        
+        if ( ! (graphStore instanceof Transactional) )
+            SystemARQ.sync(graphStore) ;
+
+        if ( dump )
+            RDFDataMgr.write(System.out, graphStore, Lang.NQUADS) ;
+    }
+
+    private void execOneFile(String filename, DatasetGraph store) {
+        UpdateRequest req = UpdateFactory.read(filename, updateSyntax) ;
+        UpdateExecutionFactory.create(req, store).execute() ;
+    }
+
+    private void execOne(String requestString, DatasetGraph store) {
+        UpdateRequest req = UpdateFactory.create(requestString, updateSyntax) ;
+        UpdateExecutionFactory.create(req, store).execute() ;
+    }
+
+    @Override
+    protected DatasetGraph dealWithNoDataset() {
+        return DatasetGraphFactory.create() ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/utf8.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/utf8.java b/jena-cmds/src/main/java/arq/utf8.java
new file mode 100644
index 0000000..bc47569
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/utf8.java
@@ -0,0 +1,29 @@
+/*
+ * 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 arq;
+
+
+public class utf8
+{
+    /** Simple program to help hunt down bad UTF-8 encoded characters */
+    public static void main(String[] args)
+    {
+        riotcmd.utf8.main(args) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/version.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/version.java b/jena-cmds/src/main/java/arq/version.java
new file mode 100644
index 0000000..e55434c
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/version.java
@@ -0,0 +1,29 @@
+/*
+ * 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 arq;
+
+import jena.cmd.ModVersion;
+
+public class version
+{
+    public static void main (String... argv)
+    {
+        new ModVersion(false).printVersionAndExit() ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/wwwdec.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/wwwdec.java b/jena-cmds/src/main/java/arq/wwwdec.java
new file mode 100644
index 0000000..60a07c5
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/wwwdec.java
@@ -0,0 +1,36 @@
+/*
+ * 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 arq;
+
+import org.apache.jena.atlas.lib.StrUtils ;
+
+public class wwwdec
+{
+    public static void main(String...args)
+    {
+        for ( String x : args)
+        {
+            String y = StrUtils.decodeHex(x, '%') ;
+            System.out.println(y) ;
+            
+//            String s2 = URLDecoder.decode(x, "utf-8") ;
+//            System.out.println(s2) ;   
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/wwwenc.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/wwwenc.java b/jena-cmds/src/main/java/arq/wwwenc.java
new file mode 100644
index 0000000..4ee19af
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/wwwenc.java
@@ -0,0 +1,61 @@
+/*
+ * 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 arq;
+
+import org.apache.jena.atlas.lib.StrUtils ;
+
+public class wwwenc
+{
+    /* http://en.wikipedia.org/wiki/Percent-encoding
+     * Reserved characters after percent-encoding 
+     *   !    *   "   '   (   )   ;   :   @   &   =   +   $   ,   /   ?   %   #   [   ]
+     *   %21  %2A %22 %27 %28 %29 %3B %3A %40 %26 %3D %2B %24 %2C %2F %3F %25 %23 %5B %5D
+     * These loose any reserved meaning if encoded.
+     *   
+     * Other common, but unreserved, characters after percent-encoding 
+     *   <   >   ~   .   {   }   |   \   -   `   _   ^
+     *   %3C %3E %7E %2E %7B %7D %7C %5C %2D %60 %5F %5E
+     * 
+     * Unreserved characters treated equivalent to their unencoded form.  
+     *   
+     *   
+     */
+    public static void main(String...args)
+    {
+        // Reserved characters + space
+        char reserved[] = 
+            {' ',
+             '\n','\t',
+             '!', '*', '"', '\'', '(', ')', ';', ':', '@', '&', 
+             '=', '+', '$', ',', '/', '?', '%', '#', '[', ']'} ;
+        
+        char[] other = {'<', '>', '~', '.', '{', '}', '|', '\\', '-', '`', '_', '^'} ;        
+        
+        for ( String x : args)
+        {
+            // Not URLEncoder which does www-form-encoding.
+            String y = StrUtils.encodeHex(x, '%', reserved) ;
+            System.out.println(y) ;
+            
+//            String s2 = URLEncoder.encode(s, "utf-8") ;
+//            System.out.println(s2) ;
+
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/RuleMap.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/RuleMap.java b/jena-cmds/src/main/java/jena/RuleMap.java
new file mode 100644
index 0000000..111f44b
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/RuleMap.java
@@ -0,0 +1,196 @@
+/*
+ * 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 jena;
+
+
+import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
+
+import java.util.*;
+import java.io.*;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.Options;
+import org.apache.jena.graph.* ;
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.reasoner.Reasoner ;
+import org.apache.jena.reasoner.rulesys.* ;
+import org.apache.jena.reasoner.rulesys.builtins.BaseBuiltin ;
+import org.apache.jena.util.FileManager ;
+import org.apache.jena.util.FileUtils ;
+
+/**
+ * General command line utility to process one RDF file into another
+ * by application of a set of forward chaining rules.
+ * <pre>
+ * Usage:  RuleMap [-il inlang] [-ol outlang] [-d] rulefile infile
+ * </pre>
+ * The resulting RDF data is written to stdout in format <code>outlang</code>
+ * (default N3). If <code>-d</code> is given then only the deductions
+ * generated by the rules are output. Otherwise all data including any input
+ * data (other than any removed triples) is output.
+ * <p>
+ * Rules are permitted an additional action "deduce" which forces triples
+ * to be added to the deductions graph even if they are already known (for use
+ * in deductions only mode). 
+ * </p>
+ */
+public class RuleMap {
+    static { setCmdLogging() ; }
+    
+    /**
+     * Load a set of rule definitions including processing of
+     * comment lines and any initial prefix definition lines.
+     * Also notes the prefix definitions for adding to a later inf model.
+     */
+    public static List<Rule> loadRules(String filename, Map<String, String> prefixes) {
+        String fname = filename;
+        if (fname.startsWith("file:///")) {
+            fname = File.separator + fname.substring(8);
+        } else if (fname.startsWith("file:/")) {
+            fname = File.separator + fname.substring(6);
+        } else if (fname.startsWith("file:")) {
+            fname = fname.substring(5);
+        }
+
+        BufferedReader src = FileUtils.openResourceFile(fname);
+        return loadRules(src, prefixes);
+    }
+    
+    /**
+     * Load a set of rule definitions including processing of
+     * comment lines and any initial prefix definition lines.
+     * Also notes the prefix definitions for adding to a later inf model.
+     */
+    public static List<Rule> loadRules(BufferedReader src, Map<String, String> prefixes) {
+        Rule.Parser parser = Rule.rulesParserFromReader(src);
+        List<Rule> rules = Rule.parseRules(parser);
+        prefixes.putAll(parser.getPrefixMap());
+        return rules;
+    }
+    
+    /**
+     * Internal implementation of the "deduce" primitve.
+     * This takes the form <code> ... -> deduce(s, p, o)</code>
+     */
+    static class Deduce extends BaseBuiltin {
+
+        /**
+         * Return a name for this builtin, normally this will be the name of the 
+         * functor that will be used to invoke it.
+         */
+        @Override
+        public String getName() {
+            return "deduce";
+        }    
+   
+        /**
+         * Return the expected number of arguments for this functor or 0 if the number is flexible.
+         */
+        @Override
+        public int getArgLength() {
+            return 3;
+        }
+
+        /**
+         * This method is invoked when the builtin is called in a rule head.
+         * Such a use is only valid in a forward rule.
+         * @param args the array of argument values for the builtin, this is an array 
+         * of Nodes.
+         * @param length the length of the argument list, may be less than the length of the args array
+         * for some rule engines
+         * @param context an execution context giving access to other relevant data
+         */
+        @Override
+        public void headAction(Node[] args, int length, RuleContext context) {
+            if (context.getGraph() instanceof FBRuleInfGraph) {
+                Triple t = new Triple(args[0], args[1], args[2]);
+                ((FBRuleInfGraph)context.getGraph()).addDeduction(t);
+            } else {
+                throw new BuiltinException(this, context, "Only usable in FBrule graphs");
+            }
+        }
+    }
+    
+    /**
+     * General command line utility to process one RDF file into another
+     * by application of a set of forward chaining rules. 
+     * <pre>
+     * Usage:  RuleMap [-il inlang] [-ol outlang] -d infile rulefile
+     * </pre>
+     */
+    public static void main(String[] args) {
+    	try {
+
+            // Parse the command line
+            String usage = "Usage:  RuleMap [-il inlang] [-ol outlang] [-d] rulefile infile (- for stdin)"; 
+            final CommandLineParser parser = new DefaultParser();
+			Options options = new Options().addOption("il", "inputLang", true, "input language")
+					.addOption("ol", "outputLang", true, "output language").addOption("d", "Deductions only?");
+			CommandLine cl = parser.parse(options, args);
+			final List<String> filenameArgs = cl.getArgList();
+            if (filenameArgs.size() != 2) {
+                System.err.println(usage);
+                System.exit(1);
+            }
+            
+            String inLang = cl.getOptionValue("inputLang");
+            String fname = filenameArgs.get(1);
+            Model inModel = null;
+            if (fname.equals("-")) {
+                inModel = ModelFactory.createDefaultModel();
+                inModel.read(System.in, null, inLang);
+            } else {
+                inModel = FileManager.get().loadModel(fname, inLang);
+            }
+            
+            String outLang = cl.hasOption("outputLang") ? cl.getOptionValue("outputLang") : "N3";            
+            
+            boolean deductionsOnly = cl.hasOption('d');
+            
+            // Fetch the rule set and create the reasoner
+            BuiltinRegistry.theRegistry.register(new Deduce());
+            Map<String, String> prefixes = new HashMap<>();
+            List<Rule> rules = loadRules(filenameArgs.get(0), prefixes);
+            Reasoner reasoner = new GenericRuleReasoner(rules);
+            
+            // Process
+            InfModel infModel = ModelFactory.createInfModel(reasoner, inModel);
+            infModel.prepare();
+            infModel.setNsPrefixes(prefixes);
+            
+            // Output
+            try ( PrintWriter writer = new PrintWriter(System.out) ) {
+                if (deductionsOnly) {
+                    Model deductions = infModel.getDeductionsModel();
+                    deductions.setNsPrefixes(prefixes);
+                    deductions.setNsPrefixes(inModel);
+                    deductions.write(writer, outLang);
+                } else {
+                    infModel.write(writer, outLang);
+                }
+            }
+        } catch (Throwable t) {
+            System.err.println("An error occured: \n" + t);
+            t.printStackTrace();
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/cmd/Arg.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/Arg.java b/jena-cmds/src/main/java/jena/cmd/Arg.java
new file mode 100644
index 0000000..d7fb8c9
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/Arg.java
@@ -0,0 +1,69 @@
+/*
+ * 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 jena.cmd;
+
+import java.util.ArrayList ;
+import java.util.List ;
+
+public class Arg
+{
+    String name ;
+    String value ;                                      // Last seen
+    List<String> values = new ArrayList<>() ;     // All seen
+    
+    Arg() { name = null ; value = null ; }
+    
+    public Arg(String _name) { this() ; setName(_name) ; }
+    
+    Arg(String _name, String _value) { this() ; setName(_name) ; setValue(_value) ; }
+    
+    void setName(String n) { name = n ; }
+    
+    public void setValue(String v) { value = v ; }
+    public void addValue(String v) { values.add(v) ; }
+    
+    public String getName() { return name ; }
+    public String getValue() { return value; }
+    public List<String> getValues() { return values; }
+    
+    public boolean hasValue() { return value != null ; }
+    
+    public boolean matches(ArgDecl decl)
+    {
+        return decl.getNames().contains(name) ;
+    }
+    
+    @Override
+    public String toString()
+    {
+        String base = (( name.length() == 1 )?"-":"--") + name ;
+        if ( getValues().size() == 0 )
+            return base ;
+
+        String str = "" ;
+        String sep = "" ;
+
+        for ( String v : getValues() )
+        {
+            str = str + sep + base + "=" + v;
+            sep = " ";
+        }
+        return str ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/cmd/ArgDecl.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/ArgDecl.java b/jena-cmds/src/main/java/jena/cmd/ArgDecl.java
new file mode 100644
index 0000000..c3781e2
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/ArgDecl.java
@@ -0,0 +1,93 @@
+/*
+ * 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 jena.cmd;
+
+import static java.util.Arrays.asList;
+
+import java.util.ArrayList ;
+import java.util.Iterator ;
+import java.util.List ;
+
+/** A command line argument specification. */
+public class ArgDecl
+{
+    boolean takesValue ;
+    
+    List<String> names = new ArrayList<>() ;
+	
+    public static final boolean HasValue = true ;
+    public static final boolean NoValue = false ;
+
+   /** Create a declaration for a command argument.
+    *
+    * @param hasValue  Does it take a value or not?
+    */
+   public ArgDecl(boolean hasValue)
+   {
+       takesValue = hasValue ;
+   }
+
+   /** Create a declaration for a command argument.
+    *
+    * @param hasValue  Does it take a value or not?
+    * @param names     Names of arguments
+    */
+   public ArgDecl(boolean hasValue, String... names)
+   {
+       this(hasValue) ;
+       asList(names).forEach(this::addName);
+   }
+   
+    public void addName(String name)
+    {
+        name = canonicalForm(name) ;
+        if ( ! names.contains(name))
+            names.add(name) ;
+    }
+    
+    public String getKeyName() { return names.get(0) ; }
+    
+    public List<String> getNames() { return names ; }
+    public Iterator<String> names() { return names.iterator() ; }
+    
+    public boolean takesValue() { return takesValue ; }
+    
+    public boolean matches(Arg a)
+    {
+    	 	String name = a.getName();
+    		return names.stream().anyMatch(name::equals);
+    }
+    
+    public boolean matches(String arg)
+    {
+        arg = canonicalForm(arg) ;
+        return names.contains(arg) ;
+    }
+    
+    public static String canonicalForm(String str)
+    {
+        if ( str.startsWith("--") )
+            return str.substring(2) ;
+        
+        if ( str.startsWith("-") )
+            return str.substring(1) ;
+        
+        return str ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/cmd/ArgModule.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/ArgModule.java b/jena-cmds/src/main/java/jena/cmd/ArgModule.java
new file mode 100644
index 0000000..82194de
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/ArgModule.java
@@ -0,0 +1,26 @@
+/**
+ * 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 jena.cmd;
+
+public interface ArgModule
+{
+    // Argument processing phase
+    public void processArgs(CmdArgModule cmdLine) ;
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/cmd/ArgModuleGeneral.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/ArgModuleGeneral.java b/jena-cmds/src/main/java/jena/cmd/ArgModuleGeneral.java
new file mode 100644
index 0000000..d6f09fa
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/ArgModuleGeneral.java
@@ -0,0 +1,25 @@
+/*
+ * 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 jena.cmd;
+
+public interface ArgModuleGeneral extends ArgModule
+{
+    // Registration phase for usage messages
+    public abstract void registerWith(CmdGeneral cmdLine) ;
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/cmd/ArgProc.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/ArgProc.java b/jena-cmds/src/main/java/jena/cmd/ArgProc.java
new file mode 100644
index 0000000..51989e7
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/ArgProc.java
@@ -0,0 +1,27 @@
+/*
+ * 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 jena.cmd;
+
+
+public interface ArgProc {
+
+    void startArgs() ;
+    void finishArgs() ;
+    void arg(String arg, int i) ;
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/cmd/CmdArgModule.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/CmdArgModule.java b/jena-cmds/src/main/java/jena/cmd/CmdArgModule.java
new file mode 100644
index 0000000..c3279dc
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/CmdArgModule.java
@@ -0,0 +1,70 @@
+/*
+ * 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 jena.cmd;
+
+import java.util.ArrayList ;
+import java.util.List ;
+
+import jena.cmd.ArgModuleGeneral;
+
+public abstract class CmdArgModule extends CmdMain
+{
+    List<ArgModuleGeneral> modules = new ArrayList<>() ;
+    
+    protected CmdArgModule(String[] argv)
+    {
+        super(argv) ;
+    }
+    
+    protected void addModule(ArgModuleGeneral argModule)
+    {
+        modules.add(argModule) ;
+    }
+
+    @Override
+    final
+    public void process()
+    {
+        super.process() ;
+        forEach(new Action(){
+            @Override
+            public void action(CmdArgModule controller, ArgModuleGeneral module)
+            { 
+                module.processArgs(controller) ;
+            }
+        } ) ;
+        processModulesAndArgs() ;
+    }
+    
+    abstract
+    protected void processModulesAndArgs() ;
+    
+    private void forEach(Action action)
+    {
+        for ( ArgModuleGeneral am : modules )
+        {
+            action.action( this, am );
+        }
+    }
+                    
+    interface Action
+    {
+        public void action(CmdArgModule controller, ArgModuleGeneral module) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/cmd/CmdException.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/CmdException.java b/jena-cmds/src/main/java/jena/cmd/CmdException.java
new file mode 100644
index 0000000..df952af
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/CmdException.java
@@ -0,0 +1,30 @@
+/*
+ * 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 jena.cmd;
+
+/**
+ * Indicate that something went wrong - while executing the command or processing the request.
+ */
+
+public class CmdException extends RuntimeException
+{
+    public CmdException()                             { super() ; }
+    public CmdException(String msg)                   { super(msg) ; }
+    public CmdException(String msg, Throwable cause)  { super(msg, cause) ; }
+}


[07/20] jena git commit: JENA-1108 : jena-cmds module

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/main/java/jena/rdfcat.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/jena/rdfcat.java b/jena-core/src/main/java/jena/rdfcat.java
deleted file mode 100644
index c292d45..0000000
--- a/jena-core/src/main/java/jena/rdfcat.java
+++ /dev/null
@@ -1,1150 +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
-///////////////
-package jena;
-
-
-// Imports
-///////////////
-
-import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
-
-import java.io.OutputStream ;
-import java.util.* ;
-import java.util.function.BiConsumer;
-
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.rdf.model.impl.RDFWriterFImpl ;
-import org.apache.jena.shared.NoWriterForLangException ;
-import org.apache.jena.system.JenaSystem ;
-import org.apache.jena.util.FileManager ;
-import org.apache.jena.util.FileUtils ;
-import org.apache.jena.vocabulary.OWL ;
-import org.apache.jena.vocabulary.RDFS ;
-
-
-/**
- * <p>
- * An RDF utility that takes its name from the Unix utility <em>cat</em>, and
- * is used to generate serialisations of the contents of zero or more
- * input model serialisations. <strong>Note</strong> In a change from previous
- * versions, but to ensure compatability with standard argument handling
- * practice, the input language options are <em>no longer sticky</em>. In
- * previous versions, <code>rdfcat -n A B C</code> would ensure that A, B
- * and C were all read as N3. From Jena 2.5.2 onwards, this requires:
- * <code>rdfcat -n A -n B -n C</code>, or the use of the <code>-in</code>
- * option.
- * </p>
- * <p>Synopsis:</p>
- * <pre>
- * java jena.rdfcat (options|input)*
- * where options are:
- *   -out N3  (aliases n, n3, ttl)
- *   -out N-TRIPLE  (aliases t, ntriple)
- *   -out RDF/XML  (aliases x, rdf, xml, rdfxml)
- *   -out RDF/XML-ABBREV (default)
- *   -in N3  (aliases n, n3, ttl)
- *   -in N-TRIPLE  (aliases t, ntriple)
- *   -in RDF/XML  (aliases x, rdf, xml, rdfxml)
- *   -include
- *   -noinclude (default)
- *
- * input is one of:
- *   -n &lt;filename&gt; for n3 input  (aliases -n3, -N3, -ttl)
- *   -x &lt;filename&gt; for rdf/xml input  (aliases -rdf, -xml, -rdfxml)
- *   -t &lt;filename&gt; for n-triple input  (aliases -ntriple)
- * or just a URL, a filename, or - for the standard input.
- * </pre>
- * <p>
- * The default
- * input language is RDF/XML, but the reader will try to guess the
- * input language based on the file extension (e.g. N3 for file with a .n3
- * file extension.
- * </p>
- * <p>The input language options set the language for the following file
- * name only. So in the following example, input
- * A is read as N3, inputs B, C and D are read as RDF/XML,
- * while stdin is read as N-TRIPLE:</p>
- * <pre>
- * java jena.rdfcat -n A B C -t - -x D
- * </pre>
- * <p>To change the default input language for all files that do
- * not have a specified language encoding, use the <code>-in</code> option.
- * </p>
- * <p>If the <code>include</code> option is set, the input files are scanned
- * for <code>rdfs:seeAlso</code> and <code>owl:imports</code> statements, and
- * the objects of these statements are read as well.  By default, <code>include</code>
- * is off. If <code>include</code> is turned on, the normal behaviour is for
- * the including statements (e.g <code>owl:imports</code> to be filtered
- * from the output models. To leave such statements in place, use the <code>--nofilter</code>
- * option.</p>
- * <p>rdfcat uses the Jena {@link org.apache.jena.util.FileManager FileManager}
- * to resolve input URI's to locations. This allows, for example, <code>http:</code>
- * URI's to be re-directed to local <code>file:</code> locations, to avoid a
- * network transaction.</p>
- * <p>Examples:</p>
- * <pre>
- * Join two RDF/XML files together into a single model in RDF/XML-ABBREV:
- * java jena.rdfcat in1 in2 &gt; out.rdf
- *
- * Convert a single RDF/XML file to N3:
- * java jena.rdfcat in1 -out N3 &gt; out.n3
- *
- * Join two owl files one N3, one XML, and their imports, into a single NTRIPLE file:
- * java jena.rdfcat -out NTRIPLE -include in1.owl -n in2.owl > out.ntriple
- *
- * Concatenate two N3-serving http URL's as N-TRIPLE
- * java jena.rdfcat -in N3 -out N-TRIPLE http://example.com/a http://example.com/b
- * </pre>
- * <p>Note that, in a difference from the Unix utility <code>cat</code>, the order
- * of input statements is not preserved. The output document is a merge of the
- * input documents, and does not preserve any statement ordering from the input
- * serialisations. Also, duplicate triples will be suppressed.</p>
- */
-@Deprecated
-public class rdfcat
-{
-    static { setCmdLogging("jena-log4j.properties") ; }
-    
-    /** The merged model containing all of the inputs */
-    protected Model m_model = ModelFactory.createDefaultModel();
-
-    /** The output format to write to, defaults to RDF/XML-ABBREV */
-    protected String m_outputFormat = "RDF/XML-ABBREV";
-
-    /** The input format we're expecting for the next URL to be read - defaults to RDF/XML */
-    protected String m_inputFormat = "RDF/XML";
-
-    /** Flag to indicate whether we include owl:imports and rdfs:seeAlso */
-    protected boolean m_include = false;
-
-    /** List of URL's that have been loaded already, occurs check */
-    protected Set<String> m_seen = new HashSet<>();
-
-    /** Flag to control whether import/include statements are filtered from merged models */
-    protected boolean m_removeIncludeStatements = true;
-
-    /** Action queue */
-    protected List<RCAction> m_actionQ = new ArrayList<>();
-
-    // Allow testing to run silent.
-    public static boolean suppressDeprecationBanner = false ;
-    
-    // Constants
-    //////////////////////////////////
-
-    /** Argument setting expected input language to N3 */
-    public final ArgDecl IN_N3 = new ArgDecl( true, "n", "n3", "ttl", "N3",
-    		(arg,val) -> m_actionQ.add( new ReadAction( val, "N3") ) );
-
-    /** Argument setting expected input language to RDF/XML */
-    public final ArgDecl IN_RDF_XML = new ArgDecl( true, "x", "xml", "rdfxml", "rdf",
-    		(arg,val) -> m_actionQ.add( new ReadAction( val, "RDF/XML") ) );
-
-    /** Argument setting expected input language to NTRIPLE */
-    public final ArgDecl IN_NTRIPLE = new ArgDecl( true, "t", "ntriples", "ntriple", "n-triple", "n-triples",
-    		(arg,val) -> m_actionQ.add( new ReadAction( val, "N-TRIPLE" ) ) );    
-
-    /** Argument to set the output language */
-    public final ArgDecl OUT_LANG = new ArgDecl( true, "out", (arg,val) -> setOutput( val ) );
-
-    /** Argument to set the default input language */
-    public final ArgDecl IN_LANG = new ArgDecl( true, "in", (arg,val) -> expectInput( val ) );
-
-    /** Argument to turn include processing on */
-    public final ArgDecl INCLUDE = new ArgDecl( false, "include", (arg,val) -> setInclude( true ) );
-
-    /** Argument to turn include processing off */
-    public final ArgDecl NOINCLUDE = new ArgDecl( false, "noinclude", (arg,val) -> setInclude( false ) );
-
-    /** Argument to leave import/seeAlso statements in place in flattened models */
-    public final ArgDecl NOFILTER = new ArgDecl( false, "nofilter", (arg,val) -> setRemoveIncludeStatements( false ) );
-
-    /** Argument to show usage */
-    public final ArgDecl HELP = new ArgDecl( false, "help", (arg,val) -> usage() );
-    public final ArgDecl USAGE = new ArgDecl( false, "usage", (arg,val) -> usage() );
-
-    // Instance variables
-    //////////////////////////////////
-
-    /** The command line processor that handles the arguments */
-    protected CommandLine m_cmdLine = new RCCommandLine().add( IN_N3 )
-                                                         .add( IN_NTRIPLE )
-                                                         .add( IN_RDF_XML )
-                                                         .add( OUT_LANG )
-                                                         .add( IN_LANG )
-                                                         .add( INCLUDE )
-                                                         .add( NOINCLUDE )
-                                                         .add( NOFILTER )
-                                                         .add( HELP )
-                                                         .add( USAGE );
-
-    // Constructors
-    //////////////////////////////////
-
-    // External signature methods
-    //////////////////////////////////
-
-    public static void main( String... args ) {
-        new rdfcat().go( args );
-    }
-
-    // Internal implementation methods
-    //////////////////////////////////
-
-    /* main loop */
-    protected void go( String[] args ) {
-    	JenaSystem.init();
-        if ( ! suppressDeprecationBanner ) {
-            System.err.println("------------------------------------------------------------------");
-    		System.err.println("   DEPRECATED: Please use 'riot' instead.");
-    		System.err.println("     http://jena.apache.org/documentation/io/#command-line-tools");
-            System.err.println("------------------------------------------------------------------");
-    		System.err.println() ;
-        }
-    	
-        m_cmdLine.process( args );
-
-        // process any stored items
-        for (int i = 0; i < m_cmdLine.numItems(); i++) {
-            m_actionQ.add(  new ReadAction( m_cmdLine.getItem( i ), getExpectedInput() ) );
-        }
-        for ( RCAction aM_actionQ : m_actionQ )
-        {
-            aM_actionQ.run( this );
-        }
-
-        // generate the output
-        m_model.write( getOutputStream(), m_outputFormat );
-    }
-
-    /** Set the input language of next and subsequent reads */
-    protected void expectInput( String lang ) {
-        m_inputFormat = lang;
-    }
-
-    /** Answer the currently expected input format */
-    protected String getExpectedInput() {
-        return m_inputFormat;
-    }
-
-    /** Set the language to write the output model in */
-    protected void setOutput( String lang ) {
-        m_outputFormat = getCheckedLanguage( lang );
-    }
-
-    /**
-         Answer the full, checked, language name expanded from <code>shortName</code>.
-        The shortName is expanded according to the table of abbreviations [below].
-        It is then checked against RDFWriterFImpl's writer table [this is hacky but
-        at the moment it's the most available interface] and the NoWriter exception
-        trapped and replaced by the original IllegalArgument exception.
-    */
-    public static String getCheckedLanguage( String shortLang )
-        {
-        String fullLang = unabbreviate.get( shortLang );
-        String tryLang = (fullLang == null ? shortLang : fullLang);
-        try { new RDFWriterFImpl().getWriter( tryLang ); }
-        catch (NoWriterForLangException e)
-            { throw new IllegalArgumentException( "'" + shortLang + "' is not recognised as a legal output format" ); }
-        return tryLang;
-        }
-
-    /**
-        Map from abbreviated names to full names.
-    */
-    public static Map<String,String> unabbreviate = makeUnabbreviateMap();
-
-    /**
-        Construct the canonical abbreviation map.
-    */
-    protected static Map<String,String> makeUnabbreviateMap()
-        {
-        Map<String,String> result = new HashMap<>();
-        result.put( "x", "RDF/XML" );
-        result.put( "rdf", "RDF/XML" );
-        result.put( "rdfxml", "RDF/XML" );
-        result.put( "xml", "RDF/XML" );
-        result.put( "n3", "N3" );
-        result.put( "n", "N3" );
-        result.put( "ttl", "N3" );
-        result.put( "ntriples", "N-TRIPLE" );
-        result.put( "ntriple", "N-TRIPLE" );
-        result.put( "t", "N-TRIPLE" );
-        result.put( "owl", "RDF/XML-ABBREV" );
-        result.put( "abbrev", "RDF/XML-ABBREV" );
-        return result;
-        }
-
-    /** Set the flag to include owl:imports and rdf:seeAlso files in the output, default off */
-    protected void setInclude( boolean incl ) {
-        m_include = incl;
-    }
-
-    /** Set the flag to leave owl:imports and rdfs:seeAlso statements in place, rather than filter them */
-    protected void setRemoveIncludeStatements( boolean f ) {
-        m_removeIncludeStatements = f;
-    }
-
-    /* Take the string as an input file or URI, and
-     * try to read using the current default input syntax.
-     */
-    protected void readInput( String inputName ) {
-        List<IncludeQueueEntry> queue = new ArrayList<>();
-        queue.add( new IncludeQueueEntry( inputName, null ) );
-
-        while (!queue.isEmpty()) {
-            IncludeQueueEntry entry = queue.remove( 0 );
-            String in = entry.m_includeURI;
-
-            if (!m_seen.contains( in )) {
-                m_seen.add( in );
-                Model inModel = ModelFactory.createDefaultModel();
-
-                // check for stdin
-                if (in.equals( "-" )) {
-                    inModel.read( System.in, null, m_inputFormat );
-                }
-                else {
-                    // lang from extension overrides default set on command line
-                    String lang = FileUtils.guessLang( in, m_inputFormat );
-                    FileManager.get().readModel( inModel, in, lang );
-                }
-
-                // check for anything more that we need to read
-                if (m_include) {
-                    addIncludes( inModel, queue );
-                }
-
-                // merge the models
-                m_model.add( inModel );
-                m_model.setNsPrefixes( inModel );
-
-                // do we remove the include statement?
-                if (m_removeIncludeStatements && entry.m_includeStmt != null) {
-                    m_model.remove( entry.m_includeStmt );
-                }
-            }
-        }
-    }
-
-    /** Return the stream to which the output is written, defaults to stdout */
-    protected OutputStream getOutputStream() {
-        return System.out;
-    }
-
-    /** Add any additional models to include given the rdfs:seeAlso and
-     * owl:imports statements in the given model
-     */
-    protected void addIncludes( Model inModel, List<IncludeQueueEntry> queue ) {
-        // first collect any rdfs:seeAlso statements
-        StmtIterator i = inModel.listStatements( null, RDFS.seeAlso, (RDFNode) null );
-        while (i.hasNext()) {
-            Statement s = i.nextStatement();
-            queue.add( new IncludeQueueEntry( getURL( s.getObject() ), s ) );
-        }
-
-        // then any owl:imports
-        i = inModel.listStatements( null, OWL.imports, (RDFNode) null );
-        while (i.hasNext()) {
-            Statement s = i.nextStatement();
-            queue.add( new IncludeQueueEntry( getURL( s.getResource() ), s ) );
-        }
-    }
-
-    protected void usage() {
-    		System.err.println( "------------------------------------" );
-    		System.err.println( "DEPRECATED: Please use riot instead." );
-    		System.err.println( "------------------------------------\n" );
-        System.err.println( "Usage: java jena.rdfcat (option|input)*" );
-        System.err.println( "Concatenates the contents of zero or more input RDF documents." );
-        System.err.println( "Options: -out N3 | N-TRIPLE | RDF/XML | RDF/XML-ABBREV" );
-        System.err.println( "         -n  expect subsequent inputs in N3 syntax" );
-        System.err.println( "         -x  expect subsequent inputs in RDF/XML syntax" );
-        System.err.println( "         -t  expect subsequent inputs in N-TRIPLE syntax" );
-        System.err.println( "         -[no]include  include rdfs:seeAlso and owl:imports" );
-        System.err.println( "input can be filename, URL, or - for stdin" );
-        System.err.println( "Recognised aliases for -n are: -n3 -ttl or -N3" );
-        System.err.println( "Recognised aliases for -x are: -xml -rdf or -rdfxml" );
-        System.err.println( "Recognised aliases for -t are: -ntriple" );
-        System.err.println( "Output format aliases: x, xml or rdf for RDF/XML, n, n3 or ttl for N3, t or ntriple for N-TRIPLE" );
-        System.err.println( "See the Javadoc for jena.rdfcat for additional details." );
-
-
-        System.exit(0);
-    }
-
-    /** Answer a URL string from a resource or literal */
-    protected String getURL( RDFNode n ) {
-        return n.isLiteral() ? ((Literal) n).getLexicalForm() : ((Resource) n).getURI();
-    }
-
-    //==============================================================================
-    // Inner class definitions
-    //==============================================================================
-
-    /** Local extension to CommandLine to handle mixed arguments and values */
-    protected class RCCommandLine
-        extends CommandLine
-    {
-        /** Don't stop processing args on the first non-arg */
-        public boolean xendProcessing( String argStr ) {
-            return false;
-        }
-
-        /** Handle an unrecognised argument by assuming it's a URI to read */
-        @Override
-        public void handleUnrecognizedArg( String argStr ) {
-            if (argStr.equals("-") || !argStr.startsWith( "-" )) {
-                // queue this action for reading later
-                m_actionQ.add( new ReadAction( argStr, getExpectedInput() ) );
-            }
-            else {
-                System.err.println( "Unrecognised argument: " + argStr );
-                usage();
-            }
-        }
-
-        /** Hook to test whether this argument should be processed further
-         */
-        @Override
-        public boolean ignoreArgument( String argStr ) {
-            return !argStr.startsWith("-") || argStr.length() == 1;
-        }
-
-        /** Answer an iterator over the non-arg items from the command line */
-        public Iterator<String> getItems() {
-            return items.iterator();
-        }
-    }
-
-    /** Queue entry that contains both a URI to be included, and a statement that may be removed */
-    protected class IncludeQueueEntry
-    {
-        protected String m_includeURI;
-        protected Statement m_includeStmt;
-        protected IncludeQueueEntry( String includeURI, Statement includeStmt ) {
-            m_includeURI = includeURI;
-            m_includeStmt = includeStmt;
-        }
-    }
-
-    /** Simple action object for local processing queue */
-    protected interface RCAction {
-        public void run( rdfcat rc );
-    }
-
-    /** Action to set the output format */
-    protected class ReadAction
-        implements RCAction
-    {
-        private String m_lang;
-        private String m_uri;
-        protected ReadAction( String uri, String lang ) {
-            m_lang = lang;
-            m_uri = uri;
-        }
-
-        /** perform the action of reading a uri */
-        @Override
-        public void run( rdfcat rc ) {
-            String l = rc.getExpectedInput();
-            if (m_lang != null) {
-                // if an input lang was given, use that
-                rc.expectInput( m_lang );
-            }
-            rc.readInput( m_uri );
-
-            // put the lang back to default
-            rc.expectInput( l );
-        }
-    }
-    
-    /**
-     * Command line argument processing based on a trigger model.
-     * An action is called whenever an argument is encountered. Example:
-     * <CODE>
-     * public static void main (String[] args)
-     * {
-     *  CommandLine cl = new CommandLine() ;
-     *  cl.add(false, "verbose")
-     *    .add(true, "--file") ;
-     *  cl.process(args) ;
-     *
-     *  for ( Iterator iter = cl.args() ; iter.hasNext() ; )
-     *  ...
-     * }
-     * </CODE>
-     * A gloabl hook is provided to inspect arguments just before the
-     * action.  Tracing is enabled by setting this to a suitable function
-     * such as that provided by trace():
-     * <CODE>
-     *  cl.setHook(cl.trace()) ;
-     * </CODE>
-     *
-     * <ul>
-     * <li>Neutral as to whether options have - or --</li>
-     * <li>Does not allow multiple single letter options to be concatenated.</li>
-     * <li>Options may be ended with - or --</li>
-     * <li>Arguments with values can use "="</li>
-     * </ul>
-     */
-
-
-    static class CommandLine
-    {
-        /* Extra processor called before the registered one when set.
-         * Used for tracing.
-         */
-        protected BiConsumer<String,String> argHook = null ;
-        protected String usage = null ;
-        protected Map<String, ArgDecl> argMap = new HashMap<>() ;
-        protected Map<String, Arg> args = new HashMap<>() ;
-        //protected boolean ignoreUnknown = false ;
-
-        // Rest of the items found on the command line
-        String indirectionMarker = "@" ;
-        protected boolean allowItemIndirect = false ;   // Allow @ to mean contents of file
-        boolean ignoreIndirectionMarker = false ;       // Allow comand line items to have leading @ but strip it.
-        protected List<String> items = new ArrayList<>() ;
-
-
-        /** Creates new CommandLine */
-        public CommandLine()
-        {
-        }
-
-        /** Set the global argument handler.  Called on every valid argument.
-         * @param argHandler Handler
-         */
-        public void setHook(BiConsumer<String, String> argHandler) { argHook = argHandler ; }
-
-        public void setUsage(String usageMessage) { usage = usageMessage ; }
-
-        public boolean hasArgs() { return args.size() > 0 ; }
-        public boolean hasItems() { return items.size() > 0 ; }
-
-        public Iterator<Arg> args() { return args.values().iterator() ; }
-//        public Map args() { return args ; }
-//        public List items() { return items ; }
-
-        public int numArgs() { return args.size() ; }
-        public int numItems() { return items.size() ; }
-        public void pushItem(String s) { items.add(s) ; }
-
-        public boolean isIndirectItem(int i)
-        { return allowItemIndirect && items.get(i).startsWith(indirectionMarker) ; }
-
-        public String getItem(int i)
-        {
-            return getItem(i, allowItemIndirect) ;
-        }
-
-        public String getItem(int i, boolean withIndirect)
-        {
-            if ( i < 0 || i >= items.size() )
-                return null ;
-
-
-            String item = items.get(i) ;
-
-            if ( withIndirect && item.startsWith(indirectionMarker) )
-            {
-                item = item.substring(1) ;
-                try { item = FileUtils.readWholeFileAsUTF8(item) ; }
-                catch (Exception ex)
-                { throw new IllegalArgumentException("Failed to read '"+item+"': "+ex.getMessage()) ; }
-            }
-            return item ;
-        }
-
-
-        /** Process a set of command line arguments.
-         * @param argv The words of the command line.
-         * @throws IllegalArgumentException Throw when something is wrong (no value found, action fails).
-         */
-        public void process(String[] argv) throws java.lang.IllegalArgumentException
-        {
-            List<String> argList = new ArrayList<>() ;
-            argList.addAll(Arrays.asList(argv)) ;
-
-            int i = 0 ;
-            for ( ; i < argList.size() ; i++ )
-            {
-                String argStr = argList.get(i) ;
-                if (endProcessing(argStr))
-                    break ;
-                
-                if ( ignoreArgument(argStr) )
-                    continue ;
-
-                // If the flag has a "=" or :, it is long form --arg=value.
-                // Split and insert the arg
-                int j1 = argStr.indexOf('=') ;
-                int j2 = argStr.indexOf(':') ;
-                int j = Integer.MAX_VALUE ;
-
-                if ( j1 > 0 && j1 < j )
-                    j = j1 ;
-                if ( j2 > 0 && j2 < j )
-                    j = j2 ;
-
-                if ( j != Integer.MAX_VALUE )
-                {
-                    String a2 = argStr.substring(j+1) ;
-                    argList.add(i+1,a2) ;
-                    argStr = argStr.substring(0,j) ;
-                }
-
-                argStr = ArgDecl.canonicalForm(argStr) ;
-                String val = null ;
-
-                if ( argMap.containsKey(argStr) )
-                {
-                    if ( ! args.containsKey(argStr))
-                        args.put(argStr, new Arg(argStr)) ;
-
-                    Arg arg = args.get(argStr) ;
-                    ArgDecl argDecl = argMap.get(argStr) ;
-
-                    if ( argDecl.takesValue() )
-                    {
-                        if ( i == (argList.size()-1) )
-                            throw new IllegalArgumentException("No value for argument: "+arg.getName()) ;
-                        i++ ;
-                        val = argList.get(i) ;
-                        arg.setValue(val) ;
-                        arg.addValue(val) ;
-                    }
-
-                    // Global hook
-                    if ( argHook != null )
-                        argHook.accept(argStr, val) ;
-
-                    argDecl.trigger(arg) ;
-                }
-                else
-                    handleUnrecognizedArg( argList.get(i) );
-//                    if ( ! getIgnoreUnknown() )
-//                        // Not recognized
-//                        throw new IllegalArgumentException("Unknown argument: "+argStr) ;
-            }
-
-            // Remainder.
-            if ( i < argList.size() )
-            {
-                if ( argList.get(i).equals("-") || argList.get(i).equals("--") )
-                    i++ ;
-                for ( ; i < argList.size() ; i++ )
-                {
-                    String item = argList.get(i) ;
-                    items.add(item) ;
-                }
-            }
-        }
-
-        /** Hook to test whether this argument should be processed further
-         */
-        public boolean ignoreArgument( String argStr )
-        { return false ; }
-        
-        /** Answer true if this argument terminates argument processing for the rest
-         * of the command line. Default is to stop just before the first arg that
-         * does not start with "-", or is "-" or "--".
-         */
-        public boolean endProcessing( String argStr )
-        {
-            return ! argStr.startsWith("-") || argStr.equals("--") || argStr.equals("-");
-        }
-
-        /**
-         * Handle an unrecognised argument; default is to throw an exception
-         * @param argStr The string image of the unrecognised argument
-         */
-        public void handleUnrecognizedArg( String argStr ) {
-            throw new IllegalArgumentException("Unknown argument: "+argStr) ;
-        }
-
-
-        /** Test whether an argument was seen.
-         */
-
-        public boolean contains(ArgDecl argDecl) { return getArg(argDecl) != null ; }
-
-        /** Test whether an argument was seen.
-         */
-
-        public boolean contains(String s) { return getArg(s) != null ; }
-
-
-        /** Test whether the command line had a particular argument
-         *
-         * @param argName
-         */
-        public boolean hasArg(String argName) { return getArg(argName) != null ; }
-
-        /** Test whether the command line had a particular argument
-         *
-         * @param argDecl
-         */
-
-        public boolean hasArg(ArgDecl argDecl) { return getArg(argDecl) != null ; }
-
-
-        /** Get the argument associated with the argument declaration.
-         *  Actually returns the LAST one seen
-         *  @param argDecl Argument declaration to find
-         *  @return Last argument that matched.
-         */
-
-        public Arg getArg(ArgDecl argDecl)
-        {
-            Arg arg = null ;
-            for ( Arg a : args.values() )
-            {
-                if ( argDecl.matches( a ) )
-                {
-                    arg = a;
-                }
-            }
-            return arg ;
-        }
-
-        /** Get the argument associated with the arguement name.
-         *  Actually returns the LAST one seen
-         *  @param arg Argument declaration to find
-         *  @return Arg - Last argument that matched.
-         */
-
-        public Arg getArg(String arg)
-        {
-            arg = ArgDecl.canonicalForm(arg) ;
-            return args.get(arg) ;
-        }
-
-        /**
-         * Returns the value (a string) for an argument with a value -
-         * returns null for no argument and no value.
-         * @param argDecl
-         * @return String
-         */
-        public String getValue(ArgDecl argDecl)
-        {
-            Arg arg = getArg(argDecl) ;
-            if ( arg == null )
-                return null ;
-            if ( arg.hasValue())
-                return arg.getValue() ;
-            return null ;
-        }
-
-        /**
-         * Returns the value (a string) for an argument with a value -
-         * returns null for no argument and no value.
-         * @param argName
-         * @return String
-         */
-        public String getValue(String argName)
-        {
-            Arg arg = getArg(argName) ;
-            if ( arg == null )
-                return null ;
-            return arg.getValue() ;
-        }
-
-        /**
-         * Returns all the values (0 or more strings) for an argument.
-         * @param argDecl
-         * @return List
-         */
-        public List<String> getValues(ArgDecl argDecl)
-        {
-            Arg arg = getArg(argDecl) ;
-            if ( arg == null )
-                return null ;
-            return arg.getValues() ;
-        }
-
-        /**
-         * Returns all the values (0 or more strings) for an argument.
-         * @param argName
-         * @return List
-         */
-        public List<String> getValues(String argName)
-        {
-            Arg arg = getArg(argName) ;
-            if ( arg == null )
-                return null ;
-            return arg.getValues() ;
-        }
-
-
-
-        /** Add an argument to those to be accepted on the command line.
-         * @param argName Name
-         * @param hasValue True if the command takes a (string) value
-         * @return The CommandLine processor object
-         */
-
-        public CommandLine add(String argName, boolean hasValue)
-        {
-            return add(new ArgDecl(hasValue, argName)) ;
-        }
-
-        /** Add an argument to those to be accepted on the command line.
-         *  Argument order reflects ArgDecl.
-         * @param hasValue True if the command takes a (string) value
-         * @param argName Name
-         * @return The CommandLine processor object
-         */
-
-        public CommandLine add(boolean hasValue, String argName)
-        {
-            return add(new ArgDecl(hasValue, argName)) ;
-        }
-
-        /** Add an argument object
-         * @param arg Argument to add
-         * @return The CommandLine processor object
-         */
-
-        public CommandLine add(ArgDecl arg)
-        {
-            for ( Iterator<String> iter = arg.names() ; iter.hasNext() ; )
-                argMap.put(iter.next(), arg) ;
-            return this ;
-        }
-
-//        public boolean getIgnoreUnknown() { return ignoreUnknown ; }
-//        public void setIgnoreUnknown(boolean ign) { ignoreUnknown = ign ; }
-
-        /**
-         * @return Returns whether items starting "@" have the value of named file.
-         */
-        public boolean allowItemIndirect()
-        {
-            return allowItemIndirect ;
-        }
-
-        /**
-         * @param allowItemIndirect Set whether items starting "@" have the value of named file.
-
-         */
-        public void setAllowItemIndirect(boolean allowItemIndirect)
-        {
-            this.allowItemIndirect = allowItemIndirect ;
-        }
-
-        /**
-         * @return Returns the ignoreIndirectionMarker.
-         */
-        public boolean isIgnoreIndirectionMarker()
-        {
-            return ignoreIndirectionMarker ;
-        }
-
-        /**
-         * @return Returns the indirectionMarker.
-         */
-        public String getIndirectionMarker()
-        {
-            return indirectionMarker ;
-        }
-
-        /**
-         * @param indirectionMarker The indirectionMarker to set.
-         */
-        public void setIndirectionMarker(String indirectionMarker)
-        {
-            this.indirectionMarker = indirectionMarker ;
-        }
-
-        /**
-         * @param ignoreIndirectionMarker The ignoreIndirectionMarker to set.
-         */
-        public void setIgnoreIndirectionMarker(boolean ignoreIndirectionMarker)
-        {
-            this.ignoreIndirectionMarker = ignoreIndirectionMarker ;
-        }
-
-	    	public BiConsumer<String, String> trace() {
-	    		return (arg, val) -> {
-	    			System.err.println("Seen: " + arg + (val != null ? " = " + val : ""));
-	    		};
-	    	}
-
-    }
-    
-    /** A command line argument that has been foundspecification.
-	 */
-	static class Arg
-	{
-	    String name ;
-	    String value ;
-	    List<String> values = new ArrayList<>() ;
-	    
-	    Arg() { name = null ; value = null ; }
-	    
-	    Arg(String _name) { this() ; setName(_name) ; }
-	    
-	    Arg(String _name, String _value) { this() ; setName(_name) ; setValue(_value) ; }
-	    
-	    void setName(String n) { name = n ; }
-	    
-	    void setValue(String v) { value = v ; }
-	    void addValue(String v) { values.add(v) ; }
-	    
-	    public String getName() { return name ; }
-	    public String getValue() { return value; }
-	    public List<String> getValues() { return values; }
-	    
-	    public boolean hasValue() { return value != null ; }
-	    
-	    public boolean matches(ArgDecl decl)
-	    {
-	        return decl.getNames().contains(name) ;
-	    }
-	    
-	}
-    
-    /** A command line argument specification.
-	 */
-	static class ArgDecl
-	{
-	    boolean takesValue ;
-	    Set<String> names = new HashSet<>() ;
-	    boolean takesArg = false ;
-		List<BiConsumer<String, String>> argHooks = new ArrayList<>() ;
-	    public static final boolean HasValue = true ;
-	    public static final boolean NoValue = false ;
-
-	    /** Create a declaration for a command argument.
-	     *
-	     * @param hasValue  Does it take a value or not?
-	     */
-
-	    public ArgDecl(boolean hasValue)
-	    {
-	        takesValue = hasValue ;
-	    }
-
-	    /** Create a declaration for a command argument.
-	     *
-	     * @param hasValue  Does it take a value or not?
-	     * @param name      Name of argument
-	     */
-
-	    public ArgDecl(boolean hasValue, String name)
-	    {
-	        this(hasValue) ;
-	        addName(name) ;
-	    }
-
-	    /** Create a declaration for a command argument.
-	     *
-	     * @param hasValue  Does it take a value or not?
-	     * @param name      Name of argument
-	     * @param handler   BiConsumer<String, String>
-	     */
-
-	    public ArgDecl(boolean hasValue, String name, BiConsumer<String, String> handler)
-	    {
-	        this(hasValue) ;
-	        addName(name) ;
-	        addHook( handler );
-	    }
-
-	    /** Create a declaration for a command argument.
-	     *
-	     * @param hasValue  Does it take a value or not?
-	     * @param name1      Name of argument
-	     * @param name2      Name of argument
-	     */
-
-	    public ArgDecl(boolean hasValue, String name1, String name2)
-	    {
-	        this(hasValue) ;
-	        addName(name1) ;
-	        addName(name2) ;
-	    }
-
-	    /** Create a declaration for a command argument.
-	     *
-	     * @param hasValue  Does it take a value or not?
-	     * @param name1      Name of argument
-	     * @param name2      Name of argument
-	     * @param handler   BiConsumer<String, String>
-	     */
-
-	    public ArgDecl(boolean hasValue, String name1, String name2, BiConsumer<String, String> handler)
-	    {
-	        this(hasValue) ;
-	        addName(name1) ;
-	        addName(name2) ;
-	        addHook( handler );
-	    }
-
-	    /** Create a declaration for a command argument.
-	     *
-	     * @param hasValue  Does it take a value or not?
-	     * @param name1      Name of argument
-	     * @param name2      Name of argument
-	     * @param name3      Name of argument
-	     */
-
-	    public ArgDecl(boolean hasValue, String name1, String name2, String name3)
-	    {
-	        this(hasValue) ;
-	        addName(name1) ;
-	        addName(name2) ;
-	        addName(name3) ;
-	    }
-
-	    /** Create a declaration for a command argument.
-	     *
-	     * @param hasValue  Does it take a value or not?
-	     * @param name1      Name of argument
-	     * @param name2      Name of argument
-	     * @param name3      Name of argument
-	     * @param handler   BiConsumer<String, String>
-	     */
-
-	    public ArgDecl(boolean hasValue, String name1, String name2, String name3, BiConsumer<String, String> handler)
-	    {
-	        this(hasValue) ;
-	        addName(name1) ;
-	        addName(name2) ;
-	        addName(name3) ;
-	        addHook( handler );
-	    }
-
-	    /** Create a declaration for a command argument.
-	     *
-	     * @param hasValue  Does it take a value or not?
-	     * @param name1      Name of argument
-	     * @param name2      Name of argument
-	     * @param name3      Name of argument
-	     * @param name4      Name of argument
-	     */
-
-	    public ArgDecl(boolean hasValue, String name1, String name2, String name3, String name4)
-	    {
-	        this(hasValue) ;
-	        addName(name1) ;
-	        addName(name2) ;
-	        addName(name3) ;
-	        addName(name4) ;
-	    }
-
-	    /** Create a declaration for a command argument.
-	     *
-	     * @param hasValue  Does it take a value or not?
-	     * @param name1      Name of argument
-	     * @param name2      Name of argument
-	     * @param name3      Name of argument
-	     * @param name4      Name of argument
-	     * @param handler    BiConsumer<String, String>
-	     */
-
-	    public ArgDecl(boolean hasValue, String name1, String name2, String name3, String name4, BiConsumer<String, String> handler)
-	    {
-	        this(hasValue) ;
-	        addName(name1) ;
-	        addName(name2) ;
-	        addName(name3) ;
-	        addName(name4) ;
-	        addHook( handler );
-	    }
-
-	    /** Create a declaration for a command argument.
-	     *
-	     * @param hasValue  Does it take a value or not?
-	     * @param name1      Name of argument
-	     * @param name2      Name of argument
-	     * @param name3      Name of argument
-	     * @param name4      Name of argument
-	     * @param name5      Name of argument
-	     * @param handler    BiConsumer<String, String>
-	     */
-
-	    public ArgDecl(boolean hasValue, String name1, String name2, String name3, String name4, String name5, BiConsumer<String, String> handler)
-	    {
-	        this(hasValue) ;
-	        addName(name1) ;
-	        addName(name2) ;
-	        addName(name3) ;
-	        addName(name4) ;
-	        addName(name5) ;
-	        addHook( handler );
-	    }
-
-	    public void addName(String name)
-	    {
-	        name = canonicalForm(name) ;
-	        names.add(name) ;
-	    }
-
-	    public Set<String> getNames() { return names ; }
-	    public Iterator<String> names() { return names.iterator() ; }
-
-	    // Callback model
-
-	    public void addHook(BiConsumer<String, String> argHandler)
-	    {
-	        argHooks.add(argHandler) ;
-	    }
-
-	    protected void trigger(Arg arg)
-	    {
-			argHooks.forEach(action -> action.accept( arg.getName(), arg.getValue() ));
-	    }
-
-	    public boolean takesValue() { return takesValue ; }
-
-	    public boolean matches(Arg a)
-	    {
-	        for ( String n : names )
-	        {
-	            if ( a.getName().equals( n ) )
-	            {
-	                return true;
-	            }
-	        }
-	        return false ;
-	    }
-
-	    public boolean matches(String arg)
-	    {
-	        arg = canonicalForm(arg) ;
-	        return names.contains(arg) ;
-	    }
-
-	    static String canonicalForm(String str)
-	    {
-	        if ( str.startsWith("--") )
-	            return str.substring(2) ;
-
-	        if ( str.startsWith("-") )
-	            return str.substring(1) ;
-
-	        return str ;
-	    }
-	}
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/main/java/jena/rdfcompare.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/jena/rdfcompare.java b/jena-core/src/main/java/jena/rdfcompare.java
deleted file mode 100644
index 95cc602..0000000
--- a/jena-core/src/main/java/jena/rdfcompare.java
+++ /dev/null
@@ -1,131 +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 jena;
-
-import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
-
-import java.net.URL;
-import java.io.FileInputStream;
-
-import org.apache.jena.rdf.model.* ;
-
-/** A program which read two RDF models and determines if they are the same.
- *
- *  <p>This program will read two RDF models, in a variety of languages,
- *     and compare them.  Input can be read either from a URL or from a file.
- *     The program writes its results to the standard output stream and sets
- *     its exit code to 0 if the models are equal, to 1 if they are not and
- *     to -1 if it encounters an error.</p>
- *
- *  <p></p>
- *
- *  <pre>java jena.rdfcompare model1 model2 [lang1 [lang2]]
- *
- *       model1 and model2 can be file names or URL's
- *       lang1 and lang2 specify the language of the input and can be:
- *           RDF/XML
- *           N-TRIPLE
- *           N3
- *  </pre>
- */
-public class rdfcompare extends java.lang.Object {
-
-    static { setCmdLogging(); }
-
-    /**
-    * @param args the command line arguments
-    */
-    public static void main (String ... args) {
-        if (args.length < 2 || args.length > 6) {
-            usage();
-            System.exit(-1);
-        }
-        
-        String in1 = args[0];
-        String in2 = args[1];
-        String lang1 = "RDF/XML";
-        if (args.length >= 3) {
-            lang1 = args[2];
-        } 
-        String lang2 = "N-TRIPLE";
-        if (args.length >= 4) {
-            lang2 = args[3];
-        }
-        String base1 = null;
-        if (args.length >= 5) {
-            base1 = args[4];
-        }
-        String base2 = base1;
-        if (args.length >= 6) {
-            base2 = args[5];
-        }
-        
-        System.out.println(in1 + " " + in2 + " " + lang1 + " " + lang2 + " " + base1 + " " + base2);
-        try {
-            Model m1 = ModelFactory.createDefaultModel();
-            Model m2 = ModelFactory.createDefaultModel();
-        
-            read(m1, in1, lang1, base1);
-            read(m2, in2, lang2, base2);
-        
-            if (m1.isIsomorphicWith(m2)) {
-                System.out.println("models are equal");
-                System.out.println();
-                System.exit(0);
-            } else {
-                System.out.println("models are unequal");
-                System.out.println();
-                System.exit(1);
-            }
-        } catch (Exception e) {
-            System.err.println("Unhandled exception:");
-            System.err.println("    " + e.toString());
-            System.exit(-1);
-        }
-    }
-    
-    protected static void usage() {
-        System.err.println("usage:");
-        System.err.println(
-            "    java jena.rdfcompare source1 source2 [lang1 [lang2 [base1 [base2]]]]");
-        System.err.println();
-        System.err.println("    source1 and source2 can be URL's or filenames");
-        System.err.println("    lang1 and lang2 can take values:");
-        System.err.println("      RDF/XML");
-        System.err.println("      N-TRIPLE");
-        System.err.println("      N3");
-        System.err.println("    lang1 defaults to RDF/XML, lang2 to N-TRIPLE");
-        System.err.println("    base1 and base2 are URIs");
-        System.err.println("    base1 defaults to null");
-        System.err.println("    base2 defaults to base1");
-        System.err.println("    If no base URIs are specified Jena determines the base URI based on the input source");
-        
-        System.err.println();
-    }
-    
-    protected static void read(Model model, String in, String lang, String base) 
-      throws java.io.FileNotFoundException {
-        try {
-            URL url = new URL(in);
-            model.read(in, base, lang);
-        } catch (java.net.MalformedURLException e) {
-            model.read(new FileInputStream(in), base, lang);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/main/java/jena/rdfcopy.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/jena/rdfcopy.java b/jena-core/src/main/java/jena/rdfcopy.java
deleted file mode 100644
index a998c37..0000000
--- a/jena-core/src/main/java/jena/rdfcopy.java
+++ /dev/null
@@ -1,158 +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 jena;
-
-import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
-
-import java.net.*;
-import java.io.*;
-
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.shared.JenaException ;
-
-/** A program which read an RDF model and copy it to the standard output stream.
- *
- *  <p>This program will read an RDF model, in a variety of languages,
- *     and copy it to the output stream in a possibly different language.
- *     Input can be read either from a URL or from a file.
- *     The program writes its results to the standard output stream and sets
- *     its exit code to 0 if the program terminate normally,  and
- *     to -1 if it encounters an error.</p>
- *
- *  <p></p>
- *
- *  <pre>java jena.rdfcopy model [inlang [outlang]]
- *
- *       model1 and model2 can be file names or URL's
- *       inlang and outlang specify the language of the input and output
- *       respectively and can be:
- *           RDF/XML
- *           N-TRIPLE
- *           TURTLE
- *           N3
- *       The input language defaults to RDF/XML and the output language
- *       defaults to N-TRIPLE.
- *  </pre>
- */
-public class rdfcopy extends java.lang.Object {
-
-    static { setCmdLogging(); }
-
-	/**
-	* @param args the command line arguments
-	*/
-	public static void main(String ... args) {
-		if ( ( args.length < 1 ) || ( "-h".equals(args[0]) ) ) {
-			usage();
-			System.exit(-1);
-		}
-
-		String in = args[0];
-		String inlang = "RDF/XML";
-		int j;
-		for (j = 1; j < args.length && args[j].contains( "=" ); j++)
-        {}
-		int lastInProp = j;
-		if (j < args.length) {
-			inlang = args[j];
-		}
-		j++;
-		String outlang = "N-TRIPLE";
-		
-		for (; j < args.length && args[j].contains( "=" ); j++)
-		{}
-		
-		int lastOutProp = j;
-		if (j < args.length) {
-			outlang = args[j];
-		}
-		if (j + 1 < args.length) {
-         //   System.err.println(j+"<<"+args.length);
-			usage();
-			System.exit(-1);
-		}
-
-		try {
-			Model m = ModelFactory.createDefaultModel();
-            String base = in ;
-			RDFReader rdr = m.getReader(inlang);
-			for (j = 1; j < lastInProp; j++) {
-				int eq = args[j].indexOf("=");
-				rdr.setProperty(
-					args[j].substring(0, eq),
-					args[j].substring(eq + 1));
-			}
-            
-            try {
-                rdr.read(m, in);
-            } catch (JenaException ex)
-            {
-                if ( ! ( ex.getCause() instanceof MalformedURLException ) )
-                    throw ex ;
-                // Tried as a URL.  Try as a file name.
-                // Make absolute
-                File f = new File(in) ;
-                base = "file:///"+f.getCanonicalPath().replace('\\','/') ;
-                rdr.read(m, new FileInputStream(in), base) ;
-            }
-			RDFWriter w = m.getWriter(outlang);
-			j++;
-			for (; j < lastOutProp; j++) {
-				int eq = args[j].indexOf("=");
-				w.setProperty(
-					args[j].substring(0, eq),
-					args[j].substring(eq + 1));
-			}
-			w.write(m, System.out, null) ;
-			System.exit(0);
-		} catch (Exception e) {
-			System.err.println("Unhandled exception:");
-			System.err.println("    " + e.toString());
-			System.exit(-1);
-		}
-	}
-
-	protected static void usage() {
-		System.err.println("usage:");
-		System.err.println("    java jena.rdfcopy in {inprop=inval}* [ inlang  {outprop=outval}* outlang]]");
-		System.err.println();
-		System.err.println("    in can be a URL or a filename");
-		System.err.println("    inlang and outlang can take values:");
-		System.err.println("      RDF/XML");
-        System.err.println("      RDF/XML-ABBREV");
-        System.err.println("      N-TRIPLE");
-        System.err.println("      TURTLE");
-		System.err.println("      N3");
-		System.err.println(
-			"    inlang defaults to RDF/XML, outlang to N-TRIPLE");
-        System.err.println("    The legal values for inprop and outprop depend on inlang and outlang.");
-        System.err.println("    The legal values for inval and outval depend on inprop and outprop.");
-		System.err.println();
-	}
-
-	protected static void read(Model model, String in, String lang)
-		throws java.io.FileNotFoundException {
-		try {
-			URL url = new URL(in);
-			model.read(in, lang);
-		} catch (java.net.MalformedURLException e) {
-			model.read(new FileInputStream(in), "", lang);
-		}
-	}
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/main/java/jena/rdfparse.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/jena/rdfparse.java b/jena-core/src/main/java/jena/rdfparse.java
deleted file mode 100644
index 0ba1eb6..0000000
--- a/jena-core/src/main/java/jena/rdfparse.java
+++ /dev/null
@@ -1,103 +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 jena;
-
-import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
-
-import java.lang.reflect.Constructor ;
-
-import org.apache.jena.rdfxml.xmlinput.NTriple ;
-import org.apache.jena.shared.Command ;
-
-/** A command line interface into ARP.
- * Creates NTriple's or just error messages.
- * <pre>
- * java &lt;class-path&gt; jena.rdfparse ( [ -[xstfu]][ -b xmlBase -[eiw] NNN[,NNN...] ] [ file ] [ url ] )...
- * 
- * java &lt;class-path&gt; jena.rdfparse --test
- * 
- * java &lt;class-path&gt; jena.rdfparse --internal-test
- * </pre>
- * 
- * <p>
- * The last two forms are for testing. <code>--test</code> runs ARP
- * against the RDF Core Working Group tests found at w3.org.
- * <code>--internal-test</code> uses a cached copy from within the jena.jar.
- * </p>
- * All options, files and URLs can be intemingled in any order.
- * They are processed from left-to-right.
- * <dl>
- * file    </dt><dd>  Converts (embedded) RDF in XML file into N-triples
- * </dd><dt>
- * url  </dt><dd>     Converts (embedded) RDF from URL into N-triples
- * </dd><dt>
- * -b uri </dt><dd>   Sets XML Base to the absolute URI.
- * </dd><dt>
- * -r    </dt><dd>    Content is RDF (no embedding, rdf:RDF tag may be omitted).
- * </dd><dt>
- * -t  </dt><dd>      No n-triple output, error checking only.
- * </dd><dt>
- * -x   </dt><dd>     Lax mode - warnings are suppressed.
- * </dd><dt>
- * -s    </dt><dd>    Strict mode - most warnings are errors.
- * </dd><dt>
- * -u     </dt><dd>   Allow unqualified attributes (defaults to warning).
- * </dd><dt>
- * -f    </dt><dd>    All errors are.error - report first one only.
- * </dd><dt>
- * -b url </dt><dd>   Sets XML Base to the absolute url.
- * </dd><dt>
- * -e NNN[,NNN...]</dt><dd>
- * Treats numbered warning conditions as errrors.
- * </dd><dt>
- * -w NNN[,NNN...]</dt><dd>
- * Treats numbered error conditions as warnings.
- * </dd><dt>
- * -i NNN[,NNN...]
- * </dt><dd>
- * Ignores numbered error/warning conditions.
- * </dl>
- */
-
-public class rdfparse {
-
-    static { setCmdLogging(); }
-
-    /** Either start an RDF/XML to NTriple converter, or run test suite.
-	 * @param args The command-line arguments.
-	 */
-	public static void main( String... args ) throws Exception {
-		if (args.length == 1 && (args[0].equals( "--test" ) || args[0].equals( "--internal-test" ))) 
-            runTests( args[0].equals( "--test" ) );
-        else
-		    NTriple.main( args );
-	}
-
-    /**
-         wrapped this way so JUnit not a compile-time requirement.
-    */
-    protected static void runTests( boolean internetTest ) throws Exception { 
-        Class<?> rdfparse = Class.forName( "jena.test.rdfparse" );
-        Constructor<?> constructor = rdfparse.getConstructor( new Class[] {boolean.class} );
-        Command c = (Command) constructor.newInstance( new Object[] { internetTest } );
-        c.execute();
-//        ARPTests.internet = internetTest;
-//        TestRunner.main( new String[] { "-noloading", ARPTests.class.getName()});
-        }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/main/java/jena/rset.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/jena/rset.java b/jena-core/src/main/java/jena/rset.java
deleted file mode 100644
index 2374681..0000000
--- a/jena-core/src/main/java/jena/rset.java
+++ /dev/null
@@ -1,29 +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 jena;
-
-
-public class rset
-{
-    // Call-through to arq command line application
-    public static void main(String... args)
-    {
-        InvokingUtil.invokeCmd("arq.rset", args) ;
-    }
-}


[09/20] jena git commit: JENA-1108 : jena-cmds module

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/tdbconfig.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/tdbconfig.java b/jena-cmds/src/main/java/tdb/tdbconfig.java
new file mode 100644
index 0000000..99aea15
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/tdbconfig.java
@@ -0,0 +1,250 @@
+/*
+ * 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 tdb;
+
+
+import java.util.List ;
+import java.util.Map ;
+
+import jena.cmd.ModVersion;
+
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.atlas.lib.DateTimeUtils ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.sparql.core.DatasetPrefixStorage ;
+import org.apache.jena.tdb.TDB ;
+import org.apache.jena.tdb.base.file.FileFactory ;
+import org.apache.jena.tdb.base.file.Location ;
+import org.apache.jena.tdb.base.objectfile.StringFile ;
+import org.apache.jena.tdb.setup.Build ;
+import org.apache.jena.tdb.solver.stats.Stats ;
+import org.apache.jena.tdb.solver.stats.StatsResults ;
+import org.apache.jena.tdb.store.DatasetGraphTDB ;
+import org.apache.jena.tdb.sys.DatasetControlNone ;
+
+import tdb.cmdline.CmdSub ;
+import tdb.cmdline.CmdTDB ;
+import tdb.cmdline.CmdTDBGraph ;
+import arq.cmdline.CmdARQ ;
+
+/** Tools to manage a TDB store.  Subcommand based. */
+public class tdbconfig extends CmdSub
+{
+    static final String CMD_CLEAN       = "clean" ;
+    static final String CMD_HELP        = "help" ;
+    static final String CMD_STATS       = "stats" ;
+    static final String CMD_NODES       = "nodes" ;
+    static final String CMD_INFO        = "info" ;
+    static final String CMD_PREFIXES    = "prefixes" ;
+    
+    static public void main(String... argv)
+    {
+        CmdTDB.init() ;
+        new tdbconfig(argv).exec();
+    }
+
+    protected tdbconfig(String[] argv)
+    {
+        super(argv) ;
+//        super.addSubCommand(CMD_CLEAN, new Exec()
+//          { @Override public void exec(String[] argv) { new tdbclean(argv).main() ; } }) ;
+        
+        super.addSubCommand(CMD_HELP, new Exec()
+        { /*@Override*/ @Override
+        public void exec(String[] argv) { new SubHelp(argv).mainRun() ; } }) ;
+        
+        super.addSubCommand(CMD_STATS, new Exec()
+        { /*@Override*/ @Override
+        public void exec(String[] argv) { new SubStats(argv).mainRun() ; } }) ;
+        
+        super.addSubCommand(CMD_NODES, new Exec()
+        { /*@Override*/ @Override
+        public void exec(String[] argv) { new SubNodes(argv).mainRun() ; } }) ;
+        
+        super.addSubCommand(CMD_INFO, new Exec()
+        { /*@Override*/ @Override
+        public void exec(String[] argv) { new SubInfo(argv).mainRun() ; } }) ;
+        
+        super.addSubCommand(CMD_PREFIXES, new Exec()
+        { /*@Override*/ @Override
+        public void exec(String[] argv) { new SubPrefixes(argv).mainRun() ; } }) ;
+
+        
+    }
+    
+    static class SubPrefixes extends CmdTDB
+    {
+        public SubPrefixes(String ... argv)
+        {
+            super(argv) ;
+            //super.addModule(modSymbol) ;
+        }
+
+        @Override
+        protected String getSummary()
+        {
+            return "tdbconfig prefixes" ;
+        }
+
+        @Override
+        protected void exec()
+        {
+            Location location = getLocation() ;
+            DatasetPrefixStorage prefixes = Build.makePrefixes(location, new DatasetControlNone()) ;
+            for ( String gn : prefixes.graphNames() )
+            {
+                System.out.println("Graph: "+gn) ;
+                PrefixMapping pmap = prefixes.getPrefixMapping(gn) ;
+                Map<String, String> x = pmap.getNsPrefixMap() ;
+                for ( String k : x.keySet() )
+                    System.out.printf("  %-10s %s\n", k+":", x.get(k)) ;
+            }
+        }
+    }
+    
+    // Subcommand : help
+    class SubHelp extends CmdARQ
+    {
+        public SubHelp(String ... argv)
+        {
+            super(argv) ;
+            //super.addModule(modSymbol) ;
+        }
+        
+        @Override
+        protected String getSummary()
+        {
+            return null ;
+        }
+
+        @Override
+        protected void exec()
+        {
+            IndentedWriter out = IndentedWriter.stdout ;
+            out.println("Sub-commands:") ;
+            out.incIndent() ;
+
+            for ( String name : subCommandNames() )
+            {
+                out.println(name) ; 
+            }
+            out.decIndent() ;
+            out.flush() ;
+        }
+
+        @Override
+        protected String getCommandName()
+        {
+            return "tdbconfig help" ;
+        }
+    }
+    
+    static class SubStats extends CmdTDBGraph
+    {
+        public SubStats(String ... argv)
+        {
+            super(argv) ;
+            //super.addModule(modSymbol) ;
+        }
+        
+        @Override
+        protected String getSummary()
+        {
+            return "tdbconfig stats" ;
+        }
+
+        @Override
+        protected void exec()
+        {
+            DatasetGraphTDB dsg = getDatasetGraphTDB() ;
+            Node gn = getGraphName() ;
+            StatsResults results = tdbstats.stats(dsg, gn) ;
+            Stats.write(System.out, results) ;
+        }
+
+        @Override
+        protected String getCommandName()
+        {
+            return "tdbconfig stats" ;
+        }
+    }
+    
+    static class SubNodes extends CmdTDB
+    {
+        public SubNodes(String ... argv)
+        {
+            super(argv) ;
+        }
+        
+        @Override
+        protected String getSummary()
+        {
+            return "tdbconfig nodes" ;
+        }
+
+        @Override
+        protected void exec()
+        {
+            List<String> args = positionals ;
+            for ( String x : args )
+            {
+                System.out.println("**** Object File: "+x) ;
+                StringFile objs = FileFactory.createStringFileDisk(x) ;
+                objs.dump() ;
+            }
+        }
+
+        @Override
+        protected String getCommandName()
+        {
+            return "tdbconfig nodes" ;
+        }
+    }
+
+    static class SubInfo extends CmdTDB
+    {
+        public SubInfo(String ... argv)
+        {
+            super(argv) ;
+        }
+        
+        @Override
+        protected String getSummary()
+        {
+            return "tdbconfig info" ;
+        }
+
+        @Override
+        protected void exec()
+        {
+            System.out.println("-- "+DateTimeUtils.nowAsString()+" --") ;
+            ModVersion v = new ModVersion(true) ;
+            v.addClass(TDB.class) ;
+            v.printVersionAndExit() ;
+        }
+
+        @Override
+        protected String getCommandName()
+        {
+            return "tdbconfig info" ;
+        }
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/tdbdump.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/tdbdump.java b/jena-cmds/src/main/java/tdb/tdbdump.java
new file mode 100644
index 0000000..093ae9e
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/tdbdump.java
@@ -0,0 +1,51 @@
+/*
+ * 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 tdb;
+
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFDataMgr ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import tdb.cmdline.CmdTDB ;
+
+public class tdbdump extends CmdTDB
+{
+    static public void main(String... argv)
+    { 
+        CmdTDB.init() ;
+        new tdbdump(argv).mainRun() ;
+    }
+
+    protected tdbdump(String[] argv)
+    {
+        super(argv) ;
+    }
+    
+    @Override
+    protected String getSummary()
+    {
+        return getCommandName()+" : Write N-Quads to stdout" ;
+    }
+
+    @Override
+    protected void exec()
+    {
+        DatasetGraph dsg = super.getDatasetGraphTDB() ;
+        RDFDataMgr.write(System.out, dsg, Lang.NQUADS) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/tdbloader.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/tdbloader.java b/jena-cmds/src/main/java/tdb/tdbloader.java
new file mode 100644
index 0000000..37ba0e4
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/tdbloader.java
@@ -0,0 +1,138 @@
+/*
+ * 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 tdb ;
+
+import java.util.List ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException;
+
+import org.apache.jena.query.ARQ ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFLanguages ;
+import org.apache.jena.tdb.TDB ;
+import org.apache.jena.tdb.TDBLoader ;
+import org.apache.jena.tdb.store.GraphTDB ;
+
+import tdb.cmdline.CmdTDB ;
+import tdb.cmdline.CmdTDBGraph ;
+
+public class tdbloader extends CmdTDBGraph {
+    // private static final ArgDecl argParallel = new ArgDecl(ArgDecl.NoValue, "parallel") ;
+    // private static final ArgDecl argIncremental = new ArgDecl(ArgDecl.NoValue, "incr", "incremental") ;
+    private static final ArgDecl argNoStats = new ArgDecl(ArgDecl.NoValue, "nostats") ;
+    private static final ArgDecl argStats = new ArgDecl(ArgDecl.HasValue,  "stats") ;
+
+    private boolean showProgress  = true ;
+    private boolean generateStats  = true ;
+    // private boolean doInParallel = false ;
+    // private boolean doIncremental = false ;
+
+    static public void main(String... argv) {
+        CmdTDB.init() ;
+        TDB.setOptimizerWarningFlag(false) ;
+        new tdbloader(argv).mainRun() ;
+    }
+
+    protected tdbloader(String[] argv) {
+        super(argv) ;
+//        super.getUsage().startCategory("Stats") ;
+        super.add(argNoStats, "--nostats", "Switch off statistics gathering") ;
+        super.add(argStats) ;   // Hidden argument
+        // super.add(argParallel, "--parallel",
+        // "Do rebuilding of secondary indexes in a parallel") ;
+        // super.add(argIncremental, "--incremental",
+        // "Do an incremental load (keep indexes during data load)") ;
+        // super.add(argStats, "--stats",
+        // "Generate statistics while loading (new graph only)") ;
+        // addModule(modRDFS) ;
+    }
+
+    @Override
+    protected void processModulesAndArgs() {
+        super.processModulesAndArgs() ;
+        // doInParallel = super.contains(argParallel) ;
+        // doIncremental = super.contains(argIncremental) ;
+    }
+
+    @Override
+    protected String getSummary() {
+        return getCommandName() + " [--desc DATASET | -loc DIR] FILE ..." ;
+    }
+
+    @Override
+    protected void exec() {
+        if ( isVerbose() ) {
+            System.out.println("Java maximum memory: " + Runtime.getRuntime().maxMemory()) ;
+            System.out.println(ARQ.getContext()) ;
+        }
+        if ( isVerbose() )
+            showProgress = true ;
+        if ( isQuiet() )
+            showProgress = false ;
+        if ( super.contains(argStats) ) {
+            if ( ! hasValueOfTrue(argStats) && ! hasValueOfFalse(argStats) )
+                throw new CmdException("Not a boolean value: "+getValue(argStats)) ;
+            generateStats = super.hasValueOfTrue(argStats) ;
+        }
+
+        if ( super.contains(argNoStats))
+            generateStats = false ;
+        
+        List<String> urls = getPositional() ;
+        if ( urls.size() == 0 )
+            urls.add("-") ;
+
+        if ( graphName == null ) {
+            loadQuads(urls) ;
+            return ;
+        }
+        
+        // There's a --graph.
+        // Check/warn that there are no quads formats mentioned
+        // (RIOT will take the default graph from quads).  
+        
+        for ( String url : urls ) {
+            Lang lang = RDFLanguages.filenameToLang(url) ;
+            if ( lang != null && RDFLanguages.isQuads(lang) ) {
+                System.err.println("Warning: Quads format given - only the default graph is loaded into the graph for --graph") ;
+                break ;
+            }
+        }
+        
+        loadNamedGraph(urls) ;
+    }
+
+//    void loadDefaultGraph(List<String> urls) {
+//        GraphTDB graph = getGraph() ;
+//        TDBLoader.load(graph, urls, showProgress) ;
+//        return ;
+//    }
+
+    void loadNamedGraph(List<String> urls) {
+        GraphTDB graph = getGraph() ;
+        TDBLoader.load(graph, urls, showProgress) ;
+        return ;
+    }
+
+    void loadQuads(List<String> urls) {
+        TDBLoader.load(getDatasetGraphTDB(), urls, showProgress, generateStats) ;
+        return ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/tdbnode.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/tdbnode.java b/jena-cmds/src/main/java/tdb/tdbnode.java
new file mode 100644
index 0000000..391c628
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/tdbnode.java
@@ -0,0 +1,84 @@
+/*
+ * 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 tdb;
+
+import java.util.Iterator ;
+
+import org.apache.jena.atlas.lib.Bytes ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.tdb.lib.NodeLib ;
+import org.apache.jena.tdb.store.DatasetGraphTDB ;
+import org.apache.jena.tdb.store.Hash ;
+import org.apache.jena.tdb.store.NodeId ;
+import org.apache.jena.tdb.store.nodetable.NodeTable ;
+import org.apache.jena.tdb.sys.SystemTDB ;
+import tdb.cmdline.CmdTDB ;
+
+public class tdbnode extends CmdTDB
+{
+    // Debugging tool.
+    static public void main(String... argv)
+    { 
+        CmdTDB.init() ;
+        new tdbnode(argv).mainRun() ;
+    }
+
+    protected tdbnode(String[] argv)
+    {
+        super(argv) ;
+    }
+
+    @Override
+    protected String getSummary()
+    {
+        return getCommandName()+" NodeId ..." ;
+    }
+
+    @Override
+    protected void exec()
+    {
+        DatasetGraphTDB dsg = getDatasetGraphTDB() ;
+        NodeTable nodeTable = dsg.getTripleTable().getNodeTupleTable().getNodeTable() ;
+        Iterator<String> iter = super.getPositional().iterator() ;
+        if ( ! iter.hasNext() )
+        {
+            System.err.println("No node ids") ;
+            return ;
+        }
+        
+        for ( ; iter.hasNext() ; )
+        {
+            String id = iter.next() ;
+            try {
+                long x = Long.parseLong(id) ;
+                NodeId nodeId = new NodeId(x) ;
+                Node n = nodeTable.getNodeForNodeId(nodeId) ;
+                //System.out.printf("%s [%d] => %s\n", id, x, n) ;
+
+                Hash h = new Hash(SystemTDB.LenNodeHash) ;
+                NodeLib.setHash(h, n) ;
+                String str = Bytes.asHex(h.getBytes()) ;
+                System.out.printf("%s %08d 0x%s # %s\n", id, x, str, n) ;
+            } catch (Exception ex)
+            {
+                System.out.println("Failed to decode: "+id) ;
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/tdbquery.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/tdbquery.java b/jena-cmds/src/main/java/tdb/tdbquery.java
new file mode 100644
index 0000000..82ee3de
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/tdbquery.java
@@ -0,0 +1,60 @@
+/*
+ * 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 tdb;
+
+import org.apache.jena.tdb.TDB ;
+import tdb.cmdline.CmdTDB ;
+import tdb.cmdline.ModTDBDataset ;
+import arq.cmdline.ModDataset ;
+
+
+public class tdbquery extends arq.query
+{
+    // Inherits from arq.query so is not a CmdTDB.  Mixins for Java!
+    public static void main(String...argv)
+    {
+        CmdTDB.init() ;
+        new tdbquery(argv).mainRun() ;
+    }
+    
+    public tdbquery(String[] argv)
+    {
+        super(argv) ;
+        // Because this inherits from an ARQ command
+        super.modVersion.addClass(TDB.class) ;
+    }
+
+    @Override
+    protected String getSummary() 
+    { 
+        return getCommandName()+" --loc=<path> --query=<query>" ; 
+    }
+    
+    @Override
+    protected void processModulesAndArgs()
+    {
+        super.processModulesAndArgs() ;
+    }
+    
+    @Override
+    protected ModDataset setModDataset()
+    {
+        return new ModTDBDataset() ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/tdbrecovery.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/tdbrecovery.java b/jena-cmds/src/main/java/tdb/tdbrecovery.java
new file mode 100644
index 0000000..2621115
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/tdbrecovery.java
@@ -0,0 +1,54 @@
+/*
+ * 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 tdb;
+
+import org.apache.jena.tdb.TDB ;
+import org.apache.jena.tdb.store.DatasetGraphTDB ;
+import org.apache.jena.tdb.transaction.JournalControl ;
+import tdb.cmdline.CmdTDB ;
+
+public class tdbrecovery extends CmdTDB
+{
+    static public void main(String... argv)
+    { 
+        CmdTDB.init() ;
+        TDB.setOptimizerWarningFlag(false) ;
+        new tdbrecovery(argv).mainRun() ;
+    }
+
+    protected tdbrecovery(String[] argv)
+    {
+        super(argv) ;
+    }
+
+    @Override
+    protected String getSummary()
+    {
+        return getCommandName()+" --loc DIRECTORY\nRun database journal recovery." ;
+    }
+
+    @Override
+    protected void exec()
+    {
+        DatasetGraphTDB dsg = super.getDatasetGraphTDB() ;
+        // Just creating the DSG does a recovery so this is not (currently) necessary:
+        // This may change (not immediately recovering on start up).
+        JournalControl.recovery(dsg) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/tdbreorder.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/tdbreorder.java b/jena-cmds/src/main/java/tdb/tdbreorder.java
new file mode 100644
index 0000000..8d9984a
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/tdbreorder.java
@@ -0,0 +1,124 @@
+/**
+ * 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 tdb;
+
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.atlas.lib.FileOps ;
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.shared.impl.PrefixMappingImpl ;
+import org.apache.jena.sparql.algebra.Op ;
+import org.apache.jena.sparql.algebra.op.OpBGP ;
+import org.apache.jena.sparql.algebra.op.OpQuadPattern ;
+import org.apache.jena.sparql.core.BasicPattern ;
+import org.apache.jena.sparql.engine.optimizer.StatsMatcher ;
+import org.apache.jena.sparql.engine.optimizer.reorder.ReorderLib ;
+import org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation ;
+import org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformationSubstitution ;
+import org.apache.jena.sparql.serializer.SerializationContext ;
+import org.apache.jena.sparql.sse.SSE ;
+import org.apache.jena.sparql.sse.writers.WriterNode ;
+import org.apache.jena.tdb.sys.Names ;
+
+public class tdbreorder
+{
+    public static void main(String... args) {
+        if ( args.length != 2 ) {
+            System.err.println("Usage: PATTERN STATS") ;
+            System.exit(1) ;
+        }
+        LogCtl.enable(StatsMatcher.class) ;
+        LogCtl.enable(ReorderTransformationSubstitution.class) ;
+        
+        if ( args.length != 2 )
+        {
+            System.err.println("Usage: op stats") ; 
+            System.exit(1) ;
+        }
+            
+        String pattern = args[0] ;
+        String statsFile = args[1] ;
+        
+        Op op = SSE.readOp(pattern) ;
+
+        BasicPattern bgp ;
+        if ( op instanceof OpQuadPattern ) {
+            bgp = ((OpQuadPattern)op).getBasicPattern() ;
+        } else if ( op instanceof OpBGP ) {
+            bgp = ((OpBGP)op).getPattern() ;
+        }
+        else {
+            System.err.println("Not a quad or triple pattern") ;
+            System.exit(2) ;
+            bgp = null ;
+        }
+        
+        ReorderTransformation reorder = chooseReorder(statsFile) ;
+        //ReorderTransformation reorder = ReorderLib.fixed() ;
+        BasicPattern bgp2 = reorder.reorder(bgp) ;
+     
+        System.out.println() ;
+        
+        print(bgp) ;
+        System.out.println() ;
+        System.out.println(" ======== >>>>>>>>") ;
+        print(bgp2) ;
+        System.out.println() ;
+    }
+    
+    private static void print(BasicPattern bgp) {
+        IndentedWriter out = IndentedWriter.stdout;
+        
+        PrefixMapping pmap = new PrefixMappingImpl() ;
+        pmap.setNsPrefixes(SSE.defaultPrefixMapWrite) ;
+//        pmap.setNsPrefix("ppi", "http://landregistry.data.gov.uk/def/ppi/") ;
+//        pmap.setNsPrefix("common", "http://landregistry.data.gov.uk/def/common/") ;
+        
+        SerializationContext sCxt = SSE.sCxt(pmap) ;
+        
+        boolean first = true ;
+        for ( Triple t : bgp )
+        {
+            if ( !first )
+                out.print("\n") ;
+            else
+                first = false ;
+            // Adds (triple ...)
+            // SSE.write(buff.getIndentedWriter(), t) ;
+            out.print("(") ;
+            WriterNode.outputPlain(out, t, sCxt) ;
+            out.print(")") ;
+        }
+        out.flush();
+        
+    }
+    private static ReorderTransformation chooseReorder(String filename)
+    {
+        if ( filename.equals(Names.optFixed) )
+            return ReorderLib.fixed() ;
+        if ( filename.equals(Names.optNone) )
+            return ReorderLib.identity() ;
+        if ( FileOps.exists(filename) )
+            return ReorderLib.weighted(filename) ;
+        else
+            throw new RuntimeException("No such file: "+filename) ;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/tdbstats.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/tdbstats.java b/jena-cmds/src/main/java/tdb/tdbstats.java
new file mode 100644
index 0000000..115c487
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/tdbstats.java
@@ -0,0 +1,103 @@
+/*
+ * 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 tdb;
+
+import java.util.Iterator ;
+
+import org.apache.jena.atlas.lib.tuple.Tuple ;
+import org.apache.jena.atlas.logging.Log ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.sparql.core.Quad ;
+import org.apache.jena.tdb.solver.SolverLib ;
+import org.apache.jena.tdb.solver.stats.Stats ;
+import org.apache.jena.tdb.solver.stats.StatsCollectorNodeId ;
+import org.apache.jena.tdb.solver.stats.StatsResults ;
+import org.apache.jena.tdb.store.DatasetGraphTDB ;
+import org.apache.jena.tdb.store.NodeId ;
+import org.apache.jena.tdb.store.nodetable.NodeTable ;
+import org.apache.jena.tdb.store.nodetupletable.NodeTupleTable ;
+import tdb.cmdline.CmdTDB ;
+import tdb.cmdline.CmdTDBGraph ;
+
+public class tdbstats extends CmdTDBGraph
+{
+    // tdbconfig?
+    static public void main(String... argv)
+    { 
+        CmdTDB.init() ;
+        new tdbstats(argv).mainRun() ;
+    }
+
+    protected tdbstats(String[] argv)
+    {
+        super(argv) ;
+    }
+    
+    @Override
+    protected String getSummary()
+    {
+        return null ;
+    }
+    
+    public static StatsResults stats(DatasetGraphTDB dsg, Node gn)
+    {
+        NodeTable nt = dsg.getTripleTable().getNodeTupleTable().getNodeTable() ;
+        StatsCollectorNodeId stats = new StatsCollectorNodeId(nt) ;
+        
+        if ( gn == null )
+        {
+            Iterator<Tuple<NodeId>> iter = dsg.getTripleTable().getNodeTupleTable().findAll() ;
+            for ( ; iter.hasNext(); )
+            {
+                Tuple<NodeId> t = iter.next() ;
+                stats.record(null, t.get(0), t.get(1), t.get(2)) ;
+            }
+        } else {
+            // If the union graph, then we need to scan all quads but with uniqueness.
+            boolean unionGraph = Quad.isUnionGraph(gn) ;
+            NodeId gnid = null ;
+            if ( ! unionGraph )
+            {
+                gnid = nt.getNodeIdForNode(gn) ;
+                if ( NodeId.isDoesNotExist(gnid) )
+                Log.warn(tdbstats.class, "No such graph: "+gn) ;
+            }
+                
+            NodeTupleTable ntt = dsg.getQuadTable().getNodeTupleTable() ;
+            Iterator<Tuple<NodeId>> iter = unionGraph
+                ? SolverLib.unionGraph(ntt)
+                : ntt.find(gnid, null, null, null) ;
+            for ( ; iter.hasNext(); )
+            {
+                Tuple<NodeId> t = iter.next() ;
+                stats.record(t.get(0), t.get(1), t.get(2), t.get(3)) ;
+            }
+        }
+        return stats.results() ;
+    }
+
+    @Override
+    protected void exec()
+    {
+        DatasetGraphTDB dsg = getDatasetGraphTDB() ;
+        Node gn = getGraphName() ;
+        StatsResults results = stats(dsg, gn) ;
+        Stats.write(System.out, results) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/tdbupdate.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/tdbupdate.java b/jena-cmds/src/main/java/tdb/tdbupdate.java
new file mode 100644
index 0000000..464ec2e
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/tdbupdate.java
@@ -0,0 +1,61 @@
+/*
+ * 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 tdb;
+
+import arq.cmdline.ModDataset ;
+import jena.cmd.CmdException ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.tdb.TDB ;
+import org.apache.jena.tdb.transaction.TransactionManager ;
+import tdb.cmdline.CmdTDB ;
+import tdb.cmdline.ModTDBDataset ;
+
+public class tdbupdate extends arq.update
+{
+    // Inherits from arq.update so is not a CmdTDB.  Mixins for Java!
+    public static void main(String...argv)
+ {
+        CmdTDB.init();
+        // Do everything with flushing transactions.
+        TransactionManager.QueueBatchSize = 0;
+        new tdbupdate(argv).mainRun();
+    }
+
+    public tdbupdate(String[] argv) {
+        super(argv);
+        // Because this inherits from an ARQ command
+        CmdTDB.init();
+        super.modVersion.addClass(TDB.class);
+    }
+
+    @Override
+    protected void processModulesAndArgs() {
+        super.processModulesAndArgs();
+    }
+
+    @Override
+    protected ModDataset setModeDataset() {
+        return new ModTDBDataset();
+    }
+    
+    @Override
+    protected DatasetGraph dealWithNoDataset() {
+        throw new CmdException("No dataset provided") ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/tools/dumpbpt.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/tools/dumpbpt.java b/jena-cmds/src/main/java/tdb/tools/dumpbpt.java
new file mode 100644
index 0000000..269150e
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/tools/dumpbpt.java
@@ -0,0 +1,178 @@
+/*
+ * 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 tdb.tools ;
+
+import java.io.PrintStream ;
+import java.util.Arrays ;
+import java.util.Iterator ;
+import java.util.List ;
+
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.lib.tuple.Tuple ;
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.tdb.base.file.Location ;
+import org.apache.jena.tdb.base.record.Record ;
+import org.apache.jena.tdb.base.record.RecordFactory ;
+import org.apache.jena.tdb.index.IndexFactory ;
+import org.apache.jena.tdb.index.RangeIndex ;
+import org.apache.jena.tdb.index.bplustree.BPlusTree ;
+import org.apache.jena.tdb.lib.ColumnMap ;
+import org.apache.jena.tdb.store.NodeId ;
+import org.apache.jena.tdb.store.tupletable.TupleIndex ;
+import org.apache.jena.tdb.store.tupletable.TupleIndexRecord ;
+import org.apache.jena.tdb.sys.Names ;
+import org.apache.jena.tdb.sys.SystemTDB ;
+
+import arq.cmdline.CmdARQ;
+import tdb.cmdline.ModLocation ;
+
+public class dumpbpt extends CmdARQ {
+    ModLocation modLocation = new ModLocation() ;
+
+    static public void main(String... argv) {
+        LogCtl.setLog4j() ;
+        new dumpbpt(argv).mainRun() ;
+    }
+
+    protected dumpbpt(String[] argv) {
+        super(argv) ;
+        super.addModule(modLocation) ;
+    }
+
+    @Override
+    protected void processModulesAndArgs() {
+        if ( modVersion.getVersionFlag() )
+            modVersion.printVersionAndExit() ;
+        if ( modLocation.getLocation() == null )
+            cmdError("Location required") ;
+        if ( super.getPositional().size() == 0 )
+            cmdError("No index specified") ;
+    }
+
+    @Override
+    protected String getSummary() {
+        return getCommandName() + " --loc=DIR IndexName" ;
+    }
+
+    @Override
+    protected String getCommandName() {
+        return Lib.className(this) ;
+    }
+
+    @Override
+    protected void exec() {
+        List<String> tripleIndexes = Arrays.asList(Names.tripleIndexes) ;
+        List<String> quadIndexes = Arrays.asList(Names.quadIndexes) ;
+        Location loc = modLocation.getLocation() ;
+
+        // The name is the order.
+        for ( String indexName : super.getPositional() ) {
+            String primary ;
+            if ( indexName.length() == 3 ) {
+                primary = Names.primaryIndexTriples ;
+            } else if ( indexName.length() == 4 ) {
+                primary = Names.primaryIndexQuads ;
+            } else {
+                cmdError("Wrong length: " + indexName) ;
+                primary = null ;
+            }
+
+            int keySubLen = SystemTDB.SizeOfNodeId ;
+            int keyUnitLen = indexName.length() ;
+            int keyLength = keySubLen * keyUnitLen ;
+            int valueLength = 0 ;
+
+            RecordFactory rf = new RecordFactory(keyLength, valueLength) ;
+            RangeIndex rIndex = IndexFactory.buildRangeIndex(loc, indexName, rf) ;
+            BPlusTree bpt = (BPlusTree)rIndex ;
+
+            if ( false ) {
+                System.out.println("---- Index structure") ;
+                bpt.dump() ;
+            }
+            if ( true ) {
+                System.out.println("---- Index contents") ;
+                Iterator<Record> iter = bpt.iterator() ;
+                if ( !iter.hasNext() )
+                    System.out.println("<<Empty>>") ;
+
+                for ( ; iter.hasNext() ; ) {
+                    Record r = iter.next() ;
+                    printRecord("", System.out, r, keyUnitLen) ;
+                }
+            }
+
+            // Check.
+            Iterator<Record> iterCheck = bpt.iterator() ;
+            Record r1 = null ;
+            int i = 0 ;
+            for ( ; iterCheck.hasNext() ; ) {
+                Record r2 = iterCheck.next() ;
+                i++ ;
+
+                if ( r1 != null ) {
+                    if ( !Record.keyLT(r1, r2) ) {
+                        System.err.println("key error@ " + i) ;
+                        printRecord("  ", System.err, r1, keyUnitLen) ;
+                        printRecord("  ", System.err, r2, keyUnitLen) ;
+                    }
+                }
+                r1 = r2 ;
+            }
+
+            if ( false ) {
+                // Dump in tuple order.
+                TupleIndex tupleIndex = new TupleIndexRecord(primary.length(), new ColumnMap(primary, indexName), indexName,
+                                                             rIndex.getRecordFactory(), rIndex) ;
+                if ( true ) {
+                    System.out.println("---- Tuple contents") ;
+                    Iterator<Tuple<NodeId>> iter2 = tupleIndex.all() ;
+                    if ( !iter2.hasNext() )
+                        System.out.println("<<Empty>>") ;
+
+                    for ( ; iter2.hasNext() ; ) {
+                        Tuple<NodeId> row = iter2.next() ;
+                        System.out.println(row) ;
+                    }
+                }
+            }
+        }
+    }
+
+    private static void printRecord(String label, PrintStream out, Record r, int keyUnitLen) {
+        // out.println(r) ;
+
+        int keySubLen = r.getKey().length / keyUnitLen ;
+        if ( label != null )
+            out.print(label) ;
+        for ( int i = 0 ; i < keyUnitLen ; i++ ) {
+            if ( i != 0 )
+                out.print(" ") ;
+
+            // Print in chunks
+            int k = i * keySubLen ;
+            for ( int j = k ; j < k + keySubLen ; j++ )
+                out.printf("%02x", r.getKey()[j]) ;
+
+            // long x = Bytes.getLong(r.getKey(), i*SystemTDB.SizeOfNodeId) ;
+            // System.out.printf("%016x", x) ;
+        }
+        out.println() ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/tools/dumpnodetable.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/tools/dumpnodetable.java b/jena-cmds/src/main/java/tdb/tools/dumpnodetable.java
new file mode 100644
index 0000000..31f6309
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/tools/dumpnodetable.java
@@ -0,0 +1,182 @@
+/*
+ * 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 tdb.tools ;
+
+import java.io.OutputStream ;
+import java.util.Arrays ;
+import java.util.Iterator ;
+import java.util.List ;
+
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.lib.Pair ;
+import org.apache.jena.atlas.logging.Log ;
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Node_Literal ;
+import org.apache.jena.sparql.util.FmtUtils ;
+import org.apache.jena.tdb.StoreConnection ;
+import org.apache.jena.tdb.base.file.Location ;
+import org.apache.jena.tdb.setup.Build ;
+import org.apache.jena.tdb.store.DatasetGraphTDB ;
+import org.apache.jena.tdb.store.NodeId ;
+import org.apache.jena.tdb.store.nodetable.NodeTable ;
+import org.apache.jena.tdb.sys.Names ;
+import org.apache.jena.tdb.sys.SystemTDB ;
+
+import arq.cmdline.CmdARQ;
+import tdb.cmdline.ModLocation ;
+
+public class dumpnodetable extends CmdARQ {
+    ModLocation modLocation = new ModLocation() ;
+
+    static public void main(String... argv) {
+        LogCtl.setLog4j() ;
+        new dumpnodetable(argv).mainRun() ;
+    }
+
+    @Override
+    protected void exec() {
+        List<String> tripleIndexes = Arrays.asList(Names.tripleIndexes) ;
+        List<String> quadIndexes = Arrays.asList(Names.quadIndexes) ;
+        Location loc = modLocation.getLocation() ;
+
+        StoreConnection sConn = StoreConnection.make(loc) ;
+        DatasetGraphTDB dsg = sConn.getBaseDataset() ;
+        NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable() ;
+        dump(System.out, nodeTable) ;
+    }
+
+    protected dumpnodetable(String[] argv) {
+        super(argv) ;
+        super.addModule(modLocation) ;
+    }
+
+    public static void dumpNodes(OutputStream w, String location) {
+        dump(w, location, Names.indexNode2Id, SystemTDB.Node2NodeIdCacheSize, Names.indexId2Node, SystemTDB.NodeId2NodeCacheSize,
+             SystemTDB.NodeMissCacheSize) ;
+    }
+
+    public static void dumpPrefixes(OutputStream w, String location) {
+        dump(w, location, Names.prefixNode2Id, 100, Names.prefixId2Node, 100, 10) ;
+    }
+
+    public static void dump(OutputStream w, String location, String indexNode2Id, int node2NodeIdCacheSize, String indexId2Node,
+                            int nodeId2NodeCacheSize, //
+
+                            int sizeNodeMissCacheSize) {
+        NodeTable nodeTable = Build.makeNodeTable(Location.create(location), indexNode2Id, node2NodeIdCacheSize, indexId2Node,
+                                                  nodeId2NodeCacheSize, sizeNodeMissCacheSize) ;
+    }
+
+    public static void dump(OutputStream w, NodeTable nodeTable) {
+        // Better to hack the indexes?
+        Iterator<Pair<NodeId, Node>> iter = nodeTable.all() ;
+        long count = 0 ;
+        try (IndentedWriter iw = new IndentedWriter(w)) {
+            for ( ; iter.hasNext() ; ) {
+                Pair<NodeId, Node> pair = iter.next() ;
+                iw.print(pair.car().toString()) ;
+                iw.print(" : ") ;
+                // iw.print(pair.cdr()) ;
+                Node n = pair.cdr() ;
+                String $ = stringForNode(n) ;
+                iw.print($) ;
+                iw.println() ;
+                count++ ;
+            }
+            iw.println() ;
+            iw.printf("Total: " + count) ;
+            iw.println() ;
+            iw.flush() ;
+        }
+    }
+
+    private static String stringForNode(Node n) {
+        if ( n == null )
+            return "<<null>>" ;
+
+        if ( n.isBlank() )
+            return "_:" + n.getBlankNodeLabel() ;
+
+        if ( n.isLiteral() )
+            return stringForLiteral((Node_Literal)n) ;
+
+        if ( n.isURI() ) {
+            String uri = n.getURI() ;
+            return stringForURI(uri) ;
+        }
+
+        if ( n.isVariable() )
+            return "?" + n.getName() ;
+
+        if ( n.equals(Node.ANY) )
+            return "ANY" ;
+
+        Log.warn(FmtUtils.class, "Failed to turn a node into a string: " + n) ;
+        return n.toString() ;
+    }
+
+    public static String stringForURI(String uri) {
+        return "<" + uri + ">" ;
+    }
+
+    public static String stringForLiteral(Node_Literal literal) {
+        String datatype = literal.getLiteralDatatypeURI() ;
+        String lang = literal.getLiteralLanguage() ;
+        String s = literal.getLiteralLexicalForm() ;
+
+        StringBuilder sbuff = new StringBuilder() ;
+        sbuff.append("\"") ;
+        FmtUtils.stringEsc(sbuff, s, true) ;
+        sbuff.append("\"") ;
+
+        // Format the language tag
+        if ( lang != null && lang.length() > 0 ) {
+            sbuff.append("@") ;
+            sbuff.append(lang) ;
+        }
+
+        if ( datatype != null ) {
+            sbuff.append("^^") ;
+            sbuff.append(stringForURI(datatype)) ;
+        }
+
+        return sbuff.toString() ;
+    }
+
+    @Override
+    protected void processModulesAndArgs() {
+        if ( modVersion.getVersionFlag() )
+            modVersion.printVersionAndExit() ;
+        if ( modLocation.getLocation() == null )
+            cmdError("Location required") ;
+    }
+
+    @Override
+    protected String getSummary() {
+        return getCommandName() + " --loc=DIR IndexName" ;
+    }
+
+    @Override
+    protected String getCommandName() {
+        return Lib.className(this) ;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/tdb/tools/tdbgenindex.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/tools/tdbgenindex.java b/jena-cmds/src/main/java/tdb/tools/tdbgenindex.java
new file mode 100644
index 0000000..9371ce2
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/tools/tdbgenindex.java
@@ -0,0 +1,86 @@
+/**
+ * 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 tdb.tools ;
+
+import java.util.Iterator ;
+
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.lib.tuple.Tuple ;
+import org.apache.jena.tdb.base.file.Location ;
+import org.apache.jena.tdb.store.NodeId ;
+import org.apache.jena.tdb.store.tupletable.TupleIndex ;
+import org.apache.jena.tdb.sys.Names ;
+import org.apache.jena.tdb.sys.SetupTDB ;
+import org.apache.jena.tdb.sys.SystemTDB ;
+
+/** copy one index to another, possibly changing the order */
+public class tdbgenindex {
+    public static void main(String... argv) {
+        // Usage: srcLocation indexName dstLocation indexName
+        if ( argv.length != 4 ) {
+            System.err.println("Usage: " + Lib.classShortName(tdbgenindex.class) + " srcLocation srcIndex dstLocation dstIndex") ;
+            System.exit(1) ;
+        }
+
+        Location srcLoc = Location.create(argv[0]) ;
+        String srcIndexName = argv[1] ;
+
+        Location dstLoc = Location.create(argv[2]) ;
+        String dstIndexName = argv[3] ;
+
+        int readCacheSize = 0 ;
+        int writeCacheSize = -1 ;
+
+        if ( srcIndexName.length() != dstIndexName.length() ) {
+            System.err.println("srcIndexName.length() != dstIndexName.length() " + srcIndexName + " :: " + dstIndexName) ;
+            System.exit(1) ;
+        }
+
+        String primary ;
+        int dftKeyLength ;
+        int dftValueLength ;
+
+        if ( srcIndexName.length() == 3 ) {
+            primary = Names.primaryIndexTriples ;
+            dftKeyLength = SystemTDB.LenIndexTripleRecord ;
+            dftValueLength = 0 ;
+        } else if ( srcIndexName.length() == 4 ) {
+            primary = Names.primaryIndexQuads ;
+            dftKeyLength = SystemTDB.LenIndexQuadRecord ;
+            dftValueLength = 0 ;
+        } else {
+            System.err.println("indexlength != 3 or 4") ;
+            System.exit(1) ;
+            primary = null ;
+            dftKeyLength = 0 ;
+            dftValueLength = 0 ;
+        }
+
+        TupleIndex srcIdx = SetupTDB.makeTupleIndex(srcLoc, primary, srcIndexName, srcIndexName, dftKeyLength) ;
+        TupleIndex dstIdx = SetupTDB.makeTupleIndex(dstLoc, primary, dstIndexName, dstIndexName, dftKeyLength) ;
+
+        Iterator<Tuple<NodeId>> iter = srcIdx.all() ;
+        for ( ; iter.hasNext() ; ) {
+            Tuple<NodeId> tuple = iter.next() ;
+            dstIdx.add(tuple) ;
+        }
+        srcIdx.close() ;
+        dstIdx.close() ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/test/java/jena/cmd/TS_Cmd.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/test/java/jena/cmd/TS_Cmd.java b/jena-cmds/src/test/java/jena/cmd/TS_Cmd.java
new file mode 100644
index 0000000..bfaf8fe
--- /dev/null
+++ b/jena-cmds/src/test/java/jena/cmd/TS_Cmd.java
@@ -0,0 +1,36 @@
+/**
+ * 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 jena.cmd;
+
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.junit.runner.RunWith ;
+import org.junit.runners.Suite ;
+import org.junit.runners.Suite.SuiteClasses ;
+
+@RunWith(Suite.class)
+@SuiteClasses( {
+    TestCmdLine.class
+    , Test_schemagen.class
+    , Test_rdfcat.class
+})
+
+public class TS_Cmd
+{
+    static { LogCtl.setLog4j(); }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/test/java/jena/cmd/TestCmdLine.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/test/java/jena/cmd/TestCmdLine.java b/jena-cmds/src/test/java/jena/cmd/TestCmdLine.java
new file mode 100644
index 0000000..a5ef521
--- /dev/null
+++ b/jena-cmds/src/test/java/jena/cmd/TestCmdLine.java
@@ -0,0 +1,104 @@
+/*
+ * 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 jena.cmd;
+import java.util.Iterator ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdLineArgs;
+
+import org.junit.Test ;
+import static org.junit.Assert.* ;
+
+public class TestCmdLine
+{
+    @Test public void test_Simple1()
+    {
+        String args[] = new String[]{""} ;
+        CmdLineArgs cl = new CmdLineArgs(args) ;
+        cl.process() ;
+    }
+    
+    @Test public void test_Flag1()
+    {
+        String args[] = new String[]{ ""} ;
+        CmdLineArgs cl = new CmdLineArgs(args) ;
+        ArgDecl argA = new ArgDecl(false, "-a") ;
+        cl.add(argA) ;
+        cl.process() ;
+        assertTrue("-a argument found" , ! cl.contains(argA) ) ; 
+    }
+    
+    @Test public void test_Flag2()
+    {
+        String args[] = new String[]{ "-a"} ;
+        CmdLineArgs cl = new CmdLineArgs(args) ;
+        ArgDecl argA = new ArgDecl(false, "-a") ;
+        cl.add(argA) ;
+        cl.process() ;
+        assertTrue("No -a argument found" , cl.contains(argA) ) ; 
+    }
+
+    @Test public void test_Flag3()
+    {
+        String args[] = new String[]{ "-a", "filename"} ;
+        CmdLineArgs cl = new CmdLineArgs(args) ;
+        ArgDecl argA = new ArgDecl(false, "-a") ;
+        cl.add(argA) ;
+        cl.process() ;
+        assertTrue("No -a argument found" , cl.contains(argA) ) ; 
+    }
+    
+    @Test public void test_Arg1()
+    {
+        String args[] = new String[]{ ""} ;
+        CmdLineArgs cl = new CmdLineArgs(args) ;
+        ArgDecl argA = new ArgDecl(true, "-arg") ;
+        cl.add(argA) ;
+        cl.process() ;
+        assertTrue("-arg argument found" , ! cl.contains(argA) ) ; 
+    }
+    
+    @Test public void test_Arg2()
+    {
+        String args[] = new String[]{ "-arg=ARG", "filename"} ;
+        CmdLineArgs cl = new CmdLineArgs(args) ;
+        ArgDecl argA = new ArgDecl(true, "arg") ;
+        cl.add(argA) ;
+        cl.process() ;
+        assertTrue("No -arg= argument found" , cl.contains(argA) ) ; 
+        assertEquals("", cl.getValue(argA) , "ARG") ;
+        assertEquals("", cl.getArg("arg").getValue() , "ARG") ;
+    }
+    
+    @Test public void test_nArg1()
+    {
+        String args[] = new String[]{ "-arg=V1", "--arg=V2", "-v"} ;
+        CmdLineArgs cl = new CmdLineArgs(args) ;
+        ArgDecl argA = new ArgDecl(true, "-arg") ;
+        cl.add(argA) ;
+        ArgDecl argV = new ArgDecl(false, "-v") ;
+        cl.add(argV) ;
+        cl.process() ;
+        assertTrue("No -arg= argument found" , cl.contains(argA) ) ;
+        
+        Iterator<String> iter = cl.getValues("arg").iterator() ;
+        assertEquals("Argument 1", iter.next() , "V1") ;
+        assertEquals("Argument 2", iter.next() , "V2") ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/test/java/jena/cmd/Test_rdfcat.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/test/java/jena/cmd/Test_rdfcat.java b/jena-cmds/src/test/java/jena/cmd/Test_rdfcat.java
new file mode 100644
index 0000000..950d06f
--- /dev/null
+++ b/jena-cmds/src/test/java/jena/cmd/Test_rdfcat.java
@@ -0,0 +1,291 @@
+/*
+ * 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 jena.cmd;
+
+import static org.junit.Assert.assertEquals ;
+import static org.junit.Assert.assertTrue ;
+
+import java.io.ByteArrayOutputStream ;
+import java.io.OutputStream ;
+import java.io.StringReader ;
+import java.util.ArrayList ;
+import java.util.List ;
+
+import jena.rdfcat;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.rdf.model.ModelFactory ;
+import org.junit.AfterClass ;
+import org.junit.BeforeClass ;
+import org.junit.Test ;
+
+@SuppressWarnings("deprecation")
+public class Test_rdfcat
+{
+    // Switch off the banner during testing.
+    @BeforeClass
+    public static void setUp() {
+        jena.rdfcat.suppressDeprecationBanner = true ;
+    }
+    
+    @AfterClass
+    public static void tearDown() {
+        jena.rdfcat.suppressDeprecationBanner = false ;
+    }
+    
+    @Test
+    public void testAbbreviationTable()
+        {
+        assertEquals( "RDF/XML", jena.rdfcat.unabbreviate.get( "x" ) );
+        assertEquals( "RDF/XML", jena.rdfcat.unabbreviate.get( "rdf" ) );
+        assertEquals( "RDF/XML", jena.rdfcat.unabbreviate.get( "rdfxml" ) );
+        assertEquals( "RDF/XML", jena.rdfcat.unabbreviate.get( "xml" ) );
+        assertEquals( "N3", jena.rdfcat.unabbreviate.get( "n3" ) );
+        assertEquals( "N3", jena.rdfcat.unabbreviate.get( "n" ) );
+        assertEquals( "N3", jena.rdfcat.unabbreviate.get( "ttl" ) );
+        assertEquals( "N-TRIPLE", jena.rdfcat.unabbreviate.get( "ntriples" ) );
+        assertEquals( "N-TRIPLE", jena.rdfcat.unabbreviate.get( "ntriple" ) );
+        assertEquals( "N-TRIPLE", jena.rdfcat.unabbreviate.get( "t" ) );
+        assertEquals( "RDF/XML-ABBREV", jena.rdfcat.unabbreviate.get( "owl" ) );
+        assertEquals( "RDF/XML-ABBREV", jena.rdfcat.unabbreviate.get( "abbrev" ) );
+        }
+
+    @Test
+    public void testExistingLanguage()
+        {
+        assertEquals( "RDF/XML", jena.rdfcat.getCheckedLanguage( "x" ) );
+        assertEquals( "RDF/XML", jena.rdfcat.getCheckedLanguage( "xml" ) );
+        assertEquals( "RDF/XML-ABBREV", jena.rdfcat.getCheckedLanguage( "owl" ) );
+        assertEquals( "N3", jena.rdfcat.getCheckedLanguage( "N3" ) );
+        assertEquals( "N-TRIPLE", jena.rdfcat.getCheckedLanguage( "N-TRIPLE" ) );
+        }
+
+    /**
+     * Test the identity transform - RDF/XML to RDF/XML
+     */
+    @Test
+    public void testRdfcatIdentity() {
+        Model source = ModelFactory.createDefaultModel();
+        source.read( "file:testing/cmd/rdfcat.xml", "RDF/XML" );
+
+        OutputStream so = new ByteArrayOutputStream();
+
+        rdfcatFixture rc = new rdfcatFixture( so );
+        rc.testGo( new String[] {"file:testing/cmd/rdfcat.xml"} );
+
+        Model output = asModel( so, "RDF/XML" );
+        assertTrue( output.isIsomorphicWith( source ));
+    }
+
+    /**
+     * Test the basic concatenation
+     */
+    @Test
+    public void testRdfcatConcat() {
+        Model source = ModelFactory.createDefaultModel();
+        source.read( "file:testing/cmd/rdfcat.xml", "RDF/XML" );
+
+        OutputStream so = new ByteArrayOutputStream();
+
+        rdfcatFixture rc = new rdfcatFixture( so );
+        rc.testGo( new String[] {"file:testing/cmd/rdfcat_1.xml", "file:testing/cmd/rdfcat_2.xml"} );
+
+        Model output = asModel( so, "RDF/XML" );
+        assertTrue( output.isIsomorphicWith( source ));
+    }
+
+    /**
+     * Change the default input language
+     */
+    @Test
+    public void testRdfcatConcat1() {
+        Model source = ModelFactory.createDefaultModel();
+        source.read( "file:testing/cmd/rdfcat.xml", "RDF/XML" );
+
+        OutputStream so = new ByteArrayOutputStream();
+
+        rdfcatFixture rc = new rdfcatFixture( so );
+        rc.testGo( new String[] {"-in", "N3", "file:testing/cmd/rdfcat_1_n3", "file:testing/cmd/rdfcat_2_n3"} );
+
+        Model output = asModel( so, "RDF/XML" );
+        assertTrue( output.isIsomorphicWith( source ));
+    }
+
+    @Test
+    public void testRdfcatN3ToRDFXML_0() {
+        doTestRdfcatOutput( "-n", "file:testing/cmd/rdfcat.n3", "RDF/XML", "RDF/XML" );
+    }
+
+    @Test
+    public void testRdfcatN3ToRDFXML_1() {
+        doTestRdfcatOutput( "-n3", "file:testing/cmd/rdfcat.n3", "RDF/XML", "RDF/XML" );
+    }
+
+    @Test
+    public void testRdfcatN3ToRDFXML_2() {
+        doTestRdfcatOutput( "-ttl", "file:testing/cmd/rdfcat.n3", "RDF/XML", "RDF/XML" );
+    }
+
+    @Test
+    public void testRdfcatN3ToRDFXML_3() {
+        doTestRdfcatOutput( "-N3", "file:testing/cmd/rdfcat.n3", "RDF/XML", "RDF/XML" );
+    }
+
+    @Test
+    public void testRdfcatN3ToNtriple() {
+        doTestRdfcatOutput( "-n", "file:testing/cmd/rdfcat.n3", "N-TRIPLE", "N-TRIPLE" );
+    }
+
+    @Test
+    public void testRdfcatN3ToN3() {
+        doTestRdfcatOutput( "-n", "file:testing/cmd/rdfcat.n3", "N3", "N3" );
+    }
+
+    @Test
+    public void testRdfcatN3ToRDFXMLDefault() {
+        doTestRdfcatOutput( null, "file:testing/cmd/rdfcat.n3", "RDF/XML", "RDF/XML" );
+    }
+
+
+    @Test
+    public void testRdfcatRDFXMLToRDFXML_0() {
+        doTestRdfcatOutput( "-x", "file:testing/cmd/rdfcat.xml", "RDF/XML", "RDF/XML" );
+    }
+
+    @Test
+    public void testRdfcatRDFXMLToRDFXML_1() {
+        doTestRdfcatOutput( "-xml", "file:testing/cmd/rdfcat.xml", "RDF/XML", "RDF/XML" );
+    }
+
+    @Test
+    public void testRdfcatRDFXMLToRDFXML_2() {
+        doTestRdfcatOutput( "-rdfxml", "file:testing/cmd/rdfcat.xml", "RDF/XML", "RDF/XML" );
+    }
+
+    @Test
+    public void testRdfcatRDFXMLToRDFXML_3() {
+        doTestRdfcatOutput( "-rdf", "file:testing/cmd/rdfcat.xml", "RDF/XML", "RDF/XML" );
+    }
+
+    @Test
+    public void testRdfcatRDFXMLToNtriple() {
+        doTestRdfcatOutput( "-x", "file:testing/cmd/rdfcat.xml", "N-TRIPLE", "N-TRIPLE" );
+    }
+
+    @Test
+    public void testRdfcatRDFXMLToN3() {
+        doTestRdfcatOutput( "-x", "file:testing/cmd/rdfcat.xml", "N3", "N3" );
+    }
+
+    @Test
+    public void testRdfcatRDFXMLToRDFXMLDefault() {
+        doTestRdfcatOutput( null, "file:testing/cmd/rdfcat.xml", "RDF/XML", "RDF/XML" );
+    }
+
+    @Test
+    public void testRdfcatNtripleToRDFXML_0() {
+        doTestRdfcatOutput( "-t", "file:testing/cmd/rdfcat.nt", "RDF/XML", "RDF/XML" );
+    }
+
+    @Test
+    public void testRdfcatNtripleToRDFXML_1() {
+        doTestRdfcatOutput( "-ntriple", "file:testing/cmd/rdfcat.nt", "RDF/XML", "RDF/XML" );
+    }
+
+    @Test
+    public void testRdfcatNtripleToRDFXML_2() {
+        doTestRdfcatOutput( "-ntriples", "file:testing/cmd/rdfcat.nt", "RDF/XML", "RDF/XML" );
+    }
+
+    @Test
+    public void testRdfcatNtripleToRDFXML_3() {
+        doTestRdfcatOutput( "-n-triple", "file:testing/cmd/rdfcat.nt", "RDF/XML", "RDF/XML" );
+    }
+
+    @Test
+    public void testRdfcatNtripleToNtriple() {
+        doTestRdfcatOutput( "-t", "file:testing/cmd/rdfcat.nt", "N-TRIPLE", "N-TRIPLE" );
+    }
+
+    @Test
+    public void testRdfcatNtripleToN3() {
+        doTestRdfcatOutput( "-t", "file:testing/cmd/rdfcat.nt", "N3", "N3" );
+    }
+
+    @Test
+    public void testRdfcatNtripleToRDFXMLDefault() {
+        doTestRdfcatOutput( null, "file:testing/cmd/rdfcat.nt", "RDF/XML", "RDF/XML" );
+    }
+
+    /**
+     * Utility to do a basic cat operation
+     */
+    public static void doTestRdfcatOutput( String inFormArg, String inputArg, String outFormArg, String parseAs ) {
+        Model source = ModelFactory.createDefaultModel();
+        source.read( "file:testing/cmd/rdfcat.xml" );
+
+        OutputStream so = new ByteArrayOutputStream();
+
+        rdfcatFixture rc = new rdfcatFixture( so );
+
+        List<String> l = new ArrayList<>();
+        if (outFormArg != null) {
+            l.add(  "-out" );
+            l.add(  outFormArg );
+        }
+        if (inFormArg != null) l.add( inFormArg );
+        l.add( inputArg );
+
+        String[] args = new String[l.size()];
+        for (int i = 0; i < l.size(); i++) {
+            args[i] = l.get(i);
+        }
+        // use file extension guessing
+        rc.testGo( args );
+
+        Model output = asModel( so, parseAs );
+        assertTrue( output.isIsomorphicWith( source ));
+    }
+
+    /** Convert an output stream holding a model content to a model */
+    protected static Model asModel( OutputStream so, String syntax ) {
+        String out = so.toString();
+        Model output = ModelFactory.createDefaultModel();
+        output.read( new StringReader( out ), "http://example.com/foo", syntax );
+        return output;
+    }
+
+    /**
+     * A minimal extension to rdfcat to provide a test fixture
+     */
+    protected static class rdfcatFixture
+        extends rdfcat
+    {
+        private OutputStream m_so;
+        protected rdfcatFixture( OutputStream so ) {
+            m_so = so;
+        }
+        @Override
+        protected OutputStream getOutputStream() {
+            return m_so;
+        }
+        protected void testGo( String[] args ) {
+            go( args );
+        }
+    }
+}


[06/20] jena git commit: JENA-1108 : jena-cmds module

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/main/java/jena/schemagen.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/jena/schemagen.java b/jena-core/src/main/java/jena/schemagen.java
deleted file mode 100644
index 0512506..0000000
--- a/jena-core/src/main/java/jena/schemagen.java
+++ /dev/null
@@ -1,2117 +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
-///////////////
-package jena;
-
-
-import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
-
-import java.io.ByteArrayOutputStream ;
-import java.io.File ;
-import java.io.FileOutputStream ;
-import java.io.PrintStream ;
-import java.net.MalformedURLException ;
-import java.net.URL ;
-import java.text.SimpleDateFormat ;
-import java.util.* ;
-import java.util.regex.Pattern ;
-import java.util.regex.PatternSyntaxException ;
-
-import org.apache.jena.ontology.Individual ;
-import org.apache.jena.ontology.OntModel ;
-import org.apache.jena.ontology.OntModelSpec ;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.shared.JenaException ;
-import org.apache.jena.util.FileManager ;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-import org.apache.jena.util.iterator.WrappedIterator ;
-import org.apache.jena.vocabulary.OWL ;
-import org.apache.jena.vocabulary.RDF ;
-import org.apache.jena.vocabulary.RDFS ;
-import org.apache.jena.vocabulary.XSD ;
-import org.apache.xerces.util.XMLChar ;
-
-
-
-/**
- * <p>
- * A vocabulary generator, that will consume an ontology or other vocabulary file,
- * and generate a Java file with the constants from the vocabulary compiled in.
- * Designed to be highly flexible and customisable.
- * </p>
- */
-public class schemagen {
-    
-    static { setCmdLogging(); }
-
-    // Constants
-    //////////////////////////////////
-
-    /** The namespace for the configuration model is {@value} */
-    public static final String NS = "http://jena.hpl.hp.com/2003/04/schemagen#";
-
-    /** The default location of the configuration model is {@value} */
-    public static final String DEFAULT_CONFIG_URI = "file:schemagen.rdf";
-
-    /** The default marker string for denoting substitutions is {@value} */
-    public static final String DEFAULT_MARKER = "%";
-
-    /** Default template for writing out value declarations */
-    public static final String DEFAULT_TEMPLATE = "public static final %valclass% %valname% = m_model.%valcreator%( \"%valuri%\" );";
-
-    /** Default template for writing out individual declarations */
-    public static final String DEFAULT_INDIVIDUAL_TEMPLATE = "public static final %valclass% %valname% = m_model.%valcreator%( \"%valuri%\", %valtype% );";
-
-    /** Default template for writing out individual declarations for non-ontology vocabularies */
-    public static final String DEFAULT_RDFS_INDIVIDUAL_TEMPLATE = "public static final %valclass% %valname% = m_model.%valcreator%( \"%valuri%\" );";
-
-    /** Default template for the file header */
-    public static final String DEFAULT_HEADER_TEMPLATE = "/* CVS $" + "Id: $ */%nl%%package% %nl%%imports% %nl%/**%nl% * Vocabulary definitions from %sourceURI% %nl% * @author Auto-generated by schemagen on %date% %nl% */";
-
-    /** Default line length for comments before wrap */
-    public static final int COMMENT_LENGTH_LIMIT = 80;
-
-
-
-    /** List of Java reserved keywords, see <a href="http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html">this list</a>. */
-    public static final String[] JAVA_KEYWORDS = {
-        "abstract",    "continue",    "for",         "new",         "switch",
-        "assert",      "default",     "goto",        "package",     "synchronized",
-        "boolean",     "do",          "if",          "private",     "this",
-        "break",       "double",      "implements",  "protected",   "throw",
-        "byte",        "else",        "import",      "public",      "throws",
-        "case",        "enum",        "instanceof",  "return",      "transient",
-        "catch",       "extends",     "int",         "short",       "try",
-        "char",        "final",       "interface",   "static",      "void",
-        "class",       "finally",     "long",        "strictfp",    "volatile",
-        "const",       "float",       "native",      "super",       "while"
-    };
-
-
-    // Static variables
-    //////////////////////////////////
-
-    private static List<String> KEYWORD_LIST;
-    static {
-        KEYWORD_LIST = Arrays.asList( JAVA_KEYWORDS );
-    }
-
-    // Instance variables
-    //////////////////////////////////
-
-    /** Schemagen options interface */
-    protected SchemagenOptions m_options;
-
-    /** The model that contains the input source */
-    protected OntModel m_source;
-
-    /** The output stream we write to */
-    protected PrintStream m_output;
-
-    /** Option definitions */
-    /** Stack of replacements to apply */
-    protected List<Replacement> m_replacements = new ArrayList<>();
-
-    /** Output file newline char - default is Unix, override with --dos */
-    protected String m_nl = "\n";
-
-    /** Size of indent step */
-    protected int m_indentStep = 4;
-
-    /** Set of names used so far */
-    protected Set<String> m_usedNames = new HashSet<>();
-
-    /** Map from resources to java names */
-    protected Map<Resource,String> m_resourcesToNames = new HashMap<>();
-
-    /** List of allowed namespace URI strings for admissible values */
-    protected List<String> m_includeURI = new ArrayList<>();
-
-
-    // Constructors
-    //////////////////////////////////
-
-    // External signature methods
-    //////////////////////////////////
-
-    /* Main entry point. See Javadoc for details of the many command line arguments */
-    public static void main( String... args ) {
-        try {
-            new schemagen().go( args );
-        }
-        catch (SchemagenException e) {
-            System.err.println( "Schemagen failed to run:" );
-            System.err.println( e.getMessage() );
-
-            if (e.getCause() != null) {
-                System.err.println( "Caused by: " + e.getCause().getMessage() );
-            }
-
-            System.exit( 1 );
-        }
-    }
-
-
-    // Internal implementation methods
-    //////////////////////////////////
-
-    /** Read the configuration parameters and do setup */
-    protected void go( String[] args ) {
-        go( new SchemagenOptionsImpl( args ) );
-    }
-
-    /** Handle initial configuration options, then initiate processing */
-    protected void go( SchemagenOptions options ) {
-        m_options = options;
-
-
-        // check for user requesting help
-        if (m_options.hasHelpOption()) {
-            usage();
-        }
-
-
-        // got the configuration, now we can begin processing
-        processInput();
-    }
-
-    /** The sequence of steps to process an entire file */
-    protected void processInput() {
-        addIncludes();
-        determineLanguage();
-        selectInput();
-        selectOutput();
-        setGlobalReplacements();
-
-        processHeader();
-        writeClassDeclaration();
-        writeInitialDeclarations();
-        writeProperties();
-        writeClasses();
-        writeIndividuals();
-        writeDatatypes();
-        writeClassClose();
-        processFooter();
-        closeOutput();
-    }
-
-    /** Add the included files */
-    protected void addIncludes() {
-        // add any extra uri's that are allowed in the filter
-        m_includeURI.addAll( m_options.getIncludeOption() );
-    }
-
-    /** Create the source model after determining which input language */
-    protected void determineLanguage() {
-        OntModelSpec s = null;
-        if (m_options.hasLangRdfsOption()) {
-            // RDFS language specified
-            if (m_options.hasUseInfOption()) {
-                s = OntModelSpec.RDFS_MEM_RDFS_INF;
-            }
-            else {
-                s = OntModelSpec.RDFS_MEM;
-            }
-        }
-        else {
-            // owl is the default
-            // s = OntModelSpec.getDefaultSpec( ProfileRegistry.OWL_LANG );
-            if (m_options.hasUseInfOption()) {
-                s = OntModelSpec.OWL_MEM_RULE_INF;
-            }
-            else {
-                s = OntModelSpec.OWL_MEM;
-            }
-        }
-
-        m_source = ModelFactory.createOntologyModel( s, null );
-        m_source.getDocumentManager().setProcessImports( false );
-
-        // turn off strict checking on request
-        if (m_options.hasNoStrictOption()) {
-            m_source.setStrictMode( false );
-        }
-    }
-
-    /** Identify the URL that is to be read in and translated to a vocabulary file, and load the source into the source model */
-    protected void selectInput() {
-        if (!m_options.hasInputOption()) {
-            usage();
-        }
-
-        String input = SchemagenUtils.urlCheck( m_options.getInputOption().getURI() );
-        String syntax = m_options.getEncodingOption();
-
-        try {
-            FileManager.get().readModel( m_source, input, syntax );
-        }
-        catch (JenaException e) {
-            abort( "Failed to read input source " + input, e );
-        }
-    }
-
-    /** Identify the file we are to write the output to */
-    protected void selectOutput() {
-        String outFile = m_options.getOutputOption();
-        if (outFile == null) {
-            m_output = System.out;
-        }
-        else {
-            try {
-                // check for package name
-                String packageName = m_options.getPackagenameOption();
-                if (packageName != null) {
-                    String packagePath = "";
-
-                    // build the package path (e.g. com.foo.bar -> /com/foo/bar)
-                    for (String p: packageName.split( "\\." )) {
-                        packagePath = packagePath + File.separator + p;
-                    }
-
-                    if (!outFile.endsWith( packagePath )) {
-                        outFile = outFile + packagePath;
-                    }
-                }
-
-                File out = new File( outFile );
-
-                if (!out.exists() && !outFile.endsWith( ".java" )) {
-                    // create the directory if needed
-                    out.mkdirs();
-                }
-
-                if (out.isDirectory()) {
-                    // create a file in this directory named classname.java
-                    String fileName = outFile + File.separator + getClassName() + ".java";
-                    out = new File( fileName );
-                }
-
-                m_output = new PrintStream( new FileOutputStream( out ) );
-            }
-            catch (Exception e) {
-                abort( "I/O error while trying to open file for writing: " + outFile, e );
-            }
-        }
-
-        // check for DOS line endings
-        if (m_options.hasDosOption()) {
-            m_nl = "\r\n";
-        }
-    }
-
-    /** Process the header at the start of the file, if defined */
-    protected void processHeader() {
-        String header = m_options.hasHeaderOption() ? m_options.getHeaderOption() : DEFAULT_HEADER_TEMPLATE;
-
-        // user can turn of header processing, default is to have it on
-        if (!m_options.hasNoheaderOption()) {
-            writeln( 0, substitute( header ) );
-        }
-        else {
-            // we have to do the imports at least
-            writeln( 0, "import org.apache.jena.rdf.model.*;" );
-            if (m_options.hasOntologyOption()) {
-                writeln( 0, "import org.apache.jena.ontology.*;" );
-            }
-            if (m_options.hasIncludeSourceOption()) {
-                writeln( 0, "import java.io.ByteArrayInputStream;" );
-            }
-        }
-    }
-
-    /** Process the footer at the end of the file, if defined */
-    protected void processFooter() {
-        String footer = m_options.getFooterOption();
-
-        if (footer != null) {
-            writeln( 0, substitute( footer ) );
-        }
-    }
-
-    /** The list of replacements that are always available */
-    protected void setGlobalReplacements() {
-        addReplacementPattern( "date", new SimpleDateFormat( "dd MMM yyyy HH:mm").format( new Date() ) );
-        addReplacementPattern( "package", m_options.hasPackagenameOption() ? ("package " + m_options.getPackagenameOption() + ";") : "" );
-        addReplacementPattern( "imports", getImports() );
-        addReplacementPattern( "classname", getClassName() );
-        addReplacementPattern( "nl", m_nl );
-
-        // protect \ in Windows file pathnames
-        // looks for file:.* or C:.* (or variants thereof)
-        String source = m_options.getInputOption().getURI();
-        if (source.matches( "(file:|[A-Za-z]:).*$" )) {
-            source = source.replace( "\\", "\\\\" );
-        }
-        addReplacementPattern( "sourceURI", source );
-    }
-
-    /** Add a pattern-value pair to the list of available patterns */
-    protected void addReplacementPattern( String key, String replacement ) {
-        if (replacement != null && key != null) {
-            String marker = m_options.getMarkerOption();
-            marker = (marker == null) ? DEFAULT_MARKER : marker;
-
-            try {
-                m_replacements.add( new Replacement( Pattern.compile( marker + key + marker ),
-                                                     replacement ) );
-            }
-            catch (PatternSyntaxException e) {
-                abort( "Malformed regexp pattern " + marker + key + marker, e );
-            }
-        }
-    }
-
-    /** Pop n replacements off the stack */
-    protected void pop( int n ) {
-        for (int i = 0;  i < n;  i++) {
-            m_replacements.remove( m_replacements.size() - 1 );
-        }
-    }
-
-
-    /** Close the output file */
-    protected void closeOutput() {
-        m_output.flush();
-        m_output.close();
-    }
-
-
-    /** Abort due to exception */
-    protected void abort( String msg, Exception cause ) {
-        throw new SchemagenException( msg, cause );
-    }
-
-    /** Print usage message and abort */
-    protected void usage() {
-        System.err.println( "Usage:" );
-        System.err.println( "  java jena.schemagen [options ...]" );
-        System.err.println();
-        System.err.println( "Commonly used options include:" );
-        System.err.println( "   -i <input> the source document as a file or URL." );
-        System.err.println( "   -n <name> the name of the created Java class." );
-        System.err.println( "   -a <uri> the namespace URI of the source document." );
-        System.err.println( "   -o <file> the file to write the generated class into." );
-        System.err.println( "   -o <dir> the directory in which the generated Java class is created." );
-        System.err.println( "            By default, output goes to stdout." );
-        System.err.println( "   -e <encoding> the encoding of the input document (N3, RDF/XML, etc)." );
-        System.err.println( "   -c <config> a filename or URL for an RDF document containing " );
-        System.err.println( "               configuration parameters." );
-        System.err.println();
-        System.err.println( "Many other options are available. See the schemagen HOWTO in the " );
-        System.err.println( "Jena documentation for full details." );
-        System.exit( 1 );
-    }
-
-    /** Use the current replacements list to do the subs in the given string */
-    protected String substitute( String sIn ) {
-        String s = sIn;
-
-        for ( Replacement r : m_replacements )
-        {
-            s = r.pattern.matcher( s ).replaceAll( r.sub );
-        }
-
-        return s;
-    }
-
-    /** Add the appropriate indent to a buffer */
-    protected int indentTo( int i, StringBuffer buf ) {
-        int indent = i * m_indentStep;
-        for (int j = 0;  j < indent; j++) {
-            buf.append( ' ' );
-        }
-
-        return indent;
-    }
-
-    /** Write a blank line, with indent and newline */
-    protected void writeln( int indent ) {
-        writeln( indent, "" );
-    }
-
-    /** Write out the given string with n spaces of indent, with newline */
-    protected void writeln( int indent, String s ) {
-        write( indent, s );
-        m_output.print( m_nl );
-    }
-
-    /** Write out the given string with n spaces of indent */
-    protected void write( int indentLevel, String s ) {
-        for (int i = 0;  i < (m_indentStep * indentLevel);  i++) {
-            m_output.print( " " );
-        }
-
-        m_output.print( s );
-    }
-
-    /** Determine the list of imports to include in the file */
-    protected String getImports() {
-        StringBuffer buf = new StringBuffer();
-        buf.append( "import org.apache.jena.rdf.model.*;" );
-        buf.append( m_nl );
-
-        if (useOntology()) {
-            buf.append( "import org.apache.jena.ontology.*;" );
-            buf.append( m_nl );
-        }
-
-        if (includeSource()) {
-            buf.append( "import java.io.ByteArrayInputStream;" );
-            buf.append( m_nl );
-        }
-
-        return buf.toString();
-    }
-
-    /** Determine the class name of the vocabulary from the URI */
-    protected String getClassName() {
-        // if a class name is given, just use that
-        if (m_options.hasClassnameOption()) {
-            return m_options.getClassnameOption();
-        }
-
-        // otherwise, we generate a name based on the URI
-        String uri = m_options.getInputOption().getURI();
-
-        // remove any suffixes
-        uri = (uri.endsWith( "#" )) ? uri.substring( 0, uri.length() - 1 ) : uri;
-        uri = (uri.endsWith( ".daml" )) ? uri.substring( 0, uri.length() - 5 ) : uri;
-        uri = (uri.endsWith( ".owl" )) ? uri.substring( 0, uri.length() - 4 ) : uri;
-        uri = (uri.endsWith( ".rdf" )) ? uri.substring( 0, uri.length() - 4 ) : uri;
-        uri = (uri.endsWith( ".rdfs" )) ? uri.substring( 0, uri.length() - 5 ) : uri;
-        uri = (uri.endsWith( ".n3" )) ? uri.substring( 0, uri.length() - 3 ) : uri;
-        uri = (uri.endsWith( ".xml" )) ? uri.substring( 0, uri.length() - 4 ) : uri;
-        uri = (uri.endsWith( ".ttl" )) ? uri.substring( 0, uri.length() - 4 ) : uri;
-
-        // now work back to the first non name character from the end
-        int i = uri.length() - 1;
-        for (; i > 0; i--) {
-            if (!Character.isUnicodeIdentifierPart( uri.charAt( i ) ) &&
-                uri.charAt( i ) != '-') {
-                i++;
-                break;
-            }
-        }
-
-        String name = uri.substring( i );
-
-        // optionally add name suffix
-        if (m_options.hasClassnameSuffixOption()) {
-            name = name + m_options.getClassnameSuffixOption();
-        }
-
-        // now we make the name into a legal Java identifier
-        return asLegalJavaID( name, true );
-    }
-
-    /** Answer true if we are using ontology terms in this vocabulary */
-    protected boolean useOntology() {
-        return m_options.hasOntologyOption();
-    }
-
-    /** Answer true if all comments are suppressed */
-    protected boolean noComments() {
-        return m_options.hasNoCommentsOption();
-    }
-
-    /** Answer true if ontology source code is to be included */
-    protected boolean includeSource() {
-        return m_options.hasIncludeSourceOption();
-    }
-
-    /** Converts to a legal Java identifier; capitalise first char if cap is true */
-    protected String asLegalJavaID( String s, boolean cap ) {
-        StringBuffer buf = new StringBuffer();
-        int i = 0;
-
-        // treat the first character specially - must be able to start a Java ID, may have to up-case
-        try {
-            for (; !Character.isJavaIdentifierStart( s.charAt( i )); i++) { /**/ }
-        }
-        catch (StringIndexOutOfBoundsException e) {
-            System.err.println( "Could not identify legal Java identifier start character in '" + s + "', replacing with __" );
-            return "__";
-        }
-        buf.append( cap ? Character.toUpperCase( s.charAt( i ) ) : s.charAt( i ) );
-
-        // copy the remaining characters - replace non-legal chars with '_'
-        for (++i; i < s.length(); i++) {
-            char c = s.charAt( i );
-            buf.append( Character.isJavaIdentifierPart( c ) ? c : '_' );
-        }
-
-        // check for illegal keyword
-        if (KEYWORD_LIST.contains( buf.toString() )) {
-            buf.append( '_' );
-        }
-
-        return buf.toString();
-    }
-
-    /** The opening class declaration */
-    protected void writeClassDeclaration() {
-        write( 0, "public class " );
-        write( 0, getClassName() );
-        write( 0, " " );
-
-        if (m_options.hasClassdecOption()) {
-            write( 0, m_options.getClassdecOption() );
-        }
-
-        writeln( 0, "{" );
-    }
-
-    /** The close of the class decoration */
-    protected void writeClassClose() {
-        writeln( 0, "}" );
-    }
-
-    /** Write the declarations at the head of the class */
-    protected void writeInitialDeclarations() {
-        writeModelDeclaration();
-        writeSource();
-        writeNamespace();
-        writeOntologyVersionInfo();
-
-        if (m_options.hasDeclarationsOption()) {
-            writeln( 0, m_options.getDeclarationsOption() );
-        }
-    }
-
-    /** Write the declaration of the model */
-    protected void writeModelDeclaration() {
-        if (useOntology()) {
-            String lang = "OWL";
-            if (m_options.hasLangRdfsOption()) {
-                lang = "RDFS";
-            }
-            writeln( 1, "/** <p>The ontology model that holds the vocabulary terms</p> */" );
-            writeln( 1, "private static OntModel m_model = ModelFactory.createOntologyModel( OntModelSpec." + lang + "_MEM, null );" );
-        }
-        else {
-            writeln( 1, "/** <p>The RDF model that holds the vocabulary terms</p> */" );
-            writeln( 1, "private static Model m_model = ModelFactory.createDefaultModel();" );
-        }
-
-        writeln( 1 );
-    }
-
-    /** Write the source code of the input model into the file itself */
-    protected void writeSource() {
-        if (includeSource()) {
-            // first save a copy of the source in compact form into a buffer
-            ByteArrayOutputStream bos = new ByteArrayOutputStream();
-            RDFWriter rw = m_source.getWriter( "Turtle" );
-            rw.setProperty( "objectLists", Boolean.FALSE.toString() );
-            rw.write( m_source, bos, null );
-            String output = bos.toString();
-
-            // now we embed each line of the source in the output
-            writeln( 1, "private static final String SOURCE = " );
-            boolean first = true;
-
-            StringTokenizer st = new StringTokenizer( output, "\n" );
-            while (st.hasMoreTokens()) {
-                String tok = st.nextToken();
-                if (tok.endsWith( "\r" )) {
-                    tok = tok.substring( 0, tok.length() - 1 );
-                }
-                write( 2, first ? "   " : " + " );
-                write( 0, "\"" );
-                write( 0, protectQuotes( tok ) );
-                writeln( 2, "\\n\"" );
-                first = false;
-            }
-
-            // then we reference the string constant when reading the source
-            // note that we avoid StringReader due to charset encoding issues
-            writeln( 1, ";" );
-            writeln( 0, "" );
-            writeln( 1, "/** Read the ontology definition into the source model */ " );
-            writeln( 1, "static { " );
-            writeln( 2, "m_model.read( new ByteArrayInputStream( SOURCE.getBytes() ), null, \"N3\" );" );
-            writeln( 1, "}" );
-            writeln( 0, "" );
-        }
-    }
-
-    /** Protect any double quotes in the given string so that it's a legal Java String */
-    private String protectQuotes( String s ) {
-        return s.replaceAll( "\\\\", "\\\\\\\\" ).replaceAll( "\"", "\\\\\"" );
-    }
-    
-    /** Write owl:versionInfo string if it exists **/
-    protected void writeOntologyVersionInfo() {
-        String versionInfo = getOntologyElementVersionInfo();
-        
-        if (null != versionInfo) {
-            writeln( 1, "/** <p>The ontology's owl:versionInfo as a string</p> */" );
-            writeln( 1, "public static final String VERSION_INFO = \"" + protectQuotes(versionInfo) + "\";" );
-            writeln( 1 );
-        }
-    }
-
-    /** Write the string and resource that represent the namespace */
-    protected void writeNamespace() {
-        String nsURI = determineNamespaceURI();
-
-        writeln( 1, "/** <p>The namespace of the vocabulary as a string</p> */" );
-        writeln( 1, "public static final String NS = \"" + nsURI + "\";" );
-        writeln( 1 );
-
-        writeln( 1, "/** <p>The namespace of the vocabulary as a string</p>" );
-        writeln( 1, " *  @see #NS */" );
-        writeln( 1, "public static String getURI() {return NS;}" );
-        writeln( 1 );
-
-        writeln( 1, "/** <p>The namespace of the vocabulary as a resource</p> */" );
-        writeln( 1, "public static final Resource NAMESPACE = m_model.createResource( NS );" );
-        writeln( 1 );
-    }
-
-
-    /** Determine what the namespace URI for this vocabulary is */
-    protected String determineNamespaceURI() {
-        // we have a sequence of strategies for determining the ontology namespace
-        String ns = getOptionNamespace();
-        if (ns == null) {
-            ns = getDefaultPrefixNamespace();
-        }
-        if (ns == null) {
-            ns = getOntologyElementNamespace();
-        }
-        if (ns == null) {
-            ns = guessNamespace();
-        }
-
-        // did we get one?
-        if (ns == null) {
-            abort( "Could not determine the base URI for the input vocabulary", null );
-        }
-
-        m_includeURI.add( ns );
-        return ns;
-    }
-
-    /** User has set namespace via a schemagen option */
-    protected String getOptionNamespace() {
-        return m_options.hasNamespaceOption() ? m_options.getNamespaceOption().getURI() : null;
-    }
-
-    /** Document has set an empty prefix for the model */
-    protected String getDefaultPrefixNamespace() {
-        // alternatively, the default namespace may be set in the prefix mapping read from the input document
-        String defaultNS = m_source.getNsPrefixURI( "" );
-        if (defaultNS == null) {
-            defaultNS = m_source.getBaseModel().getNsPrefixURI( "" );
-        }
-
-        return defaultNS;
-    }
-    
-    /** Document has an owl:Ontology or daml:Ontology element */
-    protected String getOntologyElementVersionInfo() {
-        String versionInfo = null;
-        
-        Resource ontologyClass = m_source.getProfile().ONTOLOGY();
-        if (null != ontologyClass) {
-            StmtIterator i = m_source.getBaseModel().listStatements( null, RDF.type, ontologyClass );
-            if (i.hasNext()) {
-                Resource ont = i.nextStatement().getSubject();
-                StmtIterator j = m_source.getBaseModel().listStatements( ont, OWL.versionInfo, (RDFNode)null );
-                if (j.hasNext()) {
-                    versionInfo = j.nextStatement().getObject().asLiteral().getLexicalForm();
-                    
-                    // check for ambiguous answers
-                    if (j.hasNext()) {
-                        System.err.println( "Warning: ambiguous owl:versionInfo - there are more than one owl:versionInfo statements." );
-                        System.err.println( "Picking first choice: " + versionInfo  + ". Other choices are:" );
-                        while (j.hasNext()) {
-                            System.err.print( " " );
-                            System.err.print( j.nextStatement().getObject().toString() );
-                        }
-                        System.err.println();
-                    }
-                }
-                
-                // check for ambiguous answers
-                if (i.hasNext()) {
-                    System.err.println( "Warning: ambiguous owl:versionInfo - there is more than one owl:Ontology element." );
-                    System.err.println( "Picking first choice: " + ont.getURI()  + ". Other choices are:" );
-                    while (i.hasNext()) {
-                        System.err.print( " " );
-                        System.err.print( i.nextStatement().getObject().toString() );
-                    }
-                    System.err.println();
-                }
-            }
-        }
-        
-        return versionInfo;
-    }
-
-    /** Document has an owl:Ontology or daml:Ontology element */
-    protected String getOntologyElementNamespace() {
-        // if we are using an ontology model, we can get the namespace URI from the ontology element
-        String uri = null;
-
-        StmtIterator i = m_source.getBaseModel()
-                                 .listStatements( null, RDF.type, m_source.getProfile().ONTOLOGY() );
-
-        if (i.hasNext()) {
-            Resource ont = i.nextStatement().getSubject();
-            uri = ont.getURI();
-
-            // ensure ends with namespace separator char
-            char ch = uri.charAt( uri.length() - 1 );
-            boolean endsWithNCNameCh = XMLChar.isNCName( ch );
-            uri = endsWithNCNameCh ? uri + "#" : uri;
-
-            // check for ambiguous answers
-            if (i.hasNext()) {
-                System.err.println( "Warning: ambiguous default namespace - there is more than one owl:Ontology element." );
-                System.err.println( "Picking first choice: " + uri  + ". Other choices are:" );
-                while (i.hasNext()) {
-                    System.err.print( " " );
-                    System.err.print( i.nextStatement().getString() );
-                }
-                System.err.println();
-                System.err.println( "Use the -a option to specify a particular namespace if required." );
-            }
-        }
-
-        return uri;
-    }
-
-    /** Guess the URI from the most prevalent URI */
-    protected String guessNamespace() {
-        Map<String,Integer> nsCount = new HashMap<>();
-
-        // count all of the namespaces used in the model
-        for (StmtIterator i = m_source.listStatements(); i.hasNext(); ) {
-            Statement s = i.next();
-            countNamespace( s.getSubject(), nsCount );
-            countNamespace( s.getPredicate(), nsCount );
-            if (s.getObject().isResource()) {
-                countNamespace( s.getResource(), nsCount );
-            }
-        }
-
-        // now find the maximal element
-        String ns = null;
-        int max = 0;
-        for ( String nsKey : nsCount.keySet() )
-        {
-            // we ignore the usual suspects
-            if ( !( OWL.getURI().equals( nsKey ) ||
-                RDF.getURI().equals( nsKey ) ||
-                RDFS.getURI().equals( nsKey ) ||
-                XSD.getURI().equals( nsKey ) ) )
-            {
-                // not an ignorable namespace
-                int count = nsCount.get( nsKey ).intValue();
-
-                if ( count > max )
-                {
-                    // highest count seen so far
-                    max = count;
-                    ns = nsKey;
-                }
-            }
-        }
-
-        return ns;
-    }
-
-    /** Record a use of the given namespace in the count map */
-    private void countNamespace( Resource r, Map<String,Integer> nsCount ) {
-        if (!r.isAnon()) {
-            String ns = r.getNameSpace();
-
-            // increment the count for this namespace
-            Integer count = nsCount.containsKey( ns ) ? (Integer) nsCount.get( ns ) : new Integer( 0 );
-            Integer count1 = new Integer( count.intValue() + 1 );
-
-            nsCount.put( ns, count1 );
-        }
-    }
-
-    /** Write the list of properties */
-    protected void writeProperties() {
-        if (m_options.hasNopropertiesOption()) {
-            return;
-        }
-
-        if (m_options.hasPropertySectionOption()) {
-            writeln( 0, m_options.getPropertySectionOption());
-        }
-
-        if (useOntology()) {
-            writeObjectProperties();
-            writeDatatypeProperties();
-            writeAnnotationProperties();
-
-            // we also write out the RDF properties, to mop up any props that are not stated as
-            // object, datatype or annotation properties
-            writeRDFProperties( true );
-        }
-        else {
-            writeRDFProperties( false );
-        }
-    }
-
-    /** Write any object properties in the vocabulary */
-    protected void writeObjectProperties() {
-        String template = m_options.hasPropTemplateOption() ?  m_options.getPropTemplateOption() : DEFAULT_TEMPLATE;
-
-        if (!m_options.hasLangRdfsOption()) {
-            for (Iterator<? extends RDFNode> i = sorted( m_source.listObjectProperties() ); i.hasNext(); ) {
-                writeValue( (Resource) i.next(), template, "ObjectProperty", "createObjectProperty", "_PROP" );
-            }
-        }
-    }
-
-    /** Write any datatype properties in the vocabulary */
-    protected void writeDatatypeProperties() {
-        String template = m_options.hasPropTemplateOption() ?  m_options.getPropTemplateOption() : DEFAULT_TEMPLATE;
-
-        if (!m_options.hasLangRdfsOption()) {
-            for (Iterator<? extends RDFNode> i = sorted( m_source.listDatatypeProperties() ); i.hasNext(); ) {
-                writeValue( (Resource) i.next(), template, "DatatypeProperty", "createDatatypeProperty", "_PROP" );
-            }
-        }
-    }
-
-    /** Write any annotation properties in the vocabulary */
-    protected void writeAnnotationProperties() {
-        String template = m_options.hasPropTemplateOption() ?  m_options.getPropTemplateOption() : DEFAULT_TEMPLATE;
-
-        if (!m_options.hasLangRdfsOption()) {
-            for (Iterator<? extends RDFNode> i = sorted( m_source.listAnnotationProperties() ); i.hasNext(); ) {
-                writeValue( (Resource) i.next(), template, "AnnotationProperty", "createAnnotationProperty", "_PROP" );
-            }
-        }
-    }
-
-    /** Write any vanilla RDF properties in the vocabulary */
-    protected void writeRDFProperties( boolean useOntProperty ) {
-        String template = m_options.hasPropTemplateOption() ?  m_options.getPropTemplateOption() : DEFAULT_TEMPLATE;
-        String propType = useOntProperty ? "OntProperty" : "Property";
-
-        // select the appropriate properties based on the language choice
-        Resource[] props;
-        if (m_options.hasLangOwlOption()) {
-            props = new Resource[] {OWL.ObjectProperty, OWL.DatatypeProperty, RDF.Property};
-        }
-        else {
-            props = new Resource[] {RDF.Property};
-        }
-
-        // collect the properties to be written
-        List<Resource> propertyResources = new ArrayList<>();
-        for ( Resource prop : props )
-        {
-            for ( StmtIterator i = m_source.listStatements( null, RDF.type, prop ); i.hasNext(); )
-            {
-                propertyResources.add( i.nextStatement().getSubject() );
-            }
-        }
-
-        // now write the properties
-        for (Iterator<? extends RDFNode> i = sorted( propertyResources ); i.hasNext(); ) {
-            writeValue( (Resource) i.next(), template, propType, "create" + propType, "_PROP" );
-        }
-    }
-
-    /** Write any classes in the vocabulary */
-    protected void writeClasses() {
-        if (m_options.hasNoclassesOption()) {
-            return;
-        }
-
-        if (m_options.hasClassSectionOption()) {
-            writeln( 0, m_options.getClassSectionOption());
-        }
-
-        if (useOntology()) {
-            writeOntClasses();
-        }
-        else {
-            writeRDFClasses();
-        }
-    }
-
-    /** Write classes as ontology terms */
-    protected void writeOntClasses() {
-        String template = m_options.hasClassTemplateOption() ?  m_options.getClassTemplateOption() : DEFAULT_TEMPLATE;
-
-        for (Iterator<? extends RDFNode> i = sorted( m_source.listClasses() ); i.hasNext(); ) {
-            writeValue( (Resource) i.next(), template, "OntClass", "createClass", "_CLASS" );
-        }
-    }
-
-    /** Write classes as vanilla RDF terms */
-    protected void writeRDFClasses() {
-        String template = m_options.hasClassTemplateOption() ?  m_options.getClassTemplateOption() : DEFAULT_TEMPLATE;
-
-        // make sure we're looking for the appropriate type of class
-        Resource cls = OWL.Class;
-        if (m_options.hasLangRdfsOption()) {
-            cls = RDFS.Class;
-        }
-
-        // collect the classes to list
-        List<Resource> classes = m_source.listStatements( null, RDF.type, cls ).mapWith( s -> s.getSubject()).toList();
-
-        for (Iterator<? extends RDFNode> i = sorted( classes ); i.hasNext(); ) {
-            writeValue( (Resource) i.next(), template, "Resource", "createResource", "_CLASS" );
-        }
-    }
-
-    /** Write any instances (individuals) in the vocabulary */
-    protected void writeIndividuals() {
-        if (m_options.hasNoindividualsOption()) {
-            return;
-        }
-
-        if (m_options.hasIndividualsSectionOption()) {
-            writeln( 0, m_options.getIndividualsSectionOption() );
-        }
-
-        if (useOntology()) {
-            writeOntIndividuals();
-        }
-        else {
-            writeRDFIndividuals();
-        }
-    }
-
-    /** Write individuals as ontology terms */
-    protected void writeOntIndividuals() {
-        String template = m_options.hasIndividualTemplateOption() ?  m_options.getIndividualTemplateOption() : DEFAULT_INDIVIDUAL_TEMPLATE;
-
-        for (Iterator<? extends RDFNode> i = selectIndividuals(); i.hasNext(); ) {
-            Individual ind = ((Resource) i.next()).as( Individual.class );
-
-            // do we have a local class resource
-            Resource cls = ind.getOntClass();
-            if (cls == null) { cls = OWL.Thing; }
-
-            String varName = m_resourcesToNames.get( cls );
-            String valType = (varName != null) ? varName : "m_model.createClass( \"" + cls.getURI() + "\" )";
-
-            // push the individuals type onto the stack
-            addReplacementPattern( "valtype", valType );
-            writeValue( ind, template, "Individual", "createIndividual", "_INSTANCE" );
-            pop( 1 );
-
-        }
-    }
-
-    /** Write individuals as vanilla RDF terms */
-    protected void writeRDFIndividuals() {
-        String template = m_options.hasIndividualTemplateOption() ?  m_options.getIndividualTemplateOption() : DEFAULT_RDFS_INDIVIDUAL_TEMPLATE;
-
-        for (Iterator<? extends RDFNode> i = selectIndividuals(); i.hasNext(); ) {
-            writeValue( (Resource) i.next(), template, "Resource", "createResource", "_INSTANCE" );
-        }
-    }
-
-    /** Answer an iterator over the individuals selected for output */
-    protected ExtendedIterator<? extends RDFNode> selectIndividuals() {
-        List<Resource> candidates = new ArrayList<>();
-        for (StmtIterator i = m_source.listStatements( null, RDF.type, (RDFNode) null ); i.hasNext(); ) {
-            Statement candidate = i.nextStatement();
-
-            if (candidate.getObject().isResource()) {
-                Resource candObj = candidate.getResource();
-                Resource candSubj = candidate.getSubject();
-
-                // ignore RDFS and OWL builtins
-                if (!candObj.isAnon()) {
-                    String candTypeURI = candObj.getURI();
-                    if (candTypeURI.startsWith( RDF.getURI() ) ||
-                        candTypeURI.startsWith( OWL.getURI() ) ||
-                        candTypeURI.startsWith( RDFS.getURI() )) {
-                        continue;
-                    }
-                }
-
-                // note that whether candSubj is included is tested later on by {@link #filter}
-                if (!candSubj.isAnon() && (isIncluded( candObj ) || isIncluded( candSubj )) && !candidates.contains( candSubj )) {
-                    candidates.add( candSubj );
-                }
-            }
-        }
-
-        return sorted( candidates );
-    }
-
-    /**
-     * Answer true if the given resource is accepted for presentation in the output, which
-     * is true iff it is a URI node, whose namespace is one of the accepted namespaces in
-     * {@link #m_includeURI}.
-     * @param r A resource to test
-     * @return True if the resource is to be included in the generated output
-     */
-    protected boolean isIncluded( Resource r ) {
-        boolean accepted = false;
-
-        if (!r.isAnon()) {
-            String uri = r.getURI();
-            for (Iterator<String> j = m_includeURI.iterator();  !accepted && j.hasNext(); ) {
-                accepted = uri.startsWith( j.next() );
-            }
-        }
-
-        return accepted;
-    }
-    
-    /** Write any datatypes in the vocabulary */
-    protected void writeDatatypes() {
-        if (m_options.hasNodatatypesOption()) {
-            return;
-        }
-
-        if (m_options.hasDatatypesSectionOption()) {
-            writeln( 0, m_options.getDatatypesSectionOption() );
-        }
-        
-        String template = m_options.hasDatatypeTemplateOption() ?  m_options.getDatatypeTemplateOption() : DEFAULT_TEMPLATE;
-        
-        // Cannot create a full RDFDatatype object since we don't know how to parse these custom types, but we can at least specify a Resource
-        for (Iterator<? extends RDFNode> i = selectDatatypes(); i.hasNext(); ) {
-            writeValue( (Resource) i.next(), template, "Resource", "createResource", "_DATATYPE" );
-        }
-    }
-    
-    /** Answer an iterator over the datatypes selected for output */
-    protected ExtendedIterator<? extends RDFNode> selectDatatypes() {
-        List<Resource> candidates = new ArrayList<>();
-        for (StmtIterator i = m_source.listStatements( null, RDF.type, RDFS.Datatype ); i.hasNext(); ) {
-            Statement candidate = i.nextStatement();
-
-            if (candidate.getObject().isResource()) {
-                Resource candSubj = candidate.getSubject();
-
-                // ignore XSD builtins
-                if (!candSubj.isAnon()) {
-                    String candTypeURI = candSubj.getURI();
-                    if (candTypeURI.startsWith( XSD.getURI() )) {
-                        continue;
-                    }
-                }
-
-                // note that whether candSubj is included is tested later on by {@link #filter}
-                if (!candSubj.isAnon() && !candidates.contains( candSubj )) {
-                    candidates.add( candSubj );
-                }
-            }
-        }
-
-        return sorted( candidates );
-    }
-
-    /** Write the value declaration out using the given template, optionally creating comments */
-    protected void writeValue( Resource r, String template, String valueClass, String creator, String disambiguator ) {
-        if (!filter( r )) {
-            if (!noComments()  &&  hasComment( r )) {
-                writeln( 1, formatComment( getComment( r ) ) );
-            }
-
-            // push the local bindings for the substitution onto the stack
-            addReplacementPattern( "valuri", r.getURI() );
-            addReplacementPattern( "valname", getValueName( r, disambiguator ));
-            addReplacementPattern( "valclass", valueClass );
-            addReplacementPattern( "valcreator", creator );
-
-            // write out the value
-            writeln( 1, substitute( template ) );
-            writeln( 1 );
-
-            // pop the local replacements off the stack
-            pop( 4 );
-        }
-    }
-
-    /** Answer true if the given resource has an rdf:comment */
-    protected boolean hasComment( Resource r ) {
-        return r.hasProperty( RDFS.comment ) ;
-    }
-
-    /** Answer all of the commentary on the given resource, as a string */
-    protected String getComment( Resource r ) {
-        StringBuffer comment = new StringBuffer();
-
-        // collect any RDFS or DAML comments attached to the node
-        for (NodeIterator ni = m_source.listObjectsOfProperty( r, RDFS.comment );  ni.hasNext(); ) {
-            RDFNode n = ni.nextNode();
-            if (n instanceof Literal) {
-                comment.append( ((Literal) n).getLexicalForm().trim() );
-            }
-            else {
-                System.err.println( "Warning: Comment on resource <" + r.getURI() + "> is not a literal: " + n );
-            }
-        }
-
-        return comment.toString();
-    }
-
-    /** Format the comment as Javadoc, and limit the line width */
-    protected String formatComment( String comment ) {
-        StringBuffer buf = new StringBuffer();
-        buf.append( "/** <p>" );
-
-        boolean inSpace = false;
-        int pos = buf.length();
-        boolean singleLine = true;
-
-        // now format the comment by compacting whitespace and limiting the line length
-        // add the prefix to the start of each line
-        for (int i = 0;  i < comment.length();  i++ ) {
-            char c = comment.charAt( i );
-
-            // compress whitespace
-            if (Character.isWhitespace( c )) {
-                if (inSpace) {
-                    continue;       // more than one space is ignored
-                }
-                else {
-                    c = ' ';        // map all whitespace to 0x20
-                    inSpace = true;
-                }
-            }
-            else {
-                inSpace = false;
-            }
-
-            // escapes?
-            if (c == '\\') {
-                c = comment.charAt( ++i );
-
-                switch (c) {
-                    case 'n':
-                        buf.append( m_nl );
-                        pos = indentTo( 1, buf );
-                        buf.append( " *  " );
-                        pos += 3;
-                        singleLine = false;
-                        break;
-
-                    default:
-                        // add other escape sequences above
-                        break;
-                }
-            }
-            else if (c == '<') {
-                buf.append( "&lt;" );
-                pos += 4;
-            }
-            else if (c == '>') {
-                buf.append( "&gt;" );
-                pos += 4;
-            }
-            else if (c == '&') {
-                buf.append( "&amp;" );
-                pos += 5;
-            }
-            else {
-                // add the char
-                buf.append( c );
-                pos++;
-            }
-
-            // wrap any very long lines at 120 chars
-            if ((pos > COMMENT_LENGTH_LIMIT) && (inSpace)) {
-                buf.append( m_nl );
-                pos = indentTo( 1, buf );
-                buf.append( " *  " );
-                pos += 3;
-                singleLine = false;
-            }
-        }
-
-        buf.append( "</p>" );
-        buf.append( singleLine ? "" : m_nl );
-        indentTo( singleLine ? 0 : 1, buf );
-        buf.append( " */" );
-        return buf.toString();
-    }
-
-    /** Answer true if resource r <b>does not</b> show in output */
-    protected boolean filter( Resource r ) {
-        if (r.isAnon()) {
-            return true;
-        }
-
-        // if we've already processed this resource once, ignore it next time
-        if (m_resourcesToNames.containsKey( r )) {
-            return true;
-        }
-
-        // search the allowed URI's
-        for ( String uri : m_includeURI )
-        {
-            if ( r.getURI().startsWith( uri ) )
-            {
-                // in
-                return false;
-            }
-        }
-
-        // we allow individuals whose class is not in the included NS's, unless opt strict-individuals is true */
-        if (!m_options.hasStrictIndividualsOption()) {
-            for (StmtIterator j = r.listProperties( RDF.type ); j.hasNext(); ) {
-                // we search the rdf:types of this resource
-                Resource typeRes = j.nextStatement().getResource();
-
-                if (!typeRes.isAnon()) {
-                    String typeURI = typeRes.getURI();
-
-                    // for any type that is in a permitted NS
-                    for ( String uri : m_includeURI )
-                    {
-                        if ( typeURI.startsWith( uri ) )
-                        {
-                            // in
-                            return false;
-                        }
-                    }
-                }
-            }
-        }
-
-        // default is out
-        return true;
-    }
-
-    /** Answer the Java value name for the URI */
-    protected String getValueName( Resource r, String disambiguator ) {
-        // the id name is basically the local name of the resource, possibly in upper case
-        String name = m_options.hasUcNamesOption() ? getUCValueName( r ) : r.getLocalName();
-
-        // must be legal java
-        name = asLegalJavaID( name, false );
-
-        // must not clash with an existing name
-        int attempt = 0;
-        String baseName = name;
-        while (m_usedNames.contains( name )) {
-            name = (attempt == 0) ? (name + disambiguator) : (baseName + disambiguator + attempt);
-            attempt++;
-        }
-
-        // record this name so that we don't use it again (which will stop the vocabulary from compiling)
-        m_usedNames.add( name );
-
-        // record the mapping from resource to name
-        m_resourcesToNames.put( r, name );
-
-        return name;
-    }
-
-    /** Answer the local name of resource r mapped to upper case */
-    protected String getUCValueName( Resource r ) {
-        StringBuffer buf = new StringBuffer();
-        String localName = r.getLocalName();
-        char lastChar = 0;
-
-        for (int i = 0; i < localName.length(); i++) {
-            char c = localName.charAt(i);
-
-            if (Character.isLowerCase(lastChar) && Character.isUpperCase(c)) {
-                buf.append( '_' );
-            }
-            buf.append( Character.toUpperCase(c) );
-            lastChar = c;
-        }
-
-        return buf.toString();
-    }
-
-    /** Answer an iterator that contains the elements of the given list, but sorted by URI */
-    protected ExtendedIterator<? extends RDFNode> sorted( ExtendedIterator<? extends RDFNode> i ) {
-        return sorted( i.toList() );
-    }
-
-    /** Answer an iterator that contains the elements of the given iterator, but sorted by URI */
-    protected ExtendedIterator<? extends RDFNode> sorted( List<? extends RDFNode> members ) {
-        Collections.sort( members, new Comparator<RDFNode>() {
-            @Override
-            public int compare( RDFNode n0, RDFNode n1 ) {
-                if (n0.isLiteral() || n1.isLiteral()) {
-                    if (n0.isLiteral() && n1.isLiteral()) {
-                        // two literals
-                        Literal l0 = (Literal) n0;
-                        Literal l1 = (Literal) n1;
-                        return l0.getLexicalForm().compareTo( l1.getLexicalForm() );
-                    }
-                    else {
-                        return n0.isLiteral() ? -1 : 1;
-                    }
-                }
-                else {
-                    Resource r0 = (Resource) n0;
-                    Resource r1 = (Resource) n1;
-                    if (r0.isAnon() && r1.isAnon()) {
-                        // two anonID's - the order is important as long as its consistent
-                        return r0.getId().toString().compareTo( r1.getId().toString() );
-                    }
-                    else if (r0.isAnon()) {
-                        return -1;
-                    }
-                    else if (r1.isAnon()) {
-                        return 1;
-                    }
-                    else {
-                        // two named resources
-                        return r0.getURI().compareTo( r1.getURI() );
-                    }
-                }
-            }} );
-
-        return WrappedIterator.create( members.iterator() );
-    }
-
-    //==============================================================================
-    // Inner class definitions
-    //==============================================================================
-
-    public interface SchemagenOptions {
-        /* Constants for the various options we can set */
-
-        public enum OPT {
-            /** Select an alternative config file; use <code>-c &lt;filename&gt;</code> on command line */
-            CONFIG_FILE,
-
-            /** Turn off all comment output; use <code>--nocomments</code> on command line;  use <code>sgen:noComments</code> in config file */
-            NO_COMMENTS,
-
-            /** Nominate the URL of the input document; use <code>-i &lt;URL&gt;</code> on command line;  use <code>sgen:input</code> in config file */
-            INPUT,
-
-            /** Specify that the language of the source is DAML+OIL; use <code>--daml</code> on command line;  use <code>sgen:daml</code> in config file */
-            LANG_DAML,
-
-            /** Specify that the language of the source is OWL (the default); use <code>--owl</code> on command line;  use <code>sgen:owl</code> in config file */
-            LANG_OWL,
-
-            /** Specify that the language of the source is RDFS; use <code>--rdfs</code> on command line;  use <code>sgen:rdfs</code> in config file */
-            LANG_RDFS,
-
-            /** Specify that destination file; use <code>-o &lt;fileName&gt;</code> on command line;  use <code>sgen:output</code> in config file */
-            OUTPUT,
-
-            /** Specify the file header; use <code>--header "..."</code> on command line;  use <code>sgen:header</code> in config file */
-            HEADER,
-
-            /** Specify the file footer; use <code>--footer "..."</code> on command line;  use <code>sgen:footer</code> in config file */
-            FOOTER,
-
-            /** Specify the uri of the configuration root node; use <code>--root &lt;URL&gt;</code> on command line */
-            ROOT,
-
-            /** Specify the marker string for substitutions, default is '%'; use <code>-m "..."</code> on command line; use <code>sgen:marker</code> in config file */
-            MARKER,
-
-            /** Specify the packagename; use <code>--package &lt;packagename&gt;</code> on command line; use <code>sgen:package</code> in config file */
-            PACKAGENAME,
-
-            /** Use ontology terms in preference to vanilla RDF; use <code>--ontology</code> on command line; use <code>sgen:ontology</code> in config file */
-            ONTOLOGY,
-
-            /** The name of the generated class; use <code>-n &lt;classname&gt;</code> on command line; use <code>sgen:classname</code> in config file */
-            CLASSNAME,
-
-            /** Additional decoration for class header (such as implements); use <code>--classdec &lt;classname&gt;</code> on command line; use <code>sgen:classdec</code> in config file */
-            CLASSDEC,
-
-            /** The namespace URI for the vocabulary; use <code>-a &lt;uri&gt;</code> on command line; use <code>sgen:namespace</code> in config file */
-            NAMESPACE,
-
-            /** Additional declarations to add at the top of the class; use <code>--declarations &lt;...&gt;</code> on command line; use <code>sgen:declarations</code> in config file */
-            DECLARATIONS,
-
-            /** Section declaration for properties section; use <code>--propSection &lt;...&gt;</code> on command line; use <code>sgen:propSection</code> in config file */
-            PROPERTY_SECTION,
-
-            /** Section declaration for class section; use <code>--classSection &lt;...&gt;</code> on command line; use <code>sgen:classSection</code> in config file */
-            CLASS_SECTION,
-
-            /** Section declaration for individuals section; use <code>--individualsSection &lt;...&gt;</code> on command line; use <code>sgen:individualsSection</code> in config file */
-            INDIVIDUALS_SECTION,
-            
-            /** Section declaration for datatypes section; use <code>--datatypesSection &lt;...&gt;</code> on command line; use <code>sgen:datatypesSection</code> in config file */
-            DATATYPES_SECTION,
-
-            /** Option to suppress properties in vocab file; use <code>--noproperties &lt;...&gt;</code> on command line; use <code>sgen:noproperties</code> in config file */
-            NOPROPERTIES,
-
-            /** Option to suppress classes in vocab file; use <code>--noclasses &lt;...&gt;</code> on command line; use <code>sgen:noclasses</code> in config file */
-            NOCLASSES,
-
-            /** Option to suppress individuals in vocab file; use <code>--noindividuals &lt;...&gt;</code> on command line; use <code>sgen:noindividuals</code> in config file */
-            NOINDIVIDUALS,
-            
-            /** Option to suppress datatypes in vocab file; use <code>--nodatatypes &lt;...&gt;</code> on command line; use <code>sgen:nodatatypes</code> in config file */
-            NODATATYPES,
-
-            /** Option for no file header; use <code>--noheader &lt;...&gt;</code> on command line; use <code>sgen:noheader</code> in config file */
-            NOHEADER,
-
-            /** Template for writing out property declarations; use <code>--propTemplate &lt;...&gt;</code> on command line; use <code>sgen:propTemplate</code> in config file */
-            PROP_TEMPLATE,
-
-            /** Template for writing out class declarations; use <code>--classTemplate &lt;...&gt;</code> on command line; use <code>sgen:classTemplate</code> in config file */
-            CLASS_TEMPLATE,
-
-            /** Template for writing out individual declarations; use <code>--individualTemplate &lt;...&gt;</code> on command line; use <code>sgen:individualTemplate</code> in config file */
-            INDIVIDUAL_TEMPLATE,
-            
-            /** Template for writing out datatype declarations; use <code>--datatypeTemplate &lt;...&gt;</code> on command line; use <code>sgen:datatypeTemplate</code> in config file */
-            DATATYPE_TEMPLATE,
-
-            /** Option for mapping constant names to uppercase; use <code>--uppercase &lt;...&gt;</code> on command line; use <code>sgen:uppercase</code> in config file */
-            UC_NAMES,
-
-            /** Option for including non-local URI's in vocabulary; use <code>--include &lt;uri&gt;</code> on command line; use <code>sgen:include</code> in config file */
-            INCLUDE,
-
-            /** Option for adding a suffix to the generated class name; use <code>--classnamesuffix &lt;uri&gt;</code> on command line; use <code>sgen:classnamesuffix</code> in config file */
-            CLASSNAME_SUFFIX,
-
-            /** Option for the presentation syntax (encoding) of the file; use <code>-e <i>encoding</i></code> on command line; use <code>sgen:encoding</code> in config file */
-            ENCODING,
-
-            /** Option to show the usage message; use --help on command line */
-            HELP,
-
-            /** Option to generate an output file with DOS (\r\n) line endings. Default is Unix line endings. */
-            DOS,
-
-            /** Option to generate to force the model to perform inference, off by default. */
-            USE_INF,
-
-            /** Option to exclude instances of classes in the allowed namespaces, where the individuals themselves are in other namespaces; use <code>--strictIndividuals</code> on command line; use <code>sgen:strictIndividuals</code> in config file */
-            STRICT_INDIVIDUALS,
-
-            /** Option to include the ontology source code in the generated file */
-            INCLUDE_SOURCE,
-
-            /** Option to turn off strict checking in .a() */
-            NO_STRICT
-        }
-
-
-        public static final Object[][] m_optionDefinitions = new Object[][] {
-                {OPT.CONFIG_FILE,         new OptionDefinition( "-c", "configFile" ) },
-                {OPT.ROOT,                new OptionDefinition( "-r", "root" ) },
-                {OPT.NO_COMMENTS,         new OptionDefinition( "--nocomments", "noComments" ) },
-                {OPT.INPUT,               new OptionDefinition( "-i", "input" ) },
-                {OPT.LANG_DAML,           new OptionDefinition( "--daml", "daml" ) },
-                {OPT.LANG_OWL,            new OptionDefinition( "--owl", "owl" ) },
-                {OPT.LANG_RDFS,           new OptionDefinition( "--rdfs", "rdfs" ) },
-                {OPT.OUTPUT,              new OptionDefinition( "-o", "output" ) },
-                {OPT.HEADER,              new OptionDefinition( "--header", "header" ) },
-                {OPT.FOOTER,              new OptionDefinition( "--footer", "footer" ) },
-                {OPT.MARKER,              new OptionDefinition( "--marker", "marker" ) },
-                {OPT.PACKAGENAME,         new OptionDefinition( "--package", "package" ) },
-                {OPT.ONTOLOGY,            new OptionDefinition( "--ontology", "ontology" ) },
-                {OPT.CLASSNAME,           new OptionDefinition( "-n", "classname" ) },
-                {OPT.CLASSDEC,            new OptionDefinition( "--classdec", "classdec" ) },
-                {OPT.NAMESPACE,           new OptionDefinition( "-a", "namespace" ) },
-                {OPT.DECLARATIONS,        new OptionDefinition( "--declarations", "declarations" ) },
-                {OPT.PROPERTY_SECTION,    new OptionDefinition( "--propSection", "propSection" ) },
-                {OPT.CLASS_SECTION,       new OptionDefinition( "--classSection", "classSection" ) },
-                {OPT.INDIVIDUALS_SECTION, new OptionDefinition( "--individualsSection", "individualsSection" ) },
-                {OPT.DATATYPES_SECTION,   new OptionDefinition( "--datatypesSection", "datatypesSection" ) },
-                {OPT.NOPROPERTIES,        new OptionDefinition( "--noproperties", "noproperties" ) },
-                {OPT.NOCLASSES,           new OptionDefinition( "--noclasses", "noclasses" ) },
-                {OPT.NOINDIVIDUALS,       new OptionDefinition( "--noindividuals", "noindividuals" ) },
-                {OPT.NODATATYPES,         new OptionDefinition( "--nodatatypes", "nodatatypes" ) },
-                {OPT.PROP_TEMPLATE,       new OptionDefinition( "--propTemplate", "propTemplate" ) },
-                {OPT.CLASS_TEMPLATE,      new OptionDefinition( "--classTemplate", "classTemplate" ) },
-                {OPT.INDIVIDUAL_TEMPLATE, new OptionDefinition( "--individualTemplate", "individualTemplate" ) },
-                {OPT.DATATYPE_TEMPLATE,   new OptionDefinition( "--datatypeTemplate", "datatypeTemplate" ) },
-                {OPT.UC_NAMES,            new OptionDefinition( "--uppercase", "uppercase" ) },
-                {OPT.INCLUDE,             new OptionDefinition( "--include", "include" ) },
-                {OPT.CLASSNAME_SUFFIX,    new OptionDefinition( "--classnamesuffix", "classnamesuffix" )},
-                {OPT.NOHEADER,            new OptionDefinition( "--noheader", "noheader" )},
-                {OPT.ENCODING,            new OptionDefinition( "-e", "encoding" )},
-                {OPT.HELP,                new OptionDefinition( "--help", "help" )},
-                {OPT.DOS,                 new OptionDefinition( "--dos", "dos" )},
-                {OPT.USE_INF,             new OptionDefinition( "--inference", "inference" )},
-                {OPT.STRICT_INDIVIDUALS,  new OptionDefinition( "--strictIndividuals", "strictIndividuals" )},
-                {OPT.INCLUDE_SOURCE,      new OptionDefinition( "--includeSource", "includeSource" )},
-                {OPT.NO_STRICT,           new OptionDefinition( "--nostrict", "noStrict")},
-            };
-
-        public boolean hasConfigFileOption();
-        public String getConfigFileOption();
-        public boolean hasRootOption();
-        public String getRootOption();
-        public boolean hasNoCommentsOption();
-        public String getNoCommentsOption();
-        public boolean hasInputOption();
-        public Resource getInputOption();
-        public boolean hasLangOwlOption();
-        public String getLangOwlOption();
-        public boolean hasLangRdfsOption();
-        public String getLangRdfsOption();
-        public boolean hasOutputOption();
-        public String getOutputOption();
-        public boolean hasHeaderOption();
-        public String getHeaderOption();
-        public boolean hasFooterOption();
-        public String getFooterOption();
-        public boolean hasMarkerOption();
-        public String getMarkerOption();
-        public boolean hasPackagenameOption();
-        public String getPackagenameOption();
-        public boolean hasOntologyOption();
-        public String getOntologyOption();
-        public boolean hasClassnameOption();
-        public String getClassnameOption();
-        public boolean hasClassdecOption();
-        public String getClassdecOption();
-        public boolean hasNamespaceOption();
-        public Resource getNamespaceOption();
-        public boolean hasDeclarationsOption();
-        public String getDeclarationsOption();
-        public boolean hasPropertySectionOption();
-        public String getPropertySectionOption();
-        public boolean hasClassSectionOption();
-        public String getClassSectionOption();
-        public boolean hasIndividualsSectionOption();
-        public String getIndividualsSectionOption();
-        public boolean hasDatatypesSectionOption();
-        public String getDatatypesSectionOption();
-        public boolean hasNopropertiesOption();
-        public boolean hasNoclassesOption();
-        public boolean hasNoindividualsOption();
-        public boolean hasNodatatypesOption();
-        public boolean hasPropTemplateOption();
-        public String getPropTemplateOption();
-        public boolean hasClassTemplateOption();
-        public String getClassTemplateOption();
-        public boolean hasIndividualTemplateOption();
-        public String getIndividualTemplateOption();
-        public boolean hasDatatypeTemplateOption();
-        public String getDatatypeTemplateOption();
-        public boolean hasUcNamesOption();
-        public boolean hasIncludeOption();
-        public List<String> getIncludeOption();
-        public boolean hasClassnameSuffixOption();
-        public String getClassnameSuffixOption();
-        public boolean hasNoheaderOption();
-        public boolean hasEncodingOption();
-        public String getEncodingOption();
-        public boolean hasHelpOption();
-        public String getHelpOption();
-        public boolean hasDosOption();
-        public boolean hasUseInfOption();
-        public boolean hasStrictIndividualsOption();
-        public boolean hasIncludeSourceOption();
-        public boolean hasNoStrictOption();
-    }
-
-    public static class SchemagenOptionsImpl
-        implements SchemagenOptions
-    {
-        // Instance variables
-        /** The list of command line arguments */
-        private List<String> m_cmdLineArgs = new ArrayList<>();
-
-        /** The root of the options in the config file */
-        private Resource m_root;
-
-        /** The model that contains the configuration information */
-        private Model m_config = ModelFactory.createDefaultModel();
-
-        // Constructor
-
-        public SchemagenOptionsImpl( String[] args ) {
-            m_cmdLineArgs = Arrays.asList( args );
-
-            // check to see if there's a specified config file
-            String configURL = DEFAULT_CONFIG_URI;
-            if (hasConfigFileOption()) {
-                // check for protocol; add file: if not specified
-                configURL = SchemagenUtils.urlCheck( getConfigFileOption() );
-            }
-
-            // try to read the config URI
-            try {
-                FileManager.get().readModel( m_config, configURL );
-            }
-            catch (Exception e) {
-                // if the user left the default config URI in place, it's not an error to fail to read it
-                if (!configURL.equals( DEFAULT_CONFIG_URI )) {
-                    throw new SchemagenException( "Failed to read configuration from URL: " + configURL, e );
-                }
-            }
-
-            // ensure we have a root URI for the configuration model
-            determineConfigRoot();
-        }
-
-        /**
-         * Return the configuration model used to hold config information
-         * @return Model
-         */
-        protected Model getConfigModel() {
-            return m_config;
-        }
-
-        /**
-         * Return the root resource to which configuration information is attached
-         * @return Resource
-         */
-        protected Resource getConfigRoot() {
-            if (m_root == null) {
-                determineConfigRoot();
-            }
-            return m_root;
-        }
-
-        // Internal implementation methods
-
-        /** Determine the root resource in the configuration file */
-        protected void determineConfigRoot() {
-            if (hasValue( OPT.ROOT )) {
-                m_root = m_config.getResource( getStringValue( OPT.ROOT ) );
-            }
-            else {
-                // no specified root, we assume there is only one with type sgen:Config
-                StmtIterator i = m_config.listStatements( null, RDF.type, m_config.getResource( NS + "Config" ) );
-                if (i.hasNext()) {
-                    m_root = i.nextStatement().getSubject();
-                }
-                else {
-                    // no configuration root, so we invent one
-                    m_root = m_config.createResource();
-                }
-            }
-        }
-
-        /** Answer true if the given option is set to true */
-        protected boolean isTrue( OPT option ) {
-            return getOpt( option ).isTrue( m_cmdLineArgs, m_root );
-        }
-
-        /** Answer true if the given option has value */
-        protected boolean hasValue( OPT option ) {
-            return getOpt( option ).hasValue( m_cmdLineArgs, m_root );
-        }
-
-        /** Answer the value of the option or null */
-        protected RDFNode getValue( OPT option ) {
-            return getOpt( option ).getValue( m_cmdLineArgs, m_root );
-        }
-
-        /** Answer the String value of the option or null */
-        protected String getStringValue( OPT option ) {
-            return getOpt( option ).getStringValue( m_cmdLineArgs, m_root );
-        }
-
-        /** Answer true if the given option has a resource value */
-        protected boolean hasResourceValue( OPT option ) {
-            return getOpt( option ).hasResourceValue( m_cmdLineArgs, m_root );
-        }
-
-        /** Answer the value of the option or null */
-        protected Resource getResource( OPT option ) {
-            return getOpt( option ).getResource( m_cmdLineArgs, m_root );
-        }
-
-        /** Answer all values for the given options as Strings */
-        protected List<String> getAllValues( OPT option ) {
-            List<String> values = new ArrayList<>();
-            OptionDefinition opt = getOpt( option );
-
-            // look in the command line arguments
-            for (Iterator<String> i = m_cmdLineArgs.iterator(); i.hasNext(); ) {
-                String s = i.next();
-                if (s.equals( opt.m_cmdLineForm )) {
-                    // next iterator value is the arg value
-                    values.add( i.next() );
-                }
-            }
-
-            // now look in the config file
-            for (StmtIterator i = m_root.listProperties( opt.m_prop ); i.hasNext(); ) {
-                Statement s = i.nextStatement();
-
-                if (s.getObject() instanceof Literal) {
-                    values.add( s.getString() );
-                }
-                else {
-                    values.add( s.getResource().getURI() );
-                }
-            }
-
-            return values;
-        }
-
-        /** Answer the option object for the given option */
-        protected OptionDefinition getOpt( OPT option ) {
-            for ( Object[] m_optionDefinition : m_optionDefinitions )
-            {
-                if ( m_optionDefinition[0] == option )
-                {
-                    return (OptionDefinition) m_optionDefinition[1];
-                }
-            }
-
-            return null;
-        }
-
-        // External interface methods
-
-        @Override
-        public boolean hasConfigFileOption() { return hasValue( OPT.CONFIG_FILE ); }
-        @Override
-        public String getConfigFileOption() { return getStringValue( OPT.CONFIG_FILE ); }
-        @Override
-        public boolean hasRootOption() { return hasValue( OPT.ROOT ); }
-        @Override
-        public String getRootOption() { return getStringValue( OPT.ROOT ); }
-        @Override
-        public boolean hasNoCommentsOption() { return isTrue( OPT.NO_COMMENTS ); }
-        @Override
-        public String getNoCommentsOption() { return getStringValue( OPT.NO_COMMENTS ); }
-        @Override
-        public boolean hasInputOption() { return hasValue( OPT.INPUT ); }
-        @Override
-        public Resource getInputOption() { return getResource( OPT.INPUT ); }
-        @Override
-        public boolean hasLangOwlOption() { return isTrue( OPT.LANG_OWL ); }
-        @Override
-        public String getLangOwlOption() { return getStringValue( OPT.LANG_OWL ); }
-        @Override
-        public boolean hasLangRdfsOption() { return isTrue( OPT.LANG_RDFS ); }
-        @Override
-        public String getLangRdfsOption() { return getStringValue( OPT.LANG_RDFS ); }
-        @Override
-        public boolean hasOutputOption() { return hasValue( OPT.OUTPUT ); }
-        @Override
-        public String getOutputOption() { return getStringValue( OPT.OUTPUT ); }
-        @Override
-        public boolean hasHeaderOption() { return isTrue( OPT.HEADER ); }
-        @Override
-        public String getHeaderOption() { return getStringValue( OPT.HEADER ); }
-        @Override
-        public boolean hasFooterOption() { return isTrue( OPT.FOOTER ); }
-        @Override
-        public String getFooterOption() { return getStringValue( OPT.FOOTER ); }
-        @Override
-        public boolean hasMarkerOption() { return hasValue( OPT.MARKER ); }
-        @Override
-        public String getMarkerOption() { return getStringValue( OPT.MARKER ); }
-        @Override
-        public boolean hasPackagenameOption() { return hasValue( OPT.PACKAGENAME ); }
-        @Override
-        public String getPackagenameOption() { return getStringValue( OPT.PACKAGENAME ); }
-        @Override
-        public boolean hasOntologyOption() { return isTrue( OPT.ONTOLOGY ); }
-        @Override
-        public String getOntologyOption() { return getStringValue( OPT.ONTOLOGY ); }
-        @Override
-        public boolean hasClassnameOption() { return hasValue( OPT.CLASSNAME ); }
-        @Override
-        public String getClassnameOption() { return getStringValue( OPT.CLASSNAME ); }
-        @Override
-        public boolean hasClassdecOption() { return hasValue( OPT.CLASSDEC ); }
-        @Override
-        public String getClassdecOption() { return getStringValue( OPT.CLASSDEC ); }
-        @Override
-        public boolean hasNamespaceOption() { return hasValue( OPT.NAMESPACE ); }
-        @Override
-        public Resource getNamespaceOption() { return getResource( OPT.NAMESPACE ); }
-        @Override
-        public boolean hasDeclarationsOption() { return hasValue( OPT.DECLARATIONS ); }
-        @Override
-        public String getDeclarationsOption() { return getStringValue( OPT.DECLARATIONS ); }
-        @Override
-        public boolean hasPropertySectionOption() { return hasValue( OPT.PROPERTY_SECTION ); }
-        @Override
-        public String getPropertySectionOption() { return getStringValue( OPT.PROPERTY_SECTION ); }
-        @Override
-        public boolean hasClassSectionOption() { return hasValue( OPT.CLASS_SECTION ); }
-        @Override
-        public String getClassSectionOption() { return getStringValue( OPT.CLASS_SECTION ); }
-        @Override
-        public boolean hasIndividualsSectionOption() { return hasValue( OPT.INDIVIDUALS_SECTION ); }
-        @Override
-        public String getIndividualsSectionOption() { return getStringValue( OPT.INDIVIDUALS_SECTION ); }
-        @Override
-        public boolean hasDatatypesSectionOption() { return hasValue( OPT.DATATYPES_SECTION ); }
-        @Override
-        public String getDatatypesSectionOption() { return getStringValue( OPT.DATATYPES_SECTION ); }
-        @Override
-        public boolean hasNopropertiesOption() { return isTrue( OPT.NOPROPERTIES ); }
-        @Override
-        public boolean hasNoclassesOption() { return isTrue( OPT.NOCLASSES ); }
-        @Override
-        public boolean hasNoindividualsOption() { return isTrue( OPT.NOINDIVIDUALS ); }
-        @Override
-        public boolean hasNodatatypesOption() { return isTrue( OPT.NODATATYPES ); }
-        @Override
-        public boolean hasPropTemplateOption() { return hasValue( OPT.PROP_TEMPLATE ); }
-        @Override
-        public String getPropTemplateOption() { return getStringValue( OPT.PROP_TEMPLATE ); }
-        @Override
-        public boolean hasClassTemplateOption() { return hasValue( OPT.CLASS_TEMPLATE ); }
-        @Override
-        public String getClassTemplateOption() { return getStringValue( OPT.CLASS_TEMPLATE ); }
-        @Override
-        public boolean hasIndividualTemplateOption() { return hasValue( OPT.INDIVIDUAL_TEMPLATE ); }
-        @Override
-        public String getIndividualTemplateOption() { return getStringValue( OPT.INDIVIDUAL_TEMPLATE ); }
-        @Override
-        public boolean hasDatatypeTemplateOption() { return hasValue( OPT.DATATYPE_TEMPLATE ); }
-        @Override
-        public String getDatatypeTemplateOption() { return getStringValue( OPT.DATATYPE_TEMPLATE ); }
-        @Override
-        public boolean hasUcNamesOption() { return isTrue( OPT.UC_NAMES ); }
-        @Override
-        public boolean hasIncludeOption() { return hasValue( OPT.INCLUDE ); }
-        @Override
-        public List<String> getIncludeOption() { return getAllValues( OPT.INCLUDE ); }
-        @Override
-        public boolean hasClassnameSuffixOption() { return hasValue( OPT.CLASSNAME_SUFFIX ); }
-        @Override
-        public String getClassnameSuffixOption() { return getStringValue( OPT.CLASSNAME_SUFFIX ); }
-        @Override
-        public boolean hasNoheaderOption() { return isTrue( OPT.NOHEADER ); }
-        @Override
-        public boolean hasEncodingOption() { return hasValue( OPT.ENCODING ); }
-        @Override
-        public String getEncodingOption() { return getStringValue( OPT.ENCODING ); }
-        @Override
-        public boolean hasHelpOption() { return hasValue( OPT.HELP ); }
-        @Override
-        public String getHelpOption() { return getStringValue( OPT.HELP ); }
-        @Override
-        public boolean hasDosOption() { return isTrue( OPT.DOS ); }
-        @Override
-        public boolean hasUseInfOption() { return isTrue( OPT.USE_INF ); }
-        @Override
-        public boolean hasStrictIndividualsOption() { return isTrue( OPT.STRICT_INDIVIDUALS ); }
-        @Override
-        public boolean hasIncludeSourceOption() { return isTrue( OPT.INCLUDE_SOURCE ); }
-        @Override
-        public boolean hasNoStrictOption() { return isTrue( OPT.NO_STRICT ); }
-    }
-
-    /** An option that can be set either on the command line or in the RDF config */
-    public static class OptionDefinition
-    {
-        protected String m_cmdLineForm;
-        protected Property m_prop;
-
-        protected OptionDefinition( String cmdLineForm, String name ) {
-            m_cmdLineForm = cmdLineForm;
-            if (name != null) {
-                m_prop = ResourceFactory.createProperty( NS, name );
-            }
-        }
-
-        /**
-         * Return the RDF property that is used when configuring this option
-         * via a {@link Model}
-         * @return The declaration property, or null
-         */
-        public Property getDeclarationProperty() {
-            return m_prop;
-        }
-
-        /**
-         * Return the command line form of this option
-         * @return The command line form as a String
-         */
-        public String getCommandLineForm() {
-            return m_cmdLineForm;
-        }
-
-        /**
-         * Answer true if this option is set to true, either on the command line
-         * or in the config model
-         *
-         * @return boolean
-         */
-        protected boolean isTrue( List<String> cmdLineArgs, Resource confRoot ) {
-            if (cmdLineArgs.contains( m_cmdLineForm )) {
-                return true;
-            }
-
-            if (confRoot.hasProperty( m_prop )) {
-                return confRoot.getRequiredProperty( m_prop ).getBoolean();
-            }
-
-            return false;
-        }
-
-        /**
-         * Answer the string value of the parameter if set, or null otherwise. Note command line
-         * has precedence.
-         *
-         * @return String
-         */
-        protected String getStringValue( List<String> cmdLineArgs, Resource confRoot ) {
-            RDFNode n = getValue( cmdLineArgs, confRoot );
-            return (n == null) ? null : (n.isLiteral() ? n.asLiteral().getLexicalForm() : n.toString() );
-        }
-
-        /**
-         * Return the value of the parameter if set, or null otherwise. Note command line
-         * has precedence.
-         *
-         * @return The argument value as an RDFNode
-         */
-        protected RDFNode getValue( List<String> cmdLineArgs, Resource confRoot ) {
-            int index = cmdLineArgs.indexOf( m_cmdLineForm );
-
-            if (index >= 0) {
-                try {
-                    return ResourceFactory.createPlainLiteral( cmdLineArgs.get( index + 1 ) );
-                }
-                catch (IndexOutOfBoundsException e) {
-                    throw new SchemagenException( "Value for parameter " + m_cmdLineForm  + " not set! Aborting.", e );
-                }
-            }
-
-            if (m_prop != null && confRoot != null  &&  confRoot.hasProperty( m_prop )) {
-                return confRoot.getRequiredProperty( m_prop ).getObject();
-            }
-
-            // not set
-            return null;
-        }
-
-        /**
-         * Answer true if the parameter has a value at all.
-         *
-         * @return boolean
-         */
-        protected boolean hasValue( List<String> cmdLineArgs, Resource confRoot ) {
-            return getValue( cmdLineArgs, confRoot ) != null;
-        }
-
-
-        /**
-         * Answer the resource value of the parameter if set, or null otherwise.
-         *
-         * @return String
-         */
-        protected Resource getResource( List<String> cmdLineArgs, Resource confRoot ) {
-            int index = cmdLineArgs.indexOf( m_cmdLineForm );
-
-            if (index >= 0) {
-                try {
-                    return confRoot.getModel().getResource( cmdLineArgs.get( index + 1 ) );
-                }
-                catch (IndexOutOfBoundsException e) {
-                    System.err.println( "Value for parameter " + m_cmdLineForm  + " not set! Aborting.");
-                }
-            }
-
-            if (m_prop != null  &&  confRoot.hasProperty( m_prop )) {
-                return confRoot.getRequiredProperty( m_prop ).getResource();
-            }
-
-            // not set
-            return null;
-        }
-
-        /**
-         * Answer true if the parameter has a value at all.
-         *
-         * @return boolean
-         */
-        protected boolean hasResourceValue( List<String> cmdLineArgs, Resource confRoot ) {
-            return getResource( cmdLineArgs, confRoot ) != null;
-        }
-    }  // end inner class OptionDefinition
-
-
-    /** A pairing of pattern and substitution we want to apply to output */
-    protected class Replacement
-    {
-        protected String sub;
-        protected Pattern pattern;
-
-        protected Replacement( Pattern pattern, String sub) {
-            this.sub = sub;
-            this.pattern = pattern;
-        }
-    } // end inner class Replacement
-
-    /**
-     * <p>Schemagen runtime exception</p>
-     */
-    public static class SchemagenException
-        extends RuntimeException
-    {
-        public SchemagenException( String msg, Throwable cause ) {
-            super( msg, cause );
-        }
-    }
-
-    /** Utility method container */
-    public static class SchemagenUtils
-    {
-        /** Return a URI formed from the given string, unchanged if it's already a URI or
-         *  converted to a file URI otherwise.  If not recognisable as a URL, abort.
-         */
-        public static String urlCheck( String uriOrFile ) {
-            boolean legal = true;
-            String url = uriOrFile;
-
-            // is it a URI already?  to check, we make a URL and see what happens!
-            try {
-                new URL( url );
-            }
-            catch (MalformedURLException ignore) {
-                legal = false;
-            }
-
-            // if not a legal url, assume it's a file
-            if (!legal) {
-                legal = true;
-                String slash = System.getProperty( "file.separator" );
-                url = "file:" + (uriOrFile.startsWith( slash ) ? (slash + slash) : "") + uriOrFile;
-
-                try {
-                    new URL( url );
-                }
-                catch (MalformedURLException ignore) {
-                    legal = false;
-                }
-            }
-
-            if (!legal) {
-                throw new SchemagenException( "Could not parse " + uriOrFile + " as a legal URL or a file reference. Aborting.", null );
-            }
-
-            return url;
-        }
-    } /* End class SchemagenUtils */
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/main/java/jena/sparql.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/jena/sparql.java b/jena-core/src/main/java/jena/sparql.java
deleted file mode 100644
index e3340d3..0000000
--- a/jena-core/src/main/java/jena/sparql.java
+++ /dev/null
@@ -1,29 +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 jena;
-
-
-public class sparql
-{
-    // Call-through to arq command line application
-    public static void main(String[] args)
-    {
-        InvokingUtil.invokeCmd("arq.sparql",args) ;
-    }
-}


[17/20] jena git commit: JENA-1108 : jena-cmds module

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/tokens.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/tokens.java b/jena-arq/src/main/java/arq/tokens.java
deleted file mode 100644
index a7cbbd2..0000000
--- a/jena-arq/src/main/java/arq/tokens.java
+++ /dev/null
@@ -1,24 +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 arq;
-
-public class tokens
-{
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/uparse.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/uparse.java b/jena-arq/src/main/java/arq/uparse.java
deleted file mode 100644
index 83d44cb..0000000
--- a/jena-arq/src/main/java/arq/uparse.java
+++ /dev/null
@@ -1,187 +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 arq;
-
-import java.io.IOException ;
-import java.util.List ;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdException;
-
-import org.apache.jena.atlas.io.IndentedLineBuffer ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.query.QueryParseException ;
-import org.apache.jena.query.Syntax ;
-import org.apache.jena.sparql.modify.request.UpdateWriter ;
-import org.apache.jena.update.UpdateFactory ;
-import org.apache.jena.update.UpdateRequest ;
-import org.apache.jena.util.FileUtils ;
-
-import arq.cmdline.CmdARQ ;
-
-public class uparse extends CmdARQ
-{
-    protected static final ArgDecl fileArg          = new ArgDecl(ArgDecl.HasValue, "file", "update") ;
-    protected static final ArgDecl syntaxArg        = new ArgDecl(ArgDecl.HasValue, "syntax", "syn") ;
-    protected static final ArgDecl argDeclPrint     = new ArgDecl(ArgDecl.HasValue, "print") ;
-    List<String> requestFiles = null ;
-    protected Syntax updateSyntax = null ;
-    private boolean printUpdate = false ;
-    private boolean printNone  = false ;
-    
-    public static void main (String... argv)
-    { new uparse(argv).mainRun() ; }
-    
-    protected uparse(String[] argv)
-    {
-        super(argv) ;
-        super.add(fileArg, "--file=FILE",  "Update commands to parse") ;
-        super.add(syntaxArg, "--syntax=name", "Update syntax") ;
-        super.add(argDeclPrint, "--print", "Print in various forms [update, none]") ;
-    }
-
-    @Override
-    protected void processModulesAndArgs()
-    {
-        requestFiles = getValues(fileArg) ;
-        super.processModulesAndArgs() ;
-        if ( super.cmdStrictMode )
-            updateSyntax = Syntax.syntaxSPARQL_11 ;
-
-        // Set syntax
-        if ( super.contains(syntaxArg) ) {
-            // short name
-            String s = super.getValue(syntaxArg) ;
-            Syntax syn = Syntax.lookup(s) ;
-            if ( syn == null )
-                super.cmdError("Unrecognized syntax: " + s) ;
-            updateSyntax = syn ;
-        }
-        
-        for ( String arg : getValues( argDeclPrint ) )
-        {
-            if ( arg.equalsIgnoreCase( "query" ) )
-                printUpdate = true;
-            else if ( arg.equalsIgnoreCase( "none" ) )
-                printNone = true;
-            else
-                throw new CmdException("Not a recognized print form: " + arg + " : Choices are: update, none" );
-        }
-        
-        if ( !printUpdate && ! printNone )
-            printUpdate = true ;
-        
-    }
-    
-    @Override
-    protected String getCommandName() { return Lib.className(this) ; }
-    
-    @Override
-    protected String getSummary() { return getCommandName()+" --file=<request file> | <update string>" ; }
-
-    @Override
-    protected void exec()
-    {
-        for ( String filename : requestFiles )
-        {
-            Syntax syntax = updateSyntax ;
-            if ( syntax == null )
-                syntax = Syntax.guessUpdateFileSyntax(filename) ;
-            String x = oneFile( filename );
-            if ( x != null )
-                execOne( x, syntax );
-        }
-
-        
-        
-        
-        for ( String x : super.positionals ) {
-            Syntax syntax = updateSyntax ;    
-            if ( matchesIndirect(x) ) {
-                if ( syntax == null )
-                    syntax = Syntax.guessUpdateFileSyntax(x) ;
-                x = indirect( x );
-            }
-            if ( syntax == null )
-                syntax = Syntax.defaultUpdateSyntax ;
-            execOne( x, syntax );
-        }
-
-    }
-    
-    private String oneFile(String filename)
-    {
-        divider() ;
-        try
-        {
-            return FileUtils.readWholeFileAsUTF8(filename) ;
-        } catch (IOException ex)
-        {
-            System.err.println("No such file: "+filename) ;
-            return null ;
-        }
-    }
-    
-    private void execOne(String updateString, Syntax syntax)
-    {
-        UpdateRequest req ; 
-        try {
-            req = UpdateFactory.create(updateString, syntax) ;
-        } catch (QueryParseException ex)
-        {
-            System.err.print("Parse error: ") ;
-            System.err.println(ex.getMessage()) ;
-            return ; 
-        }
-        //req.output(IndentedWriter.stderr) ;
-        if ( printUpdate )
-            System.out.print(req) ;
-        
-        if ( printNone )
-            return ;
-        
-        // And some checking.
-        IndentedLineBuffer w = new IndentedLineBuffer() ;
-        UpdateWriter.output(req, w) ;
-        String updateString2 = w.asString() ;
-        UpdateRequest req2 = null ;
-        try {
-            req2 = UpdateFactory.create(updateString2, syntax) ;
-        } catch (QueryParseException ex)
-        {
-            System.err.println("Can not reparse update after serialization") ;
-            System.err.println(updateString2) ; 
-        }
-
-        if ( ! req.equalTo(req2) )
-            System.err.println("Reparsed update does not .equalTo original parsed request") ;
-        
-        
-    }
-    
-    static final String divider = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" ;
-    //static final String divider = "" ;
-    static boolean needDivider = false ;
-    private static void divider()
-    {
-        if ( needDivider ) System.out.println(divider) ;
-        needDivider = true ;
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/update.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/update.java b/jena-arq/src/main/java/arq/update.java
deleted file mode 100644
index 333d41a..0000000
--- a/jena-arq/src/main/java/arq/update.java
+++ /dev/null
@@ -1,128 +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 arq;
-
-import java.util.List ;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdException;
-
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.query.ReadWrite ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFDataMgr ;
-import org.apache.jena.sparql.SystemARQ ;
-import org.apache.jena.sparql.core.DatasetGraph ;
-import org.apache.jena.sparql.core.DatasetGraphFactory ;
-import org.apache.jena.sparql.core.Transactional ;
-import org.apache.jena.sparql.core.TransactionalNull ;
-import org.apache.jena.update.UpdateExecutionFactory ;
-import org.apache.jena.update.UpdateFactory ;
-import org.apache.jena.update.UpdateRequest ;
-
-import arq.cmdline.CmdUpdate ;
-
-public class update extends CmdUpdate
-{
-    static final ArgDecl updateArg = new ArgDecl(ArgDecl.HasValue, "update", "file") ;
-    static final ArgDecl dumpArg = new ArgDecl(ArgDecl.NoValue, "dump") ;       // Write the result to stdout.
-    
-    List<String> requestFiles = null ;
-    boolean dump = false ;
-    
-    public static void main (String... argv)
-    { new update(argv).mainRun() ; }
-    
-    protected update(String[] argv) {
-        super(argv) ;
-        super.add(updateArg, "--update=FILE", "Update commands to execute") ;
-        super.add(dumpArg, "--dump", "Dump the resulting graph store") ;
-    }
-
-    @Override
-    protected void processModulesAndArgs() {
-        requestFiles = getValues(updateArg) ; // ????
-        dump = contains(dumpArg) ;
-        super.processModulesAndArgs() ;
-    }
-
-    @Override
-    protected String getCommandName() { return Lib.className(this) ; }
-    
-    @Override
-    protected String getSummary() { return getCommandName()+" --desc=assembler [--dump] --update=<request file>" ; }
-
-    // Subclass for specialised commands making common updates more convenient
-    @Override
-    protected void execUpdate(DatasetGraph graphStore) {
-        if ( requestFiles.size() == 0 && getPositional().size() == 0 )
-            throw new CmdException("Nothing to do") ;
-
-        Transactional transactional = (graphStore instanceof Transactional) ? (Transactional)graphStore : new TransactionalNull() ;
-
-        for ( String filename : requestFiles ) {
-            try {
-                transactional.begin(ReadWrite.WRITE) ;
-                execOneFile(filename, graphStore) ;
-                transactional.commit() ;
-            }
-            catch (Throwable ex) { 
-                try { transactional.abort() ; } catch (Exception ex2) {}
-                throw ex ;
-            }
-            finally { transactional.end() ; }
-        }
-
-        for ( String requestString : super.getPositional() ) {
-            requestString = indirect(requestString) ;
-
-            try {
-                transactional.begin(ReadWrite.WRITE) ;
-                execOne(requestString, graphStore) ;
-                transactional.commit() ;
-            }
-            catch (Throwable ex) { 
-                try { transactional.abort() ; } catch (Exception ex2) {}
-                throw ex ;
-            }
-            finally { transactional.end() ; }
-        }
-        
-        if ( ! (graphStore instanceof Transactional) )
-            SystemARQ.sync(graphStore) ;
-
-        if ( dump )
-            RDFDataMgr.write(System.out, graphStore, Lang.NQUADS) ;
-    }
-
-    private void execOneFile(String filename, DatasetGraph store) {
-        UpdateRequest req = UpdateFactory.read(filename, updateSyntax) ;
-        UpdateExecutionFactory.create(req, store).execute() ;
-    }
-
-    private void execOne(String requestString, DatasetGraph store) {
-        UpdateRequest req = UpdateFactory.create(requestString, updateSyntax) ;
-        UpdateExecutionFactory.create(req, store).execute() ;
-    }
-
-    @Override
-    protected DatasetGraph dealWithNoDataset() {
-        return DatasetGraphFactory.create() ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/utf8.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/utf8.java b/jena-arq/src/main/java/arq/utf8.java
deleted file mode 100644
index bc47569..0000000
--- a/jena-arq/src/main/java/arq/utf8.java
+++ /dev/null
@@ -1,29 +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 arq;
-
-
-public class utf8
-{
-    /** Simple program to help hunt down bad UTF-8 encoded characters */
-    public static void main(String[] args)
-    {
-        riotcmd.utf8.main(args) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/version.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/version.java b/jena-arq/src/main/java/arq/version.java
deleted file mode 100644
index e55434c..0000000
--- a/jena-arq/src/main/java/arq/version.java
+++ /dev/null
@@ -1,29 +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 arq;
-
-import jena.cmd.ModVersion;
-
-public class version
-{
-    public static void main (String... argv)
-    {
-        new ModVersion(false).printVersionAndExit() ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/wwwdec.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/wwwdec.java b/jena-arq/src/main/java/arq/wwwdec.java
deleted file mode 100644
index 60a07c5..0000000
--- a/jena-arq/src/main/java/arq/wwwdec.java
+++ /dev/null
@@ -1,36 +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 arq;
-
-import org.apache.jena.atlas.lib.StrUtils ;
-
-public class wwwdec
-{
-    public static void main(String...args)
-    {
-        for ( String x : args)
-        {
-            String y = StrUtils.decodeHex(x, '%') ;
-            System.out.println(y) ;
-            
-//            String s2 = URLDecoder.decode(x, "utf-8") ;
-//            System.out.println(s2) ;   
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/wwwenc.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/wwwenc.java b/jena-arq/src/main/java/arq/wwwenc.java
deleted file mode 100644
index 4ee19af..0000000
--- a/jena-arq/src/main/java/arq/wwwenc.java
+++ /dev/null
@@ -1,61 +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 arq;
-
-import org.apache.jena.atlas.lib.StrUtils ;
-
-public class wwwenc
-{
-    /* http://en.wikipedia.org/wiki/Percent-encoding
-     * Reserved characters after percent-encoding 
-     *   !    *   "   '   (   )   ;   :   @   &   =   +   $   ,   /   ?   %   #   [   ]
-     *   %21  %2A %22 %27 %28 %29 %3B %3A %40 %26 %3D %2B %24 %2C %2F %3F %25 %23 %5B %5D
-     * These loose any reserved meaning if encoded.
-     *   
-     * Other common, but unreserved, characters after percent-encoding 
-     *   <   >   ~   .   {   }   |   \   -   `   _   ^
-     *   %3C %3E %7E %2E %7B %7D %7C %5C %2D %60 %5F %5E
-     * 
-     * Unreserved characters treated equivalent to their unencoded form.  
-     *   
-     *   
-     */
-    public static void main(String...args)
-    {
-        // Reserved characters + space
-        char reserved[] = 
-            {' ',
-             '\n','\t',
-             '!', '*', '"', '\'', '(', ')', ';', ':', '@', '&', 
-             '=', '+', '$', ',', '/', '?', '%', '#', '[', ']'} ;
-        
-        char[] other = {'<', '>', '~', '.', '{', '}', '|', '\\', '-', '`', '_', '^'} ;        
-        
-        for ( String x : args)
-        {
-            // Not URLEncoder which does www-form-encoding.
-            String y = StrUtils.encodeHex(x, '%', reserved) ;
-            System.out.println(y) ;
-            
-//            String s2 = URLEncoder.encode(s, "utf-8") ;
-//            System.out.println(s2) ;
-
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/riotcmd/CmdLangParse.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/riotcmd/CmdLangParse.java b/jena-arq/src/main/java/riotcmd/CmdLangParse.java
deleted file mode 100644
index 61f3b96..0000000
--- a/jena-arq/src/main/java/riotcmd/CmdLangParse.java
+++ /dev/null
@@ -1,361 +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 riotcmd;
-
-import java.io.IOException ;
-import java.io.InputStream ;
-import java.io.OutputStream ;
-import java.util.zip.GZIPOutputStream ;
-
-import arq.cmdline.ModLangOutput ;
-import arq.cmdline.ModLangParse ;
-import arq.cmdline.ModContext ;
-import arq.cmdline.ModTime ;
-import jena.cmd.ArgDecl ;
-import jena.cmd.CmdException;
-import jena.cmd.CmdGeneral ;
-import org.apache.jena.Jena ;
-import org.apache.jena.atlas.io.IO ;
-import org.apache.jena.atlas.lib.InternalErrorException ;
-import org.apache.jena.atlas.lib.Pair ;
-import org.apache.jena.atlas.web.ContentType ;
-import org.apache.jena.atlas.web.TypedInputStream ;
-import org.apache.jena.query.ARQ ;
-import org.apache.jena.riot.* ;
-import org.apache.jena.riot.lang.LabelToNode ;
-import org.apache.jena.riot.lang.StreamRDFCounting ;
-import org.apache.jena.riot.out.NodeToLabel ;
-import org.apache.jena.riot.process.inf.InfFactory ;
-import org.apache.jena.riot.process.inf.InferenceSetupRDFS ;
-import org.apache.jena.riot.system.* ;
-import org.apache.jena.riot.tokens.Tokenizer ;
-import org.apache.jena.riot.tokens.TokenizerFactory ;
-import org.apache.jena.sparql.core.DatasetGraph ;
-import org.apache.jena.sparql.core.DatasetGraphFactory ;
-import org.apache.jena.system.JenaSystem ;
-
-/** Common framework for running RIOT parsers */
-public abstract class CmdLangParse extends CmdGeneral
-{
-    static { JenaSystem.init(); }
-    protected ModTime modTime                   = new ModTime() ;
-    protected ModLangParse modLangParse         = new ModLangParse() ;
-    protected ModLangOutput modLangOutput       = new ModLangOutput() ;
-    protected InferenceSetupRDFS setup          = null ; 
-    protected ModContext modContext             = new ModContext() ;
-    protected ArgDecl strictDecl                = new ArgDecl(ArgDecl.NoValue, "strict") ;
-
-    protected boolean cmdStrictMode = false ; 
-    
-    interface LangHandler {
-        String getItemsName() ;
-        String getRateName() ;
-    }
-
-    static LangHandler langHandlerQuads = new LangHandler() {
-        @Override
-        public String getItemsName()        { return "quads" ; }
-        @Override
-        public String getRateName()         { return "QPS" ; }
-    } ;
-    static LangHandler langHandlerTriples = new LangHandler() {
-        @Override
-        public String getItemsName()        { return "triples" ; }
-        @Override
-        public String getRateName()         { return "TPS" ; }
-    } ;
-    static LangHandler langHandlerAny = new LangHandler() {
-        @Override
-        public String getItemsName()        { return "tuples" ; }
-        @Override
-        public String getRateName()         { return "TPS" ; }
-    } ;
-    
-    protected LangHandler langHandlerOverall = null ;
-
-    protected CmdLangParse(String[] argv)
-    {
-        super(argv) ;
-        addModule(modContext) ;
-        addModule(modTime) ;
-        addModule(modLangOutput) ;
-        addModule(modLangParse) ;
-        
-        super.modVersion.addClass(Jena.class) ;
-        // Force - sometimes initialization does not cause these
-        // to initialized early enough for reflection.
-        String x1 = ARQ.VERSION ;
-        String x2 = ARQ.BUILD_DATE ;
-        super.modVersion.addClass(RIOT.class) ;
-        
-    }
-
-    @Override
-    protected String getSummary() {
-        return getCommandName()+" [--time] [--check|--noCheck] [--sink] [--base=IRI] [--out=FORMAT] [--compress] file ..." ;
-    }
-
-    protected long totalMillis = 0 ; 
-    protected long totalTuples = 0 ; 
-    
-    OutputStream output = System.out ;
-    StreamRDF outputStream = null ;
-
-    @Override
-    protected void processModulesAndArgs() {
-        cmdStrictMode = super.contains(strictDecl) ;
-    }
-    
-    protected interface PostParseHandler { void postParse(); }
-    
-    @Override
-    protected void exec() {
-        boolean oldStrictValue = SysRIOT.isStrictMode() ;
-        if ( modLangParse.strictMode() )
-            SysRIOT.setStrictMode(true) ;
-        try { exec$() ; }
-        finally { SysRIOT.setStrictMode(oldStrictValue) ; } 
-    }
-    
-    protected void exec$() {
-        
-        if ( modLangParse.getRDFSVocab() != null )
-            setup = new InferenceSetupRDFS(modLangParse.getRDFSVocab()) ;
-     
-        if ( modLangOutput.compressedOutput() ) {
-            try { output = new GZIPOutputStream(output, true) ; }
-            catch (IOException e) { IO.exception(e);}
-        }
-            
-        outputStream = null ;
-        PostParseHandler postParse = null ;
-
-        outputStream = createStreamSink() ;
-        if ( outputStream == null ) {
-            Pair<StreamRDF, PostParseHandler> p = createAccumulateSink() ;
-            outputStream = p.getLeft() ;
-            postParse = p.getRight();
-        }
-        
-        try {
-            if ( super.getPositional().isEmpty() )
-                parseFile("-");
-            else {
-                boolean b = super.getPositional().size() > 1;
-                for ( String fn : super.getPositional() ) {
-                    if ( b && !super.isQuiet() )
-                        SysRIOT.getLogger().info("File: " + fn);
-                    parseFile(fn);
-                }
-            }
-            if ( postParse != null )
-                postParse.postParse();
-            if ( super.getPositional().size() > 1 && modTime.timingEnabled() )
-                output("Total", totalTuples, totalMillis, langHandlerOverall) ;
-        } finally {
-            if ( output != System.out )
-                IO.close(output) ;
-            else
-                IO.flush(output);    
-            System.err.flush() ;
-        }
-    }
-    
-    public void parseFile(String filename) {
-        TypedInputStream in = null ;
-        if ( filename.equals("-") ) {
-            in = new TypedInputStream(System.in) ;
-            parseFile("http://base/", "stdin", in) ;
-        } else {
-            try {
-                in = RDFDataMgr.open(filename) ;
-            } catch (Exception ex) {
-                System.err.println("Can't open '"+filename+"' "+ex.getMessage()) ;
-                return ;
-            }
-            parseFile(null, filename, in) ;
-            IO.close(in) ;
-            
-        }
-    }
-
-    public void parseFile(String defaultBaseURI, String filename, TypedInputStream in) {   
-        String baseURI = modLangParse.getBaseIRI() ;
-        if ( baseURI == null )
-            baseURI = defaultBaseURI ;
-        parseRIOT(baseURI, filename, in) ;
-    }
-    
-    protected abstract Lang selectLang(String filename, ContentType contentType, Lang dftLang  ) ;
-
-    protected void parseRIOT(String baseURI, String filename, TypedInputStream in) {
-        ContentType ct = in.getMediaType() ;
-        
-        baseURI = SysRIOT.chooseBaseIRI(baseURI, filename) ;
-        
-        boolean checking = true ;
-        if ( modLangParse.explicitChecking() )  checking = true ;
-        if ( modLangParse.explicitNoChecking() ) checking = false ;
-        
-        ErrorHandler errHandler = null ;
-        if ( checking )
-        {
-            if ( modLangParse.stopOnBadTerm() )
-                errHandler = ErrorHandlerFactory.errorHandlerStd  ;
-            else
-                // Try to go on if possible.  This is the default behaviour.
-                errHandler = ErrorHandlerFactory.errorHandlerWarn ;
-        }
-        
-        if ( modLangParse.skipOnBadTerm() )
-        {
-            // TODO skipOnBadterm
-        }
-        
-        Lang lang = selectLang(filename, ct, RDFLanguages.NQUADS) ;  
-        LangHandler handler = null ;
-        if ( RDFLanguages.isQuads(lang) )
-            handler = langHandlerQuads ;
-        else if ( RDFLanguages.isTriples(lang) )
-            handler = langHandlerTriples ;
-        else 
-            throw new CmdException("Undefined language: "+lang) ; 
-        
-        // If multiple files, choose the overall labels. 
-        if ( langHandlerOverall == null )
-            langHandlerOverall = handler ;
-        else
-        {
-            if ( langHandlerOverall != langHandlerAny )
-            {
-                if ( langHandlerOverall != handler )
-                    langHandlerOverall = langHandlerAny ;
-            }
-        }
-        
-        // Make a flag.
-        // Input and output subflags.
-        // If input is "label, then output using NodeToLabel.createBNodeByLabelRaw() ;
-        // else use NodeToLabel.createBNodeByLabel() ;
-        // Also, as URI.
-        final boolean labelsAsGiven = false ;
-
-        NodeToLabel labels = SyntaxLabels.createNodeToLabel() ;
-        if ( labelsAsGiven )
-            labels = NodeToLabel.createBNodeByLabelEncoded() ;
-        
-        StreamRDF s = outputStream ; 
-        if ( setup != null )
-            s = InfFactory.inf(s, setup) ;
-        StreamRDFCounting sink = StreamRDFLib.count(s) ;
-        s = null ;
-        
-        ReaderRIOT reader = RDFDataMgr.createReader(lang) ;
-        try {
-            if ( checking ) {
-                if ( lang == RDFLanguages.NTRIPLES || lang == RDFLanguages.NQUADS )
-                    reader.setParserProfile(RiotLib.profile(baseURI, false, true, errHandler)) ;
-                else
-                    reader.setParserProfile(RiotLib.profile(baseURI, true, true, errHandler)) ;
-            } else
-                reader.setParserProfile(RiotLib.profile(baseURI, false, false, errHandler)) ;
-
-            if ( labelsAsGiven )
-                reader.getParserProfile().setLabelToNode(LabelToNode.createUseLabelAsGiven()) ;
-            modTime.startTimer() ;
-            sink.start() ;
-            reader.read(in, baseURI, ct, sink, null) ;
-            sink.finish() ;
-        } catch (RiotException ex) {
-            // Should have handled the exception and logged a message by now.
-            // System.err.println("++++"+ex.getMessage());
-            if ( modLangParse.stopOnBadTerm() )
-                return ;
-        } finally {
-            // Not close the output - we may write again to the underlying output stream in another call to parse a file.  
-            IO.close(in) ;
-        }
-        long x = modTime.endTimer() ;
-        long n = sink.countTriples()+sink.countQuads() ;
-
-        if ( modTime.timingEnabled() )
-            output(filename, n, x, handler) ;
-        
-        totalMillis += x ;
-        totalTuples += n ;
-    }
-    
-    /** Create a streaming output sink if possible */
-    protected StreamRDF createStreamSink() {
-        if ( modLangParse.toBitBucket() )
-            return StreamRDFLib.sinkNull() ;
-        
-        RDFFormat fmt = modLangOutput.getOutputStreamFormat() ;
-        if ( fmt == null )
-            return null ;
-        /** Create an accumulating output stream for later pretty printing */        
-        return StreamRDFWriter.getWriterStream(output, fmt) ;
-    }
-    
-    /** Create an accumulating output stream for later pretty printing */
-    protected Pair<StreamRDF, PostParseHandler> createAccumulateSink() {
-        final DatasetGraph dsg = DatasetGraphFactory.create() ;
-        StreamRDF sink = StreamRDFLib.dataset(dsg) ;
-        final RDFFormat fmt = modLangOutput.getOutputFormatted() ;
-        PostParseHandler handler = new PostParseHandler() {
-            @Override
-            public void postParse() {
-                // Try as dataset, then as graph.
-                WriterDatasetRIOTFactory w = RDFWriterRegistry.getWriterDatasetFactory(fmt) ;
-                if ( w != null ) {
-                    RDFDataMgr.write(output, dsg, fmt) ;
-                    return ;
-                }
-                WriterGraphRIOTFactory wg = RDFWriterRegistry.getWriterGraphFactory(fmt) ;
-                if ( wg != null ) {
-                    RDFDataMgr.write(System.out, dsg.getDefaultGraph(), fmt) ;
-                    return ;
-                }
-                throw new InternalErrorException("failed to find the writer: "+fmt) ;  
-            }
-        } ;
-        return Pair.create(sink, handler) ;
-    }
-    
-    protected Tokenizer makeTokenizer(InputStream in) {
-        Tokenizer tokenizer = TokenizerFactory.makeTokenizerUTF8(in) ;
-        return tokenizer ;
-    }
-    
-    protected void output(String label, long numberTriples, long timeMillis, LangHandler handler) {
-        double timeSec = timeMillis/1000.0 ;
-        
-        System.out.flush() ;
-        System.err.printf("%s : %,5.2f sec  %,d %s  %,.2f %s\n",
-                          label,
-                          timeMillis/1000.0, numberTriples,
-                          handler.getItemsName(),
-                          timeSec == 0 ? 0.0 : numberTriples/timeSec,
-                          handler.getRateName()) ;
-    }
-    
-    protected void output(String label) {
-        System.err.printf("%s : \n", label) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/riotcmd/CmdTokens.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/riotcmd/CmdTokens.java b/jena-arq/src/main/java/riotcmd/CmdTokens.java
deleted file mode 100644
index d7c1340..0000000
--- a/jena-arq/src/main/java/riotcmd/CmdTokens.java
+++ /dev/null
@@ -1,75 +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 riotcmd;
-
-import java.io.InputStream ;
-
-import org.apache.jena.atlas.io.IO ;
-import org.apache.jena.atlas.lib.Timer ;
-import org.apache.jena.riot.tokens.Token ;
-import org.apache.jena.riot.tokens.Tokenizer ;
-import org.apache.jena.riot.tokens.TokenizerFactory ;
-
-public class CmdTokens
-{
-    
-    public static void tokens(final boolean print, final boolean timing, String...args)
-    {
-        // Turn the node cache off.
-        //com.hp.hpl.jena.graph.Node.cache(false) ;
-
-        if ( args.length == 0 )
-            args = new String[] {"-"} ;
-
-        String arg = args[0] ;
-
-        if ( arg.equals("--help") || arg.equals("-help") || arg.equals("-h") || arg.equals("--h") ) 
-        {
-            System.err.println("Usage: stdin | FILE ...") ;
-            System.exit(1) ;
-        }
-        for ( String filename : args )
-        {
-            InputStream in = IO.openFile(filename) ;
-            Tokenizer tokenize = TokenizerFactory.makeTokenizerUTF8(in) ;
-            Timer timer = new Timer() ;
-            long count = 0 ; 
-            timer.startTimer() ;
-            for ( ; tokenize.hasNext() ; )
-            {
-                Token t = tokenize.next() ;
-                if ( print )
-                    System.out.println(t) ;
-                count++ ;
-            }
-            tokenize.close();
-            long millis = timer.endTimer() ;
-            if ( timing )
-            {
-                if ( millis == 0 )
-                    System.out.printf("Tokens=%,d : Time=0.00s\n", count) ;
-                else
-                {
-                    double seconds = millis/1000.0 ;
-                    System.out.printf("Tokens=%,d : Time=%,.2fs : Rate=%,.2f\n", count, seconds, count/seconds) ;
-                }
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/riotcmd/dumpthrift.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/riotcmd/dumpthrift.java b/jena-arq/src/main/java/riotcmd/dumpthrift.java
deleted file mode 100644
index cfadd38..0000000
--- a/jena-arq/src/main/java/riotcmd/dumpthrift.java
+++ /dev/null
@@ -1,51 +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 riotcmd;
-
-import java.io.InputStream ;
-
-import org.apache.jena.atlas.io.IO ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.apache.jena.riot.thrift.BinRDF ;
-import org.apache.jena.system.JenaSystem ;
-
-/** Dump an rdf-thrift file to show structure */ 
-public class dumpthrift {
-    static { LogCtl.setCmdLogging(); }
-    static { JenaSystem.init() ; }
-    
-    public static void main(String[] args) {
-        if ( args.length == 0 ) {
-            args = new String[] {"-"} ;
-        }
-        
-        if ( args.length != 1 ) {
-            System.err.println("Usage: "+Lib.classShortName(dumpthrift.class)+" FILE") ;
-            System.exit(2) ;
-        }
-        
-        // Leave a general loop ...
-        for ( String fn : args ) {
-            InputStream in = IO.openFile(fn) ; 
-            BinRDF.dump(System.out, in) ;
-        }
-    }
-}    
-

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/riotcmd/infer.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/riotcmd/infer.java b/jena-arq/src/main/java/riotcmd/infer.java
deleted file mode 100644
index d9a2983..0000000
--- a/jena-arq/src/main/java/riotcmd/infer.java
+++ /dev/null
@@ -1,154 +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 riotcmd;
-
-import java.util.List ;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdException;
-import jena.cmd.CmdGeneral;
-
-import org.apache.jena.atlas.io.IO ;
-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.process.inf.InfFactory ;
-import org.apache.jena.riot.system.StreamRDF ;
-import org.apache.jena.riot.system.StreamRDFLib ;
-import org.apache.jena.util.FileManager ;
-
-/*
- * TDB Infer
- *   RDFS
- *   owl:sameAs (in T-Box, not A-Box)
- *   owl:equivalentClass, owl:equivalentProperty
- *   owl:TransitiveProperty, owl:SymmetricProperty
- *
- * OWLprime - Oracle
-- rdfs:domain
-- rdfs:range
-- rdfs:subClassOf
-- rdfs:subPropertyOf
-- owl:equivalentClass
-- owl:equivalentProperty
-- owl:sameAs
-- owl:inverseOf
-- owl:TransitiveProperty
-- owl:SymmetricProperty
-- owl:FunctionalProperty
-- owl:InverseFunctionalProperty
-
- JimH: RDFS3:
- #
-    * equivalentClass
-    * equivalentProperty
-    * sameAs
-    * differentFrom (and allDifferent) 
-
-# Property Characteristics:
-
-    * inverseOf
-    * TransitiveProperty
-    * SymmetricProperty
-    * FunctionalProperty
-    * InverseFunctionalProperty
-    * ObjectProperty
-    * DatatypeProperty
-    * disjointWith 
-
-AllegroGraph RDFS++
-    * rdf:type
-    * rdfs:subClassOf
-    * rdfs:domain and rdfs:range
-    * rdfs:subPropertyOf
-    * owl:sameAs
-    * owl:inverseOf
-    * owl:TransitiveProperty
- */
-public class infer extends CmdGeneral
-{
-    static final ArgDecl argRDFS = new ArgDecl(ArgDecl.HasValue, "rdfs") ;
-    private Model vocab ;
-    
-    public static void main(String... argv)
-    {
-        new infer(argv).mainRun() ;
-    }        
-
-    protected infer(String[] argv)
-    {
-        super(argv) ;
-        super.add(argRDFS) ;
-    }
-
-//    public static void expand(String filename, Model vocab)
-//    {
-//        Sink<Triple> sink = new SinkTripleOutput(System.out) ;
-//        sink = new InferenceExpanderRDFS(sink, vocab) ;
-//        RiotReader.parseTriples(filename, sink) ;
-//        IO.flush(System.out); 
-//    }
-
-    @Override
-    protected String getSummary()
-    {
-        return "infer --rdfs=vocab FILE ..." ;
-    }
-
-    @Override
-    protected void processModulesAndArgs()
-    {
-        if ( ! contains(argRDFS) )
-            throw new CmdException("Required argument missing: --"+argRDFS.getKeyName()) ;
-        String fn = getValue(argRDFS) ;
-        vocab = FileManager.get().loadModel(fn) ;
-    }
-
-    @Override
-    protected void exec()
-    {
-        StreamRDF sink = StreamRDFLib.writer(System.out) ;
-        sink = InfFactory.inf(sink, vocab) ;
-        
-        List<String> files = getPositionalOrStdin() ;
-        if ( files.isEmpty() )
-            files.add("-") ;
-            
-        for ( String fn : files )
-            processFile(fn, sink) ;
-        IO.flush(System.out); 
-    }
-
-    private void processFile(String filename, StreamRDF sink)
-    {
-        Lang lang = filename.equals("-") ? RDFLanguages.NQUADS : RDFLanguages.filenameToLang(filename, RDFLanguages.NQUADS) ;
-
-        if ( filename.equals("-") )
-            RDFDataMgr.parse(sink, System.in, null, RDFLanguages.NQUADS, null) ;
-        else
-            RDFDataMgr.parse(sink, filename) ;
-    }
-
-    @Override
-    protected String getCommandName()
-    {
-        return "infer" ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/riotcmd/json.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/riotcmd/json.java b/jena-arq/src/main/java/riotcmd/json.java
deleted file mode 100644
index 1c77073..0000000
--- a/jena-arq/src/main/java/riotcmd/json.java
+++ /dev/null
@@ -1,52 +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 riotcmd;
-
-import org.apache.jena.atlas.io.IndentedWriter ;
-import org.apache.jena.atlas.json.JSON ;
-import org.apache.jena.atlas.json.JsonParseException ;
-import org.apache.jena.atlas.json.JsonValue ;
-
-/** Command to read and print JSON */
-public class json
-{
-    public static void main(String... args)
-    {
-        if ( args.length == 0 )
-            args = new String[] {"-"} ;
-
-        try {
-            for ( String fn : args )
-            {
-                JsonValue json =null ;
-                try {
-                 json = JSON.readAny(fn) ;
-                } catch (JsonParseException ex)
-                {
-                    String name = fn.equals("-") ? "<stdin>" : fn ; 
-                    System.err.println(name+": "+JsonParseException.formatMessage(ex.getMessage(), ex.getLine(), ex.getColumn())) ;
-                    continue ;
-                }
-                JSON.write(IndentedWriter.stdout, json) ;
-                IndentedWriter.stdout.ensureStartOfLine() ;
-            }
-        } finally { IndentedWriter.stdout.flush() ; }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/riotcmd/nquads.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/riotcmd/nquads.java b/jena-arq/src/main/java/riotcmd/nquads.java
deleted file mode 100644
index d76cf96..0000000
--- a/jena-arq/src/main/java/riotcmd/nquads.java
+++ /dev/null
@@ -1,48 +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 riotcmd;
-
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.web.ContentType ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFLanguages ;
-
-/** Run the N-Quads parser - and produce N-Quads */
-public class nquads extends CmdLangParse
-{
-    public static void main(String... argv)
-    {
-        new nquads(argv).mainRun() ;
-    }    
-    
-    protected nquads(String[] argv)
-    {
-        super(argv) ;
-    }
-
-    @Override
-    protected String getCommandName()
-    {
-        return Lib.classShortName(nquads.class) ;
-    }
-    
-    @Override
-    protected Lang selectLang(String filename  , ContentType contentType  , Lang lang  ) 
-    { return RDFLanguages.NQUADS ; }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/riotcmd/ntriples.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/riotcmd/ntriples.java b/jena-arq/src/main/java/riotcmd/ntriples.java
deleted file mode 100644
index dd20e82..0000000
--- a/jena-arq/src/main/java/riotcmd/ntriples.java
+++ /dev/null
@@ -1,48 +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 riotcmd;
-
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.web.ContentType ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFLanguages ;
-
-/** Run the N-triples parser - and produce N-triples */
-public class ntriples extends CmdLangParse
-{
-    public static void main(String... argv)
-    {
-        new ntriples(argv).mainRun() ;
-    }        
-
-    protected ntriples(String[] argv)
-    {
-        super(argv) ;
-    }
-    
-    @Override
-    protected String getCommandName()
-    {
-        return Lib.classShortName(ntriples.class) ;
-    }
-    
-    @Override
-    protected Lang selectLang(String filename  , ContentType contentType  , Lang lang  ) 
-    { return RDFLanguages.NTRIPLES ; }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/riotcmd/perftokens.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/riotcmd/perftokens.java b/jena-arq/src/main/java/riotcmd/perftokens.java
deleted file mode 100644
index 8da571e..0000000
--- a/jena-arq/src/main/java/riotcmd/perftokens.java
+++ /dev/null
@@ -1,28 +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 riotcmd;
-
-
-public class perftokens
-{
-    public static void main(String...args)
-    {
-        CmdTokens.tokens(false, true, args) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/riotcmd/printtokens.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/riotcmd/printtokens.java b/jena-arq/src/main/java/riotcmd/printtokens.java
deleted file mode 100644
index 4be74bb..0000000
--- a/jena-arq/src/main/java/riotcmd/printtokens.java
+++ /dev/null
@@ -1,28 +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 riotcmd;
-
-
-public class printtokens
-{
-    public static void main(String...args)
-    {
-        CmdTokens.tokens(true, false, args) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/riotcmd/rdfxml.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/riotcmd/rdfxml.java b/jena-arq/src/main/java/riotcmd/rdfxml.java
deleted file mode 100644
index d4346da..0000000
--- a/jena-arq/src/main/java/riotcmd/rdfxml.java
+++ /dev/null
@@ -1,48 +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 riotcmd;
-
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.web.ContentType ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFLanguages ;
-
-/** Run the RDf/XML parser - and produce triples */
-public class rdfxml extends CmdLangParse
-{
-    public static void main(String... argv)
-    {
-        new rdfxml(argv).mainRun() ;
-    }    
-    
-    protected rdfxml(String[] argv)
-    {
-        super(argv) ;
-    }
-
-    @Override
-    protected String getCommandName()
-    {
-        return Lib.classShortName(rdfxml.class) ;
-    }
-    
-    @Override
-    protected Lang selectLang(String filename  , ContentType contentType  , Lang lang  ) 
-    { return RDFLanguages.RDFXML ; }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/riotcmd/riot.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/riotcmd/riot.java b/jena-arq/src/main/java/riotcmd/riot.java
deleted file mode 100644
index 1bf8cf6..0000000
--- a/jena-arq/src/main/java/riotcmd/riot.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 riotcmd;
-
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.web.ContentType ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFLanguages ;
-import org.apache.jena.riot.WebContent ;
-
-/**
- * Guess the syntax from the filename. 
- */
-public class riot extends CmdLangParse
-{
-    public static void main(String... argv)
-    {
-        new riot(argv).mainRun() ;
-    }        
-
-    protected riot(String[] argv)
-    {
-        super(argv) ;
-    }
-    
-    @Override
-    protected Lang selectLang(String filename, ContentType contentType, Lang dftLang)
-    {
-        if ( modLangParse.getLang() != null )
-            return modLangParse.getLang() ;
-        
-        if ( contentType != null && ! WebContent.matchContentType(WebContent.ctTextPlain, contentType) )
-            return RDFLanguages.contentTypeToLang(contentType) ;
-
-        Lang lang =  RDFLanguages.filenameToLang(filename) ;
-        if ( lang == null )
-            lang = dftLang ;
-        return lang ;
-    }
-
-    @Override
-    protected String getCommandName()
-    {
-        return Lib.classShortName(riot.class) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/riotcmd/trig.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/riotcmd/trig.java b/jena-arq/src/main/java/riotcmd/trig.java
deleted file mode 100644
index 08a24df..0000000
--- a/jena-arq/src/main/java/riotcmd/trig.java
+++ /dev/null
@@ -1,48 +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 riotcmd;
-
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.web.ContentType ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFLanguages ;
-
-/** Run the TriG parser - and produce N-Quads */
-public class trig extends CmdLangParse
-{
-    public static void main(String... argv)
-    {
-        new trig(argv).mainRun() ;
-    }    
-    
-    protected trig(String[] argv)
-    {
-        super(argv) ;
-    }
-
-    @Override
-    protected String getCommandName()
-    {
-        return Lib.classShortName(trig.class) ;
-    }
-
-    @Override
-    protected Lang selectLang(String filename  , ContentType contentType  , Lang lang  ) 
-    { return RDFLanguages.TRIG ; }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/riotcmd/turtle.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/riotcmd/turtle.java b/jena-arq/src/main/java/riotcmd/turtle.java
deleted file mode 100644
index 776803b..0000000
--- a/jena-arq/src/main/java/riotcmd/turtle.java
+++ /dev/null
@@ -1,48 +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 riotcmd;
-
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.web.ContentType ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFLanguages ;
-
-/** Run the Turtle parser - and produce N-triples */
-public class turtle extends CmdLangParse
-{
-    public static void main(String... argv)
-    {
-        new turtle(argv).mainRun() ;
-    }    
-    
-    protected turtle(String[] argv)
-    {
-        super(argv) ;
-    }
-
-    @Override
-    protected String getCommandName()
-    {
-        return Lib.classShortName(turtle.class) ;
-    }
-
-    @Override
-    protected Lang selectLang(String filename  , ContentType contentType  , Lang dftLang  ) 
-    { return RDFLanguages.TURTLE ; }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/riotcmd/utf8.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/riotcmd/utf8.java b/jena-arq/src/main/java/riotcmd/utf8.java
deleted file mode 100644
index 1fa5598..0000000
--- a/jena-arq/src/main/java/riotcmd/utf8.java
+++ /dev/null
@@ -1,75 +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 riotcmd;
-
-import java.io.InputStream ;
-
-import org.apache.jena.atlas.AtlasException ;
-import org.apache.jena.atlas.io.IO ;
-import org.apache.jena.atlas.io.InStreamUTF8 ;
-import org.apache.jena.atlas.io.InputStreamBuffered ;
-
-public class utf8
-{
-    /** Simple program to help hunt down bad UTF-8 encoded characters */
-    public static void main(String[] args) {
-        long INIT_LINE = 1 ;
-        long INIT_COL = 1 ;
-
-        if ( args.length == 0 )
-            args = new String[]{"-"} ;
-
-        String label = "" ;
-        for ( String fn : args ) {
-            if ( args.length > 1 )
-                label = fn + ": " ;
-            InputStream in = IO.openFile(fn) ;
-            in = new InputStreamBuffered(in) ;
-
-            long charCount = 0 ;
-            long lineNum = INIT_LINE ;
-            long colNum = INIT_COL ;
-
-            InStreamUTF8 utf8 = null ;
-            try {
-                utf8 = new InStreamUTF8(in) ;
-                for ( ; ; ) {
-                    int ch = utf8.read() ;
-                    if ( ch == -1 )
-                        break ;
-                    charCount++ ;
-                    if ( ch == '\n' ) {
-                        lineNum++ ;
-                        colNum = INIT_COL ;
-                    } else
-                        colNum++ ;
-                    if ( !Character.isDefined(ch) )
-                        throw new AtlasException(String.format("No such codepoint: 0x%04X", ch)) ;
-                }
-                System.out.printf("%s: chars = %d , lines = %d\n", fn, charCount, lineNum) ;
-            }
-            catch (AtlasException ex) {
-                System.out.printf(label + "[line=%d, col=%d] %s\n", lineNum, colNum, ex.getMessage()) ;
-            }
-            finally {
-                IO.close(utf8) ;
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/test/java/arq/TS_Cmd.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/arq/TS_Cmd.java b/jena-arq/src/test/java/arq/TS_Cmd.java
deleted file mode 100644
index 53a47eb..0000000
--- a/jena-arq/src/test/java/arq/TS_Cmd.java
+++ /dev/null
@@ -1,31 +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 arq;
-
-import org.junit.runner.RunWith ;
-import org.junit.runners.Suite ;
-import org.junit.runners.Suite.SuiteClasses ;
-
-@RunWith(Suite.class)
-@SuiteClasses( {
-    TestCmdLine.class
-})
-
-public class TS_Cmd
-{}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/test/java/arq/TestCmdLine.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/arq/TestCmdLine.java b/jena-arq/src/test/java/arq/TestCmdLine.java
deleted file mode 100644
index a421b21..0000000
--- a/jena-arq/src/test/java/arq/TestCmdLine.java
+++ /dev/null
@@ -1,104 +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 arq;
-import java.util.Iterator ;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdLineArgs;
-
-import org.apache.jena.atlas.junit.BaseTest ;
-import org.junit.Test ;
-
-public class TestCmdLine extends BaseTest
-{
-    @Test public void test_Simple1()
-    {
-        String args[] = new String[]{""} ;
-        CmdLineArgs cl = new CmdLineArgs(args) ;
-        cl.process() ;
-    }
-    
-    @Test public void test_Flag1()
-    {
-        String args[] = new String[]{ ""} ;
-        CmdLineArgs cl = new CmdLineArgs(args) ;
-        ArgDecl argA = new ArgDecl(false, "-a") ;
-        cl.add(argA) ;
-        cl.process() ;
-        assertTrue("-a argument found" , ! cl.contains(argA) ) ; 
-    }
-    
-    @Test public void test_Flag2()
-    {
-        String args[] = new String[]{ "-a"} ;
-        CmdLineArgs cl = new CmdLineArgs(args) ;
-        ArgDecl argA = new ArgDecl(false, "-a") ;
-        cl.add(argA) ;
-        cl.process() ;
-        assertTrue("No -a argument found" , cl.contains(argA) ) ; 
-    }
-
-    @Test public void test_Flag3()
-    {
-        String args[] = new String[]{ "-a", "filename"} ;
-        CmdLineArgs cl = new CmdLineArgs(args) ;
-        ArgDecl argA = new ArgDecl(false, "-a") ;
-        cl.add(argA) ;
-        cl.process() ;
-        assertTrue("No -a argument found" , cl.contains(argA) ) ; 
-    }
-    
-    @Test public void test_Arg1()
-    {
-        String args[] = new String[]{ ""} ;
-        CmdLineArgs cl = new CmdLineArgs(args) ;
-        ArgDecl argA = new ArgDecl(true, "-arg") ;
-        cl.add(argA) ;
-        cl.process() ;
-        assertTrue("-arg argument found" , ! cl.contains(argA) ) ; 
-    }
-    
-    @Test public void test_Arg2()
-    {
-        String args[] = new String[]{ "-arg=ARG", "filename"} ;
-        CmdLineArgs cl = new CmdLineArgs(args) ;
-        ArgDecl argA = new ArgDecl(true, "arg") ;
-        cl.add(argA) ;
-        cl.process() ;
-        assertTrue("No -arg= argument found" , cl.contains(argA) ) ; 
-        assertEquals("", cl.getValue(argA) , "ARG") ;
-        assertEquals("", cl.getArg("arg").getValue() , "ARG") ;
-    }
-    
-    @Test public void test_nArg1()
-    {
-        String args[] = new String[]{ "-arg=V1", "--arg=V2", "-v"} ;
-        CmdLineArgs cl = new CmdLineArgs(args) ;
-        ArgDecl argA = new ArgDecl(true, "-arg") ;
-        cl.add(argA) ;
-        ArgDecl argV = new ArgDecl(false, "-v") ;
-        cl.add(argV) ;
-        cl.process() ;
-        assertTrue("No -arg= argument found" , cl.contains(argA) ) ;
-        
-        Iterator<String> iter = cl.getValues("arg").iterator() ;
-        assertEquals("Argument 1", iter.next() , "V1") ;
-        assertEquals("Argument 2", iter.next() , "V2") ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/test/java/arq/qtest.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/arq/qtest.java b/jena-arq/src/test/java/arq/qtest.java
deleted file mode 100644
index 87a9d32..0000000
--- a/jena-arq/src/test/java/arq/qtest.java
+++ /dev/null
@@ -1,274 +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 arq;
-
-import java.io.File ;
-
-import arq.cmdline.CmdARQ ;
-import arq.cmdline.ModEngine ;
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdException;
-import jena.cmd.TerminationException;
-import junit.framework.TestSuite ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.query.ARQ ;
-import org.apache.jena.rdf.model.Literal ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.rdf.model.Resource ;
-import org.apache.jena.sparql.ARQTestSuite ;
-import org.apache.jena.sparql.expr.E_Function ;
-import org.apache.jena.sparql.expr.NodeValue ;
-import org.apache.jena.sparql.junit.EarlReport ;
-import org.apache.jena.sparql.junit.ScriptTestSuiteFactory ;
-import org.apache.jena.sparql.junit.SimpleTestRunner ;
-import org.apache.jena.sparql.util.NodeFactoryExtra ;
-import org.apache.jena.sparql.vocabulary.DOAP ;
-import org.apache.jena.sparql.vocabulary.FOAF ;
-import org.apache.jena.sparql.vocabulary.TestManifest ;
-import org.apache.jena.vocabulary.DC ;
-import org.apache.jena.vocabulary.DCTerms ;
-import org.apache.jena.vocabulary.RDF ;
-import org.apache.jena.vocabulary.XSD ;
-
-
-/** A program to execute query test suites
- * 
- * <pre>
- * Usage: 
- *   [--all]
- *   [--dawg]
- *   <i>testManifest</i>
- *   [ --query <i>query</i> --data <i>data</i> --result <i>result</i> ] -- run one test
- * </pre>
- */
-
-public class qtest extends CmdARQ
-{
-    protected ArgDecl allDecl =    new ArgDecl(ArgDecl.NoValue, "all") ;
-    protected ArgDecl wgDecl =     new ArgDecl(ArgDecl.NoValue, "wg", "dawg") ;
-    protected ArgDecl queryDecl =  new ArgDecl(ArgDecl.HasValue, "query") ;
-    protected ArgDecl dataDecl =   new ArgDecl(ArgDecl.HasValue, "data") ;
-    protected ArgDecl resultDecl = new ArgDecl(ArgDecl.HasValue, "result") ;
-    protected ArgDecl earlDecl =   new ArgDecl(ArgDecl.NoValue, "earl") ;
-    
-    protected ModEngine modEngine = null ;
-    
-    protected TestSuite suite = null;
-    protected boolean execAllTests = false;
-    protected boolean execDAWGTests = false;
-    protected String testfile = null;
-    protected boolean createEarlReport = false;
-    
-    public static void main (String... argv)
-    {
-        try {
-            new qtest(argv).mainRun() ;
-        }
-        catch (TerminationException ex) { System.exit(ex.getCode()) ; }
-    }
-    
-    public qtest(String[] argv)
-    {
-        super(argv) ;
-        
-        modEngine = setModEngine() ;
-        addModule(modEngine) ;
-        
-        getUsage().startCategory("Tests (single query)") ;
-        add(queryDecl, "--query", "run the given query") ;
-        add(dataDecl, "--data", "data file to be queried") ;
-        add(resultDecl, "--result", "file that specifies the expected result") ;
-        
-        getUsage().startCategory("Tests (built-in tests)") ;
-        add(allDecl, "--all", "run all built-in tests") ;
-        add(wgDecl, "--dawg", "run working group tests") ;
-        
-        getUsage().startCategory("Tests (execute test manifest)") ;
-        getUsage().addUsage("<manifest>", "run the tests specified in the given manifest") ;
-        add(earlDecl, "--earl", "create EARL report") ;
-    }
-    
-    protected ModEngine setModEngine()
-    {
-        return new ModEngine() ;
-    }
-    
-    @Override
-    protected String getCommandName() { return Lib.className(this) ; }
-    
-    @Override
-    protected String getSummary() { return getCommandName()+" [ --data=<file> --query=<query> --result=<results> ] | --all | --dawg | <manifest>" ; }
-    
-    @Override
-    protected void processModulesAndArgs()
-    {
-        super.processModulesAndArgs() ;
-        
-        if ( contains(queryDecl) || contains(dataDecl) || contains(resultDecl) )
-        {
-            if ( ! ( contains(queryDecl) && contains(dataDecl) && contains(resultDecl) ) )
-                throw new CmdException("Must give query, data and result to run a single test") ;
-            
-            String query = getValue(queryDecl) ;
-            String data = getValue(dataDecl) ;
-            String result = getValue(resultDecl) ;
-            
-            suite = ScriptTestSuiteFactory.make(query, data, result) ;
-        }
-        else if ( contains(allDecl) )
-        {
-            execAllTests = true ;
-        }
-        else if ( contains(wgDecl) )
-        {
-            execDAWGTests = true ;
-        }
-        else
-        {
-            // OK - running a manifest
-            
-            if ( ! hasPositional() )
-                throw new CmdException("No manifest file") ;
-
-            testfile = getPositionalArg(0) ;
-            createEarlReport = contains(earlDecl) ;
-        }
-    }
-    
-    @Override
-    protected void exec()
-    {
-        if ( cmdStrictMode )
-            ARQ.setStrictMode() ;
-        
-        if ( suite != null )
-            SimpleTestRunner.runAndReport(suite) ;
-        else if ( execAllTests )
-            allTests() ;
-        else if ( execDAWGTests )
-            dawgTests() ;
-        else
-        {
-            // running a manifest
-            
-            NodeValue.VerboseWarnings = false ;
-            E_Function.WarnOnUnknownFunction = false ;
-            
-            if ( createEarlReport )
-                oneManifestEarl(testfile) ;
-            else
-                oneManifest(testfile) ;
-        }
-    }
-    
-    static void oneManifest(String testManifest)
-    {
-        TestSuite suite = ScriptTestSuiteFactory.make(testManifest) ;
-
-        //junit.textui.TestRunner.run(suite) ;
-        SimpleTestRunner.runAndReport(suite) ;
-    }
-    
-    static void oneManifestEarl(String testManifest)
-    {
-        String name =  "ARQ" ;
-        String releaseName =  "ARQ" ;
-        String version = "2.9.1" ;
-        String homepage = "http://jena.apache.org/" ;
-        String systemURI = "http://jena.apache.org/#arq" ;  // Null for bNode.
-        
-        // Include information later.
-        EarlReport report = new EarlReport(systemURI, name, version, homepage) ;
-        ScriptTestSuiteFactory.results = report ;
-        
-        Model model = report.getModel() ;
-        model.setNsPrefix("dawg", TestManifest.getURI()) ;
-        
-        // Update the EARL report. 
-        Resource jena = model.createResource()
-                    .addProperty(FOAF.homepage, model.createResource("http://jena.apache.org/")) ;
-        
-        // ARQ is part fo Jena.
-        Resource arq = report.getSystem()
-                        .addProperty(DCTerms.isPartOf, jena) ;
-        
-        // Andy wrote the test software (updates the thing being tested as well as they are the same). 
-        Resource who = model.createResource(FOAF.Person)
-                                .addProperty(FOAF.name, "Andy Seaborne")
-                                .addProperty(FOAF.homepage, 
-                                             model.createResource("http://people.apache.org/~andy")) ;
-        
-        Resource reporter = report.getReporter() ;
-        reporter.addProperty(DC.creator, who) ;
-
-        model.setNsPrefix("doap", DOAP.getURI()) ; 
-        model.setNsPrefix("xsd", XSD.getURI()) ;
-        
-        // DAWG specific stuff.
-        Resource system = report.getSystem() ;
-        system.addProperty(RDF.type, DOAP.Project) ;
-        system.addProperty(DOAP.name, name) ;
-        system.addProperty(DOAP.homepage, homepage) ;
-        system.addProperty(DOAP.maintainer, who) ;
-        
-        Resource release = model.createResource(DOAP.Version) ;
-        system.addProperty(DOAP.release, release) ;
-        
-        Node today_node = NodeFactoryExtra.todayAsDate() ;
-        Literal today = model.createTypedLiteral(today_node.getLiteralLexicalForm(), today_node.getLiteralDatatype()) ;
-        release.addProperty(DOAP.created, today) ;
-        release.addProperty(DOAP.name, releaseName) ;      // Again
-        
-        TestSuite suite = ScriptTestSuiteFactory.make(testManifest) ;
-        SimpleTestRunner.runSilent(suite) ;
-        
-        ScriptTestSuiteFactory.results.getModel().write(System.out, "TTL") ;
-        
-    }
-    
-    static void allTests()
-    {
-        // This should load all the built in tests.
-        // Check to see if expected directories are present or not.
-        
-        ensureDirExists("testing") ;
-        ensureDirExists("testing/ARQ") ;
-        ensureDirExists("testing/DAWG") ;
-        
-        TestSuite ts = ARQTestSuite.suite() ;
-        junit.textui.TestRunner.run(ts) ;
-        //SimpleTestRunner.runAndReport(ts) ;
-    }
-
-    static void dawgTests()
-    {
-        System.err.println("DAWG tests not packaged up yet") ;
-    }
-    
-    static void ensureDirExists(String dirname)
-    {
-        File f = new File(dirname) ;
-        if ( ! f.exists() || !f.isDirectory() )
-        {
-            System.err.println("Can't find required directory: '"+dirname+"'") ;
-            throw new TerminationException(8) ;
-        }
-    }
- }

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/test/java/org/apache/jena/sparql/ARQTestSuite.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/ARQTestSuite.java b/jena-arq/src/test/java/org/apache/jena/sparql/ARQTestSuite.java
index c3c2639..f40d8eb 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/ARQTestSuite.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/ARQTestSuite.java
@@ -18,7 +18,6 @@
 
 package org.apache.jena.sparql;
 
-import arq.TS_Cmd ;
 import junit.framework.JUnit4TestAdapter ;
 import junit.framework.TestSuite ;
 import org.apache.jena.atlas.legacy.BaseTest2 ;
@@ -60,7 +59,6 @@ public class ARQTestSuite extends TestSuite
         ts.addTest(new JUnit4TestAdapter(TC_Common.class)) ;
         ts.addTest(new JUnit4TestAdapter(TC_Riot.class)) ;
 
-        ts.addTest(new JUnit4TestAdapter(TS_Cmd.class)) ;
         ts.addTest(new JUnit4TestAdapter(TS_Web.class)) ;
         
         // Main ARQ internal test suite.


[20/20] jena git commit: JENA-1108: Merge pull request https://github.com/apache/jena/pull/118

Posted by an...@apache.org.
JENA-1108: Merge pull request https://github.com/apache/jena/pull/118

This closes #118.


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

Branch: refs/heads/master
Commit: 216209190640eb646a05f95f2f78afd50b42dbb2
Parents: ff7f361
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Jan 5 12:38:36 2016 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Jan 5 12:39:07 2016 +0000

----------------------------------------------------------------------

----------------------------------------------------------------------



[05/20] jena git commit: JENA-1108 : jena-cmds module

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/main/java/jena/turtle.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/jena/turtle.java b/jena-core/src/main/java/jena/turtle.java
deleted file mode 100644
index 36557eb..0000000
--- a/jena-core/src/main/java/jena/turtle.java
+++ /dev/null
@@ -1,29 +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 jena;
-
-
-
-public class turtle
-{
-    public static void main(String... args)
-    {
-        InvokingUtil.invokeCmd("riotcmd.turtle",args) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/main/java/jena/version.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/jena/version.java b/jena-core/src/main/java/jena/version.java
deleted file mode 100644
index ea47d66..0000000
--- a/jena-core/src/main/java/jena/version.java
+++ /dev/null
@@ -1,49 +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 jena;
-
-import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
-
-import java.lang.reflect.*;
-
-import org.apache.jena.Jena ;
-
-/**
- * jena.version
- * Print out jena version information and exit.
- */
-public class version implements Jena {
-
-    static { setCmdLogging(); }
-
-    /**
-	 * Print out jena version information and exit.
-	 * @param args
-	 * @throws IllegalAccessException 
-	 * @throws IllegalArgumentException 
-	 */
-	public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException {
-		Field f[] = Jena.class.getDeclaredFields();
-        for ( Field aF : f )
-        {
-            System.out.println( aF.getName() + ": " + aF.get( null ) );
-        }
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/test/java/jena/test/TestPackage.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/jena/test/TestPackage.java b/jena-core/src/test/java/jena/test/TestPackage.java
deleted file mode 100644
index 67de969..0000000
--- a/jena-core/src/test/java/jena/test/TestPackage.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
-///////////////
-package jena.test;
-
-
-// Imports
-///////////////
-import junit.framework.TestSuite;
-
-
-
-
-/**
- * <p>
- * Suite of tests for command line utilities
- * </p>
- */
-public class TestPackage
-    extends TestSuite
-{
-    static public TestSuite suite() {
-        return new TestPackage();
-    }
-
-    /** Creates new TestPackage */
-    private TestPackage() {
-        super("cmdline");
-        addTest( new TestSuite( Test_schemagen.class  ) );
-        addTest( new TestSuite( Test_rdfcat.class ));
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/test/java/jena/test/Test_rdfcat.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/jena/test/Test_rdfcat.java b/jena-core/src/test/java/jena/test/Test_rdfcat.java
deleted file mode 100644
index 1e2a589..0000000
--- a/jena-core/src/test/java/jena/test/Test_rdfcat.java
+++ /dev/null
@@ -1,269 +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 jena.test;
-
-import java.io.*;
-import java.util.*;
-
-import jena.rdfcat;
-import junit.framework.TestCase;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.rdf.model.ModelFactory ;
-
-@SuppressWarnings("deprecation")
-public class Test_rdfcat extends TestCase
-{
-    // Switch off the banner during testing.
-    @Override
-    public void setUp() {
-        jena.rdfcat.suppressDeprecationBanner = true ;
-    }
-    
-    @Override
-    public void tearDown() {
-        jena.rdfcat.suppressDeprecationBanner = false ;
-    }
-    
-    public void testAbbreviationTable()
-        {
-        assertEquals( "RDF/XML", jena.rdfcat.unabbreviate.get( "x" ) );
-        assertEquals( "RDF/XML", jena.rdfcat.unabbreviate.get( "rdf" ) );
-        assertEquals( "RDF/XML", jena.rdfcat.unabbreviate.get( "rdfxml" ) );
-        assertEquals( "RDF/XML", jena.rdfcat.unabbreviate.get( "xml" ) );
-        assertEquals( "N3", jena.rdfcat.unabbreviate.get( "n3" ) );
-        assertEquals( "N3", jena.rdfcat.unabbreviate.get( "n" ) );
-        assertEquals( "N3", jena.rdfcat.unabbreviate.get( "ttl" ) );
-        assertEquals( "N-TRIPLE", jena.rdfcat.unabbreviate.get( "ntriples" ) );
-        assertEquals( "N-TRIPLE", jena.rdfcat.unabbreviate.get( "ntriple" ) );
-        assertEquals( "N-TRIPLE", jena.rdfcat.unabbreviate.get( "t" ) );
-        assertEquals( "RDF/XML-ABBREV", jena.rdfcat.unabbreviate.get( "owl" ) );
-        assertEquals( "RDF/XML-ABBREV", jena.rdfcat.unabbreviate.get( "abbrev" ) );
-        }
-
-    public void testExistingLanguage()
-        {
-        assertEquals( "RDF/XML", jena.rdfcat.getCheckedLanguage( "x" ) );
-        assertEquals( "RDF/XML", jena.rdfcat.getCheckedLanguage( "xml" ) );
-        assertEquals( "RDF/XML-ABBREV", jena.rdfcat.getCheckedLanguage( "owl" ) );
-        assertEquals( "N3", jena.rdfcat.getCheckedLanguage( "N3" ) );
-        assertEquals( "N-TRIPLE", jena.rdfcat.getCheckedLanguage( "N-TRIPLE" ) );
-        }
-
-    public void testNonexistantLanguage()
-        {
-        try
-            { jena.rdfcat.getCheckedLanguage( "noSuchLanguageAsThisOneFruitcake" );
-            fail( "should trap non-existant language" ); }
-        catch (IllegalArgumentException e)
-            {
-            assertTrue( "message should mention bad language", e.getMessage().indexOf( "Fruitcake" ) > 0 );
-            }
-        }
-
-    /**
-     * Test the identity transform - RDF/XML to RDF/XML
-     */
-    public void testRdfcatIdentity() {
-        Model source = ModelFactory.createDefaultModel();
-        source.read( "file:testing/cmd/rdfcat.xml", "RDF/XML" );
-
-        OutputStream so = new ByteArrayOutputStream();
-
-        rdfcatFixture rc = new rdfcatFixture( so );
-        rc.testGo( new String[] {"file:testing/cmd/rdfcat.xml"} );
-
-        Model output = asModel( so, "RDF/XML" );
-        assertTrue( output.isIsomorphicWith( source ));
-    }
-
-    /**
-     * Test the basic concatenation
-     */
-    public void testRdfcatConcat() {
-        Model source = ModelFactory.createDefaultModel();
-        source.read( "file:testing/cmd/rdfcat.xml", "RDF/XML" );
-
-        OutputStream so = new ByteArrayOutputStream();
-
-        rdfcatFixture rc = new rdfcatFixture( so );
-        rc.testGo( new String[] {"file:testing/cmd/rdfcat_1.xml", "file:testing/cmd/rdfcat_2.xml"} );
-
-        Model output = asModel( so, "RDF/XML" );
-        assertTrue( output.isIsomorphicWith( source ));
-    }
-
-    /**
-     * Change the default input language
-     */
-    public void testRdfcatConcat1() {
-        Model source = ModelFactory.createDefaultModel();
-        source.read( "file:testing/cmd/rdfcat.xml", "RDF/XML" );
-
-        OutputStream so = new ByteArrayOutputStream();
-
-        rdfcatFixture rc = new rdfcatFixture( so );
-        rc.testGo( new String[] {"-in", "N3", "file:testing/cmd/rdfcat_1_n3", "file:testing/cmd/rdfcat_2_n3"} );
-
-        Model output = asModel( so, "RDF/XML" );
-        assertTrue( output.isIsomorphicWith( source ));
-    }
-
-    public void testRdfcatN3ToRDFXML_0() {
-        doTestRdfcatOutput( "-n", "file:testing/cmd/rdfcat.n3", "RDF/XML", "RDF/XML" );
-    }
-
-    public void testRdfcatN3ToRDFXML_1() {
-        doTestRdfcatOutput( "-n3", "file:testing/cmd/rdfcat.n3", "RDF/XML", "RDF/XML" );
-    }
-
-    public void testRdfcatN3ToRDFXML_2() {
-        doTestRdfcatOutput( "-ttl", "file:testing/cmd/rdfcat.n3", "RDF/XML", "RDF/XML" );
-    }
-
-    public void testRdfcatN3ToRDFXML_3() {
-        doTestRdfcatOutput( "-N3", "file:testing/cmd/rdfcat.n3", "RDF/XML", "RDF/XML" );
-    }
-
-    public void testRdfcatN3ToNtriple() {
-        doTestRdfcatOutput( "-n", "file:testing/cmd/rdfcat.n3", "N-TRIPLE", "N-TRIPLE" );
-    }
-
-    public void testRdfcatN3ToN3() {
-        doTestRdfcatOutput( "-n", "file:testing/cmd/rdfcat.n3", "N3", "N3" );
-    }
-
-    public void testRdfcatN3ToRDFXMLDefault() {
-        doTestRdfcatOutput( null, "file:testing/cmd/rdfcat.n3", "RDF/XML", "RDF/XML" );
-    }
-
-
-    public void testRdfcatRDFXMLToRDFXML_0() {
-        doTestRdfcatOutput( "-x", "file:testing/cmd/rdfcat.xml", "RDF/XML", "RDF/XML" );
-    }
-
-    public void testRdfcatRDFXMLToRDFXML_1() {
-        doTestRdfcatOutput( "-xml", "file:testing/cmd/rdfcat.xml", "RDF/XML", "RDF/XML" );
-    }
-
-    public void testRdfcatRDFXMLToRDFXML_2() {
-        doTestRdfcatOutput( "-rdfxml", "file:testing/cmd/rdfcat.xml", "RDF/XML", "RDF/XML" );
-    }
-
-    public void testRdfcatRDFXMLToRDFXML_3() {
-        doTestRdfcatOutput( "-rdf", "file:testing/cmd/rdfcat.xml", "RDF/XML", "RDF/XML" );
-    }
-
-    public void testRdfcatRDFXMLToNtriple() {
-        doTestRdfcatOutput( "-x", "file:testing/cmd/rdfcat.xml", "N-TRIPLE", "N-TRIPLE" );
-    }
-
-    public void testRdfcatRDFXMLToN3() {
-        doTestRdfcatOutput( "-x", "file:testing/cmd/rdfcat.xml", "N3", "N3" );
-    }
-
-    public void testRdfcatRDFXMLToRDFXMLDefault() {
-        doTestRdfcatOutput( null, "file:testing/cmd/rdfcat.xml", "RDF/XML", "RDF/XML" );
-    }
-
-
-    public void testRdfcatNtripleToRDFXML_0() {
-        doTestRdfcatOutput( "-t", "file:testing/cmd/rdfcat.nt", "RDF/XML", "RDF/XML" );
-    }
-
-    public void testRdfcatNtripleToRDFXML_1() {
-        doTestRdfcatOutput( "-ntriple", "file:testing/cmd/rdfcat.nt", "RDF/XML", "RDF/XML" );
-    }
-
-    public void testRdfcatNtripleToRDFXML_2() {
-        doTestRdfcatOutput( "-ntriples", "file:testing/cmd/rdfcat.nt", "RDF/XML", "RDF/XML" );
-    }
-
-    public void testRdfcatNtripleToRDFXML_3() {
-        doTestRdfcatOutput( "-n-triple", "file:testing/cmd/rdfcat.nt", "RDF/XML", "RDF/XML" );
-    }
-
-    public void testRdfcatNtripleToNtriple() {
-        doTestRdfcatOutput( "-t", "file:testing/cmd/rdfcat.nt", "N-TRIPLE", "N-TRIPLE" );
-    }
-
-    public void testRdfcatNtripleToN3() {
-        doTestRdfcatOutput( "-t", "file:testing/cmd/rdfcat.nt", "N3", "N3" );
-    }
-
-    public void testRdfcatNtripleToRDFXMLDefault() {
-        doTestRdfcatOutput( null, "file:testing/cmd/rdfcat.nt", "RDF/XML", "RDF/XML" );
-    }
-
-    /**
-     * Utility to do a basic cat operation
-     */
-    public void doTestRdfcatOutput( String inFormArg, String inputArg, String outFormArg, String parseAs ) {
-        Model source = ModelFactory.createDefaultModel();
-        source.read( "file:testing/cmd/rdfcat.xml" );
-
-        OutputStream so = new ByteArrayOutputStream();
-
-        rdfcatFixture rc = new rdfcatFixture( so );
-
-        List<String> l = new ArrayList<>();
-        if (outFormArg != null) {
-            l.add(  "-out" );
-            l.add(  outFormArg );
-        }
-        if (inFormArg != null) l.add( inFormArg );
-        l.add( inputArg );
-
-        String[] args = new String[l.size()];
-        for (int i = 0; i < l.size(); i++) {
-            args[i] = l.get(i);
-        }
-        // use file extension guessing
-        rc.testGo( args );
-
-        Model output = asModel( so, parseAs );
-        assertTrue( output.isIsomorphicWith( source ));
-    }
-
-    /** Convert an output stream holding a model content to a model */
-    protected Model asModel( OutputStream so, String syntax ) {
-        String out = so.toString();
-        Model output = ModelFactory.createDefaultModel();
-        output.read( new StringReader( out ), "http://example.com/foo", syntax );
-        return output;
-    }
-
-    /**
-     * A minimal extension to rdfcat to provide a test fixture
-     */
-    protected class rdfcatFixture
-        extends rdfcat
-    {
-        private OutputStream m_so;
-        protected rdfcatFixture( OutputStream so ) {
-            m_so = so;
-        }
-        @Override
-        protected OutputStream getOutputStream() {
-            return m_so;
-        }
-        protected void testGo( String[] args ) {
-            go( args );
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/test/java/jena/test/Test_schemagen.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/jena/test/Test_schemagen.java b/jena-core/src/test/java/jena/test/Test_schemagen.java
deleted file mode 100644
index 5188005..0000000
--- a/jena-core/src/test/java/jena/test/Test_schemagen.java
+++ /dev/null
@@ -1,798 +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
-///////////////
-package jena.test;
-
-
-// Imports
-///////////////
-import java.io.*;
-import java.lang.reflect.Method;
-import java.util.*;
-import java.util.regex.Pattern;
-
-import jena.schemagen;
-import jena.schemagen.SchemagenOptionsImpl;
-import junit.framework.TestCase;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.util.FileUtils ;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * <p>
- * Unit tests for schemagen
- * </p>
- */
-public class Test_schemagen
-    extends TestCase
-{
-    // Constants
-    //////////////////////////////////
-
-    String PREFIX = "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n" +
-            "@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n" +
-            "@prefix owl: <http://www.w3.org/2002/07/owl#> .\n" +
-            "@prefix ex: <http://example.com/sg#> .\n";
-
-    // Static variables
-    //////////////////////////////////
-
-    private static Logger log = LoggerFactory.getLogger( Test_schemagen.class );
-
-    // Instance variables
-    //////////////////////////////////
-
-    // Constructors
-    //////////////////////////////////
-
-    // External signature methods
-    //////////////////////////////////
-
-    /** This test used to fail with an abort, but we now guess the NS based on prevalence */
-    public void testNoBaseURI0() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {},
-                             new String[] {".*public static final Resource A =.*"},
-                             new String[] {} );
-    }
-
-    public void testClass0() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl"},
-                             new String[] {".*public static final Resource A.*"},
-                             new String[] {} );
-    }
-
-    public void testClass1() throws Exception {
-        String SOURCE = PREFIX + "ex:A a rdfs:Class .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl"},
-                             new String[] {},
-                             new String[] {".*public static final Resource A.*"} );
-    }
-
-    public void testClass2() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--rdfs"},
-                             new String[] {},
-                             new String[] {".*public static final Resource A.*"} );
-    }
-
-    public void testClass3() throws Exception {
-        String SOURCE = PREFIX + "ex:A a rdfs:Class .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--rdfs"},
-                             new String[] {".*public static final Resource A.*"},
-                             new String[] {} );
-    }
-
-    public void testProperty0() throws Exception {
-        String SOURCE = PREFIX + "ex:p a owl:ObjectProperty .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl"},
-                             new String[] {".*public static final Property p.*"},
-                             new String[] {} );
-    }
-
-    public void testProperty1() throws Exception {
-        String SOURCE = PREFIX + "ex:p a rdf:Property .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl"},
-                             // in OWL mode we permit rdf:properties
-                             new String[] {".*public static final Property p.*"},
-                             new String[] {} );
-    }
-
-    public void testProperty2() throws Exception {
-        String SOURCE = PREFIX + "ex:p a owl:ObjectProperty .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--rdfs"},
-                             new String[] {},
-                             new String[] {".*public static final Property p.*"} );
-    }
-
-    public void testProperty3() throws Exception {
-        String SOURCE = PREFIX + "ex:p a rdf:Property .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--rdfs"},
-                             new String[] {".*public static final Property p.*"},
-                             new String[] {} );
-    }
-
-    public void testInstance0() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl"},
-                             new String[] {".*public static final Resource i.*"},
-                             new String[] {} );
-    }
-
-    public void testInstance1() throws Exception {
-        String SOURCE = PREFIX + "ex:A a rdfs:Class . ex:i a ex:A .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl"},
-                             new String[] {".*public static final Resource i.*"},
-                             new String[] {} );
-    }
-
-    /* TODO this test fails, because the isInstance check in schemagen is quite weak.
-     * Consider whether to fix the test or the code... *
-    public void testInstance2() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--rdfs"},
-                             new String[] {},
-                             new String[] {".*public static final Resource i.*"} );
-    }
-    */
-
-    public void testInstance3() throws Exception {
-        String SOURCE = PREFIX + "ex:A a rdfs:Class . ex:i a ex:A .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--rdfs"},
-                             new String[] {".*public static final Resource i.*"},
-                             new String[] {} );
-    }
-
-    /** Bug report by Brian: instance is in the namespace, but the class itself is not */
-    public void testInstance4() throws Exception {
-        String SOURCE = PREFIX + "@prefix ex2: <http://example.org/otherNS#>. ex2:A a rdfs:Class . ex:i a ex2:A .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--rdfs"},
-                             new String[] {".*public static final Resource i.*"},
-                             new String[] {} );
-    }
-
-    /** Bug report by Brian: instances not being recognised */
-    public void testInstance5() throws Exception {
-        String SOURCE = "@prefix :        <http://ontology.earthster.org/eco/impact#> .\n" +
-                "@prefix core:    <http://ontology.earthster.org/eco/core#> .\n" +
-                "@prefix ecoinvent:  <http://ontology.earthster.org/eco/ecoinvent#> .\n" +
-                "@prefix owl:     <http://www.w3.org/2002/07/owl#> .\n" +
-                "@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n" +
-                "@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .\n" +
-                "@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .\n" +
-                "\n" +
-                "<http://ontology.earthster.org/eco/impact>\n" +
-                "      rdf:type owl:Ontology ;\n" +
-                "      owl:imports <http://ontology.earthster.org/eco/ecoinvent> , <http://ontology.earthster.org/eco/core> ;\n" +
-                "      owl:versionInfo \"Created with TopBraid Composer\"^^xsd:string .\n" +
-                "\n" +
-                ":CD-CML2001-AbioticDepletion\n" +
-                "      rdf:type core:ImpactAssessmentMethodCategoryDescription ;\n" +
-                "      rdfs:label \"abiotic resource depletion\"^^xsd:string ;\n" +
-                "      core:hasImpactCategory\n" +
-                "              :abioticDepletion .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"--owl", "--inference"},
-                             new String[] {".*public static final Resource CD_CML2001_AbioticDepletion.*"},
-                             new String[] {".*valtype.*"} );
-    }
-
-    public void testDatatype0() throws Exception {
-        String SOURCE = PREFIX + "ex:d a rdfs:Datatype . ex:d rdfs:comment \"custom datatype\" .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl"},
-                             new String[] {".*public static final Resource d.*"},
-                             new String[] {} );
-    }
-    
-    public void testDatatype1() throws Exception {
-        String SOURCE = PREFIX + "ex:d a rdfs:Datatype . ex:d rdfs:comment \"custom datatype\" .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl", "--nodatatypes"},
-                             new String[] {},
-                             new String[] {".*public static final Resource d.*"} );
-    }
-    
-    /** Bug report by Richard Cyganiak */
-    public void testRC0() throws Exception {
-        String SOURCE = PREFIX + "ex:class a owl:Class .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl"},
-                             new String[] {},
-                             new String[] {".*public static final Resource class .*"} );
-    }
-
-
-    public void testComment0() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class ; rdfs:comment \"commentcomment\" .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl"},
-                             new String[] {" */\\*\\* <p>commentcomment</p> \\*/ *"},
-                             new String[] {} );
-    }
-
-    public void testComment1() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class ; rdfs:comment \"commentcomment\" .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl", "--nocomments"},
-                             new String[] {},
-                             new String[] {" */\\*\\* <p>commentcomment</p> \\*/ *"} );
-    }
-
-    public void testComment2() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class ; rdfs:comment \"commentcomment\" .";
-
-        // we don't want the input fixed to be http://example.com/sg
-        SchemaGenAux sga = new SchemaGenAux() {
-            @Override
-            protected void go( String[] args ) {
-                go( new SchemagenOptionsImpl( args ) );
-            }
-        };
-        testSchemagenOutput( SOURCE, sga,
-                             new String[] {"-a", "http://example.com/sg#", "--owl", "-i", "file:\\\\C:\\Users\\fubar/vocabs/test.ttl"},
-                             new String[] {".*Vocabulary definitions from file:\\\\\\\\C:\\\\Users\\\\fubar/vocabs/test.ttl.*"},
-                             new String[] {} );
-    }
-
-    public void testComment3() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class ; rdfs:comment \"commentcomment\" .";
-
-        // we don't want the input fixed to be http://example.com/sg
-        SchemaGenAux sga = new SchemaGenAux() {
-            @Override
-            protected void go( String[] args ) {
-                go( new SchemagenOptionsImpl( args ) );
-            }
-        };
-        testSchemagenOutput( SOURCE, sga,
-                             new String[] {"-a", "http://example.com/sg#", "--owl", "-i", "C:\\Users\\fubar/vocabs/test.ttl"},
-                             new String[] {".*Vocabulary definitions from C:\\\\Users\\\\fubar/vocabs/test.ttl.*"},
-                             new String[] {} );
-    }
-
-    public void testOntClass0() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl", "--ontology"},
-                             new String[] {".*public static final OntClass A.*"},
-                             new String[] {} );
-    }
-
-    public void testOntClass1() throws Exception {
-        String SOURCE = PREFIX + "ex:A a rdfs:Class .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl", "--ontology"},
-                             new String[] {},
-                             new String[] {".*public static final OntClass A.*"} );
-    }
-
-    public void testOntClass2() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--rdfs", "--ontology"},
-                             new String[] {},
-                             new String[] {".*public static final OntClass A.*"} );
-    }
-
-    public void testOntClass3() throws Exception {
-        String SOURCE = PREFIX + "ex:A a rdfs:Class .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--rdfs", "--ontology"},
-                             new String[] {".*public static final OntClass A.*"},
-                             new String[] {} );
-    }
-
-    public void testOntProperty0() throws Exception {
-        String SOURCE = PREFIX + "ex:p a owl:ObjectProperty .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl", "--ontology"},
-                             new String[] {".*public static final ObjectProperty p.*"},
-                             new String[] {} );
-    }
-
-    public void testOntProperty1() throws Exception {
-        String SOURCE = PREFIX + "ex:p a rdf:Property .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl", "--ontology"},
-                             // in OWL mode we permit rdf:properties
-                             new String[] {".*public static final OntProperty p.*"},
-                             new String[] {} );
-    }
-
-    public void testOntProperty2() throws Exception {
-        String SOURCE = PREFIX + "ex:p a owl:ObjectProperty .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--rdfs", "--ontology"},
-                             new String[] {},
-                             new String[] {".*public static final ObjectProperty p.*"} );
-    }
-
-    public void testOntProperty3() throws Exception {
-        String SOURCE = PREFIX + "ex:p a rdf:Property .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--rdfs", "--ontology"},
-                             new String[] {".*public static final OntProperty p.*"},
-                             new String[] {} );
-    }
-
-    public void testHeader() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--ontology", "--header", "/* header */\n%package%\n%imports%\n"},
-                             new String[] {"/\\* header \\*/"},
-                             new String[] {} );
-    }
-
-    public void testFooter() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--ontology", "--footer", "/* footer */"},
-                             new String[] {"/\\* footer \\*/"},
-                             new String[] {} );
-    }
-
-    public void testPackage() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--ontology", "--package", "test.test"},
-                             new String[] {"package test.test;\\s*"},
-                             new String[] {} );
-    }
-
-    public void testClassname() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class .";
-        SchemaGenAux fixture = new SchemaGenAux() {
-            @Override
-            protected void go( String[] args ) {
-                SchemagenOptionsFixture sgf = new SchemagenOptionsFixture( args ) {
-                    @Override
-                    public Resource getInputOption() {
-                        return ResourceFactory.createResource( "http://example.org/soggy" );
-                    }
-                };
-                go( sgf );
-            }
-        };
-
-        testSchemagenOutput( SOURCE, fixture,
-                             new String[] {"-a", "http://example.com/soggy#", "--ontology", "--package", "test.test", "-n", "Sg"},
-                             new String[] {},
-                             new String[] {} );
-    }
-
-    public void testClassdec() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--ontology", "--classdec", "\n    implements java.lang.Cloneable\n"},
-                             new String[] {"\\s*implements java.lang.Cloneable\\s*"},
-                             new String[] {} );
-    }
-
-    public void testDeclarations() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--ontology", "--declarations", "protected String m_gnole = \"Fungle\";;\n"},
-                             new String[] {".*Fungle.*"},
-                             new String[] {} );
-    }
-
-    public void testNoClasses() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--ontology", "--noclasses"},
-                             new String[] {},
-                             new String[] {".*OntClass A.*"} );
-    }
-
-    public void testNoProperties() throws Exception {
-        String SOURCE = PREFIX + "ex:p a owl:ObjectProperty .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl", "--ontology", "--noproperties"},
-                             new String[] {},
-                             new String[] {".*Property p.*"} );
-    }
-
-    public void testNoIndividuals() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl", "--noindividuals"},
-                             new String[] {".*Resource A.*"},
-                             new String[] {".*Resource i.*"} );
-    }
-
-    public void testNoHeader() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl", "--noheader"},
-                             new String[] {},
-                             new String[] {"/\\*\\*.*"} );
-    }
-
-    public void testUCNames() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl", "--uppercase"},
-                             new String[] {".*Resource A.*",".*Resource I.*"},
-                             new String[] {} );
-    }
-
-    public void testInference0() throws Exception {
-        String SOURCE = PREFIX + "ex:p rdfs:domain ex:A .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl"},
-                             new String[] {},
-                             new String[] {".*Resource A.*",".*Property p.*"} );
-    }
-
-    public void testInference1() throws Exception {
-        String SOURCE = PREFIX + "ex:p rdfs:domain ex:A .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl", "--inference"},
-                             new String[] {".*Resource A.*",".*Property p.*"},
-                             new String[] {} );
-    }
-
-    public void testInference2() throws Exception {
-        String SOURCE = PREFIX + "ex:p rdfs:domain ex:A .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--rdfs", "--inference"},
-                             new String[] {".*Resource A.*",".*Property p.*"},
-                             new String[] {} );
-    }
-
-    public void testStrictIndividuals0() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A . <http://example.com/different#j> a ex:A .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--rdfs"},
-                             new String[] {".*Resource i.*",".*Resource j.*"},
-                             new String[] {} );
-    }
-
-    public void testStrictIndividuals1() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A . <http://example.com/different#j> a ex:A .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--rdfs", "--strictIndividuals"},
-                             new String[] {".*Resource i.*"},
-                             new String[] {".*Resource j.*"} );
-    }
-
-    public void testLineEnd0() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A . ex:p a rdf:Property .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--rdfs", "--strictIndividuals"},
-                             new String[] {},
-                             new String[] {".*\r.*"} );
-    }
-
-    public void testLineEnd1() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A . ex:p a rdf:Property .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--rdfs", "--dos"},
-                             new String[] {".*\\r"},
-                             new String[] {".*[^\r]"} );
-    }
-
-    public void testIncludeSource0() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class . ex:i a ex:A . ex:p a owl:ObjectProperty .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl", "--includeSource"},
-                             new String[] {".*private static final String SOURCE.*",
-                                            ".*ex:A *(a|rdf:type) *owl:Class.*"} ,
-                             new String[] {} );
-    }
-
-    public void testIncludeSource1() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class ; rdfs:comment \"comment\".";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-a", "http://example.com/sg#", "--owl", "--includeSource"},
-                             new String[] {".*\\\\\"comment\\\\\".*\""},
-                             new String[] {} );
-    }
-
-
-    public void testIncludeSource2() throws Exception {
-        // had a report of the following not compiling ....
-        String SOURCE = PREFIX + "@prefix skos: <http://www.w3.org/2004/02/skos/core#>.\n" +
-                       " <http://purl.org/dc/elements/1.1/relation> skos:note \"\"\"A second property with the same name as this property has been declared in the dcterms: namespace (http://purl.org/dc/terms/).  See the Introduction to the document \"DCMI Metadata Terms\" (http://dublincore.org/documents/dcmi-terms/) for an explanation.\"\"\".";
-
-        testSchemagenOutput( SOURCE, null,
-                new String[] {"-a", "http://example.com/sg#", "--owl", "--includeSource"},
-                new String[] {},
-                new String[] {} );
-
-    }
-
-    public void testIncludeSource3() throws Exception {
-        // multiple literals on one line can cause double-quote issues
-        String SOURCE = PREFIX +
-                       " ex:foo a ex:Foo; rdfs:label \"thing called foo\"@en, \"le foo\"@fr, \"das foo\"@de. ";
-
-        testSchemagenOutput( SOURCE, null,
-                new String[] {"-a", "http://example.com/sg#", "--rdfs", "--includeSource"},
-                new String[] {},
-                new String[] {} );
-
-    }
-
-    public void testConfigFile() throws Exception {
-        String SOURCE = PREFIX + "ex:A a owl:Class .";
-        testSchemagenOutput( SOURCE, null,
-                             new String[] {"-c", "testing/cmd/sg-test-config.rdf"},
-                             new String[] {".*OntClass.*"}, // if config is not processed, we will not get --ontology output
-                             new String[] {} );
-
-    }
-
-    // Internal implementation methods
-    //////////////////////////////////
-
-    /**
-     * Test the output from schemagen by saving the output to a string,
-     * then ensuring that every positive regex matches at least one line, and
-     * every negative regex matches at most no lines. Also checks that
-     * compiling the file does not cause any errors.
-     *
-     * @param source String defining the model, using N3
-     * @param sg The schemagen object to test, or null for a default
-     * @param args list of args to pass to SG
-     * @param posPatterns array of regexps that must match at least once in the output
-     * @param negPatterns arrays of regexps that must not match the output
-     * @return The string defining the java class
-     */
-    protected String testSchemagenOutput( String source, SchemaGenAux sg, String[] args,
-                                          String[] posPatterns, String[] negPatterns )
-        throws Exception
-    {
-        Model m = ModelFactory.createDefaultModel();
-        m.read(  new StringReader( source ), "http://example.com/sg#", "N3" );
-        return testSchemagenOutput( m, sg, args, posPatterns, negPatterns );
-    }
-
-    /**
-     * Test the output from schemagen by saving the output to a string,
-     * then ensuring that every positive regex matches at least one line, and
-     * every negative regex matches at most no lines. Also checks that
-     * compiling the file does not cause any errors.
-     *
-     * @param m Source model to read from
-     * @param sg The schemagen object to test, or null for a default
-     * @param args list of args to pass to SG
-     * @param posPatterns array of regexps that must match at least once in the output
-     * @param negPatterns arrays of regexps that must not match the output
-     * @return The string defining the java class
-     */
-    protected String testSchemagenOutput( Model m, SchemaGenAux sg, String[] args,
-                                          String[] posPatterns, String[] negPatterns )
-        throws Exception
-    {
-        sg = (sg == null) ? new SchemaGenAux() : sg;
-        sg.setSource( m );
-
-        ByteArrayOutputStream buf = new ByteArrayOutputStream();
-        sg.setOutput( new PrintStream( buf ) );
-
-        // run schemagen
-        sg.testGo( args );
-
-        // now run the test pattern over the lines in the file
-        String result = buf.toString();
-//        if (log.isDebugEnabled()) {
-//            log.debug(  result );
-//        }
-        StringTokenizer tokens = new StringTokenizer( result, "\n" );
-
-        boolean[] foundPos = new boolean[posPatterns.length];
-
-        // look for any line that matches the patterns
-        while (tokens.hasMoreTokens()) {
-            String line = tokens.nextToken();
-
-            // try each positive pattern
-            for (int i = 0; i < posPatterns.length; i++) {
-                Pattern pat = Pattern.compile( posPatterns[i] );
-                foundPos[i] |= pat.matcher( line ).matches();
-            }
-
-            // try each negative pattern
-            for ( String negPattern : negPatterns )
-            {
-                Pattern pat = Pattern.compile( negPattern );
-                assertFalse( "negative match pattern ||" + negPattern + "|| matched on line: " + line,
-                             pat.matcher( line ).matches() );
-            }
-        }
-
-        for (int i = 0; i < posPatterns.length; i++) {
-            String msg = "Expecting a positive match to pattern: ||" + posPatterns[i] + "||";
-            assertTrue( msg + " in:\n" + result, foundPos[i] );
-        }
-
-        // check that the file compiles with javac
-        testCompile( result, "Sg" );
-
-        return result;
-    }
-
-    /**
-     * Test the compilability of the generated output string by saving it to a
-     * class file, and invoking javac on that file.
-     * @param source
-     * @param className
-     * @throws Exception
-     */
-    protected void testCompile( String source, String defaultClassName )
-        throws Exception
-    {
-        String className = defaultClassName;
-
-        // ensure we use the right class name for the temp file
-        // should do this with a regex, but java Pattern & Matcher is borked
-        String key = "public class ";
-        int i = source.indexOf( key );
-        if (i > 0) {
-            i += key.length();
-            className = source.substring( i, source.indexOf( " ", i ) );
-        }
-
-        // first write the source file to a temp dir
-        File tmpDir = FileUtils.getScratchDirectory( "schemagen" );
-        File srcFile = new File( tmpDir, className + ".java" );
-        try ( FileWriter out = new FileWriter( srcFile ) ) {
-            out.write( source );
-        }
-
-        // now get ready to invoke javac using the new javax.tools package
-        try {
-            Class<?> tp = Class.forName(  "javax.tools.ToolProvider" );
-
-            // static method to get the Java compiler tool
-            Method gsjc = tp.getMethod( "getSystemJavaCompiler" );
-            Object sjc = gsjc.invoke( null );
-
-            // get the run method for the Java compiler tool
-            Class<?> jc = Class.forName( "javax.tools.JavaCompiler" );
-            Method jcRun = jc.getMethod( "run", new Class[] {InputStream.class, OutputStream.class, OutputStream.class, String[].class} );
-
-            if (sjc != null && jcRun != null) {
-                // build the args list for javac
-                String[] args = new String[] {"-classpath", getClassPath( tmpDir ), "-d", tmpDir.getPath(), srcFile.getPath()};
-
-                int success = (Integer) jcRun.invoke( sjc, null, null, null, args );
-                assertEquals( "Errors reported from compilation of schemagen output", 0, success );
-            }
-            else {
-                log.debug( "Could not resolve javax.tools.JavaCompiler.run() method. Is the CLASSPATH defined correctly?" );
-            }
-        }
-        catch (ClassNotFoundException nf) {
-            log.debug( "javax.tools not found (no tools.jar on classpath?). schemagen compilation test skipped." );
-        }
-        catch (Exception e) {
-            log.debug( e.getMessage(), e );
-            fail( e.getMessage() );
-        }
-
-        // clean up
-        List<File> toClean = new ArrayList<>();
-        toClean.add( tmpDir );
-
-        while (!toClean.isEmpty()) {
-            File f = toClean.remove( 0 );
-            f.deleteOnExit();
-
-            if (f.isDirectory()) {
-                for (File g: f.listFiles()) {toClean.add( g );}
-            }
-        }
-    }
-
-    /**
-     * Return the classpath we can use to compile the sg output files
-     * @param tmpDir
-     * @return
-     */
-    protected String getClassPath( File tmpDir ) {
-        Properties pp = System.getProperties();
-        // if we're running under maven, use Special Secret Knowledge to identify the class path
-        // otherwise, default to the CP that Java thinks it's using
-        return pp.getProperty( "surefire.test.class.path", pp.getProperty( "java.class.path" ) );
-    }
-
-    //==============================================================================
-    // Inner class definitions
-    //==============================================================================
-
-    /**
-     * An extension to standard schemagen to create a test fixture; we override the
-     * input and output methods.
-     */
-    static class SchemaGenAux
-        extends schemagen
-    {
-        protected PrintStream m_auxOutput;
-        protected Model m_auxSource;
-        public void setOutput( PrintStream out ) {
-            m_auxOutput = out;
-        }
-        public void setSource( Model m ) {
-            m_auxSource = m;
-        }
-
-        // override the behaviours from schemagen
-        @Override
-        protected void selectInput() {
-            m_source.add( m_auxSource );
-            m_source.setNsPrefixes( m_auxSource );
-        }
-        @Override
-        protected void selectOutput() {
-            // call super to allow option processing
-            super.selectOutput();
-            // then override the result
-            m_output = m_auxOutput;
-        }
-
-        public void testGo( String[] args ) {
-            go( args );
-        }
-
-        @Override
-        protected void go( String[] args ) {
-            go( new SchemagenOptionsFixture( args ) );
-        }
-
-        @Override
-        protected void abort( String msg, Exception e ) {
-            throw new RuntimeException( msg, e );
-        }
-    }
-
-    static class SchemagenOptionsFixture
-        extends SchemagenOptionsImpl
-    {
-
-        public SchemagenOptionsFixture( String[] args ) {
-            super( args );
-        }
-
-        @Override
-        public Resource getInputOption() {
-            return ResourceFactory.createResource( "http://example.org/sg" );
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/src/test/java/org/apache/jena/test/TestPackage.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/org/apache/jena/test/TestPackage.java b/jena-core/src/test/java/org/apache/jena/test/TestPackage.java
index 6b8e973..80a2694 100644
--- a/jena-core/src/test/java/org/apache/jena/test/TestPackage.java
+++ b/jena-core/src/test/java/org/apache/jena/test/TestPackage.java
@@ -57,7 +57,6 @@ public class TestPackage extends TestCase {
         addTest(ts,  "Reasoners", org.apache.jena.reasoner.test.TestPackage.suite());
         addTest(ts,  "Composed graphs", org.apache.jena.graph.compose.test.TestPackage.suite() );
         addTest(ts,  "Ontology", org.apache.jena.ontology.impl.TestPackage.suite() );
-        addTest(ts,  "cmd line utils", jena.test.TestPackage.suite() );
         return ts ;
     }
 

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/testing/cmd/README_LICENSE
----------------------------------------------------------------------
diff --git a/jena-core/testing/cmd/README_LICENSE b/jena-core/testing/cmd/README_LICENSE
deleted file mode 100644
index bb80806..0000000
--- a/jena-core/testing/cmd/README_LICENSE
+++ /dev/null
@@ -1,16 +0,0 @@
-The following statement applied to all files in this directory unless otherwise noted:
-
-   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.

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/testing/cmd/rdfcat.n3
----------------------------------------------------------------------
diff --git a/jena-core/testing/cmd/rdfcat.n3 b/jena-core/testing/cmd/rdfcat.n3
deleted file mode 100644
index e3ae5fb..0000000
--- a/jena-core/testing/cmd/rdfcat.n3
+++ /dev/null
@@ -1,18 +0,0 @@
-@prefix rdf:        <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
-@prefix rdfs:	    <http://www.w3.org/2000/01/rdf-schema#> .
-@prefix jms:        <http://jena.hpl.hp.com/2003/08/jms#> .
-@prefix dc:         <http://purl.org/dc/elements/1.1/> .
-
-jms:MakerSpec           rdf:type     rdfs:Class .
-jms:FileMakerSpec       rdf:type     rdfs:Class .
-jms:MemMakerSpec        rdf:type     rdfs:Class .
-jms:RDBMakerSpec        rdf:type     rdfs:Class .
-jms:ModelSpec           rdf:type     rdfs:Class .
-jms:PlainModelSpec      rdf:type     rdfs:Class .
-jms:InfModelSpec        rdf:type     rdfs:Class .
-jms:OntModelSpec        rdf:type     rdfs:Class .
-
-jms:MemMakerSpec        rdfs:subClassOf     jms:MakerSpec .
-jms:FileMakerSpec       rdfs:subClassOf     jms:MakerSpec .
-jms:RDBMakerSpec        rdfs:subClassOf     jms:MakerSpec .
-        

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/testing/cmd/rdfcat.nt
----------------------------------------------------------------------
diff --git a/jena-core/testing/cmd/rdfcat.nt b/jena-core/testing/cmd/rdfcat.nt
deleted file mode 100644
index 39d1562..0000000
--- a/jena-core/testing/cmd/rdfcat.nt
+++ /dev/null
@@ -1,11 +0,0 @@
-<http://jena.hpl.hp.com/2003/08/jms#MemMakerSpec> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
-<http://jena.hpl.hp.com/2003/08/jms#MemMakerSpec> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://jena.hpl.hp.com/2003/08/jms#MakerSpec> .
-<http://jena.hpl.hp.com/2003/08/jms#FileMakerSpec> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
-<http://jena.hpl.hp.com/2003/08/jms#FileMakerSpec> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://jena.hpl.hp.com/2003/08/jms#MakerSpec> .
-<http://jena.hpl.hp.com/2003/08/jms#PlainModelSpec> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
-<http://jena.hpl.hp.com/2003/08/jms#OntModelSpec> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
-<http://jena.hpl.hp.com/2003/08/jms#ModelSpec> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
-<http://jena.hpl.hp.com/2003/08/jms#MakerSpec> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
-<http://jena.hpl.hp.com/2003/08/jms#InfModelSpec> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
-<http://jena.hpl.hp.com/2003/08/jms#RDBMakerSpec> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
-<http://jena.hpl.hp.com/2003/08/jms#RDBMakerSpec> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://jena.hpl.hp.com/2003/08/jms#MakerSpec> .

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/testing/cmd/rdfcat.xml
----------------------------------------------------------------------
diff --git a/jena-core/testing/cmd/rdfcat.xml b/jena-core/testing/cmd/rdfcat.xml
deleted file mode 100644
index 15fe7b2..0000000
--- a/jena-core/testing/cmd/rdfcat.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<rdf:RDF
-    xmlns:jms="http://jena.hpl.hp.com/2003/08/jms#"
-    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
-    xmlns:dc="http://purl.org/dc/elements/1.1/">
-  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#InfModelSpec"/>
-  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#OntModelSpec"/>
-  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#PlainModelSpec"/>
-  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#MakerSpec"/>
-  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#RDBMakerSpec">
-    <rdfs:subClassOf rdf:resource="http://jena.hpl.hp.com/2003/08/jms#MakerSpec"/>
-  </rdfs:Class>
-  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#FileMakerSpec">
-    <rdfs:subClassOf rdf:resource="http://jena.hpl.hp.com/2003/08/jms#MakerSpec"/>
-  </rdfs:Class>
-  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#ModelSpec"/>
-  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#MemMakerSpec">
-    <rdfs:subClassOf rdf:resource="http://jena.hpl.hp.com/2003/08/jms#MakerSpec"/>
-  </rdfs:Class>
-</rdf:RDF>

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/testing/cmd/rdfcat_1.xml
----------------------------------------------------------------------
diff --git a/jena-core/testing/cmd/rdfcat_1.xml b/jena-core/testing/cmd/rdfcat_1.xml
deleted file mode 100644
index 8cf143f..0000000
--- a/jena-core/testing/cmd/rdfcat_1.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-<rdf:RDF
-    xmlns:jms="http://jena.hpl.hp.com/2003/08/jms#"
-    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
-    xmlns:dc="http://purl.org/dc/elements/1.1/">
-  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#InfModelSpec"/>
-  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#OntModelSpec"/>
-  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#PlainModelSpec"/>
-  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#MakerSpec"/>
-</rdf:RDF>

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/testing/cmd/rdfcat_1_n3
----------------------------------------------------------------------
diff --git a/jena-core/testing/cmd/rdfcat_1_n3 b/jena-core/testing/cmd/rdfcat_1_n3
deleted file mode 100644
index bc9ccc9..0000000
--- a/jena-core/testing/cmd/rdfcat_1_n3
+++ /dev/null
@@ -1,17 +0,0 @@
-@prefix dc:      <http://purl.org/dc/elements/1.1/> .
-@prefix jms:     <http://jena.hpl.hp.com/2003/08/jms#> .
-@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
-@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
-@prefix :        <#> .
-
-jms:InfModelSpec
-      a       rdfs:Class .
-
-jms:OntModelSpec
-      a       rdfs:Class .
-
-jms:MakerSpec
-      a       rdfs:Class .
-
-jms:PlainModelSpec
-      a       rdfs:Class .

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/testing/cmd/rdfcat_2.xml
----------------------------------------------------------------------
diff --git a/jena-core/testing/cmd/rdfcat_2.xml b/jena-core/testing/cmd/rdfcat_2.xml
deleted file mode 100644
index 137c092..0000000
--- a/jena-core/testing/cmd/rdfcat_2.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<rdf:RDF
-    xmlns:jms="http://jena.hpl.hp.com/2003/08/jms#"
-    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
-    xmlns:dc="http://purl.org/dc/elements/1.1/">
-  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#RDBMakerSpec">
-    <rdfs:subClassOf rdf:resource="http://jena.hpl.hp.com/2003/08/jms#MakerSpec"/>
-  </rdfs:Class>
-  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#FileMakerSpec">
-    <rdfs:subClassOf rdf:resource="http://jena.hpl.hp.com/2003/08/jms#MakerSpec"/>
-  </rdfs:Class>
-  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#ModelSpec"/>
-  <rdfs:Class rdf:about="http://jena.hpl.hp.com/2003/08/jms#MemMakerSpec">
-    <rdfs:subClassOf rdf:resource="http://jena.hpl.hp.com/2003/08/jms#MakerSpec"/>
-  </rdfs:Class>
-</rdf:RDF>

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/testing/cmd/rdfcat_2_n3
----------------------------------------------------------------------
diff --git a/jena-core/testing/cmd/rdfcat_2_n3 b/jena-core/testing/cmd/rdfcat_2_n3
deleted file mode 100644
index fc284d2..0000000
--- a/jena-core/testing/cmd/rdfcat_2_n3
+++ /dev/null
@@ -1,20 +0,0 @@
-@prefix dc:      <http://purl.org/dc/elements/1.1/> .
-@prefix jms:     <http://jena.hpl.hp.com/2003/08/jms#> .
-@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
-@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
-@prefix :        <#> .
-
-jms:RDBMakerSpec
-      a       rdfs:Class ;
-      rdfs:subClassOf jms:MakerSpec .
-
-jms:FileMakerSpec
-      a       rdfs:Class ;
-      rdfs:subClassOf jms:MakerSpec .
-
-jms:ModelSpec
-      a       rdfs:Class .
-
-jms:MemMakerSpec
-      a       rdfs:Class ;
-      rdfs:subClassOf jms:MakerSpec .

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-core/testing/cmd/sg-test-config.rdf
----------------------------------------------------------------------
diff --git a/jena-core/testing/cmd/sg-test-config.rdf b/jena-core/testing/cmd/sg-test-config.rdf
deleted file mode 100644
index df7adb7..0000000
--- a/jena-core/testing/cmd/sg-test-config.rdf
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version='1.0'?>
-
-<!DOCTYPE rdf:RDF [
-    <!ENTITY jena    'http://jena.hpl.hp.com/'>
-
-    <!ENTITY rdf     'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
-    <!ENTITY rdfs    'http://www.w3.org/2000/01/rdf-schema#'>
-    <!ENTITY owl     'http://www.w3.org/2002/07/owl#'>
-    <!ENTITY xsd     'http://www.w3.org/2001/XMLSchema#'>
-    <!ENTITY base    '&jena;2003/04/schemagen'>
-    <!ENTITY sgen    '&base;#'>
-]>
-
-<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:owl="http://www.w3.org/2002/07/owl#"
-  xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:sgen="http://jena.hpl.hp.com/2003/04/schemagen#">
-
-  <sgen:Config>
-    <!-- specifies that the source document uses OWL -->
-    <sgen:owl rdf:datatype="&xsd;boolean">true</sgen:owl>
-    <!-- specifies that we want the generated vocab to use OntClass, OntProperty, etc, not Resource and Property -->
-    <sgen:ontology rdf:datatype="&xsd;boolean">true</sgen:ontology>
-  </sgen:Config>
-</rdf:RDF>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-csv/pom.xml
----------------------------------------------------------------------
diff --git a/jena-csv/pom.xml b/jena-csv/pom.xml
index 7b940a7..142d730 100644
--- a/jena-csv/pom.xml
+++ b/jena-csv/pom.xml
@@ -59,6 +59,12 @@
       <version>3.1.0-SNAPSHOT</version>
       <type>pom</type>
     </dependency>
+
+    <dependency>
+      <groupId>org.apache.jena</groupId>
+      <artifactId>jena-cmds</artifactId>
+      <version>3.1.0-SNAPSHOT</version>
+    </dependency>
     
     <!-- Testing support -->
     <dependency>

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-sdb/pom.xml
----------------------------------------------------------------------
diff --git a/jena-sdb/pom.xml b/jena-sdb/pom.xml
index 8f74ffd..cdb6884 100644
--- a/jena-sdb/pom.xml
+++ b/jena-sdb/pom.xml
@@ -46,6 +46,12 @@
       <version>3.1.0-SNAPSHOT</version>
     </dependency>
 
+    <dependency>
+      <groupId>org.apache.jena</groupId>
+      <artifactId>jena-cmds</artifactId>
+      <version>3.1.0-SNAPSHOT</version>
+    </dependency>
+    
     <!-- Need the tests as well -->
     <dependency>
       <groupId>org.apache.jena</groupId>

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-spatial/pom.xml
----------------------------------------------------------------------
diff --git a/jena-spatial/pom.xml b/jena-spatial/pom.xml
index 097d114..49232d8 100644
--- a/jena-spatial/pom.xml
+++ b/jena-spatial/pom.xml
@@ -47,6 +47,12 @@
       <type>pom</type>
     </dependency>
 
+    <dependency>
+      <groupId>org.apache.jena</groupId>
+      <artifactId>jena-cmds</artifactId>
+      <version>3.1.0-SNAPSHOT</version>
+    </dependency>
+
     <!-- Testing support -->
     <dependency>
       <groupId>org.apache.jena</groupId>

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/org/apache/jena/tdb/lib/DumpOps.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/lib/DumpOps.java b/jena-tdb/src/main/java/org/apache/jena/tdb/lib/DumpOps.java
index 8265d33..4f3f88f 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/lib/DumpOps.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/lib/DumpOps.java
@@ -24,8 +24,6 @@ import java.util.HashSet ;
 import java.util.Iterator ;
 import java.util.Set ;
 
-import jena.cmd.CmdException;
-
 import org.apache.jena.atlas.io.IndentedWriter ;
 import org.apache.jena.atlas.lib.ByteBufferLib ;
 import org.apache.jena.atlas.lib.Pair ;
@@ -34,6 +32,7 @@ import org.apache.jena.atlas.lib.tuple.TupleFactory ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.query.Dataset ;
 import org.apache.jena.riot.out.NodeFmtLib ;
+import org.apache.jena.tdb.TDBException ;
 import org.apache.jena.tdb.base.block.Block ;
 import org.apache.jena.tdb.base.block.BlockMgr ;
 import org.apache.jena.tdb.index.bplustree.BPlusTree ;
@@ -55,14 +54,12 @@ public class DumpOps
         NodeTupleTable nodeTupleTableQuads = dsg.getQuadTable().getNodeTupleTable() ;
 
         if ( nodeTupleTableTriples.getNodeTable() != nodeTupleTableQuads.getNodeTable() )
-            throw new CmdException("Different node tables for triples and quads") ;
+            throw new TDBException("Different node tables for triples and quads") ;
 
         NodeTable nodeTable = nodeTupleTableTriples.getNodeTable() ;
         // V special.
         Set<NodeTable> dumpedNodeTables = new HashSet<>() ;
 
-
-
         if ( true )
         {
             System.out.print("## Node Table\n") ;

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexBuild.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexBuild.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexBuild.java
index a577725..e5a8f6e 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexBuild.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexBuild.java
@@ -36,7 +36,6 @@ import org.apache.jena.tdb.index.bplustree.BPlusTreeRewriter ;
 import org.apache.jena.tdb.lib.ColumnMap ;
 import org.apache.jena.tdb.sys.Names ;
 import org.apache.jena.tdb.sys.SystemTDB ;
-import tdb.cmdline.CmdTDB ;
 
 /** From a file of records, build a (packed) index */ 
 public class CmdIndexBuild
@@ -45,17 +44,15 @@ public class CmdIndexBuild
     
     public static void main(String...argv)
     {
-        CmdTDB.init() ;
         // DATA IN S/P/O columns but sorted by index order.
-        
-        if ( argv.length != 3 )
-        {
-            System.err.println("Usage: Location Index dataFile") ;
-            System.exit(1) ;
+
+        if ( argv.length != 3 ) {
+            System.err.println("Usage: Location Index dataFile");
+            System.exit(1);
         }
-        
-        String locationStr = argv[0] ;
-        String indexName = argv[1] ;
+
+        String locationStr = argv[0];
+        String indexName = argv[1];
         
 //        if ( ! Arrays.asList(Names.tripleIndexes).contains(indexName) &&
 //            ! Arrays.asList(Names.quadIndexes).contains(indexName) )
@@ -83,53 +80,47 @@ public class CmdIndexBuild
         // Null column map => no churn.
         // Do record -> record copy, not Tuple, Tuple copy.
 
-        String primaryOrder ;
-        int dftKeyLength ;
-        int dftValueLength ;
-        int tupleLength = indexName.length() ;
+        String primaryOrder;
+        int dftKeyLength;
+        int dftValueLength;
+        int tupleLength = indexName.length();
 
-        if ( tupleLength == 3 )
-        {
-            primaryOrder = Names.primaryIndexTriples ;
-            dftKeyLength = SystemTDB.LenIndexTripleRecord ;
-            dftValueLength = 0 ;
+        if ( tupleLength == 3 ) {
+            primaryOrder = Names.primaryIndexTriples;
+            dftKeyLength = SystemTDB.LenIndexTripleRecord;
+            dftValueLength = 0;
+        } else if ( tupleLength == 4 ) {
+            primaryOrder = Names.primaryIndexQuads;
+            dftKeyLength = SystemTDB.LenIndexQuadRecord;
+            dftValueLength = 0;
+        } else {
+            throw new AtlasException("Index name: " + indexName);
         }
-        else if ( tupleLength == 4 )
-        {
-            primaryOrder = Names.primaryIndexQuads ;
-            dftKeyLength = SystemTDB.LenIndexQuadRecord ;
-            dftValueLength = 0 ;
-        }
-        else
-        {
-            throw new AtlasException("Index name: "+indexName) ;
-        }
-        
-        ColumnMap colMap = new ColumnMap(primaryOrder, indexName) ;
 
+        ColumnMap colMap = new ColumnMap(primaryOrder, indexName) ;
 
         // -1? Write only.
         // Also flush cache every so often => block writes (but not sequential so boring).
-        int readCacheSize = 10 ;
-        int writeCacheSize = 100 ;
+        int readCacheSize = 10;
+        int writeCacheSize = 100;
 
-        int blockSize = SystemTDB.BlockSize ;
-        RecordFactory recordFactory = new RecordFactory(dftKeyLength, dftValueLength) ;
-        
-        int order = BPlusTreeParams.calcOrder(blockSize, recordFactory) ;
-        BPlusTreeParams bptParams = new BPlusTreeParams(order, recordFactory) ;
+        int blockSize = SystemTDB.BlockSize;
+        RecordFactory recordFactory = new RecordFactory(dftKeyLength, dftValueLength);
 
-        int blockSizeNodes = blockSize ;
-        int blockSizeRecords = blockSize ;
+        int order = BPlusTreeParams.calcOrder(blockSize, recordFactory);
+        BPlusTreeParams bptParams = new BPlusTreeParams(order, recordFactory);
 
-        FileSet destination = new FileSet(location, indexName) ;
+        int blockSizeNodes = blockSize;
+        int blockSizeRecords = blockSize;
 
-        BlockMgr blkMgrNodes = BlockMgrFactory.create(destination, Names.bptExtTree, blockSizeNodes, readCacheSize, writeCacheSize) ;
-        BlockMgr blkMgrRecords = BlockMgrFactory.create(destination, Names.bptExtRecords, blockSizeRecords, readCacheSize, writeCacheSize) ;
-        
-        int rowBlock = 1000 ;
-        Iterator<Record> iter = new RecordsFromInput(input, tupleLength, colMap, rowBlock) ;
-        BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(iter, bptParams, recordFactory, blkMgrNodes, blkMgrRecords) ;
-        bpt2.close() ;
+        FileSet destination = new FileSet(location, indexName);
+
+        BlockMgr blkMgrNodes = BlockMgrFactory.create(destination, Names.bptExtTree, blockSizeNodes, readCacheSize, writeCacheSize);
+        BlockMgr blkMgrRecords = BlockMgrFactory.create(destination, Names.bptExtRecords, blockSizeRecords, readCacheSize, writeCacheSize);
+
+        int rowBlock = 1000;
+        Iterator<Record> iter = new RecordsFromInput(input, tupleLength, colMap, rowBlock);
+        BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(iter, bptParams, recordFactory, blkMgrNodes, blkMgrRecords);
+        bpt2.close();
     }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexCopy.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexCopy.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexCopy.java
index efcda1a..14609d5 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexCopy.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexCopy.java
@@ -31,7 +31,6 @@ import org.apache.jena.tdb.store.tupletable.TupleIndex ;
 import org.apache.jena.tdb.sys.SystemTDB ;
 import org.slf4j.Logger ;
 import org.slf4j.LoggerFactory ;
-import tdb.cmdline.CmdTDB ;
 
 /** Copy one index to another, probably with a different key order */
 public class CmdIndexCopy
@@ -44,8 +43,6 @@ public class CmdIndexCopy
     
     public static void main(String...argv)
     {
-        CmdTDB.init() ;
-        
         // Ideas:
         // Copy to buffer, sort, write in sequential clumps.
         // Profile code for hotspots
@@ -54,11 +51,10 @@ public class CmdIndexCopy
         // non-memory mapped file as we read it through once, in natural order,
         // and it may be laid out in increasing block order on-disk, e.g. repacked
         // and in increasing order with occassional oddities if SPO from the bulk loader.
-        
-        if ( argv.length != 4 )
-        {
-            System.err.println("Usage: Location1 Index1 Location2 Index2") ;
-            System.exit(1) ;
+
+        if ( argv.length != 4 ) {
+            System.err.println("Usage: Location1 Index1 Location2 Index2");
+            System.exit(1);
         }
         
         String locationStr1 = argv[0] ;
@@ -87,37 +83,33 @@ public class CmdIndexCopy
         index2.close() ;
     }
 
-    private static void tupleIndexCopy(TupleIndex index1, TupleIndex index2, String label)
-    {
-        ProgressLogger monitor = new ProgressLogger(log, label, tickQuantum, superTick) ;
-        monitor.start() ;
-        
-        Iterator<Tuple<NodeId>> iter1 = index1.all() ;
-        
-        long counter = 0 ;
-        for ( ; iter1.hasNext(); )
-        {
-            counter++ ;
-            Tuple<NodeId> tuple = iter1.next() ;
-            index2.add(tuple) ;
-            monitor.tick() ;
+    private static void tupleIndexCopy(TupleIndex index1, TupleIndex index2, String label) {
+        ProgressLogger monitor = new ProgressLogger(log, label, tickQuantum, superTick);
+        monitor.start();
+
+        Iterator<Tuple<NodeId>> iter1 = index1.all();
+
+        long counter = 0;
+        for ( ; iter1.hasNext() ; ) {
+            counter++;
+            Tuple<NodeId> tuple = iter1.next();
+            index2.add(tuple);
+            monitor.tick();
         }
-        
-        index2.sync() ;
-        long time = monitor.finish() ;
-        float elapsedSecs = time/1000F ;
-        
-        float rate = (elapsedSecs!=0) ? counter/elapsedSecs : 0 ;
-        
-        print("Total: %,d records : %,.2f seconds : %,.2f records/sec [%s]", counter, elapsedSecs, rate, DateTimeUtils.nowAsString()) ;
+
+        index2.sync();
+        long time = monitor.finish();
+        float elapsedSecs = time / 1000F;
+
+        float rate = (elapsedSecs != 0) ? counter / elapsedSecs : 0;
+
+        print("Total: %,d records : %,.2f seconds : %,.2f records/sec [%s]", counter, elapsedSecs, rate, DateTimeUtils.nowAsString());
     }
-    
-    static private void print(String fmt, Object...args)
-    {
-        if ( log != null && log.isInfoEnabled() )
-        {
-            String str = String.format(fmt, args) ;
-            log.info(str) ;
+
+    static private void print(String fmt, Object... args) {
+        if ( log != null && log.isInfoEnabled() ) {
+            String str = String.format(fmt, args);
+            log.info(str);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdNodeTableBuilder.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdNodeTableBuilder.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdNodeTableBuilder.java
deleted file mode 100644
index 7fb7765..0000000
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdNodeTableBuilder.java
+++ /dev/null
@@ -1,305 +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.tdb.store.bulkloader2;
-
-import java.io.FileNotFoundException ;
-import java.io.FileOutputStream ;
-import java.io.OutputStream ;
-import java.util.Arrays ;
-import java.util.List ;
-import java.util.Objects ;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdException;
-import jena.cmd.CmdGeneral;
-
-import org.apache.jena.atlas.AtlasException ;
-import org.apache.jena.atlas.io.IO ;
-import org.apache.jena.atlas.lib.DateTimeUtils ;
-import org.apache.jena.atlas.lib.FileOps ;
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.apache.jena.atlas.logging.ProgressLogger ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFDataMgr ;
-import org.apache.jena.riot.RDFLanguages ;
-import org.apache.jena.sparql.core.Quad ;
-import org.apache.jena.system.JenaSystem ;
-import org.apache.jena.tdb.TDB ;
-import org.apache.jena.tdb.base.file.Location ;
-import org.apache.jena.tdb.setup.DatasetBuilderStd ;
-import org.apache.jena.tdb.solver.stats.Stats ;
-import org.apache.jena.tdb.solver.stats.StatsCollectorNodeId ;
-import org.apache.jena.tdb.store.DatasetGraphTDB ;
-import org.apache.jena.tdb.store.NodeId ;
-import org.apache.jena.tdb.store.bulkloader.BulkLoader ;
-import org.apache.jena.tdb.store.bulkloader.BulkStreamRDF ;
-import org.apache.jena.tdb.store.nodetable.NodeTable ;
-import org.apache.jena.tdb.store.nodetupletable.NodeTupleTable ;
-import org.apache.jena.tdb.sys.Names ;
-import org.slf4j.Logger ;
-
-import tdb.cmdline.CmdTDB ;
-
-/** Build node table - write triples/quads as text file */
-public class CmdNodeTableBuilder extends CmdGeneral
-{
-    static { LogCtl.setLog4j() ; }
-    static { JenaSystem.init(); }
-    private static Logger cmdLog = TDB.logLoader ;
-
-    private static ArgDecl argLocation      = new ArgDecl(ArgDecl.HasValue, "loc", "location") ;
-    private static ArgDecl argTriplesOut    = new ArgDecl(ArgDecl.HasValue, "triples") ;
-    private static ArgDecl argQuadsOut      = new ArgDecl(ArgDecl.HasValue, "quads") ;
-    private static ArgDecl argNoStats       = new ArgDecl(ArgDecl.NoValue, "nostats") ;
-    
-    private String locationString ;
-    private String dataFileTriples ;
-    private String dataFileQuads ;
-    private List<String> datafiles ;
-    private Location location ;
-    private boolean collectStats = true ;
-    
-    public static void main(String...argv)
-    {
-        System.err.println("CmdNodeTableBuilder");
-        CmdTDB.init() ;
-        DatasetBuilderStd.setOptimizerWarningFlag(false) ;
-        new CmdNodeTableBuilder(argv).mainRun() ;
-    }
-    
-    public CmdNodeTableBuilder(String...argv)
-    {
-        super(argv) ;
-        super.add(argLocation,      "--loc",        "Location") ;
-        super.add(argTriplesOut,    "--triples",    "Output file for triples") ;
-        super.add(argQuadsOut,      "--quads",      "Output file for quads") ;
-        super.add(argNoStats,       "--nostats",    "Don't collect stats") ;
-    }
-        
-    @Override
-    protected void processModulesAndArgs()
-    {
-        if ( !super.contains(argLocation) ) throw new CmdException("Required: --loc DIR") ;
-//        if ( !super.contains(argTriplesOut) ) throw new CmdException("Required: --triples FILE") ;
-//        if ( !super.contains(argQuadsOut) ) throw new CmdException("Required: --quads FILE") ;
-        
-        locationString   = super.getValue(argLocation) ;
-        location = Location.create(locationString) ;
-
-        dataFileTriples  = super.getValue(argTriplesOut) ;
-        if ( dataFileTriples == null )
-            dataFileTriples = location.getPath("triples", "tmp") ;
-        
-        dataFileQuads    = super.getValue(argQuadsOut) ;
-        if ( dataFileQuads == null )
-            dataFileQuads = location.getPath("quads", "tmp") ;
-        
-        if ( Objects.equals(dataFileTriples, dataFileQuads) )
-            cmdError("Triples and Quads work files are the same") ;
-        
-        if ( super.contains(argNoStats) )
-            collectStats = false ;
-        
-        //datafiles  = getPositionalOrStdin() ;
-        datafiles  = getPositional() ;
-        if ( datafiles.isEmpty() )
-            datafiles = Arrays.asList("-") ;
-        
-        // ---- Checking.
-        for( String filename : datafiles)
-        {
-            Lang lang = RDFLanguages.filenameToLang(filename, RDFLanguages.NQUADS) ;
-            if ( lang == null )
-                // Does not happen due to default above.
-                cmdError("File suffix not recognized: " +filename) ;
-            if ( ! filename.equals("-") && ! FileOps.exists(filename) )
-                cmdError("File does not exist: "+filename) ;
-        }
-    }
-    
-    @Override
-    protected void exec()
-    {
-        // This formats the location correctly.
-        // But we're not really interested in it all.
-        DatasetGraphTDB dsg = DatasetBuilderStd.create(location) ;
-        
-        // so close indexes and the prefix table.
-        dsg.getTripleTable().getNodeTupleTable().getTupleTable().close();
-        dsg.getQuadTable().getNodeTupleTable().getTupleTable().close();
-        
-        ProgressLogger monitor = new ProgressLogger(cmdLog, "Data", BulkLoader.DataTickPoint, BulkLoader.superTick) ;
-        OutputStream outputTriples = null ;
-        OutputStream outputQuads = null ;
-        
-        try { 
-            outputTriples = new FileOutputStream(dataFileTriples) ; 
-            outputQuads = new FileOutputStream(dataFileQuads) ;
-        }
-        catch (FileNotFoundException e) { throw new AtlasException(e) ; }
-        
-        NodeTableBuilder sink = new NodeTableBuilder(dsg, monitor, outputTriples, outputQuads, collectStats) ; 
-        monitor.start() ;
-        sink.startBulk() ;
-        for( String filename : datafiles) {
-            if ( datafiles.size() > 0 )
-                cmdLog.info("Load: "+filename+" -- "+DateTimeUtils.nowAsString()) ;
-            RDFDataMgr.parse(sink, filename) ;
-        }
-        sink.finishBulk() ;
-        IO.close(outputTriples) ;
-        IO.close(outputQuads) ;
-        
-        // ---- Stats
-        
-        // See Stats class.
-        if ( ! location.isMem() && sink.getCollector() != null )
-            Stats.write(dsg.getLocation().getPath(Names.optStats), sink.getCollector().results()) ;
-        
-        // ---- Monitor
-        long time = monitor.finish() ;
-
-        long total = monitor.getTicks() ;
-        float elapsedSecs = time/1000F ;
-        float rate = (elapsedSecs!=0) ? total/elapsedSecs : 0 ;
-        String str =  String.format("Total: %,d tuples : %,.2f seconds : %,.2f tuples/sec [%s]", total, elapsedSecs, rate, DateTimeUtils.nowAsString()) ;
-        cmdLog.info(str) ;
-    }
-
-    static class NodeTableBuilder implements BulkStreamRDF
-    {
-        private DatasetGraphTDB dsg ;
-        private NodeTable nodeTable ;
-        private WriteRows writerTriples ;
-        private WriteRows writerQuads ;
-        private ProgressLogger monitor ;
-        private StatsCollectorNodeId stats ;
-
-        NodeTableBuilder(DatasetGraphTDB dsg, ProgressLogger monitor, OutputStream outputTriples, OutputStream outputQuads, boolean collectStats)
-        {
-            this.dsg = dsg ;
-            this.monitor = monitor ;
-            NodeTupleTable ntt = dsg.getTripleTable().getNodeTupleTable() ; 
-            this.nodeTable = ntt.getNodeTable() ;
-            this.writerTriples = new WriteRows(outputTriples, 3, 20000) ; 
-            this.writerQuads = new WriteRows(outputQuads, 4, 20000) ; 
-            if ( collectStats )
-                this.stats = new StatsCollectorNodeId(nodeTable) ;
-        }
-        
-        @Override
-        public void startBulk()
-        {}
-
-        @Override
-        public void start()
-        {}
-
-        @Override
-        public void finish()
-        {}
-
-        @Override
-        public void finishBulk()
-        {
-            writerTriples.flush() ;
-            writerQuads.flush() ;
-            nodeTable.sync() ;
-            dsg.getPrefixes().sync() ;
-        }
-            
-        @Override
-        public void triple(Triple triple)
-        {
-            Node s = triple.getSubject() ;
-            Node p = triple.getPredicate() ;
-            Node o = triple.getObject() ;
-            process(Quad.tripleInQuad,s,p,o);
-        }
-
-        @Override
-        public void quad(Quad quad)
-        {
-            Node s = quad.getSubject() ;
-            Node p = quad.getPredicate() ;
-            Node o = quad.getObject() ;
-            Node g = null ;
-            // Union graph?!
-            if ( ! quad.isTriple() && ! quad.isDefaultGraph() )
-                g = quad.getGraph() ;
-            process(g,s,p,o);
-        }
-
-       
-        private void process(Node g, Node s, Node p, Node o)
-        {
-            NodeId sId = nodeTable.getAllocateNodeId(s) ; 
-            NodeId pId = nodeTable.getAllocateNodeId(p) ;
-            NodeId oId = nodeTable.getAllocateNodeId(o) ;
-            
-            if ( g != null )
-            {
-                NodeId gId = nodeTable.getAllocateNodeId(g) ;
-                writerQuads.write(gId.getId()) ;
-                writerQuads.write(sId.getId()) ;
-                writerQuads.write(pId.getId()) ;
-                writerQuads.write(oId.getId()) ;
-                writerQuads.endOfRow() ;
-                if ( stats != null )
-                    stats.record(gId, sId, pId, oId) ;
-            }
-            else
-            {
-                writerTriples.write(sId.getId()) ;
-                writerTriples.write(pId.getId()) ;
-                writerTriples.write(oId.getId()) ;
-                writerTriples.endOfRow() ;
-                if ( stats != null )
-                    stats.record(null, sId, pId, oId) ;
-            }
-            monitor.tick() ;
-        }
-
-        public StatsCollectorNodeId getCollector() { return stats ; }
-
-        @Override
-        public void base(String base)
-        {}
-
-        @Override
-        public void prefix(String prefix, String iri)
-        {
-            dsg.getPrefixes().getPrefixMapping().setNsPrefix(prefix, iri) ;
-        }
-    }
-
-    @Override
-    protected String getSummary()
-    {
-        return getCommandName()+" --loc=DIR [--triples=tmpFile1] [--quads=tmpFile2] FILE ..." ;
-    }
-
-    @Override
-    protected String getCommandName()
-    {
-        return this.getClass().getName() ;
-    }
-}


[03/20] jena git commit: JENA-1108 : jena-cmds module

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/tools/tdbgenindex.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/tools/tdbgenindex.java b/jena-tdb/src/main/java/tdb/tools/tdbgenindex.java
deleted file mode 100644
index 9371ce2..0000000
--- a/jena-tdb/src/main/java/tdb/tools/tdbgenindex.java
+++ /dev/null
@@ -1,86 +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 tdb.tools ;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.lib.tuple.Tuple ;
-import org.apache.jena.tdb.base.file.Location ;
-import org.apache.jena.tdb.store.NodeId ;
-import org.apache.jena.tdb.store.tupletable.TupleIndex ;
-import org.apache.jena.tdb.sys.Names ;
-import org.apache.jena.tdb.sys.SetupTDB ;
-import org.apache.jena.tdb.sys.SystemTDB ;
-
-/** copy one index to another, possibly changing the order */
-public class tdbgenindex {
-    public static void main(String... argv) {
-        // Usage: srcLocation indexName dstLocation indexName
-        if ( argv.length != 4 ) {
-            System.err.println("Usage: " + Lib.classShortName(tdbgenindex.class) + " srcLocation srcIndex dstLocation dstIndex") ;
-            System.exit(1) ;
-        }
-
-        Location srcLoc = Location.create(argv[0]) ;
-        String srcIndexName = argv[1] ;
-
-        Location dstLoc = Location.create(argv[2]) ;
-        String dstIndexName = argv[3] ;
-
-        int readCacheSize = 0 ;
-        int writeCacheSize = -1 ;
-
-        if ( srcIndexName.length() != dstIndexName.length() ) {
-            System.err.println("srcIndexName.length() != dstIndexName.length() " + srcIndexName + " :: " + dstIndexName) ;
-            System.exit(1) ;
-        }
-
-        String primary ;
-        int dftKeyLength ;
-        int dftValueLength ;
-
-        if ( srcIndexName.length() == 3 ) {
-            primary = Names.primaryIndexTriples ;
-            dftKeyLength = SystemTDB.LenIndexTripleRecord ;
-            dftValueLength = 0 ;
-        } else if ( srcIndexName.length() == 4 ) {
-            primary = Names.primaryIndexQuads ;
-            dftKeyLength = SystemTDB.LenIndexQuadRecord ;
-            dftValueLength = 0 ;
-        } else {
-            System.err.println("indexlength != 3 or 4") ;
-            System.exit(1) ;
-            primary = null ;
-            dftKeyLength = 0 ;
-            dftValueLength = 0 ;
-        }
-
-        TupleIndex srcIdx = SetupTDB.makeTupleIndex(srcLoc, primary, srcIndexName, srcIndexName, dftKeyLength) ;
-        TupleIndex dstIdx = SetupTDB.makeTupleIndex(dstLoc, primary, dstIndexName, dstIndexName, dftKeyLength) ;
-
-        Iterator<Tuple<NodeId>> iter = srcIdx.all() ;
-        for ( ; iter.hasNext() ; ) {
-            Tuple<NodeId> tuple = iter.next() ;
-            dstIdx.add(tuple) ;
-        }
-        srcIdx.close() ;
-        dstIdx.close() ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-text/pom.xml
----------------------------------------------------------------------
diff --git a/jena-text/pom.xml b/jena-text/pom.xml
index 7b8b78d..8f81f13 100644
--- a/jena-text/pom.xml
+++ b/jena-text/pom.xml
@@ -46,6 +46,12 @@
     </dependency>
     
     <dependency>
+      <groupId>org.apache.jena</groupId>
+      <artifactId>jena-cmds</artifactId>
+      <version>3.1.0-SNAPSHOT</version>
+    </dependency>
+    
+    <dependency>
       <groupId>commons-codec</groupId>
       <artifactId>commons-codec</artifactId>
     </dependency>


[15/20] jena git commit: JENA-1108 : jena-cmds module

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneral.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneral.java b/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneral.java
new file mode 100644
index 0000000..5960f02
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneral.java
@@ -0,0 +1,119 @@
+/*
+ * 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 arq.cmdline;
+
+import java.util.List ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral;
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.query.DatasetFactory ;
+import org.apache.jena.query.LabelExistsException ;
+import org.apache.jena.riot.RDFDataMgr ;
+import org.apache.jena.shared.JenaException ;
+import org.apache.jena.sparql.util.DatasetUtils ;
+
+/** ModDataset: arguments to build a dataset - 
+ * see also ModDatasetAssembler which extends ModDataset
+ * with a description parameter. */ 
+
+public class ModDatasetGeneral extends ModDataset
+{
+    // See also ModDatasetAssembler
+    protected final ArgDecl graphDecl      = new ArgDecl(ArgDecl.HasValue, "graph") ;
+    protected final ArgDecl dataDecl      = new ArgDecl(ArgDecl.HasValue, "data") ;
+    protected final ArgDecl namedGraphDecl = new ArgDecl(ArgDecl.HasValue, "named", "namedgraph", "namedGraph", "namedData", "nameddata") ;
+    //protected final ArgDecl dataFmtDecl    = new ArgDecl(ArgDecl.HasValue, "fmt", "format") ;
+    //protected final ArgDecl dirDecl        = new ArgDecl(ArgDecl.HasValue, "dir") ;
+    
+    private List<String> dataURLs                = null ;
+    private List<String> graphURLs               = null ;
+    private List<String> namedGraphURLs          = null ;
+    protected ModDatasetGeneral() {}
+    
+    @Override
+    public void registerWith(CmdGeneral cl)
+    {
+        cl.getUsage().startCategory("Dataset") ;
+        cl.add(dataDecl,
+               "--data=FILE",
+               "Data for the datset - triple or quad formats") ;
+        cl.add(graphDecl,
+               "--graph=FILE",
+               "Graph for default graph of the datset") ;
+        cl.add(namedGraphDecl,
+               "--namedGraph=FILE",
+               "Add a graph into the dataset as a named graph") ;
+    }
+    
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        dataURLs = cmdLine.getValues(dataDecl) ;
+        graphURLs = cmdLine.getValues(graphDecl) ;
+        namedGraphURLs = cmdLine.getValues(namedGraphDecl) ;
+    }
+    
+    @Override
+    public Dataset createDataset()
+    {
+        // If nothing specified to the module.  Leave alone and hope the query has FROM/FROM NAMED
+        if (  ( dataURLs == null || dataURLs.size() == 0) &&
+              (graphURLs == null || graphURLs.size() == 0) &&
+              (namedGraphURLs == null || namedGraphURLs.size() == 0 ) )
+            return null ;
+        
+        Dataset ds = DatasetFactory.createTxnMem() ;
+        addGraphs(ds) ;
+        dataset = ds ;
+        return dataset ;
+    }
+        
+    protected void addGraphs(Dataset ds)
+    {
+        try {
+            if ( dataURLs != null ) 
+            {
+                for ( String url : dataURLs )
+                    RDFDataMgr.read(ds, url) ;
+            }
+            
+            if ( (graphURLs != null) || (namedGraphURLs != null) )
+                ds = DatasetUtils.addInGraphs(ds, graphURLs, namedGraphURLs, null) ;
+        } 
+        catch (LabelExistsException ex)
+        { throw new CmdException(ex.getMessage()) ; }
+        catch (JenaException ex)
+        { throw ex ; }
+        catch (Exception ex)
+        { throw new CmdException("Error creating dataset", ex) ; }
+    }
+
+    public List<String> getGraphURLs()
+    {
+        return graphURLs ;
+    }
+
+    public List<String> getNamedGraphURLs()
+    {
+        return namedGraphURLs ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneralAssembler.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneralAssembler.java b/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneralAssembler.java
new file mode 100644
index 0000000..c6ec7b5
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneralAssembler.java
@@ -0,0 +1,56 @@
+/*
+ * 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 arq.cmdline;
+
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+
+import org.apache.jena.query.Dataset ;
+
+/** Add assembler to a general dataset description */
+public class ModDatasetGeneralAssembler extends ModDatasetGeneral
+{
+    public ModDatasetGeneralAssembler() {}
+    
+    private ModDatasetAssembler modAssembler = new ModDatasetAssembler() ;
+    
+    @Override
+    public Dataset createDataset()
+    {
+        Dataset ds = modAssembler.createDataset() ;
+        if ( ds == null )
+            ds = super.createDataset() ;
+        return ds ;
+    }
+
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        modAssembler.registerWith(cmdLine) ;
+        super.registerWith(cmdLine) ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        modAssembler.processArgs(cmdLine) ;
+        super.processArgs(cmdLine) ;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModEngine.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModEngine.java b/jena-cmds/src/main/java/arq/cmdline/ModEngine.java
new file mode 100644
index 0000000..998d656
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModEngine.java
@@ -0,0 +1,110 @@
+/*
+ * 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 arq.cmdline;
+
+import java.util.List ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.sparql.engine.main.QueryEngineMain ;
+import org.apache.jena.sparql.engine.main.QueryEngineMainQuad ;
+import org.apache.jena.sparql.engine.ref.QueryEngineRef ;
+import org.apache.jena.sparql.engine.ref.QueryEngineRefQuad ;
+
+
+public class ModEngine extends ModBase
+{
+    // Special case of a "ModEnvironment"
+    // Alters the ARQ environment but provides nothing at execution time.
+    // Combine with ModSymbol?
+    
+    protected final ArgDecl engineDecl = new ArgDecl(ArgDecl.HasValue, "engine") ;
+    protected final ArgDecl unEngineDecl = new ArgDecl(ArgDecl.HasValue,
+                                                       "unengine",
+                                                       "unEngine",
+                                                       "removeEngine",
+                                                       "removeengine"
+                                                       ) ;
+    
+    private boolean timing = false ;
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Query Engine") ;
+        cmdLine.add(engineDecl, "--engine=EngineName", "Register another engine factory[ref]") ; 
+        cmdLine.add(unEngineDecl, "--unengine=EngineName", "Unregister an engine factory") ;
+    }
+    
+    public void checkCommandLine(CmdGeneral cmdLine)
+    {}
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+       
+        List<String> engineDecls = cmdLine.getValues(engineDecl) ;
+        
+//        if ( x.size() > 0 )
+//            QueryEngineRegistry.get().factories().clear() ;
+
+        for ( String engineName : engineDecls )
+        {
+			switch (engineName.toLowerCase()) {
+				case "reference":
+				case "ref":
+					QueryEngineRef.register();
+					continue;
+				case "refQuad":
+					QueryEngineRefQuad.register();
+					continue;
+				case "main":
+					QueryEngineMain.register();
+					continue;
+				case "quad":
+					QueryEngineMainQuad.register();
+					continue;
+				}
+			throw new CmdException("Engine name not recognized: " + engineName);
+		}
+
+        List<String> unEngineDecls = cmdLine.getValues(unEngineDecl) ;
+        for (String engineName : unEngineDecls)
+        {
+	        	switch (engineName.toLowerCase()) {
+				case "reference":
+				case "ref":
+					QueryEngineRef.register();
+					continue;
+				case "refQuad":
+					QueryEngineRefQuad.register();
+					continue;
+				case "main":
+					QueryEngineMain.register();
+					QueryEngineMainQuad.register();
+					continue;      
+	        }
+        		throw new CmdException("Engine name not recognized: "+engineName) ;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModFormat.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModFormat.java b/jena-cmds/src/main/java/arq/cmdline/ModFormat.java
new file mode 100644
index 0000000..b73215e
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModFormat.java
@@ -0,0 +1,91 @@
+/*
+ * 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 arq.cmdline;
+
+
+import java.util.Arrays;
+import java.util.List;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+public class ModFormat extends ModBase
+{
+    protected final 
+    ArgDecl resultsFmtDecl = new ArgDecl(ArgDecl.HasValue, "fmt", "format") ;
+
+    private String format = "N-TRIPLES" ;
+    
+    public ModFormat() {}
+    
+    @Override
+    public void processArgs(CmdArgModule cmdline) throws IllegalArgumentException
+    {
+        if ( cmdline.contains(resultsFmtDecl) )
+        {
+            String rFmt = cmdline.getValue(resultsFmtDecl) ;
+            format = lookup(rFmt) ;
+            if ( format == null )
+                cmdline.cmdError("Unrecognized format: "+rFmt) ;
+        }
+    }
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Output format") ;
+        cmdLine.add(resultsFmtDecl,
+                    "--format",
+                    "Format (Result sets: text, XML, JSON; Graph: RDF serialization)") ;  
+    }
+
+    public void checkCommandLine(CmdArgModule cmdLine)
+    {}
+
+    public String getFormat() { return format ; } 
+    
+    public String getFormat(String defaultFormat)
+    { 
+        if ( format == null )
+            return defaultFormat ;
+        return format ;
+    }
+  
+    private String lookup(String fmt)
+    {
+    		return formats.stream().filter(fmt::equalsIgnoreCase).findFirst().orElse("TURTLE");
+    }
+
+    static final List<String> formats = Arrays.asList(
+        "RDF/XML",
+        "RDF/XML-ABBREV",
+        "N-TRIPLE",
+        "N-TRIPLES",
+        "N3",
+        "N3-PP" ,
+        "N3-PLAIN" ,
+        "N3-TRIPLES" ,
+        "N3-TRIPLE" ,
+        "TURTLE" ,
+        //"Turtle" ,
+        "TTL"
+        ) ;
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModItem.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModItem.java b/jena-cmds/src/main/java/arq/cmdline/ModItem.java
new file mode 100644
index 0000000..c7ee7c1
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModItem.java
@@ -0,0 +1,80 @@
+/*
+ * 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 arq.cmdline;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.sparql.sse.Item ;
+import org.apache.jena.sparql.sse.SSE ;
+import org.apache.jena.util.FileManager ;
+
+public class ModItem extends ModBase
+{
+    protected final ArgDecl queryFileDecl = new ArgDecl(ArgDecl.HasValue, "file") ;
+
+    private String filename = null ;
+    private String parseString = null ; 
+    private Item item = null ;
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Item") ;
+        cmdLine.add(queryFileDecl, "--file=", "File") ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        if ( cmdLine.contains(queryFileDecl) )
+        {
+            filename = cmdLine.getValue(queryFileDecl) ;
+            parseString = FileManager.get().readWholeFileAsUTF8(filename) ;
+            return ;
+        }
+    
+        if ( cmdLine.getNumPositional() == 0 && filename == null )
+            cmdLine.cmdError("No query string or query file") ;
+
+        if ( cmdLine.getNumPositional() > 1 )
+            cmdLine.cmdError("Only one query string allowed") ;
+    
+        if ( cmdLine.getNumPositional() == 1 && filename != null )
+            cmdLine.cmdError("Either query string or query file - not both") ;
+
+        if ( filename == null )
+        {
+            String qs = cmdLine.getPositionalArg(0) ;
+            parseString = cmdLine.indirect(qs) ;
+        }
+    }
+    
+    public Item getItem()
+    {
+        if ( item != null )
+            return item ;
+        // Need to get the (outer) prologue.
+        item = SSE.parseItem(parseString) ;
+        return item ;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModLangOutput.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModLangOutput.java b/jena-cmds/src/main/java/arq/cmdline/ModLangOutput.java
new file mode 100644
index 0000000..ecc82ca
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModLangOutput.java
@@ -0,0 +1,150 @@
+/*
+ * 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 arq.cmdline;
+
+import java.io.PrintStream ;
+import java.util.HashSet ;
+import java.util.Set ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFFormat ;
+import org.apache.jena.riot.RDFLanguages ;
+import org.apache.jena.riot.RDFWriterRegistry ;
+import org.apache.jena.riot.system.StreamRDFWriter ;
+
+public class ModLangOutput extends ModBase
+{
+    protected ArgDecl argOutput       = new ArgDecl(ArgDecl.HasValue, "out", "output") ;
+    protected ArgDecl argPretty       = new ArgDecl(ArgDecl.HasValue, "formatted", "pretty", "fmt") ;
+    protected ArgDecl argStream       = new ArgDecl(ArgDecl.HasValue, "stream") ;
+    protected ArgDecl argCompress     = new ArgDecl(ArgDecl.NoValue, "compress") ;
+    private boolean compressedOutput = false ;
+    private RDFFormat streamOutput    = null ;
+    private RDFFormat formattedOutput = null ;
+
+    @Override
+    public void registerWith(CmdGeneral cmdLine) {
+        cmdLine.getUsage().startCategory("Output control") ;
+        cmdLine.add(argOutput,    "--output=FMT",     "Output in the given format, streaming if possible.") ;
+        cmdLine.add(argPretty,    "--formatted=FMT",  "Output, using pretty printing (consumes memory)") ;
+        cmdLine.add(argStream,    "--stream=FMT",     "Output, using a streaming format") ;
+        cmdLine.add(argCompress,  "--compress",       "Compress the output with gzip") ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine) {
+        if ( cmdLine.contains(argPretty) ) {
+            String langName = cmdLine.getValue(argPretty) ;
+            Lang lang = RDFLanguages.nameToLang(langName) ;
+            if ( lang == null )
+                throw new CmdException("Not recognized as an RDF language : '"+langName+"'") ;
+            formattedOutput = RDFWriterRegistry.defaultSerialization(lang) ;
+            if ( formattedOutput == null ) {
+                System.err.println("Language '"+lang.getLabel()+"' not registered.") ;
+                printRegistered(System.err) ;
+                throw new CmdException("No output set: '"+langName+"'") ;
+            }
+        }
+        
+        if ( cmdLine.contains(argStream) ) {
+            String langName = cmdLine.getValue(argStream) ;
+            Lang lang = RDFLanguages.nameToLang(langName) ;
+            if ( lang == null )
+                throw new CmdException("Not recognized as an RDF language : '"+langName+"'") ;
+            streamOutput = StreamRDFWriter.defaultSerialization(lang) ;
+            if ( streamOutput == null ) {
+                System.err.println("Language '"+lang.getLabel()+"' not registered for streaming.") ;
+                printRegistered(System.err) ;
+                throw new CmdException("No output set: '"+langName+"'") ;
+            }
+        }
+        
+        if ( cmdLine.contains(argOutput) ) {
+            String langName = cmdLine.getValue(argOutput) ;
+            Lang lang = RDFLanguages.nameToLang(langName) ;
+            if ( lang == null )
+                throw new CmdException("Not recognized as an RDF language : '"+langName+"'") ;
+            
+            if ( StreamRDFWriter.registered(lang) ) {
+                streamOutput = StreamRDFWriter.defaultSerialization(lang) ;
+            } else {
+                formattedOutput = RDFWriterRegistry.defaultSerialization(lang) ;
+                if ( formattedOutput == null ) {
+                    System.err.println("Language '"+lang.getLabel()+"' not recognized.") ;
+                    printRegistered(System.err) ;
+                    throw new CmdException("No output set: '"+langName+"'") ;
+                }
+            }
+        }
+        
+        if ( cmdLine.contains(argCompress))
+            compressedOutput = true ;
+        
+        if ( streamOutput == null && formattedOutput == null )
+            streamOutput = RDFFormat.NQUADS ;
+    }
+
+    private static Set<Lang>  hiddenLanguages = new HashSet<>() ;
+    static {
+        hiddenLanguages.add(Lang.RDFNULL) ;
+        hiddenLanguages.add(Lang.CSV) ;
+    }
+    
+    private static void printRegistered(PrintStream out) {
+        out.println("Streaming languages:") ;
+        Set<Lang> seen = new HashSet<>() ;
+        for ( RDFFormat fmt : StreamRDFWriter.registered()) {
+            Lang lang = fmt.getLang() ;
+            if ( hiddenLanguages.contains(lang)) 
+                continue ;
+            if ( seen.contains(lang) )
+                continue ;
+            seen.add(lang) ;
+            out.println("   "+lang.getLabel()) ;
+        }
+        System.err.println("Non-streaming languages:") ;
+        for ( RDFFormat fmt : RDFWriterRegistry.registered() ) {
+            Lang lang = fmt.getLang() ;
+            if ( hiddenLanguages.contains(lang)) 
+                continue ;
+            if ( seen.contains(lang) )
+                continue ;
+            seen.add(lang) ;
+            out.println("   "+lang.getLabel()) ;
+        }
+    }
+    
+    public RDFFormat getOutputStreamFormat() {
+        return streamOutput ;
+    }
+    
+    public RDFFormat getOutputFormatted() {
+        return formattedOutput ;
+    }
+    
+    public boolean compressedOutput() {
+        return compressedOutput ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModLangParse.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModLangParse.java b/jena-cmds/src/main/java/arq/cmdline/ModLangParse.java
new file mode 100644
index 0000000..212807d
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModLangParse.java
@@ -0,0 +1,180 @@
+/*
+ * 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 arq.cmdline;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.iri.IRI ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFLanguages ;
+import org.apache.jena.riot.RiotException ;
+import org.apache.jena.riot.system.IRIResolver ;
+import org.apache.jena.util.FileManager ;
+
+public class ModLangParse extends ModBase
+{
+    private ArgDecl argCheck    = new ArgDecl(ArgDecl.NoValue, "check") ;
+    private ArgDecl argNoCheck  = new ArgDecl(ArgDecl.NoValue, "nocheck", "noCheck") ;
+    private ArgDecl argSink     = new ArgDecl(ArgDecl.NoValue, "sink", "null") ;
+
+    private ArgDecl argStrict   = new ArgDecl(ArgDecl.NoValue, "strict") ;
+    private ArgDecl argValidate = new ArgDecl(ArgDecl.NoValue, "validate") ;
+    
+    private ArgDecl argSkip     = new ArgDecl(ArgDecl.NoValue, "skip") ;
+    private ArgDecl argNoSkip   = new ArgDecl(ArgDecl.NoValue, "noSkip") ;
+    private ArgDecl argStop     = new ArgDecl(ArgDecl.NoValue, "stopOnError", "stoponerror", "stop") ;
+    
+    private ArgDecl argBase     = new ArgDecl(ArgDecl.HasValue, "base") ;
+    
+    private ArgDecl argRDFS     = new ArgDecl(ArgDecl.HasValue, "rdfs") ;
+    
+    private ArgDecl argSyntax     = new ArgDecl(ArgDecl.HasValue, "syntax") ;
+
+    private  String rdfsVocabFilename   = null ;
+    private  Model  rdfsVocab           = null ;
+    private  String baseIRI             = null ;
+    private boolean explicitCheck       = false ;
+    private boolean explicitNoCheck     = false ;
+    private boolean skipOnBadTerm       = false ;
+    private boolean stopOnBadTerm       = false ;
+    private boolean bitbucket           = false ; 
+    private boolean strict              = false ;
+    private boolean validate            = false ;
+    private Lang lang                   = null ;
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine) {
+        cmdLine.getUsage().startCategory("Parser control") ;
+        cmdLine.add(argSink,    "--sink",           "Parse but throw away output") ;
+        cmdLine.add(argSyntax,  "--syntax=NAME",    "Set syntax (otherwise syntax guessed from file extension)") ;
+        cmdLine.add(argBase,    "--base=URI",       "Set the base URI (does not apply to N-triples and N-Quads)") ;
+        cmdLine.add(argCheck,   "--check",          "Addition checking of RDF terms") ; // (default: off for N-triples, N-Quads, on for Turtle and TriG)") ;
+        cmdLine.add(argStrict,  "--strict",         "Run with in strict mode") ;
+        cmdLine.add(argValidate,"--validate",       "Same as --sink --check --strict") ;
+        cmdLine.add(argRDFS,    "--rdfs=file",      "Apply some RDFS inference using the vocabulary in the file") ;
+        
+        cmdLine.add(argNoCheck, "--nocheck",        "Turn off checking of RDF terms") ;
+//        cmdLine.add(argSkip,    "--noSkip",         "Skip (do not output) triples failing the RDF term tests") ;
+//        cmdLine.add(argNoSkip,  "--skip",           "Include triples failing the RDF term tests (not recommended)") ;
+        cmdLine.add(argStop,    "--stop",           "Stop parsing on encountering a bad RDF term") ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine) {
+        if ( cmdLine.contains(argValidate) ) {
+            validate = true ;
+            strict = true ;
+            explicitCheck = true ;
+            bitbucket = true ;
+        }
+
+        if ( cmdLine.contains(argSyntax) ) {
+            String syntax = cmdLine.getValue(argSyntax) ;
+            Lang lang$ = RDFLanguages.nameToLang(syntax) ;
+            if ( lang$ == null )
+                throw new CmdException("Can not detemine the syntax from '" + syntax + "'") ;
+            this.lang = lang$ ;
+        }
+
+        if ( cmdLine.contains(argCheck) )
+            explicitCheck = true ;
+
+        if ( cmdLine.contains(argNoCheck) )
+            explicitNoCheck = true ;
+
+        if ( cmdLine.contains(argStrict) )
+            strict = true ;
+
+        if ( cmdLine.contains(argSkip) )
+            skipOnBadTerm = true ;
+        if ( cmdLine.contains(argNoSkip) )
+            skipOnBadTerm = false ;
+
+        if ( cmdLine.contains(argBase) ) {
+            baseIRI = cmdLine.getValue(argBase) ;
+            IRI iri = IRIResolver.resolveIRI(baseIRI) ;
+            if ( iri.hasViolation(false) )
+                throw new CmdException("Bad base IRI: " + baseIRI) ;
+            if ( !iri.isAbsolute() )
+                throw new CmdException("Base IRI must be an absolute IRI: " + baseIRI) ;
+        }
+
+        if ( cmdLine.contains(argStop) )
+            stopOnBadTerm = true ;
+
+        if ( cmdLine.contains(argSink) )
+            bitbucket = true ;
+
+        if ( cmdLine.contains(argRDFS) ) {
+            try {
+                rdfsVocabFilename = cmdLine.getArg(argRDFS).getValue() ;
+                rdfsVocab = FileManager.get().loadModel(rdfsVocabFilename) ;
+            } catch (RiotException ex) {
+                throw new CmdException("Error in RDFS vocabulary: " + rdfsVocabFilename) ;
+            } catch (Exception ex) {
+                throw new CmdException("Error: " + ex.getMessage()) ;
+            }
+        }
+    }
+
+    public boolean explicitChecking() {
+        return explicitCheck ;
+    }
+
+    public boolean explicitNoChecking() {
+        return explicitNoCheck ;
+    }
+
+    public boolean strictMode() {
+        return strict ;
+    }
+
+    public boolean validate() {
+        return validate ;
+    }
+
+    public boolean skipOnBadTerm() {
+        return skipOnBadTerm ;
+    }
+
+    public boolean stopOnBadTerm() {
+        return stopOnBadTerm ;
+    }
+
+    public boolean toBitBucket() {
+        return bitbucket ;
+    }
+
+    public String getBaseIRI() {
+        return baseIRI ;
+    }
+
+    public Model getRDFSVocab() {
+        return rdfsVocab ;
+    }
+
+    public Lang getLang() {
+        return lang ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModQueryIn.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModQueryIn.java b/jena-cmds/src/main/java/arq/cmdline/ModQueryIn.java
new file mode 100644
index 0000000..290df7c
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModQueryIn.java
@@ -0,0 +1,156 @@
+/*
+ * 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 arq.cmdline ;
+
+import java.io.IOException ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+import jena.cmd.TerminationException;
+
+import org.apache.jena.query.Query ;
+import org.apache.jena.query.QueryFactory ;
+import org.apache.jena.query.Syntax ;
+import org.apache.jena.shared.JenaException ;
+import org.apache.jena.sparql.ARQInternalErrorException ;
+import org.apache.jena.util.FileUtils ;
+
+public class ModQueryIn extends ModBase {
+    protected final ArgDecl queryFileDecl   = new ArgDecl(ArgDecl.HasValue, "query", "file") ;
+    protected final ArgDecl querySyntaxDecl = new ArgDecl(ArgDecl.HasValue, "syntax", "syn", "in") ;
+    protected final ArgDecl queryBaseDecl   = new ArgDecl(ArgDecl.HasValue, "base") ;
+
+    private Syntax          defaultQuerySyntax     = Syntax.syntaxARQ ;
+    private Syntax          querySyntax     = null ;
+    private String          queryFilename   = null ;
+    private String          queryString     = null ;
+    private Query           query           = null ;
+    private String          baseURI         = null ;
+
+    public ModQueryIn(Syntax defaultSyntax) {
+        defaultQuerySyntax = defaultSyntax ;
+        querySyntax = defaultSyntax ;
+    }
+
+    @Override
+    public void registerWith(CmdGeneral cmdLine) {
+        cmdLine.getUsage().startCategory("Query") ;
+        cmdLine.add(queryFileDecl,   "--query, --file",  "File containing a query") ;
+        cmdLine.add(querySyntaxDecl, "--syntax, --in",   "Syntax of the query") ;
+        cmdLine.add(queryBaseDecl,   "--base",           "Base URI for the query") ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdline) throws IllegalArgumentException {
+        if ( cmdline.contains(queryBaseDecl) )
+            baseURI = cmdline.getValue(queryBaseDecl) ;
+
+        if ( cmdline.contains(queryFileDecl) ) {
+            queryFilename = cmdline.getValue(queryFileDecl) ;
+            querySyntax = Syntax.guessFileSyntax(queryFilename, defaultQuerySyntax) ;
+        }
+
+        if ( cmdline.getNumPositional() == 0 && queryFilename == null )
+            cmdline.cmdError("No query string or query file") ;
+
+        if ( cmdline.getNumPositional() > 1 )
+            cmdline.cmdError("Only one query string allowed") ;
+
+        if ( cmdline.getNumPositional() == 1 && queryFilename != null )
+            cmdline.cmdError("Either query string or query file - not both") ;
+
+        if ( queryFilename == null ) {
+            // One positional argument.
+            String qs = cmdline.getPositionalArg(0) ;
+            if ( cmdline.matchesIndirect(qs) )
+                querySyntax = Syntax.guessFileSyntax(qs, defaultQuerySyntax) ;
+
+            queryString = cmdline.indirect(qs) ;
+        }
+
+        // Set syntax
+        if ( cmdline.contains(querySyntaxDecl) ) {
+            // short name
+            String s = cmdline.getValue(querySyntaxDecl) ;
+            Syntax syn = Syntax.lookup(s) ;
+            if ( syn == null )
+                cmdline.cmdError("Unrecognized syntax: " + s) ;
+            querySyntax = syn ;
+        }
+    }
+
+    public Syntax getQuerySyntax() {
+        return querySyntax ;
+    }
+
+    public Query getQuery() {
+        if ( query != null )
+            return query ;
+
+        if ( queryFilename != null && queryString != null ) {
+            System.err.println("Both query string and query file name given") ;
+            throw new TerminationException(1) ;
+        }
+
+        if ( queryFilename == null && queryString == null ) {
+            System.err.println("No query string and no query file name given") ;
+            throw new TerminationException(1) ;
+        }
+
+        try {
+            if ( queryFilename != null ) {
+                if ( queryFilename.equals("-") ) {
+                    try {
+                        // Stderr?
+                        queryString = FileUtils.readWholeFileAsUTF8(System.in) ;
+                        // And drop into next if
+                    } catch (IOException ex) {
+                        throw new CmdException("Error reading stdin", ex) ;
+                    }
+                } else {
+                    query = QueryFactory.read(queryFilename, baseURI, getQuerySyntax()) ;
+                    return query ;
+                }
+            }
+
+            query = QueryFactory.create(queryString, baseURI, getQuerySyntax()) ;
+            return query ;
+        } catch (ARQInternalErrorException intEx) {
+            System.err.println(intEx.getMessage()) ;
+            if ( intEx.getCause() != null ) {
+                System.err.println("Cause:") ;
+                intEx.getCause().printStackTrace(System.err) ;
+                System.err.println() ;
+            }
+            intEx.printStackTrace(System.err) ;
+            throw new TerminationException(99) ;
+        }
+        catch (JenaException ex) {
+            System.err.println(ex.getMessage()) ;
+            throw new TerminationException(2) ;
+        } catch (Exception ex) {
+            System.out.flush() ;
+            ex.printStackTrace(System.err) ;
+            throw new TerminationException(98) ;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModQueryOut.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModQueryOut.java b/jena-cmds/src/main/java/arq/cmdline/ModQueryOut.java
new file mode 100644
index 0000000..d32f6c0
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModQueryOut.java
@@ -0,0 +1,92 @@
+/*
+ * 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 arq.cmdline;
+
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.query.Query ;
+import org.apache.jena.query.Syntax ;
+import org.apache.jena.sparql.util.QueryOutputUtils ;
+
+public class ModQueryOut extends ModBase
+{
+    protected final ArgDecl queryOutputSyntaxDecl  = new ArgDecl(ArgDecl.HasValue, "out", "format") ;
+    protected final ArgDecl queryNumberDecl        = new ArgDecl(ArgDecl.NoValue, "num", "number") ;
+
+    private Syntax outputSyntax = Syntax.syntaxSPARQL ;
+    private boolean lineNumbers = false ;
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Output") ;
+        cmdLine.add(queryOutputSyntaxDecl, "--out, --format",  "Output syntax") ;
+        cmdLine.add(queryNumberDecl, "--num", "Print line numbers") ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdline) throws IllegalArgumentException
+    {
+        if ( cmdline.contains(queryOutputSyntaxDecl) )
+        {
+            // short name
+            String s = cmdline.getValue(queryOutputSyntaxDecl) ;
+            Syntax syn = Syntax.lookup(s) ;
+            if ( syn == null )
+                cmdline.cmdError("Unrecognized syntax: "+s) ;
+            outputSyntax = syn ; 
+        }        
+        
+        lineNumbers = cmdline.contains(queryNumberDecl) ;
+    }
+    
+    public Syntax getOutputSyntax()
+    {
+        return outputSyntax ;
+    }
+
+    public void output(Query query)
+    { output(out(), query) ; }
+    
+    public void output(IndentedWriter out, Query query)
+    { QueryOutputUtils.printQuery(out, query, outputSyntax) ; }
+    
+    public void outputOp(Query query, boolean printOptimized)
+    { outputOp(out(), query, printOptimized) ; }
+
+    public void outputOp(IndentedWriter out, Query query, boolean printOptimized)
+    { QueryOutputUtils.printOp(out, query, printOptimized) ; }
+    
+    public void outputQuad(Query query, boolean printOptimized)
+    { outputQuad(out(), query, printOptimized) ; }
+    
+    public void outputQuad(IndentedWriter out, Query query, boolean printOptimized)
+    { QueryOutputUtils.printQuad(out, query, printOptimized) ; }
+    
+    private IndentedWriter out()
+    {
+        return new IndentedWriter(System.out, lineNumbers) ;
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModRemote.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModRemote.java b/jena-cmds/src/main/java/arq/cmdline/ModRemote.java
new file mode 100644
index 0000000..97f03eb
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModRemote.java
@@ -0,0 +1,75 @@
+/*
+ * 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 arq.cmdline;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+
+public class ModRemote extends ModBase
+{
+    protected final 
+    ArgDecl serviceDecl = new ArgDecl(ArgDecl.HasValue, "service") ;
+    
+    // Or --serviceType GET, POST, SOAP
+    protected final 
+    ArgDecl postServiceDecl = new ArgDecl(ArgDecl.NoValue, "post", "POST") ;
+    
+    private String serviceURL ;
+    private boolean usePost ;
+    
+    public void checkCommandLine(CmdArgModule cmdLine)
+    {}
+    
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        serviceURL = cmdLine.getValue(serviceDecl) ;
+        usePost = cmdLine.contains(postServiceDecl) ;
+    }
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Remote") ;
+        cmdLine.add(serviceDecl,
+                    "--service=",
+                    "Service endpoint URL") ;
+        cmdLine.add(postServiceDecl,
+                    "--post",
+                    "Force use of HTTP POST") ;
+
+    }
+
+    public String getServiceURL()
+    {
+        return serviceURL ;
+    }
+
+    public boolean usePost()
+    {
+        return usePost ;
+    }
+    
+    
+    
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModResultsIn.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModResultsIn.java b/jena-cmds/src/main/java/arq/cmdline/ModResultsIn.java
new file mode 100644
index 0000000..c560767
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModResultsIn.java
@@ -0,0 +1,138 @@
+/*
+ * 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 arq.cmdline;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+import jena.cmd.TerminationException;
+
+import org.apache.jena.query.ResultSet ;
+import org.apache.jena.query.ResultSetFactory ;
+import org.apache.jena.shared.NotFoundException ;
+import org.apache.jena.sparql.ARQInternalErrorException ;
+import org.apache.jena.sparql.resultset.ResultsFormat ;
+
+public class ModResultsIn extends ModBase
+{
+    protected final ArgDecl resultsInputFmtDecl = new ArgDecl(ArgDecl.HasValue, "in") ;
+    protected final ArgDecl fileDecl = new ArgDecl(ArgDecl.HasValue, "file") ;
+
+    private ResultsFormat inputFormat = ResultsFormat.FMT_TEXT ;
+    private String resultsFilename = null ;
+    private ResultSet resultSet = null ;
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Results") ;
+        cmdLine.add(fileDecl,
+                    "--file",
+                    "Input file") ;
+        cmdLine.add(resultsInputFmtDecl,
+                    "--in",
+                    "Results format (XML, JSON; RDF serialization)") ;  
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdline) throws IllegalArgumentException
+    {
+        // Input file.
+        if ( cmdline.contains(fileDecl) )
+            resultsFilename = cmdline.getValue(fileDecl) ;
+        
+        if ( cmdline.getNumPositional() == 0 && resultsFilename == null )
+            cmdline.cmdError("No results file") ;
+
+        if ( cmdline.getNumPositional() > 1 )
+            cmdline.cmdError("Only one result set file allowed") ;
+            
+        if ( cmdline.getNumPositional() == 1 && resultsFilename != null )
+            cmdline.cmdError("Either result set file or --file - not both") ;
+
+        if ( resultsFilename == null )
+            // One positional argument.
+            resultsFilename = cmdline.getPositionalArg(0) ;
+        
+        // Guess format
+        if ( resultsFilename != null )
+            inputFormat = ResultsFormat.guessSyntax(resultsFilename) ;
+
+        // Set format
+        if ( cmdline.contains(resultsInputFmtDecl) )
+        {
+            String rFmt = cmdline.getValue(resultsInputFmtDecl) ;
+            inputFormat = ResultsFormat.lookup(rFmt) ;
+            if ( inputFormat == null )
+                cmdline.cmdError("Unrecognized output format: "+rFmt) ;
+        }
+    }
+    
+    public void checkCommandLine(CmdArgModule cmdLine)
+    {}
+    
+    
+    public ResultSet getResultSet()
+    {
+        if ( resultSet != null )
+            return resultSet ;
+        
+        if ( resultsFilename == null )
+        {
+            System.err.println("No result file name" ) ;
+            throw new TerminationException(1) ;
+        }
+
+        try
+        {
+            if ( resultsFilename.equals("-") )
+                return ResultSetFactory.load(System.in, inputFormat) ;
+            ResultSet rs = ResultSetFactory.load(resultsFilename, inputFormat) ;
+            if ( rs == null )
+            {
+                System.err.println("Failed to read the result set") ;
+                throw new TerminationException(9) ;
+            }
+            resultSet = rs ;
+            return resultSet ;
+        }
+        catch (NotFoundException ex)
+        {
+            System.err.println("File not found: "+resultsFilename) ;
+            throw new TerminationException(9) ;
+        }
+        catch (ARQInternalErrorException intEx)
+        {
+            System.err.println(intEx.getMessage()) ;
+            if ( intEx.getCause() != null )
+            {
+                System.err.println("Cause:") ;
+                intEx.getCause().printStackTrace(System.err) ;
+                System.err.println() ;
+            }
+            intEx.printStackTrace(System.err) ;
+            throw new TerminationException(99) ;
+        }
+    }
+
+    
+    public ResultsFormat getInputFormat() { return inputFormat ; }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModResultsOut.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModResultsOut.java b/jena-cmds/src/main/java/arq/cmdline/ModResultsOut.java
new file mode 100644
index 0000000..938be5f
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModResultsOut.java
@@ -0,0 +1,70 @@
+/*
+ * 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 arq.cmdline;
+
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.query.ResultSet ;
+import org.apache.jena.sparql.core.Prologue ;
+import org.apache.jena.sparql.resultset.ResultsFormat ;
+import org.apache.jena.sparql.util.QueryExecUtils ;
+
+public class ModResultsOut extends ModBase
+{
+    protected final 
+    ArgDecl resultsFmtDecl = new ArgDecl(ArgDecl.HasValue, "results", "out", "rfmt") ;
+
+    private ResultsFormat resultsFormat = ResultsFormat.FMT_UNKNOWN ;
+    
+    @Override
+    public void processArgs(CmdArgModule cmdline) throws IllegalArgumentException
+    {
+        if ( cmdline.contains(resultsFmtDecl) )
+        {
+            String rFmt = cmdline.getValue(resultsFmtDecl) ;
+            resultsFormat = ResultsFormat.lookup(rFmt) ;
+            if ( resultsFormat == null )
+                cmdline.cmdError("Unrecognized output format: "+rFmt) ;
+        }
+    }
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Results") ;
+        cmdLine.add(resultsFmtDecl,
+                    "--results=",
+                    "Results format (Result set: text, XML, JSON, CSV, TSV; Graph: RDF serialization)") ;  
+    }
+
+    public void checkCommandLine(CmdArgModule cmdLine)
+    {}
+
+    public void printResultSet(ResultSet resultSet, Prologue prologue)
+    {
+        QueryExecUtils.outputResultSet(resultSet, prologue, resultsFormat) ;
+    }
+    
+    public ResultsFormat getResultsFormat() { return resultsFormat ; }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModSymbol.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModSymbol.java b/jena-cmds/src/main/java/arq/cmdline/ModSymbol.java
new file mode 100644
index 0000000..b465644
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModSymbol.java
@@ -0,0 +1,26 @@
+/*
+ * 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 arq.cmdline;
+
+/** Set Context items
+ *  @deprecated Use ModContext.
+ */
+@Deprecated
+public class ModSymbol extends ModContext {
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModTime.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModTime.java b/jena-cmds/src/main/java/arq/cmdline/ModTime.java
new file mode 100644
index 0000000..03a2096
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModTime.java
@@ -0,0 +1,73 @@
+/*
+ * 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 arq.cmdline;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.atlas.lib.Timer ;
+
+
+public class ModTime extends ModBase
+{
+
+    protected final ArgDecl timeDecl = new ArgDecl(ArgDecl.NoValue, "time") ;
+    
+    protected Timer timer = new Timer() ;
+    
+    private boolean timing = false ;
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Time") ;
+        cmdLine.add(timeDecl, "--time", "Time the operation") ;
+    }
+    
+    public void checkCommandLine(CmdArgModule cmdLine)
+    {}
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        timing = cmdLine.contains(timeDecl) ;
+    }
+    
+    public boolean timingEnabled() { return timing ; }
+    
+    public void setTimingEnabled(boolean timingEnabled) { timing = timingEnabled ; }
+    
+    public void startTimer()
+    { timer.startTimer() ; } 
+    
+    public long endTimer()
+    { return timer.endTimer() ; } 
+    
+    public long readTimer() 
+    { return timer.readTimer() ; }
+    
+    public long getTimeInterval()
+    { return timer.getTimeInterval() ; }
+    
+    public String timeStr(long timeInterval)
+    { return Timer.timeStr(timeInterval) ; }
+    
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/iri.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/iri.java b/jena-cmds/src/main/java/arq/iri.java
new file mode 100644
index 0000000..2d5232c
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/iri.java
@@ -0,0 +1,57 @@
+/*
+ * 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 arq;
+
+import java.util.Iterator ;
+
+
+import org.apache.jena.iri.IRI ;
+import org.apache.jena.iri.IRIFactory ;
+import org.apache.jena.iri.Violation ;
+import org.apache.jena.riot.system.IRIResolver ;
+
+public class iri
+{
+
+    public static void main(String[] args)
+    {
+        //IRIFactory iriFactory = IRIFactory.iriImplementation() ;
+        IRIFactory iriFactory = IRIResolver.iriFactory ;
+        
+        boolean first = true ;
+        for ( String iriStr : args )
+        {
+            if ( ! first )
+                System.out.println() ;
+            first = false ;
+            
+            IRI iri = iriFactory.create(iriStr) ;
+            System.out.println(iriStr + " ==> "+iri) ;
+            if ( iri.isRelative() )
+                System.out.println("Relative: "+iri.isRelative()) ;
+
+            Iterator<Violation> vIter = iri.violations(true) ;
+            for ( ; vIter.hasNext() ; )
+            {
+                System.out.println(vIter.next().getShortMessage()) ;
+            }
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/juuid.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/juuid.java b/jena-cmds/src/main/java/arq/juuid.java
new file mode 100644
index 0000000..ccd6fd1
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/juuid.java
@@ -0,0 +1,173 @@
+/*
+ * 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 arq;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.shared.uuid.* ;
+
+public class juuid extends CmdGeneral
+{
+    ModJUUID modJUUID = new ModJUUID() ;
+    int number = 1 ;
+    boolean resetEachTime = false ;
+    int uuidType = 0 ;
+    boolean asURN = false ;
+    boolean asURI = false ;
+    boolean asPlain = false ;
+
+    public static void main (String [] argv)
+    {
+        new juuid(argv).mainAndExit() ;
+    }
+    
+    private juuid(String argv[])
+    {
+        super(argv) ;
+        super.addModule(modJUUID) ;
+    }
+
+    @Override
+    protected String getSummary()
+    {
+        return getCommandName()+" [--num=N] [--reset] [--type={1|4}]" ;
+    }
+
+    @Override
+    protected void exec()
+    {
+        if ( uuidType == UUID_V1.version )
+            JenaUUID.setFactory(new UUID_V1_Gen()) ;
+        if ( uuidType == UUID_V4.version )
+            JenaUUID.setFactory(new UUID_V4_Gen()) ;
+
+        for ( int i = 0 ; i < number ; i++ )
+        {
+            if ( resetEachTime && i != 0)
+                JenaUUID.reset() ;
+            JenaUUID uuid = JenaUUID.generate() ;
+            String str = null ;
+            if ( asURN )
+                str = uuid.asURN() ; 
+            else if ( asURI )
+                str = uuid.asURI() ; 
+            else if ( asPlain )
+                str = uuid.asString() ; 
+            if ( str == null )
+                str = uuid.asString() ;
+            System.out.println(str) ;
+        }
+    }
+
+    @Override
+    protected String getCommandName()
+    {
+        return "uuid" ;
+    }
+
+    @Override
+    protected void processModulesAndArgs()
+    {
+        
+    }
+    
+    static ArgDecl argDeclNum      = new ArgDecl(ArgDecl.HasValue,  "num", "n") ;
+    static ArgDecl argDeclReset    = new ArgDecl(ArgDecl.NoValue,   "reset") ;
+    static ArgDecl argDeclGen      = new ArgDecl(ArgDecl.HasValue,  "gen", "scheme", "type", "ver") ;
+    static ArgDecl argDeclURN      = new ArgDecl(ArgDecl.NoValue,   "urn") ;
+    static ArgDecl argDeclURI      = new ArgDecl(ArgDecl.NoValue,   "uri") ;
+    static ArgDecl argDeclPlain    = new ArgDecl(ArgDecl.NoValue,   "plain") ;
+
+    class ModJUUID extends ModBase
+    {
+        @Override
+        public void registerWith(CmdGeneral cmdLine)
+        {
+            cmdLine.add(argDeclNum) ;
+            cmdLine.add(argDeclReset) ;
+            cmdLine.add(argDeclGen) ;
+            cmdLine.add(argDeclURN) ;
+            cmdLine.add(argDeclURI) ;
+            cmdLine.add(argDeclPlain) ;
+        }
+        
+        @Override
+        public void processArgs(CmdArgModule cmdLine)
+        {
+            String numStr = null ;
+            
+            if ( getNumPositional() > 1)
+                cmdError("Too many positional arguments") ;
+            
+            if ( cmdLine.contains(argDeclNum) )
+            {
+                if ( getNumPositional() != 0 )
+                    cmdError("--num and positional arguments don't go together") ;
+                numStr = getValue(argDeclNum) ;
+            }
+            
+            if ( numStr == null && cmdLine.getNumPositional() == 1 )
+                numStr = cmdLine.getPositionalArg(0) ;
+            
+            if ( numStr != null )
+            {
+                try
+                {
+                    number = Integer.parseInt(numStr) ;
+                    if ( number < 0 || number > 10000 )
+                        cmdLine.cmdError("Number out of range:" + numStr);
+                }
+                catch (NumberFormatException e)
+                {
+                    cmdLine.cmdError("Bad argument: " + numStr);
+                }
+            }
+
+            resetEachTime = cmdLine.contains(argDeclReset) ;
+            
+            if ( contains(argDeclGen) ) 
+            {
+                String s = getValue(argDeclGen) ;
+                if ( s.equalsIgnoreCase("time") || s.equalsIgnoreCase("1"))
+                    uuidType = UUID_V1.version ;
+                else if ( s.equalsIgnoreCase("random") || s.equalsIgnoreCase("rand") || s.equalsIgnoreCase("4"))
+                    uuidType = UUID_V4.version ;
+                else
+                    cmdError("Unrecognized UUID scheme: "+s) ;
+            }
+            
+            if ( contains(argDeclURN) || contains(argDeclURI) || contains(argDeclPlain) )
+            {
+                asURN = contains(argDeclURN) ;
+                asURI = contains(argDeclURI) ;
+                asPlain = contains(argDeclPlain) ;
+            }
+            else
+            {
+                // Defaults
+                asURN = true ;
+                asURI = false ;
+                asPlain = false ;
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/load.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/load.java b/jena-cmds/src/main/java/arq/load.java
new file mode 100644
index 0000000..b5d75c8
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/load.java
@@ -0,0 +1,120 @@
+/*
+ * 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 arq;
+
+import java.util.Iterator ;
+import java.util.List ;
+
+import arq.cmdline.CmdUpdate ;
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException;
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.sparql.modify.request.UpdateLoad ;
+import org.apache.jena.sparql.sse.SSE ;
+import org.apache.jena.sparql.util.graph.GraphLoadMonitor ;
+import org.apache.jena.update.UpdateExecutionFactory ;
+import org.apache.jena.update.UpdateRequest ;
+
+public class load extends CmdUpdate
+{
+    static private final ArgDecl graphNameArg = new ArgDecl(ArgDecl.HasValue, "--graph") ;
+    static private final ArgDecl dumpArg = new ArgDecl(ArgDecl.NoValue, "--dump") ;
+    
+    String graphName = null ;
+    List<String> loadFiles = null ;
+    boolean dump = false ;
+    
+    public static void main (String... argv)
+    { new load(argv).mainRun() ; }
+    
+    protected load(String[] argv)
+    {
+        super(argv) ;
+        super.add(graphNameArg, "--graph=IRI", "Graph IRI (loads default graph if absent)") ;
+        super.add(dumpArg, "--dump", "Dump the resulting graph store") ;
+    }
+
+    @Override
+    protected void processModulesAndArgs()
+    {
+        if ( containsMultiple(graphNameArg) )
+            throw new CmdException("At most one --graph allowed") ;
+        
+        graphName = getValue(graphNameArg) ;
+        loadFiles = super.getPositional() ;
+        dump = contains(dumpArg) ;
+        super.processModulesAndArgs() ;
+    }
+    
+    @Override
+    protected String getCommandName() { return Lib.className(this) ; }
+    
+    @Override
+    protected String getSummary() { return getCommandName()+" --desc=assembler [--dump] --update=<request file>" ; }
+
+    @Override
+    protected void execUpdate(DatasetGraph graphStore)
+    {
+        if ( loadFiles.size() == 0 )
+            throw new CmdException("Nothing to do") ;
+        
+        UpdateRequest req = new UpdateRequest() ;
+        for ( String filename : loadFiles )
+        {
+            UpdateLoad loadReq = new UpdateLoad( filename, graphName );
+            req.add( loadReq );
+        }
+        
+        if ( true )
+        {
+            // Need a better way
+            monitor(graphStore.getDefaultGraph()) ;
+            for ( Iterator<Node> iter = graphStore.listGraphNodes() ; iter.hasNext() ; )
+            {
+                Graph g = graphStore.getGraph(iter.next()) ;
+                monitor(g) ;
+            }
+        }
+        
+        UpdateExecutionFactory.create(req, graphStore).execute() ;
+        
+        if ( dump )
+        {
+            IndentedWriter out = IndentedWriter.stdout ;
+            SSE.write(graphStore) ;
+            out.flush();
+        }
+    }
+
+    private void monitor(Graph graph)
+    {
+        GraphLoadMonitor m = new GraphLoadMonitor(20000,false) ;
+        //m.setSummaryLabel(getCommandName()) ;
+        graph.getEventManager().register(m)  ;
+    }
+    
+    @Override
+    protected DatasetGraph dealWithNoDataset() {
+        throw new CmdException("No dataset provided") ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/qexpr.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/qexpr.java b/jena-cmds/src/main/java/arq/qexpr.java
new file mode 100644
index 0000000..2408907
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/qexpr.java
@@ -0,0 +1,223 @@
+/*
+ * 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 arq;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException;
+import jena.cmd.CmdLineArgs;
+import jena.cmd.TerminationException;
+
+import org.apache.jena.Jena ;
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.query.ARQ ;
+import org.apache.jena.query.QueryParseException ;
+import org.apache.jena.riot.out.NodeFmtLib ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.sparql.ARQConstants ;
+import org.apache.jena.sparql.core.Prologue ;
+import org.apache.jena.sparql.engine.ExecutionContext ;
+import org.apache.jena.sparql.expr.Expr ;
+import org.apache.jena.sparql.expr.ExprEvalException ;
+import org.apache.jena.sparql.expr.ExprLib ;
+import org.apache.jena.sparql.expr.NodeValue ;
+import org.apache.jena.sparql.function.FunctionEnv ;
+import org.apache.jena.sparql.sse.WriterSSE ;
+import org.apache.jena.sparql.util.ExprUtils ;
+import org.apache.jena.sparql.util.NodeFactoryExtra ;
+
+/** A program to execute expressions from the command line. */
+
+public class qexpr
+{
+    // TODO Convert to extends CmdArgModule 
+    static { LogCtl.setCmdLogging(); }
+
+    public static void main (String... argv)
+    {
+        try {
+            main2(argv) ;
+        }
+        catch (TerminationException ex) { System.exit(ex.getCode()) ; }
+        catch (CmdException ex)
+        {
+            System.err.println(ex.getMessage()) ;
+            if ( ex.getCause() != null )
+                ex.getCause().printStackTrace(System.err) ;
+        }
+        
+    }
+    
+    public static void execAndReturn(String... argv)
+    {
+        try {
+            main2(argv) ;
+        }
+        catch (TerminationException ex) { return ; }
+        catch (CmdException ex)
+        {
+            System.err.println(ex.getMessage()) ;
+            if ( ex.getCause() != null )
+                ex.getCause().printStackTrace(System.err) ;
+        }
+    }
+        
+    public static void main2(String... argv)
+    {
+        
+        CmdLineArgs cl = new CmdLineArgs(argv) ;
+        
+        ArgDecl helpDecl = new ArgDecl(ArgDecl.NoValue, "h", "help") ;
+        cl.add(helpDecl) ;
+        
+        ArgDecl verboseDecl = new ArgDecl(ArgDecl.NoValue, "v", "verbose") ;
+        cl.add(verboseDecl) ;
+        
+        ArgDecl versionDecl = new ArgDecl(ArgDecl.NoValue, "ver", "version", "V") ;
+        cl.add(versionDecl) ;
+        
+        ArgDecl quietDecl = new ArgDecl(ArgDecl.NoValue, "q", "quiet") ;
+        cl.add(quietDecl) ;
+
+        ArgDecl reduceDecl =  new ArgDecl(ArgDecl.NoValue, "reduce", "fold", "simplify" ) ;
+        cl.add(reduceDecl) ;
+
+        ArgDecl strictDecl =  new ArgDecl(ArgDecl.NoValue, "strict") ;
+        cl.add(strictDecl) ;
+        
+        ArgDecl printDecl =  new ArgDecl(ArgDecl.HasValue, "print") ;
+        cl.add(printDecl) ;
+
+        try {
+            cl.process() ;
+        } catch (IllegalArgumentException ex)
+        {
+            System.err.println(ex.getMessage()) ;
+            usage(System.err) ;
+            throw new CmdException() ;
+        }
+
+        if ( cl.contains(helpDecl) )
+        {
+            usage() ;
+            throw new TerminationException(0) ;
+        }
+        
+        if ( cl.contains(versionDecl) )
+        {
+            System.out.println("ARQ Version: "+ARQ.VERSION+" (Jena: "+Jena.VERSION+")") ;
+            throw new TerminationException(0) ;
+        }
+ 
+        // ==== General things
+        boolean verbose = cl.contains(verboseDecl) ;
+        boolean quiet = cl.contains(quietDecl) ;
+
+        if ( cl.contains(strictDecl) )
+            ARQ.setStrictMode() ;
+        
+        boolean actionCopySubstitute = cl.contains(reduceDecl) ;
+        boolean actionPrintPrefix = false ;
+        boolean actionPrintSPARQL = false ; 
+        boolean actionPrint = cl.contains(printDecl) ;
+
+        for ( String v : cl.getValues( printDecl ) )
+        {
+            if ( v.equalsIgnoreCase( "prefix" ) || v.equalsIgnoreCase( "op" ) )
+            {
+                actionPrintPrefix = true;
+            }
+            else if ( v.equalsIgnoreCase( "expr" ) )
+            {
+                actionPrintSPARQL = true;
+            }
+            else
+            {
+                System.err.println( "Unknown print form: " + v );
+                throw new TerminationException( 0 );
+            }
+        }
+
+        // ==== Do it
+        
+        for ( int i = 0 ; i < cl.getNumPositional() ; i++ )
+        {
+            String exprStr = cl.getPositionalArg(i) ;
+            exprStr = cl.indirect(exprStr) ;
+            
+            try {
+                PrefixMapping pmap = PrefixMapping.Factory.create()  ;
+                pmap.setNsPrefixes(ARQConstants.getGlobalPrefixMap()) ;
+                pmap.setNsPrefix("", "http://example/") ;
+                pmap.setNsPrefix("ex", "http://example/ns#") ;
+//              Node n = asNode() ;
+//              return makeNode(n) ;
+
+                Expr expr = ExprUtils.parse(exprStr, pmap) ;
+                if ( verbose )
+                    System.out.print(expr.toString()+" => ") ;
+                
+                if ( actionPrint )
+                {
+                    if ( actionPrintSPARQL )
+                        System.out.println(ExprUtils.fmtSPARQL(expr)) ;
+                    if ( actionPrintPrefix )
+                        WriterSSE.out(IndentedWriter.stdout, expr, new Prologue(pmap)) ;
+                    continue ;
+                }
+                
+                try {
+                    if ( actionCopySubstitute )
+                    {
+                        Expr e = ExprLib.foldConstants(expr) ;
+                        System.out.println(e) ;
+                    }
+                    else
+                    {
+                        // Default action
+                        ARQ.getContext().set(ARQConstants.sysCurrentTime, NodeFactoryExtra.nowAsDateTime()) ;
+                        FunctionEnv env = new ExecutionContext(ARQ.getContext(), null, null, null) ; 
+                        NodeValue r = expr.eval(null, env) ;
+                        //System.out.println(r.asQuotedString()) ;
+                        Node n = r.asNode() ;
+                        String s = NodeFmtLib.displayStr(n) ;
+                        System.out.println(s) ;
+                    }
+                } catch (ExprEvalException ex)
+                {
+                    System.out.println("Exception: "+ex.getMessage()) ;
+                    throw new TerminationException(2) ;
+                }
+            } catch (QueryParseException ex)
+            {
+                System.err.println("Parse error: "+ex.getMessage()) ;
+                throw new TerminationException(2) ;
+            }
+        }
+    }
+    
+    static void usage() { usage(System.out) ; }
+    
+    static void usage(java.io.PrintStream out)
+    {
+        out.println("Usage: [--print=[prefix|expr]] expression") ;
+    }
+
+ }

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/qparse.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/qparse.java b/jena-cmds/src/main/java/arq/qparse.java
new file mode 100644
index 0000000..749ab66
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/qparse.java
@@ -0,0 +1,269 @@
+/*
+ * 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 arq;
+
+import java.io.PrintStream ;
+import java.util.Iterator ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException;
+
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.query.* ;
+import org.apache.jena.shared.JenaException ;
+import org.apache.jena.sparql.ARQInternalErrorException ;
+import org.apache.jena.sparql.core.QueryCheckException ;
+import org.apache.jena.sparql.lang.ParserBase ;
+import org.apache.jena.sparql.resultset.ResultSetException ;
+import org.apache.jena.sparql.util.QueryOutputUtils ;
+import org.apache.jena.sparql.util.QueryUtils ;
+
+import arq.cmdline.CmdARQ ;
+import arq.cmdline.ModEngine ;
+import arq.cmdline.ModQueryIn ;
+import arq.cmdline.ModQueryOut ;
+
+/** A program to parse and print a query. */
+
+public class qparse extends CmdARQ
+{
+    protected ModQueryIn    modQuery        = new ModQueryIn(Syntax.syntaxSPARQL_11) ;
+    protected ModQueryOut   modOutput       = new ModQueryOut() ; 
+    protected ModEngine     modEngine       = new ModEngine() ;
+    protected final ArgDecl argDeclPrint    = new ArgDecl(ArgDecl.HasValue, "print") ;
+    protected final ArgDecl argDeclOpt      = new ArgDecl(ArgDecl.NoValue, "opt", "optimize") ;
+    protected final ArgDecl argDeclExplain  = new ArgDecl(ArgDecl.NoValue, "explain") ;
+    
+    protected boolean printNone             = false ;
+    protected boolean printQuery            = false ;
+    protected boolean printOp               = false ;
+    protected boolean printOpt              = false ;
+    protected boolean printQuad             = false ;
+    protected boolean printQuadOpt          = false ;
+    protected boolean printPlan             = false ;
+    
+    public static void main(String... argv)
+    {
+        new qparse(argv).mainRun() ;
+    }
+    
+    public qparse(String[] argv)
+    {
+        super(argv) ;
+        super.addModule(modQuery) ;
+        super.addModule(modOutput) ;
+        super.addModule(modEngine) ;
+        super.getUsage().startCategory(null) ;
+        super.add(argDeclPrint, "--print", "Print in various forms [query, op, quad, plan]") ;
+        super.add(argDeclExplain, "--explain", "Print with algebra-level optimization") ;
+        super.add(argDeclOpt, "--opt", "[deprecated]") ; 
+    }
+    
+    @Override
+    protected void processModulesAndArgs()
+    {
+        super.processModulesAndArgs() ;
+        
+        if ( contains(argDeclOpt) )
+            printOpt = true ;
+        if ( contains(argDeclExplain) )
+        {
+            printQuery = true ;
+            printOpt = true ;
+        }
+
+        for ( String arg : getValues( argDeclPrint ) )
+        {
+            if ( arg.equalsIgnoreCase( "query" ) )
+            {
+                printQuery = true;
+            }
+            else if ( arg.equalsIgnoreCase( "op" ) ||
+                arg.equalsIgnoreCase( "alg" ) ||
+                arg.equalsIgnoreCase( "algebra" ) )
+            {
+                printOp = true;
+            }
+            else if ( arg.equalsIgnoreCase( "quad" ) )
+            {
+                printQuad = true;
+            }
+            else if ( arg.equalsIgnoreCase( "quads" ) )
+            {
+                printQuad = true;
+            }
+            else if ( arg.equalsIgnoreCase( "plan" ) )
+            {
+                printPlan = true;
+            }
+            else if ( arg.equalsIgnoreCase( "opt" ) )
+            {
+                printOpt = true;
+            }
+            else if ( arg.equalsIgnoreCase( "optquad" ) )
+            {
+                printQuadOpt = true;
+            }
+            else if ( arg.equalsIgnoreCase( "quadopt" ) )
+            {
+                printQuadOpt = true;
+            }
+            else if ( arg.equalsIgnoreCase( "none" ) )
+            {
+                printNone = true;
+            }
+            else
+            {
+                throw new CmdException(
+                    "Not a recognized print form: " + arg + " : Choices are: query, op, quad, opt, optquad" );
+            }
+        }
+        
+        if ( ! printQuery && ! printOp && ! printQuad && ! printPlan && ! printOpt && ! printQuadOpt && ! printNone )
+            printQuery = true ;
+    }
+
+    static String usage = qparse.class.getName()+" [--in syntax] [--out syntax] [--print=FORM] [\"query\"] | --query <file>" ;
+    
+    @Override
+    protected String getSummary()
+    {
+        return usage ;
+    }
+    
+    static final String divider = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" ;
+    //static final String divider = "" ;
+    boolean needDivider = false ;
+    private void divider()
+    {
+        if ( needDivider ) System.out.println(divider) ;
+        needDivider = true ;
+    }
+    
+    @Override
+    protected void exec()
+    {
+        try{
+            Query query = modQuery.getQuery() ;
+            try {
+                LogCtl.disable(ParserBase.ParserLoggerName) ;
+                QueryUtils.checkQuery(query, true) ;
+            } catch (QueryCheckException ex)
+            {
+                System.err.println() ;
+                System.err.println("**** Check failure: "+ex.getMessage()) ;
+                if ( ex.getCause() != null )
+                    ex.getCause().printStackTrace(System.err) ;
+            }
+            finally { LogCtl.set(ParserBase.ParserLoggerName, "INFO") ; }
+
+            
+            // Print the query out in some syntax
+            if ( printQuery )
+            { divider() ; modOutput.output(query) ; }
+
+            // Print internal forms.
+            if ( printOp )
+            { divider() ; modOutput.outputOp(query, false) ; }
+            
+            if ( printQuad )
+            { divider() ; modOutput.outputQuad(query, false) ; }
+            
+            if ( printOpt )
+            { divider() ; modOutput.outputOp(query, true) ; }
+            
+            if ( printQuadOpt )
+            { divider() ; modOutput.outputQuad(query, true) ; }
+            
+            if ( printPlan )
+            { 
+                divider() ;
+                // This forces internal query initialization - must be after QueryUtils.checkQuery
+                QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.createGeneral()) ;
+                QueryOutputUtils.printPlan(query, qExec) ; 
+            }
+        }
+        catch (ARQInternalErrorException intEx)
+        {
+            System.err.println(intEx.getMessage()) ;
+            if ( intEx.getCause() != null )
+            {
+                System.err.println("Cause:") ;
+                intEx.getCause().printStackTrace(System.err) ;
+                System.err.println() ;
+            }
+            intEx.printStackTrace(System.err) ;
+        }
+        catch (ResultSetException ex)
+        {
+            System.err.println(ex.getMessage()) ;
+            ex.printStackTrace(System.err) ;
+        }
+        catch (QueryException qEx)
+        {
+            //System.err.println(qEx.getMessage()) ;
+            throw new CmdException("Query Exeception", qEx) ;
+        }
+        catch (JenaException ex) { 
+            ex.printStackTrace() ;
+            throw ex ; } 
+        catch (CmdException ex) { throw ex ; } 
+        catch (Exception ex)
+        {
+            throw new CmdException("Exception", ex) ;
+        }
+    }
+
+    @Override
+    protected String getCommandName() { return Lib.className(this) ; }
+
+//    static String usage = qparse.class.getName()+
+//            " [--in syntax] [--out syntax] [\"query\" | --query <file>\n"+
+//            "  where syntax is one of ARQ, SPARQL\n" +
+//            "Other options: \n"+
+//            "  --num on|off   Line number ('on' by default)\n"+
+//            "  -n             Same as --num=off\n"+
+//            "  --base URI     Set the base URI for resolving relative URIs\n"+
+//            "  --plain        No pretty printing\n"+
+//            "  --parse        Parse only - don't print\n"+
+//            "  ---planning    Turn planning on/off\n"+
+//            "  --show X       Show internal structure (X = query or plan)\n" ;
+    
+    static void writeSyntaxes(String msg, PrintStream out)
+    {
+        if ( msg != null )
+            out.println(msg) ;
+        for ( Iterator<String> iter = Syntax.querySyntaxNames.keys() ; iter.hasNext() ; )
+        {
+            String k = iter.next() ;
+            Syntax v = Syntax.lookup(k) ;
+            k = padOut(k,10) ;
+            out.println("  "+k+"  "+v) ;
+        }
+    }
+    // printf ... java 1.5 .. mutter,mutter
+    static String padOut(String x, int len)
+    {
+        StringBuilder r = new StringBuilder(x) ;
+        for ( int i = x.length() ; i <= len ; i++ )
+            r.append(" ") ;
+        return r.toString() ; 
+    }
+}


[19/20] jena git commit: JENA-1108 : jena-cmds module

Posted by an...@apache.org.
JENA-1108 : jena-cmds module

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

Branch: refs/heads/master
Commit: 498b2264143f67024085a32c354f7920a74802ae
Parents: eb9eec0
Author: Andy Seaborne <an...@apache.org>
Authored: Sat Jan 2 21:28:04 2016 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Jan 5 12:31:35 2016 +0000

----------------------------------------------------------------------
 jena-arq/src/main/java/arq/arq.java             |   37 -
 jena-arq/src/main/java/arq/bindings.java        |   42 -
 jena-arq/src/main/java/arq/cmdline/CmdARQ.java  |   65 -
 .../src/main/java/arq/cmdline/CmdARQ_SSE.java   |   45 -
 .../src/main/java/arq/cmdline/CmdUpdate.java    |   63 -
 .../src/main/java/arq/cmdline/ModAlgebra.java   |   82 -
 .../src/main/java/arq/cmdline/ModAssembler.java |   84 -
 .../src/main/java/arq/cmdline/ModContext.java   |   91 -
 .../src/main/java/arq/cmdline/ModDataset.java   |   49 -
 .../java/arq/cmdline/ModDatasetAssembler.java   |   70 -
 .../java/arq/cmdline/ModDatasetGeneral.java     |  119 -
 .../arq/cmdline/ModDatasetGeneralAssembler.java |   56 -
 .../src/main/java/arq/cmdline/ModEngine.java    |  110 -
 .../src/main/java/arq/cmdline/ModFormat.java    |   91 -
 jena-arq/src/main/java/arq/cmdline/ModItem.java |   80 -
 .../main/java/arq/cmdline/ModLangOutput.java    |  150 --
 .../src/main/java/arq/cmdline/ModLangParse.java |  180 --
 .../src/main/java/arq/cmdline/ModQueryIn.java   |  156 --
 .../src/main/java/arq/cmdline/ModQueryOut.java  |   92 -
 .../src/main/java/arq/cmdline/ModRemote.java    |   75 -
 .../src/main/java/arq/cmdline/ModResultsIn.java |  138 --
 .../main/java/arq/cmdline/ModResultsOut.java    |   70 -
 .../src/main/java/arq/cmdline/ModSymbol.java    |   26 -
 jena-arq/src/main/java/arq/cmdline/ModTime.java |   73 -
 jena-arq/src/main/java/arq/iri.java             |   57 -
 jena-arq/src/main/java/arq/juuid.java           |  173 --
 jena-arq/src/main/java/arq/load.java            |  120 -
 jena-arq/src/main/java/arq/qexpr.java           |  223 --
 jena-arq/src/main/java/arq/qparse.java          |  269 ---
 jena-arq/src/main/java/arq/query.java           |  257 ---
 jena-arq/src/main/java/arq/rdfdiff.java         |  312 ---
 jena-arq/src/main/java/arq/rset.java            |   73 -
 jena-arq/src/main/java/arq/rsparql.java         |   95 -
 jena-arq/src/main/java/arq/rupdate.java         |   98 -
 jena-arq/src/main/java/arq/sparql.java          |   37 -
 jena-arq/src/main/java/arq/sse.java             |  108 -
 jena-arq/src/main/java/arq/sse_exec.java        |   50 -
 jena-arq/src/main/java/arq/sse_expr.java        |   24 -
 jena-arq/src/main/java/arq/sse_query.java       |  162 --
 jena-arq/src/main/java/arq/tokens.java          |   24 -
 jena-arq/src/main/java/arq/uparse.java          |  187 --
 jena-arq/src/main/java/arq/update.java          |  128 --
 jena-arq/src/main/java/arq/utf8.java            |   29 -
 jena-arq/src/main/java/arq/version.java         |   29 -
 jena-arq/src/main/java/arq/wwwdec.java          |   36 -
 jena-arq/src/main/java/arq/wwwenc.java          |   61 -
 .../src/main/java/riotcmd/CmdLangParse.java     |  361 ---
 jena-arq/src/main/java/riotcmd/CmdTokens.java   |   75 -
 jena-arq/src/main/java/riotcmd/dumpthrift.java  |   51 -
 jena-arq/src/main/java/riotcmd/infer.java       |  154 --
 jena-arq/src/main/java/riotcmd/json.java        |   52 -
 jena-arq/src/main/java/riotcmd/nquads.java      |   48 -
 jena-arq/src/main/java/riotcmd/ntriples.java    |   48 -
 jena-arq/src/main/java/riotcmd/perftokens.java  |   28 -
 jena-arq/src/main/java/riotcmd/printtokens.java |   28 -
 jena-arq/src/main/java/riotcmd/rdfxml.java      |   48 -
 jena-arq/src/main/java/riotcmd/riot.java        |   62 -
 jena-arq/src/main/java/riotcmd/trig.java        |   48 -
 jena-arq/src/main/java/riotcmd/turtle.java      |   48 -
 jena-arq/src/main/java/riotcmd/utf8.java        |   75 -
 jena-arq/src/test/java/arq/TS_Cmd.java          |   31 -
 jena-arq/src/test/java/arq/TestCmdLine.java     |  104 -
 jena-arq/src/test/java/arq/qtest.java           |  274 ---
 .../org/apache/jena/sparql/ARQTestSuite.java    |    2 -
 jena-arq/src/test/java/riotcmd/rdflangtest.java |  213 --
 jena-base/src/main/java/jena/cmd/Arg.java       |   69 -
 jena-base/src/main/java/jena/cmd/ArgDecl.java   |   93 -
 jena-base/src/main/java/jena/cmd/ArgModule.java |   26 -
 .../main/java/jena/cmd/ArgModuleGeneral.java    |   25 -
 jena-base/src/main/java/jena/cmd/ArgProc.java   |   27 -
 .../src/main/java/jena/cmd/CmdArgModule.java    |   70 -
 .../src/main/java/jena/cmd/CmdException.java    |   30 -
 .../src/main/java/jena/cmd/CmdGeneral.java      |   92 -
 .../src/main/java/jena/cmd/CmdLineArgs.java     |  413 ----
 jena-base/src/main/java/jena/cmd/CmdMain.java   |  108 -
 .../src/main/java/jena/cmd/CommandLineBase.java |  136 --
 jena-base/src/main/java/jena/cmd/ModBase.java   |   23 -
 .../src/main/java/jena/cmd/ModGeneral.java      |   57 -
 .../src/main/java/jena/cmd/ModVersion.java      |   67 -
 .../java/jena/cmd/TerminationException.java     |   31 -
 jena-base/src/main/java/jena/cmd/Usage.java     |  102 -
 .../src/main/java/jena/cmd/package-info.java    |    6 -
 jena-cmds/pom.xml                               |  117 +
 jena-cmds/src/main/java/arq/arq.java            |   37 +
 jena-cmds/src/main/java/arq/bindings.java       |   42 +
 jena-cmds/src/main/java/arq/cmdline/CmdARQ.java |   65 +
 .../src/main/java/arq/cmdline/CmdARQ_SSE.java   |   45 +
 .../src/main/java/arq/cmdline/CmdUpdate.java    |   63 +
 .../src/main/java/arq/cmdline/ModAlgebra.java   |   82 +
 .../src/main/java/arq/cmdline/ModAssembler.java |   84 +
 .../src/main/java/arq/cmdline/ModContext.java   |   91 +
 .../src/main/java/arq/cmdline/ModDataset.java   |   49 +
 .../java/arq/cmdline/ModDatasetAssembler.java   |   70 +
 .../java/arq/cmdline/ModDatasetGeneral.java     |  119 +
 .../arq/cmdline/ModDatasetGeneralAssembler.java |   56 +
 .../src/main/java/arq/cmdline/ModEngine.java    |  110 +
 .../src/main/java/arq/cmdline/ModFormat.java    |   91 +
 .../src/main/java/arq/cmdline/ModItem.java      |   80 +
 .../main/java/arq/cmdline/ModLangOutput.java    |  150 ++
 .../src/main/java/arq/cmdline/ModLangParse.java |  180 ++
 .../src/main/java/arq/cmdline/ModQueryIn.java   |  156 ++
 .../src/main/java/arq/cmdline/ModQueryOut.java  |   92 +
 .../src/main/java/arq/cmdline/ModRemote.java    |   75 +
 .../src/main/java/arq/cmdline/ModResultsIn.java |  138 ++
 .../main/java/arq/cmdline/ModResultsOut.java    |   70 +
 .../src/main/java/arq/cmdline/ModSymbol.java    |   26 +
 .../src/main/java/arq/cmdline/ModTime.java      |   73 +
 jena-cmds/src/main/java/arq/iri.java            |   57 +
 jena-cmds/src/main/java/arq/juuid.java          |  173 ++
 jena-cmds/src/main/java/arq/load.java           |  120 +
 jena-cmds/src/main/java/arq/qexpr.java          |  223 ++
 jena-cmds/src/main/java/arq/qparse.java         |  269 +++
 jena-cmds/src/main/java/arq/query.java          |  257 +++
 jena-cmds/src/main/java/arq/rdfdiff.java        |  312 +++
 jena-cmds/src/main/java/arq/rset.java           |   73 +
 jena-cmds/src/main/java/arq/rsparql.java        |   95 +
 jena-cmds/src/main/java/arq/rupdate.java        |   98 +
 jena-cmds/src/main/java/arq/sparql.java         |   37 +
 jena-cmds/src/main/java/arq/sse.java            |  108 +
 jena-cmds/src/main/java/arq/sse_exec.java       |   50 +
 jena-cmds/src/main/java/arq/sse_expr.java       |   24 +
 jena-cmds/src/main/java/arq/sse_query.java      |  162 ++
 jena-cmds/src/main/java/arq/tokens.java         |   24 +
 jena-cmds/src/main/java/arq/uparse.java         |  187 ++
 jena-cmds/src/main/java/arq/update.java         |  128 ++
 jena-cmds/src/main/java/arq/utf8.java           |   29 +
 jena-cmds/src/main/java/arq/version.java        |   29 +
 jena-cmds/src/main/java/arq/wwwdec.java         |   36 +
 jena-cmds/src/main/java/arq/wwwenc.java         |   61 +
 jena-cmds/src/main/java/jena/RuleMap.java       |  196 ++
 jena-cmds/src/main/java/jena/cmd/Arg.java       |   69 +
 jena-cmds/src/main/java/jena/cmd/ArgDecl.java   |   93 +
 jena-cmds/src/main/java/jena/cmd/ArgModule.java |   26 +
 .../main/java/jena/cmd/ArgModuleGeneral.java    |   25 +
 jena-cmds/src/main/java/jena/cmd/ArgProc.java   |   27 +
 .../src/main/java/jena/cmd/CmdArgModule.java    |   70 +
 .../src/main/java/jena/cmd/CmdException.java    |   30 +
 .../src/main/java/jena/cmd/CmdGeneral.java      |   92 +
 .../src/main/java/jena/cmd/CmdLineArgs.java     |  413 ++++
 jena-cmds/src/main/java/jena/cmd/CmdMain.java   |  108 +
 .../src/main/java/jena/cmd/CommandLineBase.java |  136 ++
 jena-cmds/src/main/java/jena/cmd/ModBase.java   |   23 +
 .../src/main/java/jena/cmd/ModGeneral.java      |   57 +
 .../src/main/java/jena/cmd/ModVersion.java      |   67 +
 .../java/jena/cmd/TerminationException.java     |   31 +
 jena-cmds/src/main/java/jena/cmd/Usage.java     |  102 +
 .../src/main/java/jena/cmd/package-info.java    |    6 +
 jena-cmds/src/main/java/jena/package.html       |   34 +
 jena-cmds/src/main/java/jena/query.java         |   26 +
 jena-cmds/src/main/java/jena/rdfcat.java        | 1150 ++++++++++
 jena-cmds/src/main/java/jena/rdfcompare.java    |  131 ++
 jena-cmds/src/main/java/jena/rdfcopy.java       |  158 ++
 jena-cmds/src/main/java/jena/rdfparse.java      |  103 +
 jena-cmds/src/main/java/jena/rset.java          |   25 +
 jena-cmds/src/main/java/jena/schemagen.java     | 2117 ++++++++++++++++++
 jena-cmds/src/main/java/jena/sparql.java        |   25 +
 jena-cmds/src/main/java/jena/turtle.java        |   25 +
 jena-cmds/src/main/java/jena/version.java       |   49 +
 .../src/main/java/riotcmd/CmdLangParse.java     |  361 +++
 jena-cmds/src/main/java/riotcmd/CmdTokens.java  |   75 +
 jena-cmds/src/main/java/riotcmd/dumpthrift.java |   51 +
 jena-cmds/src/main/java/riotcmd/infer.java      |  154 ++
 jena-cmds/src/main/java/riotcmd/json.java       |   52 +
 jena-cmds/src/main/java/riotcmd/nquads.java     |   48 +
 jena-cmds/src/main/java/riotcmd/ntriples.java   |   48 +
 jena-cmds/src/main/java/riotcmd/perftokens.java |   28 +
 .../src/main/java/riotcmd/printtokens.java      |   28 +
 jena-cmds/src/main/java/riotcmd/rdfxml.java     |   48 +
 jena-cmds/src/main/java/riotcmd/riot.java       |   62 +
 jena-cmds/src/main/java/riotcmd/trig.java       |   48 +
 jena-cmds/src/main/java/riotcmd/turtle.java     |   48 +
 jena-cmds/src/main/java/riotcmd/utf8.java       |   75 +
 .../src/main/java/tdb/CmdNodeTableBuilder.java  |  132 ++
 .../src/main/java/tdb/CmdRewriteIndex.java      |  147 ++
 jena-cmds/src/main/java/tdb/cmdline/CmdSub.java |   77 +
 jena-cmds/src/main/java/tdb/cmdline/CmdTDB.java |   87 +
 .../src/main/java/tdb/cmdline/CmdTDBGraph.java  |   81 +
 .../src/main/java/tdb/cmdline/ModLocation.java  |   56 +
 .../src/main/java/tdb/cmdline/ModModel.java     |   66 +
 .../main/java/tdb/cmdline/ModTDBAssembler.java  |   90 +
 .../main/java/tdb/cmdline/ModTDBDataset.java    |  139 ++
 jena-cmds/src/main/java/tdb/tdbbackup.java      |   49 +
 jena-cmds/src/main/java/tdb/tdbconfig.java      |  250 +++
 jena-cmds/src/main/java/tdb/tdbdump.java        |   51 +
 jena-cmds/src/main/java/tdb/tdbloader.java      |  138 ++
 jena-cmds/src/main/java/tdb/tdbnode.java        |   84 +
 jena-cmds/src/main/java/tdb/tdbquery.java       |   60 +
 jena-cmds/src/main/java/tdb/tdbrecovery.java    |   54 +
 jena-cmds/src/main/java/tdb/tdbreorder.java     |  124 +
 jena-cmds/src/main/java/tdb/tdbstats.java       |  103 +
 jena-cmds/src/main/java/tdb/tdbupdate.java      |   61 +
 jena-cmds/src/main/java/tdb/tools/dumpbpt.java  |  178 ++
 .../src/main/java/tdb/tools/dumpnodetable.java  |  182 ++
 .../src/main/java/tdb/tools/tdbgenindex.java    |   86 +
 jena-cmds/src/test/java/jena/cmd/TS_Cmd.java    |   36 +
 .../src/test/java/jena/cmd/TestCmdLine.java     |  104 +
 .../src/test/java/jena/cmd/Test_rdfcat.java     |  291 +++
 .../src/test/java/jena/cmd/Test_schemagen.java  |  848 +++++++
 jena-cmds/src/test/java/jena/cmd/qtest.java     |  274 +++
 .../src/test/java/riotcmd/rdflangtest.java      |  213 ++
 jena-cmds/testing/cmd/README_LICENSE            |   16 +
 jena-cmds/testing/cmd/rdfcat.n3                 |   18 +
 jena-cmds/testing/cmd/rdfcat.nt                 |   11 +
 jena-cmds/testing/cmd/rdfcat.xml                |   20 +
 jena-cmds/testing/cmd/rdfcat_1.xml              |   10 +
 jena-cmds/testing/cmd/rdfcat_1_n3               |   17 +
 jena-cmds/testing/cmd/rdfcat_2.xml              |   16 +
 jena-cmds/testing/cmd/rdfcat_2_n3               |   20 +
 jena-cmds/testing/cmd/sg-test-config.rdf        |   23 +
 jena-core/src/main/java/jena/InvokingUtil.java  |   66 -
 jena-core/src/main/java/jena/RuleMap.java       |  196 --
 jena-core/src/main/java/jena/package.html       |   34 -
 jena-core/src/main/java/jena/qtest.java         |   29 -
 jena-core/src/main/java/jena/query.java         |   33 -
 jena-core/src/main/java/jena/rdfcat.java        | 1150 ----------
 jena-core/src/main/java/jena/rdfcompare.java    |  131 --
 jena-core/src/main/java/jena/rdfcopy.java       |  158 --
 jena-core/src/main/java/jena/rdfparse.java      |  103 -
 jena-core/src/main/java/jena/rset.java          |   29 -
 jena-core/src/main/java/jena/schemagen.java     | 2117 ------------------
 jena-core/src/main/java/jena/sparql.java        |   29 -
 jena-core/src/main/java/jena/turtle.java        |   29 -
 jena-core/src/main/java/jena/version.java       |   49 -
 .../src/test/java/jena/test/TestPackage.java    |   50 -
 .../src/test/java/jena/test/Test_rdfcat.java    |  269 ---
 .../src/test/java/jena/test/Test_schemagen.java |  798 -------
 .../java/org/apache/jena/test/TestPackage.java  |    1 -
 jena-core/testing/cmd/README_LICENSE            |   16 -
 jena-core/testing/cmd/rdfcat.n3                 |   18 -
 jena-core/testing/cmd/rdfcat.nt                 |   11 -
 jena-core/testing/cmd/rdfcat.xml                |   20 -
 jena-core/testing/cmd/rdfcat_1.xml              |   10 -
 jena-core/testing/cmd/rdfcat_1_n3               |   17 -
 jena-core/testing/cmd/rdfcat_2.xml              |   16 -
 jena-core/testing/cmd/rdfcat_2_n3               |   20 -
 jena-core/testing/cmd/sg-test-config.rdf        |   23 -
 jena-csv/pom.xml                                |    6 +
 jena-sdb/pom.xml                                |    6 +
 jena-spatial/pom.xml                            |    6 +
 .../java/org/apache/jena/tdb/lib/DumpOps.java   |    7 +-
 .../tdb/store/bulkloader2/CmdIndexBuild.java    |   87 +-
 .../tdb/store/bulkloader2/CmdIndexCopy.java     |   66 +-
 .../store/bulkloader2/CmdNodeTableBuilder.java  |  305 ---
 .../store/bulkloader2/ProcNodeTableBuilder.java |  211 ++
 jena-tdb/src/main/java/tdb/CmdRewriteIndex.java |  147 --
 jena-tdb/src/main/java/tdb/cmdline/CmdSub.java  |   77 -
 jena-tdb/src/main/java/tdb/cmdline/CmdTDB.java  |   87 -
 .../src/main/java/tdb/cmdline/CmdTDBGraph.java  |   81 -
 .../src/main/java/tdb/cmdline/ModLocation.java  |   56 -
 .../src/main/java/tdb/cmdline/ModModel.java     |   66 -
 .../main/java/tdb/cmdline/ModTDBAssembler.java  |   90 -
 .../main/java/tdb/cmdline/ModTDBDataset.java    |  139 --
 jena-tdb/src/main/java/tdb/tdbbackup.java       |   49 -
 jena-tdb/src/main/java/tdb/tdbconfig.java       |  250 ---
 jena-tdb/src/main/java/tdb/tdbdump.java         |   51 -
 jena-tdb/src/main/java/tdb/tdbloader.java       |  138 --
 jena-tdb/src/main/java/tdb/tdbnode.java         |   84 -
 jena-tdb/src/main/java/tdb/tdbquery.java        |   60 -
 jena-tdb/src/main/java/tdb/tdbrecovery.java     |   54 -
 jena-tdb/src/main/java/tdb/tdbreorder.java      |  124 -
 jena-tdb/src/main/java/tdb/tdbstats.java        |  103 -
 jena-tdb/src/main/java/tdb/tdbupdate.java       |   61 -
 jena-tdb/src/main/java/tdb/tools/dumpbpt.java   |  178 --
 .../src/main/java/tdb/tools/dumpnodetable.java  |  182 --
 .../src/main/java/tdb/tools/tdbgenindex.java    |   86 -
 jena-text/pom.xml                               |    6 +
 266 files changed, 15770 insertions(+), 15701 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/arq.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/arq.java b/jena-arq/src/main/java/arq/arq.java
deleted file mode 100644
index 5fc9c6c..0000000
--- a/jena-arq/src/main/java/arq/arq.java
+++ /dev/null
@@ -1,37 +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 arq;
-
-import org.apache.jena.query.Syntax ;
-
-/** A program to execute queries from the command line in ARQ mode. */
-
-public class arq extends query
-{
-    public static void main (String... argv) {
-        new arq(argv).mainRun() ;
-    }
-    
-    public arq(String[] argv) {
-        super(argv) ; 
-    }
-
-    @Override
-    protected Syntax getDefaultSyntax()     { return Syntax.syntaxARQ ; } 
- }

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/bindings.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/bindings.java b/jena-arq/src/main/java/arq/bindings.java
deleted file mode 100644
index f9d3b2c..0000000
--- a/jena-arq/src/main/java/arq/bindings.java
+++ /dev/null
@@ -1,42 +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 arq;
-
-import java.io.InputStream ;
-import java.io.OutputStream ;
-
-import org.apache.jena.sparql.engine.binding.BindingInputStream ;
-import org.apache.jena.sparql.engine.binding.BindingOutputStream ;
-
-/** Simple command for testing bindings */
-public class bindings
-{
-    public static void main(String[] args)
-    {
-        InputStream in = System.in ;
-        OutputStream out = System.out ;
-        
-        BindingInputStream input = new BindingInputStream(in) ;
-        BindingOutputStream output = new BindingOutputStream(out) ;
-        
-        for ( ; input.hasNext() ; )
-            output.send(input.next()) ;
-        output.flush() ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/CmdARQ.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/CmdARQ.java b/jena-arq/src/main/java/arq/cmdline/CmdARQ.java
deleted file mode 100644
index d6fb553..0000000
--- a/jena-arq/src/main/java/arq/cmdline/CmdARQ.java
+++ /dev/null
@@ -1,65 +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 arq.cmdline;
-
-import jena.cmd.ArgDecl ;
-import jena.cmd.CmdGeneral ;
-import org.apache.jena.Jena ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.query.ARQ ;
-import org.apache.jena.riot.RIOT ;
-import org.apache.jena.sparql.engine.iterator.QueryIteratorBase ;
-import org.apache.jena.system.JenaSystem ;
-
-public abstract class CmdARQ extends CmdGeneral
-{
-	static { JenaSystem.init() ; }
-
-    protected ModContext modContext = new ModContext() ;
-    ArgDecl  strictDecl = new ArgDecl(ArgDecl.NoValue, "strict") ;
-    
-    protected boolean cmdStrictMode = false ; 
-    
-    protected CmdARQ(String[] argv)
-    {
-        super(argv) ;
-        modVersion.addClass(Jena.class) ;
-        modVersion.addClass(ARQ.class) ;
-        modVersion.addClass(RIOT.class) ;
-        super.add(strictDecl, "--strict", "Operate in strict SPARQL mode (no extensions of any kind)") ; 
-        addModule(modContext) ;
-    }
-    
-    @Override
-    protected void processModulesAndArgs()
-    {
-        super.processModulesAndArgs();
-        if ( super.contains(strictDecl) ) 
-            ARQ.setStrictMode() ;
-        cmdStrictMode = super.contains(strictDecl) ;
-        if ( modGeneral.debug )
-            QueryIteratorBase.traceIterators = true ;
-    }
-    
-    @Override
-    protected String getCommandName()
-    {
-        return Lib.className(this) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/CmdARQ_SSE.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/CmdARQ_SSE.java b/jena-arq/src/main/java/arq/cmdline/CmdARQ_SSE.java
deleted file mode 100644
index 7834a12..0000000
--- a/jena-arq/src/main/java/arq/cmdline/CmdARQ_SSE.java
+++ /dev/null
@@ -1,45 +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 arq.cmdline;
-
-import org.apache.jena.sparql.sse.Item ;
-
-/** Root of read an SSE file and do something */
-public abstract class CmdARQ_SSE extends CmdARQ
-{
-    protected ModItem modItem = new ModItem() ; 
-    
-    public CmdARQ_SSE(String[] argv)
-    {
-        super(argv) ;
-        super.addModule(modItem) ;
-    }
-    
-    @Override
-    protected String getSummary() { return getCommandName()+" [--file<file> | string]" ; }
-
-    @Override
-    final protected void exec()
-    {
-        Item item = modItem.getItem() ;
-        exec(item) ;
-    }
-    
-    protected abstract void exec(Item item) ;
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/CmdUpdate.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/CmdUpdate.java b/jena-arq/src/main/java/arq/cmdline/CmdUpdate.java
deleted file mode 100644
index 9ff706c..0000000
--- a/jena-arq/src/main/java/arq/cmdline/CmdUpdate.java
+++ /dev/null
@@ -1,63 +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 arq.cmdline;
-
-import org.apache.jena.query.Syntax ;
-import org.apache.jena.rdf.model.ModelFactory ;
-import org.apache.jena.sparql.core.DatasetGraph ;
-
-public abstract class CmdUpdate extends CmdARQ
-{
-    protected ModDataset modDataset = null ;
-    protected Syntax updateSyntax = Syntax.defaultUpdateSyntax ;
-
-    protected CmdUpdate(String[] argv)
-    {
-        super(argv) ;
-        modDataset = setModeDataset() ;
-        addModule(modDataset) ;
-    }
-    
-    protected ModDataset setModeDataset() {
-        return new ModDatasetGeneralAssembler() ;
-    }
-
-    @Override
-    protected void processModulesAndArgs()
-    {
-        super.processModulesAndArgs() ;
-        if ( super.cmdStrictMode )
-            updateSyntax = Syntax.syntaxSPARQL_11 ;
-    }
-    
-    @Override
-    protected final void exec() {
-        DatasetGraph dataset = modDataset.getDatasetGraph() ;
-        if ( dataset == null )
-            dataset = dealWithNoDataset() ;
-        
-        if ( dataset.getDefaultGraph() == null )
-            dataset.setDefaultGraph(ModelFactory.createDefaultModel().getGraph()) ;
-        execUpdate(dataset) ;
-    }
-
-    protected abstract DatasetGraph dealWithNoDataset() ;
-
-    protected abstract void execUpdate(DatasetGraph graphStore) ;
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModAlgebra.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModAlgebra.java b/jena-arq/src/main/java/arq/cmdline/ModAlgebra.java
deleted file mode 100644
index cb269b5..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModAlgebra.java
+++ /dev/null
@@ -1,82 +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 arq.cmdline;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdGeneral;
-import jena.cmd.ModBase;
-
-import org.apache.jena.sparql.algebra.Op ;
-import org.apache.jena.sparql.sse.SSE ;
-import org.apache.jena.util.FileManager ;
-
-public class ModAlgebra extends ModBase
-{
-    protected final ArgDecl queryFileDecl = new ArgDecl(ArgDecl.HasValue, "query", "file") ;
-
-    private String queryFilename   = null ;
-    private String queryString = null ;
-    private Op op = null ;
-    
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        cmdLine.getUsage().startCategory("Query") ;
-        cmdLine.add(queryFileDecl,
-                    "--query, --file",
-                    "File containing an algebra query") ;
-    }
-
-    @Override
-    public void processArgs(CmdArgModule cmdLine)
-    {
-        if ( cmdLine.contains(queryFileDecl) )
-        {
-            queryFilename = cmdLine.getValue(queryFileDecl) ;
-            queryString = FileManager.get().readWholeFileAsUTF8(queryFilename) ;
-        }
-    
-        if ( cmdLine.getNumPositional() == 0 && queryFilename == null )
-            cmdLine.cmdError("No query string or query file") ;
-
-        if ( cmdLine.getNumPositional() > 1 )
-            cmdLine.cmdError("Only one query string allowed") ;
-    
-        if ( cmdLine.getNumPositional() == 1 && queryFilename != null )
-            cmdLine.cmdError("Either query string or query file - not both") ;
-
-        
-        if ( queryFilename == null )
-        {
-            String qs = cmdLine.getPositionalArg(0) ;
-            queryString = cmdLine.indirect(qs) ;
-        }
-    }
-    
-    public Op getOp()
-    {
-        if ( op != null )
-            return op ;
-        op = SSE.parseOp(queryString) ;
-        if ( op == null )
-            System.err.println("Failed to parse : "+queryString) ;
-        return op ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModAssembler.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModAssembler.java b/jena-arq/src/main/java/arq/cmdline/ModAssembler.java
deleted file mode 100644
index 30e4573..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModAssembler.java
+++ /dev/null
@@ -1,84 +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 arq.cmdline;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdException;
-import jena.cmd.CmdGeneral;
-import jena.cmd.ModBase;
-
-import org.apache.jena.rdf.model.Resource ;
-import org.apache.jena.shared.JenaException ;
-import org.apache.jena.shared.NotFoundException ;
-import org.apache.jena.sparql.ARQException ;
-import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
-
-
-public class ModAssembler extends ModBase
-{
-    public static final ArgDecl assemblerDescDecl = new ArgDecl(ArgDecl.HasValue, "desc", "dataset") ;
-    private String assemblerFile = null ;
-    Object thingDescribed = null ;
-    
-    public ModAssembler()
-    { 
-        // Wire in assembler implementations
-        AssemblerUtils.init() ;
-    }
-    
-    // Dataset : default graph and named graphs
-
-    @Override
-    public void processArgs(CmdArgModule cmdLine)
-    {
-        if ( cmdLine.contains(assemblerDescDecl) )
-            assemblerFile = cmdLine.getValue(assemblerDescDecl) ;
-    }
-    
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        //cmdLine.getUsage().startCategory("Dataset") ;
-        cmdLine.add(assemblerDescDecl,
-                    "--desc=",
-                    "Assembler description file") ;
-    }
-    
-    public String getAssemblerFile() { return assemblerFile ; }
-    
-    // Should subclass and apply typing.
-    
-    public Object create(Resource type)
-    {
-        Object thing = null ;
-        try {
-            thing = AssemblerUtils.build(assemblerFile, type) ;
-        }
-        catch (ARQException ex) { throw ex; }
-        catch (NotFoundException ex)
-        { throw new CmdException("Not found: "+ex.getMessage()) ; }
-        catch (JenaException ex)
-        { throw ex ; }
-        catch (Exception ex)
-        { throw new CmdException("Error creating", ex) ; }
-        
-        return thing ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModContext.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModContext.java b/jena-arq/src/main/java/arq/cmdline/ModContext.java
deleted file mode 100644
index 2d20f87..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModContext.java
+++ /dev/null
@@ -1,91 +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 arq.cmdline;
-
-import java.io.PrintStream ;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdGeneral;
-import jena.cmd.ModBase;
-
-import org.apache.jena.atlas.io.IndentedWriter ;
-import org.apache.jena.query.ARQ ;
-import org.apache.jena.sparql.util.Context ;
-import org.apache.jena.sparql.util.MappingRegistry ;
-import org.apache.jena.sparql.util.Symbol ;
-import org.apache.jena.system.JenaSystem ;
-
-/** Set Context items */
-public class ModContext extends ModBase
-{
-    static { JenaSystem.init(); }
-
-    protected final ArgDecl setDecl = new ArgDecl(ArgDecl.HasValue, "set", "define", "defn", "def") ;
-
-    private Context context = new Context() ;
-
-    @Override
-    public void registerWith(CmdGeneral cmdLine) {
-        cmdLine.getUsage().startCategory("Symbol definition");
-        cmdLine.add(setDecl, "--set", "Set a configuration symbol to a value");
-    }
-
-    public void checkCommandLine(CmdArgModule cmdLine) {}
-
-    @Override
-    public void processArgs(CmdArgModule cmdLine) {
-        if ( cmdLine.getValues(setDecl) == null || cmdLine.getValues(setDecl).size() == 0 )
-            return;
-
-        for ( String arg : cmdLine.getValues(setDecl) ) {
-            String[] frags = arg.split("=", 2);
-            if ( frags.length != 2 ) {
-                throw new RuntimeException("Can't split '" + arg + "' -- looking for '=' to separate name and value");
-            }
-
-            String symbolName = frags[0];
-            String value = frags[1];
-
-            // Make it a long name.
-            symbolName = MappingRegistry.mapPrefixName(symbolName);
-            Symbol symbol = Symbol.create(symbolName);
-            context.set(symbol, value);
-        }
-
-        ARQ.getContext().putAll(context);
-    }
-
-    public void verbose() {
-        verbose(System.out);
-    }
-
-    public void verbose(PrintStream stream) {
-        IndentedWriter out = new IndentedWriter(stream);
-        verbose(out);
-        out.flush();
-    }
-
-    public void verbose(IndentedWriter out) {
-        for ( Symbol symbol : context.keys() ) {
-            String value = context.getAsString(symbol);
-            out.println(symbol + " -> " + value);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModDataset.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModDataset.java b/jena-arq/src/main/java/arq/cmdline/ModDataset.java
deleted file mode 100644
index 01a0bb8..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModDataset.java
+++ /dev/null
@@ -1,49 +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 arq.cmdline;
-
-import jena.cmd.ModBase;
-
-import org.apache.jena.query.Dataset ;
-import org.apache.jena.sparql.core.DatasetGraph ;
-
-public abstract class ModDataset extends ModBase
-{
-    protected boolean createAttempted = false ;
-    protected Dataset dataset = null ;
-    
-    public ModDataset() {}
-    
-    final
-    public Dataset getDataset() { 
-        if ( ! createAttempted )
-            dataset = createDataset() ;
-        createAttempted = true ;
-        return dataset ;
-    }
-    
-    public DatasetGraph getDatasetGraph() {
-        Dataset ds = getDataset() ;
-        if ( ds == null )
-            return null ;
-        return ds.asDatasetGraph() ;
-    }
-
-    public abstract Dataset createDataset() ; 
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModDatasetAssembler.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModDatasetAssembler.java b/jena-arq/src/main/java/arq/cmdline/ModDatasetAssembler.java
deleted file mode 100644
index 840136c..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModDatasetAssembler.java
+++ /dev/null
@@ -1,70 +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 arq.cmdline;
-
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdException;
-import jena.cmd.CmdGeneral;
-
-import org.apache.jena.query.Dataset ;
-import org.apache.jena.shared.JenaException ;
-import org.apache.jena.shared.NotFoundException ;
-import org.apache.jena.sparql.ARQException ;
-import org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab ;
-
-/** Add assembler to a general dataset description */
-public class ModDatasetAssembler extends ModDataset
-{
-    private ModAssembler modAssembler = new ModAssembler() ;
-
-    @Override
-    public Dataset createDataset()
-    {
-        if ( modAssembler.getAssemblerFile() == null )
-            return null ;
-        
-        try {
-            dataset = (Dataset)modAssembler.create(DatasetAssemblerVocab.tDataset) ;
-            if ( dataset == null )
-                throw new CmdException("No dataset description found in: "+modAssembler.getAssemblerFile()) ;
-        }
-        catch (CmdException | ARQException ex) { throw ex ; }
-        catch (NotFoundException ex)
-        { throw new CmdException("Not found: "+ex.getMessage()) ; }
-        catch (JenaException ex)
-        { throw ex ; }
-        catch (Exception ex)
-        { throw new CmdException("Error creating dataset", ex) ; }
-        return dataset ;
-        
-    }
-
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        modAssembler.registerWith(cmdLine) ;
-    }
-
-    @Override
-    public void processArgs(CmdArgModule cmdLine)
-    {
-        modAssembler.processArgs(cmdLine) ;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModDatasetGeneral.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModDatasetGeneral.java b/jena-arq/src/main/java/arq/cmdline/ModDatasetGeneral.java
deleted file mode 100644
index 5960f02..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModDatasetGeneral.java
+++ /dev/null
@@ -1,119 +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 arq.cmdline;
-
-import java.util.List ;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdException;
-import jena.cmd.CmdGeneral;
-import org.apache.jena.query.Dataset ;
-import org.apache.jena.query.DatasetFactory ;
-import org.apache.jena.query.LabelExistsException ;
-import org.apache.jena.riot.RDFDataMgr ;
-import org.apache.jena.shared.JenaException ;
-import org.apache.jena.sparql.util.DatasetUtils ;
-
-/** ModDataset: arguments to build a dataset - 
- * see also ModDatasetAssembler which extends ModDataset
- * with a description parameter. */ 
-
-public class ModDatasetGeneral extends ModDataset
-{
-    // See also ModDatasetAssembler
-    protected final ArgDecl graphDecl      = new ArgDecl(ArgDecl.HasValue, "graph") ;
-    protected final ArgDecl dataDecl      = new ArgDecl(ArgDecl.HasValue, "data") ;
-    protected final ArgDecl namedGraphDecl = new ArgDecl(ArgDecl.HasValue, "named", "namedgraph", "namedGraph", "namedData", "nameddata") ;
-    //protected final ArgDecl dataFmtDecl    = new ArgDecl(ArgDecl.HasValue, "fmt", "format") ;
-    //protected final ArgDecl dirDecl        = new ArgDecl(ArgDecl.HasValue, "dir") ;
-    
-    private List<String> dataURLs                = null ;
-    private List<String> graphURLs               = null ;
-    private List<String> namedGraphURLs          = null ;
-    protected ModDatasetGeneral() {}
-    
-    @Override
-    public void registerWith(CmdGeneral cl)
-    {
-        cl.getUsage().startCategory("Dataset") ;
-        cl.add(dataDecl,
-               "--data=FILE",
-               "Data for the datset - triple or quad formats") ;
-        cl.add(graphDecl,
-               "--graph=FILE",
-               "Graph for default graph of the datset") ;
-        cl.add(namedGraphDecl,
-               "--namedGraph=FILE",
-               "Add a graph into the dataset as a named graph") ;
-    }
-    
-    @Override
-    public void processArgs(CmdArgModule cmdLine)
-    {
-        dataURLs = cmdLine.getValues(dataDecl) ;
-        graphURLs = cmdLine.getValues(graphDecl) ;
-        namedGraphURLs = cmdLine.getValues(namedGraphDecl) ;
-    }
-    
-    @Override
-    public Dataset createDataset()
-    {
-        // If nothing specified to the module.  Leave alone and hope the query has FROM/FROM NAMED
-        if (  ( dataURLs == null || dataURLs.size() == 0) &&
-              (graphURLs == null || graphURLs.size() == 0) &&
-              (namedGraphURLs == null || namedGraphURLs.size() == 0 ) )
-            return null ;
-        
-        Dataset ds = DatasetFactory.createTxnMem() ;
-        addGraphs(ds) ;
-        dataset = ds ;
-        return dataset ;
-    }
-        
-    protected void addGraphs(Dataset ds)
-    {
-        try {
-            if ( dataURLs != null ) 
-            {
-                for ( String url : dataURLs )
-                    RDFDataMgr.read(ds, url) ;
-            }
-            
-            if ( (graphURLs != null) || (namedGraphURLs != null) )
-                ds = DatasetUtils.addInGraphs(ds, graphURLs, namedGraphURLs, null) ;
-        } 
-        catch (LabelExistsException ex)
-        { throw new CmdException(ex.getMessage()) ; }
-        catch (JenaException ex)
-        { throw ex ; }
-        catch (Exception ex)
-        { throw new CmdException("Error creating dataset", ex) ; }
-    }
-
-    public List<String> getGraphURLs()
-    {
-        return graphURLs ;
-    }
-
-    public List<String> getNamedGraphURLs()
-    {
-        return namedGraphURLs ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModDatasetGeneralAssembler.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModDatasetGeneralAssembler.java b/jena-arq/src/main/java/arq/cmdline/ModDatasetGeneralAssembler.java
deleted file mode 100644
index c6ec7b5..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModDatasetGeneralAssembler.java
+++ /dev/null
@@ -1,56 +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 arq.cmdline;
-
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdGeneral;
-
-import org.apache.jena.query.Dataset ;
-
-/** Add assembler to a general dataset description */
-public class ModDatasetGeneralAssembler extends ModDatasetGeneral
-{
-    public ModDatasetGeneralAssembler() {}
-    
-    private ModDatasetAssembler modAssembler = new ModDatasetAssembler() ;
-    
-    @Override
-    public Dataset createDataset()
-    {
-        Dataset ds = modAssembler.createDataset() ;
-        if ( ds == null )
-            ds = super.createDataset() ;
-        return ds ;
-    }
-
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        modAssembler.registerWith(cmdLine) ;
-        super.registerWith(cmdLine) ;
-    }
-
-    @Override
-    public void processArgs(CmdArgModule cmdLine)
-    {
-        modAssembler.processArgs(cmdLine) ;
-        super.processArgs(cmdLine) ;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModEngine.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModEngine.java b/jena-arq/src/main/java/arq/cmdline/ModEngine.java
deleted file mode 100644
index 998d656..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModEngine.java
+++ /dev/null
@@ -1,110 +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 arq.cmdline;
-
-import java.util.List ;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdException;
-import jena.cmd.CmdGeneral;
-import jena.cmd.ModBase;
-
-import org.apache.jena.sparql.engine.main.QueryEngineMain ;
-import org.apache.jena.sparql.engine.main.QueryEngineMainQuad ;
-import org.apache.jena.sparql.engine.ref.QueryEngineRef ;
-import org.apache.jena.sparql.engine.ref.QueryEngineRefQuad ;
-
-
-public class ModEngine extends ModBase
-{
-    // Special case of a "ModEnvironment"
-    // Alters the ARQ environment but provides nothing at execution time.
-    // Combine with ModSymbol?
-    
-    protected final ArgDecl engineDecl = new ArgDecl(ArgDecl.HasValue, "engine") ;
-    protected final ArgDecl unEngineDecl = new ArgDecl(ArgDecl.HasValue,
-                                                       "unengine",
-                                                       "unEngine",
-                                                       "removeEngine",
-                                                       "removeengine"
-                                                       ) ;
-    
-    private boolean timing = false ;
-    
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        cmdLine.getUsage().startCategory("Query Engine") ;
-        cmdLine.add(engineDecl, "--engine=EngineName", "Register another engine factory[ref]") ; 
-        cmdLine.add(unEngineDecl, "--unengine=EngineName", "Unregister an engine factory") ;
-    }
-    
-    public void checkCommandLine(CmdGeneral cmdLine)
-    {}
-
-    @Override
-    public void processArgs(CmdArgModule cmdLine)
-    {
-       
-        List<String> engineDecls = cmdLine.getValues(engineDecl) ;
-        
-//        if ( x.size() > 0 )
-//            QueryEngineRegistry.get().factories().clear() ;
-
-        for ( String engineName : engineDecls )
-        {
-			switch (engineName.toLowerCase()) {
-				case "reference":
-				case "ref":
-					QueryEngineRef.register();
-					continue;
-				case "refQuad":
-					QueryEngineRefQuad.register();
-					continue;
-				case "main":
-					QueryEngineMain.register();
-					continue;
-				case "quad":
-					QueryEngineMainQuad.register();
-					continue;
-				}
-			throw new CmdException("Engine name not recognized: " + engineName);
-		}
-
-        List<String> unEngineDecls = cmdLine.getValues(unEngineDecl) ;
-        for (String engineName : unEngineDecls)
-        {
-	        	switch (engineName.toLowerCase()) {
-				case "reference":
-				case "ref":
-					QueryEngineRef.register();
-					continue;
-				case "refQuad":
-					QueryEngineRefQuad.register();
-					continue;
-				case "main":
-					QueryEngineMain.register();
-					QueryEngineMainQuad.register();
-					continue;      
-	        }
-        		throw new CmdException("Engine name not recognized: "+engineName) ;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModFormat.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModFormat.java b/jena-arq/src/main/java/arq/cmdline/ModFormat.java
deleted file mode 100644
index b73215e..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModFormat.java
+++ /dev/null
@@ -1,91 +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 arq.cmdline;
-
-
-import java.util.Arrays;
-import java.util.List;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdGeneral;
-import jena.cmd.ModBase;
-
-public class ModFormat extends ModBase
-{
-    protected final 
-    ArgDecl resultsFmtDecl = new ArgDecl(ArgDecl.HasValue, "fmt", "format") ;
-
-    private String format = "N-TRIPLES" ;
-    
-    public ModFormat() {}
-    
-    @Override
-    public void processArgs(CmdArgModule cmdline) throws IllegalArgumentException
-    {
-        if ( cmdline.contains(resultsFmtDecl) )
-        {
-            String rFmt = cmdline.getValue(resultsFmtDecl) ;
-            format = lookup(rFmt) ;
-            if ( format == null )
-                cmdline.cmdError("Unrecognized format: "+rFmt) ;
-        }
-    }
-    
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        cmdLine.getUsage().startCategory("Output format") ;
-        cmdLine.add(resultsFmtDecl,
-                    "--format",
-                    "Format (Result sets: text, XML, JSON; Graph: RDF serialization)") ;  
-    }
-
-    public void checkCommandLine(CmdArgModule cmdLine)
-    {}
-
-    public String getFormat() { return format ; } 
-    
-    public String getFormat(String defaultFormat)
-    { 
-        if ( format == null )
-            return defaultFormat ;
-        return format ;
-    }
-  
-    private String lookup(String fmt)
-    {
-    		return formats.stream().filter(fmt::equalsIgnoreCase).findFirst().orElse("TURTLE");
-    }
-
-    static final List<String> formats = Arrays.asList(
-        "RDF/XML",
-        "RDF/XML-ABBREV",
-        "N-TRIPLE",
-        "N-TRIPLES",
-        "N3",
-        "N3-PP" ,
-        "N3-PLAIN" ,
-        "N3-TRIPLES" ,
-        "N3-TRIPLE" ,
-        "TURTLE" ,
-        //"Turtle" ,
-        "TTL"
-        ) ;
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModItem.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModItem.java b/jena-arq/src/main/java/arq/cmdline/ModItem.java
deleted file mode 100644
index c7ee7c1..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModItem.java
+++ /dev/null
@@ -1,80 +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 arq.cmdline;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdGeneral;
-import jena.cmd.ModBase;
-
-import org.apache.jena.sparql.sse.Item ;
-import org.apache.jena.sparql.sse.SSE ;
-import org.apache.jena.util.FileManager ;
-
-public class ModItem extends ModBase
-{
-    protected final ArgDecl queryFileDecl = new ArgDecl(ArgDecl.HasValue, "file") ;
-
-    private String filename = null ;
-    private String parseString = null ; 
-    private Item item = null ;
-    
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        cmdLine.getUsage().startCategory("Item") ;
-        cmdLine.add(queryFileDecl, "--file=", "File") ;
-    }
-
-    @Override
-    public void processArgs(CmdArgModule cmdLine)
-    {
-        if ( cmdLine.contains(queryFileDecl) )
-        {
-            filename = cmdLine.getValue(queryFileDecl) ;
-            parseString = FileManager.get().readWholeFileAsUTF8(filename) ;
-            return ;
-        }
-    
-        if ( cmdLine.getNumPositional() == 0 && filename == null )
-            cmdLine.cmdError("No query string or query file") ;
-
-        if ( cmdLine.getNumPositional() > 1 )
-            cmdLine.cmdError("Only one query string allowed") ;
-    
-        if ( cmdLine.getNumPositional() == 1 && filename != null )
-            cmdLine.cmdError("Either query string or query file - not both") ;
-
-        if ( filename == null )
-        {
-            String qs = cmdLine.getPositionalArg(0) ;
-            parseString = cmdLine.indirect(qs) ;
-        }
-    }
-    
-    public Item getItem()
-    {
-        if ( item != null )
-            return item ;
-        // Need to get the (outer) prologue.
-        item = SSE.parseItem(parseString) ;
-        return item ;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModLangOutput.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModLangOutput.java b/jena-arq/src/main/java/arq/cmdline/ModLangOutput.java
deleted file mode 100644
index ecc82ca..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModLangOutput.java
+++ /dev/null
@@ -1,150 +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 arq.cmdline;
-
-import java.io.PrintStream ;
-import java.util.HashSet ;
-import java.util.Set ;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdException;
-import jena.cmd.CmdGeneral;
-import jena.cmd.ModBase;
-
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFFormat ;
-import org.apache.jena.riot.RDFLanguages ;
-import org.apache.jena.riot.RDFWriterRegistry ;
-import org.apache.jena.riot.system.StreamRDFWriter ;
-
-public class ModLangOutput extends ModBase
-{
-    protected ArgDecl argOutput       = new ArgDecl(ArgDecl.HasValue, "out", "output") ;
-    protected ArgDecl argPretty       = new ArgDecl(ArgDecl.HasValue, "formatted", "pretty", "fmt") ;
-    protected ArgDecl argStream       = new ArgDecl(ArgDecl.HasValue, "stream") ;
-    protected ArgDecl argCompress     = new ArgDecl(ArgDecl.NoValue, "compress") ;
-    private boolean compressedOutput = false ;
-    private RDFFormat streamOutput    = null ;
-    private RDFFormat formattedOutput = null ;
-
-    @Override
-    public void registerWith(CmdGeneral cmdLine) {
-        cmdLine.getUsage().startCategory("Output control") ;
-        cmdLine.add(argOutput,    "--output=FMT",     "Output in the given format, streaming if possible.") ;
-        cmdLine.add(argPretty,    "--formatted=FMT",  "Output, using pretty printing (consumes memory)") ;
-        cmdLine.add(argStream,    "--stream=FMT",     "Output, using a streaming format") ;
-        cmdLine.add(argCompress,  "--compress",       "Compress the output with gzip") ;
-    }
-
-    @Override
-    public void processArgs(CmdArgModule cmdLine) {
-        if ( cmdLine.contains(argPretty) ) {
-            String langName = cmdLine.getValue(argPretty) ;
-            Lang lang = RDFLanguages.nameToLang(langName) ;
-            if ( lang == null )
-                throw new CmdException("Not recognized as an RDF language : '"+langName+"'") ;
-            formattedOutput = RDFWriterRegistry.defaultSerialization(lang) ;
-            if ( formattedOutput == null ) {
-                System.err.println("Language '"+lang.getLabel()+"' not registered.") ;
-                printRegistered(System.err) ;
-                throw new CmdException("No output set: '"+langName+"'") ;
-            }
-        }
-        
-        if ( cmdLine.contains(argStream) ) {
-            String langName = cmdLine.getValue(argStream) ;
-            Lang lang = RDFLanguages.nameToLang(langName) ;
-            if ( lang == null )
-                throw new CmdException("Not recognized as an RDF language : '"+langName+"'") ;
-            streamOutput = StreamRDFWriter.defaultSerialization(lang) ;
-            if ( streamOutput == null ) {
-                System.err.println("Language '"+lang.getLabel()+"' not registered for streaming.") ;
-                printRegistered(System.err) ;
-                throw new CmdException("No output set: '"+langName+"'") ;
-            }
-        }
-        
-        if ( cmdLine.contains(argOutput) ) {
-            String langName = cmdLine.getValue(argOutput) ;
-            Lang lang = RDFLanguages.nameToLang(langName) ;
-            if ( lang == null )
-                throw new CmdException("Not recognized as an RDF language : '"+langName+"'") ;
-            
-            if ( StreamRDFWriter.registered(lang) ) {
-                streamOutput = StreamRDFWriter.defaultSerialization(lang) ;
-            } else {
-                formattedOutput = RDFWriterRegistry.defaultSerialization(lang) ;
-                if ( formattedOutput == null ) {
-                    System.err.println("Language '"+lang.getLabel()+"' not recognized.") ;
-                    printRegistered(System.err) ;
-                    throw new CmdException("No output set: '"+langName+"'") ;
-                }
-            }
-        }
-        
-        if ( cmdLine.contains(argCompress))
-            compressedOutput = true ;
-        
-        if ( streamOutput == null && formattedOutput == null )
-            streamOutput = RDFFormat.NQUADS ;
-    }
-
-    private static Set<Lang>  hiddenLanguages = new HashSet<>() ;
-    static {
-        hiddenLanguages.add(Lang.RDFNULL) ;
-        hiddenLanguages.add(Lang.CSV) ;
-    }
-    
-    private static void printRegistered(PrintStream out) {
-        out.println("Streaming languages:") ;
-        Set<Lang> seen = new HashSet<>() ;
-        for ( RDFFormat fmt : StreamRDFWriter.registered()) {
-            Lang lang = fmt.getLang() ;
-            if ( hiddenLanguages.contains(lang)) 
-                continue ;
-            if ( seen.contains(lang) )
-                continue ;
-            seen.add(lang) ;
-            out.println("   "+lang.getLabel()) ;
-        }
-        System.err.println("Non-streaming languages:") ;
-        for ( RDFFormat fmt : RDFWriterRegistry.registered() ) {
-            Lang lang = fmt.getLang() ;
-            if ( hiddenLanguages.contains(lang)) 
-                continue ;
-            if ( seen.contains(lang) )
-                continue ;
-            seen.add(lang) ;
-            out.println("   "+lang.getLabel()) ;
-        }
-    }
-    
-    public RDFFormat getOutputStreamFormat() {
-        return streamOutput ;
-    }
-    
-    public RDFFormat getOutputFormatted() {
-        return formattedOutput ;
-    }
-    
-    public boolean compressedOutput() {
-        return compressedOutput ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModLangParse.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModLangParse.java b/jena-arq/src/main/java/arq/cmdline/ModLangParse.java
deleted file mode 100644
index 212807d..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModLangParse.java
+++ /dev/null
@@ -1,180 +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 arq.cmdline;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdException;
-import jena.cmd.CmdGeneral;
-import jena.cmd.ModBase;
-
-import org.apache.jena.iri.IRI ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFLanguages ;
-import org.apache.jena.riot.RiotException ;
-import org.apache.jena.riot.system.IRIResolver ;
-import org.apache.jena.util.FileManager ;
-
-public class ModLangParse extends ModBase
-{
-    private ArgDecl argCheck    = new ArgDecl(ArgDecl.NoValue, "check") ;
-    private ArgDecl argNoCheck  = new ArgDecl(ArgDecl.NoValue, "nocheck", "noCheck") ;
-    private ArgDecl argSink     = new ArgDecl(ArgDecl.NoValue, "sink", "null") ;
-
-    private ArgDecl argStrict   = new ArgDecl(ArgDecl.NoValue, "strict") ;
-    private ArgDecl argValidate = new ArgDecl(ArgDecl.NoValue, "validate") ;
-    
-    private ArgDecl argSkip     = new ArgDecl(ArgDecl.NoValue, "skip") ;
-    private ArgDecl argNoSkip   = new ArgDecl(ArgDecl.NoValue, "noSkip") ;
-    private ArgDecl argStop     = new ArgDecl(ArgDecl.NoValue, "stopOnError", "stoponerror", "stop") ;
-    
-    private ArgDecl argBase     = new ArgDecl(ArgDecl.HasValue, "base") ;
-    
-    private ArgDecl argRDFS     = new ArgDecl(ArgDecl.HasValue, "rdfs") ;
-    
-    private ArgDecl argSyntax     = new ArgDecl(ArgDecl.HasValue, "syntax") ;
-
-    private  String rdfsVocabFilename   = null ;
-    private  Model  rdfsVocab           = null ;
-    private  String baseIRI             = null ;
-    private boolean explicitCheck       = false ;
-    private boolean explicitNoCheck     = false ;
-    private boolean skipOnBadTerm       = false ;
-    private boolean stopOnBadTerm       = false ;
-    private boolean bitbucket           = false ; 
-    private boolean strict              = false ;
-    private boolean validate            = false ;
-    private Lang lang                   = null ;
-    
-    @Override
-    public void registerWith(CmdGeneral cmdLine) {
-        cmdLine.getUsage().startCategory("Parser control") ;
-        cmdLine.add(argSink,    "--sink",           "Parse but throw away output") ;
-        cmdLine.add(argSyntax,  "--syntax=NAME",    "Set syntax (otherwise syntax guessed from file extension)") ;
-        cmdLine.add(argBase,    "--base=URI",       "Set the base URI (does not apply to N-triples and N-Quads)") ;
-        cmdLine.add(argCheck,   "--check",          "Addition checking of RDF terms") ; // (default: off for N-triples, N-Quads, on for Turtle and TriG)") ;
-        cmdLine.add(argStrict,  "--strict",         "Run with in strict mode") ;
-        cmdLine.add(argValidate,"--validate",       "Same as --sink --check --strict") ;
-        cmdLine.add(argRDFS,    "--rdfs=file",      "Apply some RDFS inference using the vocabulary in the file") ;
-        
-        cmdLine.add(argNoCheck, "--nocheck",        "Turn off checking of RDF terms") ;
-//        cmdLine.add(argSkip,    "--noSkip",         "Skip (do not output) triples failing the RDF term tests") ;
-//        cmdLine.add(argNoSkip,  "--skip",           "Include triples failing the RDF term tests (not recommended)") ;
-        cmdLine.add(argStop,    "--stop",           "Stop parsing on encountering a bad RDF term") ;
-    }
-
-    @Override
-    public void processArgs(CmdArgModule cmdLine) {
-        if ( cmdLine.contains(argValidate) ) {
-            validate = true ;
-            strict = true ;
-            explicitCheck = true ;
-            bitbucket = true ;
-        }
-
-        if ( cmdLine.contains(argSyntax) ) {
-            String syntax = cmdLine.getValue(argSyntax) ;
-            Lang lang$ = RDFLanguages.nameToLang(syntax) ;
-            if ( lang$ == null )
-                throw new CmdException("Can not detemine the syntax from '" + syntax + "'") ;
-            this.lang = lang$ ;
-        }
-
-        if ( cmdLine.contains(argCheck) )
-            explicitCheck = true ;
-
-        if ( cmdLine.contains(argNoCheck) )
-            explicitNoCheck = true ;
-
-        if ( cmdLine.contains(argStrict) )
-            strict = true ;
-
-        if ( cmdLine.contains(argSkip) )
-            skipOnBadTerm = true ;
-        if ( cmdLine.contains(argNoSkip) )
-            skipOnBadTerm = false ;
-
-        if ( cmdLine.contains(argBase) ) {
-            baseIRI = cmdLine.getValue(argBase) ;
-            IRI iri = IRIResolver.resolveIRI(baseIRI) ;
-            if ( iri.hasViolation(false) )
-                throw new CmdException("Bad base IRI: " + baseIRI) ;
-            if ( !iri.isAbsolute() )
-                throw new CmdException("Base IRI must be an absolute IRI: " + baseIRI) ;
-        }
-
-        if ( cmdLine.contains(argStop) )
-            stopOnBadTerm = true ;
-
-        if ( cmdLine.contains(argSink) )
-            bitbucket = true ;
-
-        if ( cmdLine.contains(argRDFS) ) {
-            try {
-                rdfsVocabFilename = cmdLine.getArg(argRDFS).getValue() ;
-                rdfsVocab = FileManager.get().loadModel(rdfsVocabFilename) ;
-            } catch (RiotException ex) {
-                throw new CmdException("Error in RDFS vocabulary: " + rdfsVocabFilename) ;
-            } catch (Exception ex) {
-                throw new CmdException("Error: " + ex.getMessage()) ;
-            }
-        }
-    }
-
-    public boolean explicitChecking() {
-        return explicitCheck ;
-    }
-
-    public boolean explicitNoChecking() {
-        return explicitNoCheck ;
-    }
-
-    public boolean strictMode() {
-        return strict ;
-    }
-
-    public boolean validate() {
-        return validate ;
-    }
-
-    public boolean skipOnBadTerm() {
-        return skipOnBadTerm ;
-    }
-
-    public boolean stopOnBadTerm() {
-        return stopOnBadTerm ;
-    }
-
-    public boolean toBitBucket() {
-        return bitbucket ;
-    }
-
-    public String getBaseIRI() {
-        return baseIRI ;
-    }
-
-    public Model getRDFSVocab() {
-        return rdfsVocab ;
-    }
-
-    public Lang getLang() {
-        return lang ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModQueryIn.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModQueryIn.java b/jena-arq/src/main/java/arq/cmdline/ModQueryIn.java
deleted file mode 100644
index 290df7c..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModQueryIn.java
+++ /dev/null
@@ -1,156 +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 arq.cmdline ;
-
-import java.io.IOException ;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdException;
-import jena.cmd.CmdGeneral;
-import jena.cmd.ModBase;
-import jena.cmd.TerminationException;
-
-import org.apache.jena.query.Query ;
-import org.apache.jena.query.QueryFactory ;
-import org.apache.jena.query.Syntax ;
-import org.apache.jena.shared.JenaException ;
-import org.apache.jena.sparql.ARQInternalErrorException ;
-import org.apache.jena.util.FileUtils ;
-
-public class ModQueryIn extends ModBase {
-    protected final ArgDecl queryFileDecl   = new ArgDecl(ArgDecl.HasValue, "query", "file") ;
-    protected final ArgDecl querySyntaxDecl = new ArgDecl(ArgDecl.HasValue, "syntax", "syn", "in") ;
-    protected final ArgDecl queryBaseDecl   = new ArgDecl(ArgDecl.HasValue, "base") ;
-
-    private Syntax          defaultQuerySyntax     = Syntax.syntaxARQ ;
-    private Syntax          querySyntax     = null ;
-    private String          queryFilename   = null ;
-    private String          queryString     = null ;
-    private Query           query           = null ;
-    private String          baseURI         = null ;
-
-    public ModQueryIn(Syntax defaultSyntax) {
-        defaultQuerySyntax = defaultSyntax ;
-        querySyntax = defaultSyntax ;
-    }
-
-    @Override
-    public void registerWith(CmdGeneral cmdLine) {
-        cmdLine.getUsage().startCategory("Query") ;
-        cmdLine.add(queryFileDecl,   "--query, --file",  "File containing a query") ;
-        cmdLine.add(querySyntaxDecl, "--syntax, --in",   "Syntax of the query") ;
-        cmdLine.add(queryBaseDecl,   "--base",           "Base URI for the query") ;
-    }
-
-    @Override
-    public void processArgs(CmdArgModule cmdline) throws IllegalArgumentException {
-        if ( cmdline.contains(queryBaseDecl) )
-            baseURI = cmdline.getValue(queryBaseDecl) ;
-
-        if ( cmdline.contains(queryFileDecl) ) {
-            queryFilename = cmdline.getValue(queryFileDecl) ;
-            querySyntax = Syntax.guessFileSyntax(queryFilename, defaultQuerySyntax) ;
-        }
-
-        if ( cmdline.getNumPositional() == 0 && queryFilename == null )
-            cmdline.cmdError("No query string or query file") ;
-
-        if ( cmdline.getNumPositional() > 1 )
-            cmdline.cmdError("Only one query string allowed") ;
-
-        if ( cmdline.getNumPositional() == 1 && queryFilename != null )
-            cmdline.cmdError("Either query string or query file - not both") ;
-
-        if ( queryFilename == null ) {
-            // One positional argument.
-            String qs = cmdline.getPositionalArg(0) ;
-            if ( cmdline.matchesIndirect(qs) )
-                querySyntax = Syntax.guessFileSyntax(qs, defaultQuerySyntax) ;
-
-            queryString = cmdline.indirect(qs) ;
-        }
-
-        // Set syntax
-        if ( cmdline.contains(querySyntaxDecl) ) {
-            // short name
-            String s = cmdline.getValue(querySyntaxDecl) ;
-            Syntax syn = Syntax.lookup(s) ;
-            if ( syn == null )
-                cmdline.cmdError("Unrecognized syntax: " + s) ;
-            querySyntax = syn ;
-        }
-    }
-
-    public Syntax getQuerySyntax() {
-        return querySyntax ;
-    }
-
-    public Query getQuery() {
-        if ( query != null )
-            return query ;
-
-        if ( queryFilename != null && queryString != null ) {
-            System.err.println("Both query string and query file name given") ;
-            throw new TerminationException(1) ;
-        }
-
-        if ( queryFilename == null && queryString == null ) {
-            System.err.println("No query string and no query file name given") ;
-            throw new TerminationException(1) ;
-        }
-
-        try {
-            if ( queryFilename != null ) {
-                if ( queryFilename.equals("-") ) {
-                    try {
-                        // Stderr?
-                        queryString = FileUtils.readWholeFileAsUTF8(System.in) ;
-                        // And drop into next if
-                    } catch (IOException ex) {
-                        throw new CmdException("Error reading stdin", ex) ;
-                    }
-                } else {
-                    query = QueryFactory.read(queryFilename, baseURI, getQuerySyntax()) ;
-                    return query ;
-                }
-            }
-
-            query = QueryFactory.create(queryString, baseURI, getQuerySyntax()) ;
-            return query ;
-        } catch (ARQInternalErrorException intEx) {
-            System.err.println(intEx.getMessage()) ;
-            if ( intEx.getCause() != null ) {
-                System.err.println("Cause:") ;
-                intEx.getCause().printStackTrace(System.err) ;
-                System.err.println() ;
-            }
-            intEx.printStackTrace(System.err) ;
-            throw new TerminationException(99) ;
-        }
-        catch (JenaException ex) {
-            System.err.println(ex.getMessage()) ;
-            throw new TerminationException(2) ;
-        } catch (Exception ex) {
-            System.out.flush() ;
-            ex.printStackTrace(System.err) ;
-            throw new TerminationException(98) ;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModQueryOut.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModQueryOut.java b/jena-arq/src/main/java/arq/cmdline/ModQueryOut.java
deleted file mode 100644
index d32f6c0..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModQueryOut.java
+++ /dev/null
@@ -1,92 +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 arq.cmdline;
-
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdGeneral;
-import jena.cmd.ModBase;
-
-import org.apache.jena.atlas.io.IndentedWriter ;
-import org.apache.jena.query.Query ;
-import org.apache.jena.query.Syntax ;
-import org.apache.jena.sparql.util.QueryOutputUtils ;
-
-public class ModQueryOut extends ModBase
-{
-    protected final ArgDecl queryOutputSyntaxDecl  = new ArgDecl(ArgDecl.HasValue, "out", "format") ;
-    protected final ArgDecl queryNumberDecl        = new ArgDecl(ArgDecl.NoValue, "num", "number") ;
-
-    private Syntax outputSyntax = Syntax.syntaxSPARQL ;
-    private boolean lineNumbers = false ;
-    
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        cmdLine.getUsage().startCategory("Output") ;
-        cmdLine.add(queryOutputSyntaxDecl, "--out, --format",  "Output syntax") ;
-        cmdLine.add(queryNumberDecl, "--num", "Print line numbers") ;
-    }
-
-    @Override
-    public void processArgs(CmdArgModule cmdline) throws IllegalArgumentException
-    {
-        if ( cmdline.contains(queryOutputSyntaxDecl) )
-        {
-            // short name
-            String s = cmdline.getValue(queryOutputSyntaxDecl) ;
-            Syntax syn = Syntax.lookup(s) ;
-            if ( syn == null )
-                cmdline.cmdError("Unrecognized syntax: "+s) ;
-            outputSyntax = syn ; 
-        }        
-        
-        lineNumbers = cmdline.contains(queryNumberDecl) ;
-    }
-    
-    public Syntax getOutputSyntax()
-    {
-        return outputSyntax ;
-    }
-
-    public void output(Query query)
-    { output(out(), query) ; }
-    
-    public void output(IndentedWriter out, Query query)
-    { QueryOutputUtils.printQuery(out, query, outputSyntax) ; }
-    
-    public void outputOp(Query query, boolean printOptimized)
-    { outputOp(out(), query, printOptimized) ; }
-
-    public void outputOp(IndentedWriter out, Query query, boolean printOptimized)
-    { QueryOutputUtils.printOp(out, query, printOptimized) ; }
-    
-    public void outputQuad(Query query, boolean printOptimized)
-    { outputQuad(out(), query, printOptimized) ; }
-    
-    public void outputQuad(IndentedWriter out, Query query, boolean printOptimized)
-    { QueryOutputUtils.printQuad(out, query, printOptimized) ; }
-    
-    private IndentedWriter out()
-    {
-        return new IndentedWriter(System.out, lineNumbers) ;
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModRemote.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModRemote.java b/jena-arq/src/main/java/arq/cmdline/ModRemote.java
deleted file mode 100644
index 97f03eb..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModRemote.java
+++ /dev/null
@@ -1,75 +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 arq.cmdline;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdGeneral;
-import jena.cmd.ModBase;
-
-
-public class ModRemote extends ModBase
-{
-    protected final 
-    ArgDecl serviceDecl = new ArgDecl(ArgDecl.HasValue, "service") ;
-    
-    // Or --serviceType GET, POST, SOAP
-    protected final 
-    ArgDecl postServiceDecl = new ArgDecl(ArgDecl.NoValue, "post", "POST") ;
-    
-    private String serviceURL ;
-    private boolean usePost ;
-    
-    public void checkCommandLine(CmdArgModule cmdLine)
-    {}
-    
-    @Override
-    public void processArgs(CmdArgModule cmdLine)
-    {
-        serviceURL = cmdLine.getValue(serviceDecl) ;
-        usePost = cmdLine.contains(postServiceDecl) ;
-    }
-    
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        cmdLine.getUsage().startCategory("Remote") ;
-        cmdLine.add(serviceDecl,
-                    "--service=",
-                    "Service endpoint URL") ;
-        cmdLine.add(postServiceDecl,
-                    "--post",
-                    "Force use of HTTP POST") ;
-
-    }
-
-    public String getServiceURL()
-    {
-        return serviceURL ;
-    }
-
-    public boolean usePost()
-    {
-        return usePost ;
-    }
-    
-    
-    
-
-}


[12/20] jena git commit: JENA-1108 : jena-cmds module

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/rdfcopy.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/rdfcopy.java b/jena-cmds/src/main/java/jena/rdfcopy.java
new file mode 100644
index 0000000..a998c37
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/rdfcopy.java
@@ -0,0 +1,158 @@
+/*
+ * 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 jena;
+
+import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
+
+import java.net.*;
+import java.io.*;
+
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.shared.JenaException ;
+
+/** A program which read an RDF model and copy it to the standard output stream.
+ *
+ *  <p>This program will read an RDF model, in a variety of languages,
+ *     and copy it to the output stream in a possibly different language.
+ *     Input can be read either from a URL or from a file.
+ *     The program writes its results to the standard output stream and sets
+ *     its exit code to 0 if the program terminate normally,  and
+ *     to -1 if it encounters an error.</p>
+ *
+ *  <p></p>
+ *
+ *  <pre>java jena.rdfcopy model [inlang [outlang]]
+ *
+ *       model1 and model2 can be file names or URL's
+ *       inlang and outlang specify the language of the input and output
+ *       respectively and can be:
+ *           RDF/XML
+ *           N-TRIPLE
+ *           TURTLE
+ *           N3
+ *       The input language defaults to RDF/XML and the output language
+ *       defaults to N-TRIPLE.
+ *  </pre>
+ */
+public class rdfcopy extends java.lang.Object {
+
+    static { setCmdLogging(); }
+
+	/**
+	* @param args the command line arguments
+	*/
+	public static void main(String ... args) {
+		if ( ( args.length < 1 ) || ( "-h".equals(args[0]) ) ) {
+			usage();
+			System.exit(-1);
+		}
+
+		String in = args[0];
+		String inlang = "RDF/XML";
+		int j;
+		for (j = 1; j < args.length && args[j].contains( "=" ); j++)
+        {}
+		int lastInProp = j;
+		if (j < args.length) {
+			inlang = args[j];
+		}
+		j++;
+		String outlang = "N-TRIPLE";
+		
+		for (; j < args.length && args[j].contains( "=" ); j++)
+		{}
+		
+		int lastOutProp = j;
+		if (j < args.length) {
+			outlang = args[j];
+		}
+		if (j + 1 < args.length) {
+         //   System.err.println(j+"<<"+args.length);
+			usage();
+			System.exit(-1);
+		}
+
+		try {
+			Model m = ModelFactory.createDefaultModel();
+            String base = in ;
+			RDFReader rdr = m.getReader(inlang);
+			for (j = 1; j < lastInProp; j++) {
+				int eq = args[j].indexOf("=");
+				rdr.setProperty(
+					args[j].substring(0, eq),
+					args[j].substring(eq + 1));
+			}
+            
+            try {
+                rdr.read(m, in);
+            } catch (JenaException ex)
+            {
+                if ( ! ( ex.getCause() instanceof MalformedURLException ) )
+                    throw ex ;
+                // Tried as a URL.  Try as a file name.
+                // Make absolute
+                File f = new File(in) ;
+                base = "file:///"+f.getCanonicalPath().replace('\\','/') ;
+                rdr.read(m, new FileInputStream(in), base) ;
+            }
+			RDFWriter w = m.getWriter(outlang);
+			j++;
+			for (; j < lastOutProp; j++) {
+				int eq = args[j].indexOf("=");
+				w.setProperty(
+					args[j].substring(0, eq),
+					args[j].substring(eq + 1));
+			}
+			w.write(m, System.out, null) ;
+			System.exit(0);
+		} catch (Exception e) {
+			System.err.println("Unhandled exception:");
+			System.err.println("    " + e.toString());
+			System.exit(-1);
+		}
+	}
+
+	protected static void usage() {
+		System.err.println("usage:");
+		System.err.println("    java jena.rdfcopy in {inprop=inval}* [ inlang  {outprop=outval}* outlang]]");
+		System.err.println();
+		System.err.println("    in can be a URL or a filename");
+		System.err.println("    inlang and outlang can take values:");
+		System.err.println("      RDF/XML");
+        System.err.println("      RDF/XML-ABBREV");
+        System.err.println("      N-TRIPLE");
+        System.err.println("      TURTLE");
+		System.err.println("      N3");
+		System.err.println(
+			"    inlang defaults to RDF/XML, outlang to N-TRIPLE");
+        System.err.println("    The legal values for inprop and outprop depend on inlang and outlang.");
+        System.err.println("    The legal values for inval and outval depend on inprop and outprop.");
+		System.err.println();
+	}
+
+	protected static void read(Model model, String in, String lang)
+		throws java.io.FileNotFoundException {
+		try {
+			URL url = new URL(in);
+			model.read(in, lang);
+		} catch (java.net.MalformedURLException e) {
+			model.read(new FileInputStream(in), "", lang);
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/rdfparse.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/rdfparse.java b/jena-cmds/src/main/java/jena/rdfparse.java
new file mode 100644
index 0000000..0ba1eb6
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/rdfparse.java
@@ -0,0 +1,103 @@
+/*
+ * 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 jena;
+
+import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
+
+import java.lang.reflect.Constructor ;
+
+import org.apache.jena.rdfxml.xmlinput.NTriple ;
+import org.apache.jena.shared.Command ;
+
+/** A command line interface into ARP.
+ * Creates NTriple's or just error messages.
+ * <pre>
+ * java &lt;class-path&gt; jena.rdfparse ( [ -[xstfu]][ -b xmlBase -[eiw] NNN[,NNN...] ] [ file ] [ url ] )...
+ * 
+ * java &lt;class-path&gt; jena.rdfparse --test
+ * 
+ * java &lt;class-path&gt; jena.rdfparse --internal-test
+ * </pre>
+ * 
+ * <p>
+ * The last two forms are for testing. <code>--test</code> runs ARP
+ * against the RDF Core Working Group tests found at w3.org.
+ * <code>--internal-test</code> uses a cached copy from within the jena.jar.
+ * </p>
+ * All options, files and URLs can be intemingled in any order.
+ * They are processed from left-to-right.
+ * <dl>
+ * file    </dt><dd>  Converts (embedded) RDF in XML file into N-triples
+ * </dd><dt>
+ * url  </dt><dd>     Converts (embedded) RDF from URL into N-triples
+ * </dd><dt>
+ * -b uri </dt><dd>   Sets XML Base to the absolute URI.
+ * </dd><dt>
+ * -r    </dt><dd>    Content is RDF (no embedding, rdf:RDF tag may be omitted).
+ * </dd><dt>
+ * -t  </dt><dd>      No n-triple output, error checking only.
+ * </dd><dt>
+ * -x   </dt><dd>     Lax mode - warnings are suppressed.
+ * </dd><dt>
+ * -s    </dt><dd>    Strict mode - most warnings are errors.
+ * </dd><dt>
+ * -u     </dt><dd>   Allow unqualified attributes (defaults to warning).
+ * </dd><dt>
+ * -f    </dt><dd>    All errors are.error - report first one only.
+ * </dd><dt>
+ * -b url </dt><dd>   Sets XML Base to the absolute url.
+ * </dd><dt>
+ * -e NNN[,NNN...]</dt><dd>
+ * Treats numbered warning conditions as errrors.
+ * </dd><dt>
+ * -w NNN[,NNN...]</dt><dd>
+ * Treats numbered error conditions as warnings.
+ * </dd><dt>
+ * -i NNN[,NNN...]
+ * </dt><dd>
+ * Ignores numbered error/warning conditions.
+ * </dl>
+ */
+
+public class rdfparse {
+
+    static { setCmdLogging(); }
+
+    /** Either start an RDF/XML to NTriple converter, or run test suite.
+	 * @param args The command-line arguments.
+	 */
+	public static void main( String... args ) throws Exception {
+		if (args.length == 1 && (args[0].equals( "--test" ) || args[0].equals( "--internal-test" ))) 
+            runTests( args[0].equals( "--test" ) );
+        else
+		    NTriple.main( args );
+	}
+
+    /**
+         wrapped this way so JUnit not a compile-time requirement.
+    */
+    protected static void runTests( boolean internetTest ) throws Exception { 
+        Class<?> rdfparse = Class.forName( "jena.test.rdfparse" );
+        Constructor<?> constructor = rdfparse.getConstructor( new Class[] {boolean.class} );
+        Command c = (Command) constructor.newInstance( new Object[] { internetTest } );
+        c.execute();
+//        ARPTests.internet = internetTest;
+//        TestRunner.main( new String[] { "-noloading", ARPTests.class.getName()});
+        }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/rset.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/rset.java b/jena-cmds/src/main/java/jena/rset.java
new file mode 100644
index 0000000..6db2a1c
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/rset.java
@@ -0,0 +1,25 @@
+/*
+ * 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 jena;
+
+public class rset {
+    public static void main(String... args) {
+        arq.rset.main(args);
+    }
+}


[11/20] jena git commit: JENA-1108 : jena-cmds module

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/schemagen.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/schemagen.java b/jena-cmds/src/main/java/jena/schemagen.java
new file mode 100644
index 0000000..0512506
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/schemagen.java
@@ -0,0 +1,2117 @@
+/*
+ * 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
+///////////////
+package jena;
+
+
+import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
+
+import java.io.ByteArrayOutputStream ;
+import java.io.File ;
+import java.io.FileOutputStream ;
+import java.io.PrintStream ;
+import java.net.MalformedURLException ;
+import java.net.URL ;
+import java.text.SimpleDateFormat ;
+import java.util.* ;
+import java.util.regex.Pattern ;
+import java.util.regex.PatternSyntaxException ;
+
+import org.apache.jena.ontology.Individual ;
+import org.apache.jena.ontology.OntModel ;
+import org.apache.jena.ontology.OntModelSpec ;
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.shared.JenaException ;
+import org.apache.jena.util.FileManager ;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+import org.apache.jena.util.iterator.WrappedIterator ;
+import org.apache.jena.vocabulary.OWL ;
+import org.apache.jena.vocabulary.RDF ;
+import org.apache.jena.vocabulary.RDFS ;
+import org.apache.jena.vocabulary.XSD ;
+import org.apache.xerces.util.XMLChar ;
+
+
+
+/**
+ * <p>
+ * A vocabulary generator, that will consume an ontology or other vocabulary file,
+ * and generate a Java file with the constants from the vocabulary compiled in.
+ * Designed to be highly flexible and customisable.
+ * </p>
+ */
+public class schemagen {
+    
+    static { setCmdLogging(); }
+
+    // Constants
+    //////////////////////////////////
+
+    /** The namespace for the configuration model is {@value} */
+    public static final String NS = "http://jena.hpl.hp.com/2003/04/schemagen#";
+
+    /** The default location of the configuration model is {@value} */
+    public static final String DEFAULT_CONFIG_URI = "file:schemagen.rdf";
+
+    /** The default marker string for denoting substitutions is {@value} */
+    public static final String DEFAULT_MARKER = "%";
+
+    /** Default template for writing out value declarations */
+    public static final String DEFAULT_TEMPLATE = "public static final %valclass% %valname% = m_model.%valcreator%( \"%valuri%\" );";
+
+    /** Default template for writing out individual declarations */
+    public static final String DEFAULT_INDIVIDUAL_TEMPLATE = "public static final %valclass% %valname% = m_model.%valcreator%( \"%valuri%\", %valtype% );";
+
+    /** Default template for writing out individual declarations for non-ontology vocabularies */
+    public static final String DEFAULT_RDFS_INDIVIDUAL_TEMPLATE = "public static final %valclass% %valname% = m_model.%valcreator%( \"%valuri%\" );";
+
+    /** Default template for the file header */
+    public static final String DEFAULT_HEADER_TEMPLATE = "/* CVS $" + "Id: $ */%nl%%package% %nl%%imports% %nl%/**%nl% * Vocabulary definitions from %sourceURI% %nl% * @author Auto-generated by schemagen on %date% %nl% */";
+
+    /** Default line length for comments before wrap */
+    public static final int COMMENT_LENGTH_LIMIT = 80;
+
+
+
+    /** List of Java reserved keywords, see <a href="http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html">this list</a>. */
+    public static final String[] JAVA_KEYWORDS = {
+        "abstract",    "continue",    "for",         "new",         "switch",
+        "assert",      "default",     "goto",        "package",     "synchronized",
+        "boolean",     "do",          "if",          "private",     "this",
+        "break",       "double",      "implements",  "protected",   "throw",
+        "byte",        "else",        "import",      "public",      "throws",
+        "case",        "enum",        "instanceof",  "return",      "transient",
+        "catch",       "extends",     "int",         "short",       "try",
+        "char",        "final",       "interface",   "static",      "void",
+        "class",       "finally",     "long",        "strictfp",    "volatile",
+        "const",       "float",       "native",      "super",       "while"
+    };
+
+
+    // Static variables
+    //////////////////////////////////
+
+    private static List<String> KEYWORD_LIST;
+    static {
+        KEYWORD_LIST = Arrays.asList( JAVA_KEYWORDS );
+    }
+
+    // Instance variables
+    //////////////////////////////////
+
+    /** Schemagen options interface */
+    protected SchemagenOptions m_options;
+
+    /** The model that contains the input source */
+    protected OntModel m_source;
+
+    /** The output stream we write to */
+    protected PrintStream m_output;
+
+    /** Option definitions */
+    /** Stack of replacements to apply */
+    protected List<Replacement> m_replacements = new ArrayList<>();
+
+    /** Output file newline char - default is Unix, override with --dos */
+    protected String m_nl = "\n";
+
+    /** Size of indent step */
+    protected int m_indentStep = 4;
+
+    /** Set of names used so far */
+    protected Set<String> m_usedNames = new HashSet<>();
+
+    /** Map from resources to java names */
+    protected Map<Resource,String> m_resourcesToNames = new HashMap<>();
+
+    /** List of allowed namespace URI strings for admissible values */
+    protected List<String> m_includeURI = new ArrayList<>();
+
+
+    // Constructors
+    //////////////////////////////////
+
+    // External signature methods
+    //////////////////////////////////
+
+    /* Main entry point. See Javadoc for details of the many command line arguments */
+    public static void main( String... args ) {
+        try {
+            new schemagen().go( args );
+        }
+        catch (SchemagenException e) {
+            System.err.println( "Schemagen failed to run:" );
+            System.err.println( e.getMessage() );
+
+            if (e.getCause() != null) {
+                System.err.println( "Caused by: " + e.getCause().getMessage() );
+            }
+
+            System.exit( 1 );
+        }
+    }
+
+
+    // Internal implementation methods
+    //////////////////////////////////
+
+    /** Read the configuration parameters and do setup */
+    protected void go( String[] args ) {
+        go( new SchemagenOptionsImpl( args ) );
+    }
+
+    /** Handle initial configuration options, then initiate processing */
+    protected void go( SchemagenOptions options ) {
+        m_options = options;
+
+
+        // check for user requesting help
+        if (m_options.hasHelpOption()) {
+            usage();
+        }
+
+
+        // got the configuration, now we can begin processing
+        processInput();
+    }
+
+    /** The sequence of steps to process an entire file */
+    protected void processInput() {
+        addIncludes();
+        determineLanguage();
+        selectInput();
+        selectOutput();
+        setGlobalReplacements();
+
+        processHeader();
+        writeClassDeclaration();
+        writeInitialDeclarations();
+        writeProperties();
+        writeClasses();
+        writeIndividuals();
+        writeDatatypes();
+        writeClassClose();
+        processFooter();
+        closeOutput();
+    }
+
+    /** Add the included files */
+    protected void addIncludes() {
+        // add any extra uri's that are allowed in the filter
+        m_includeURI.addAll( m_options.getIncludeOption() );
+    }
+
+    /** Create the source model after determining which input language */
+    protected void determineLanguage() {
+        OntModelSpec s = null;
+        if (m_options.hasLangRdfsOption()) {
+            // RDFS language specified
+            if (m_options.hasUseInfOption()) {
+                s = OntModelSpec.RDFS_MEM_RDFS_INF;
+            }
+            else {
+                s = OntModelSpec.RDFS_MEM;
+            }
+        }
+        else {
+            // owl is the default
+            // s = OntModelSpec.getDefaultSpec( ProfileRegistry.OWL_LANG );
+            if (m_options.hasUseInfOption()) {
+                s = OntModelSpec.OWL_MEM_RULE_INF;
+            }
+            else {
+                s = OntModelSpec.OWL_MEM;
+            }
+        }
+
+        m_source = ModelFactory.createOntologyModel( s, null );
+        m_source.getDocumentManager().setProcessImports( false );
+
+        // turn off strict checking on request
+        if (m_options.hasNoStrictOption()) {
+            m_source.setStrictMode( false );
+        }
+    }
+
+    /** Identify the URL that is to be read in and translated to a vocabulary file, and load the source into the source model */
+    protected void selectInput() {
+        if (!m_options.hasInputOption()) {
+            usage();
+        }
+
+        String input = SchemagenUtils.urlCheck( m_options.getInputOption().getURI() );
+        String syntax = m_options.getEncodingOption();
+
+        try {
+            FileManager.get().readModel( m_source, input, syntax );
+        }
+        catch (JenaException e) {
+            abort( "Failed to read input source " + input, e );
+        }
+    }
+
+    /** Identify the file we are to write the output to */
+    protected void selectOutput() {
+        String outFile = m_options.getOutputOption();
+        if (outFile == null) {
+            m_output = System.out;
+        }
+        else {
+            try {
+                // check for package name
+                String packageName = m_options.getPackagenameOption();
+                if (packageName != null) {
+                    String packagePath = "";
+
+                    // build the package path (e.g. com.foo.bar -> /com/foo/bar)
+                    for (String p: packageName.split( "\\." )) {
+                        packagePath = packagePath + File.separator + p;
+                    }
+
+                    if (!outFile.endsWith( packagePath )) {
+                        outFile = outFile + packagePath;
+                    }
+                }
+
+                File out = new File( outFile );
+
+                if (!out.exists() && !outFile.endsWith( ".java" )) {
+                    // create the directory if needed
+                    out.mkdirs();
+                }
+
+                if (out.isDirectory()) {
+                    // create a file in this directory named classname.java
+                    String fileName = outFile + File.separator + getClassName() + ".java";
+                    out = new File( fileName );
+                }
+
+                m_output = new PrintStream( new FileOutputStream( out ) );
+            }
+            catch (Exception e) {
+                abort( "I/O error while trying to open file for writing: " + outFile, e );
+            }
+        }
+
+        // check for DOS line endings
+        if (m_options.hasDosOption()) {
+            m_nl = "\r\n";
+        }
+    }
+
+    /** Process the header at the start of the file, if defined */
+    protected void processHeader() {
+        String header = m_options.hasHeaderOption() ? m_options.getHeaderOption() : DEFAULT_HEADER_TEMPLATE;
+
+        // user can turn of header processing, default is to have it on
+        if (!m_options.hasNoheaderOption()) {
+            writeln( 0, substitute( header ) );
+        }
+        else {
+            // we have to do the imports at least
+            writeln( 0, "import org.apache.jena.rdf.model.*;" );
+            if (m_options.hasOntologyOption()) {
+                writeln( 0, "import org.apache.jena.ontology.*;" );
+            }
+            if (m_options.hasIncludeSourceOption()) {
+                writeln( 0, "import java.io.ByteArrayInputStream;" );
+            }
+        }
+    }
+
+    /** Process the footer at the end of the file, if defined */
+    protected void processFooter() {
+        String footer = m_options.getFooterOption();
+
+        if (footer != null) {
+            writeln( 0, substitute( footer ) );
+        }
+    }
+
+    /** The list of replacements that are always available */
+    protected void setGlobalReplacements() {
+        addReplacementPattern( "date", new SimpleDateFormat( "dd MMM yyyy HH:mm").format( new Date() ) );
+        addReplacementPattern( "package", m_options.hasPackagenameOption() ? ("package " + m_options.getPackagenameOption() + ";") : "" );
+        addReplacementPattern( "imports", getImports() );
+        addReplacementPattern( "classname", getClassName() );
+        addReplacementPattern( "nl", m_nl );
+
+        // protect \ in Windows file pathnames
+        // looks for file:.* or C:.* (or variants thereof)
+        String source = m_options.getInputOption().getURI();
+        if (source.matches( "(file:|[A-Za-z]:).*$" )) {
+            source = source.replace( "\\", "\\\\" );
+        }
+        addReplacementPattern( "sourceURI", source );
+    }
+
+    /** Add a pattern-value pair to the list of available patterns */
+    protected void addReplacementPattern( String key, String replacement ) {
+        if (replacement != null && key != null) {
+            String marker = m_options.getMarkerOption();
+            marker = (marker == null) ? DEFAULT_MARKER : marker;
+
+            try {
+                m_replacements.add( new Replacement( Pattern.compile( marker + key + marker ),
+                                                     replacement ) );
+            }
+            catch (PatternSyntaxException e) {
+                abort( "Malformed regexp pattern " + marker + key + marker, e );
+            }
+        }
+    }
+
+    /** Pop n replacements off the stack */
+    protected void pop( int n ) {
+        for (int i = 0;  i < n;  i++) {
+            m_replacements.remove( m_replacements.size() - 1 );
+        }
+    }
+
+
+    /** Close the output file */
+    protected void closeOutput() {
+        m_output.flush();
+        m_output.close();
+    }
+
+
+    /** Abort due to exception */
+    protected void abort( String msg, Exception cause ) {
+        throw new SchemagenException( msg, cause );
+    }
+
+    /** Print usage message and abort */
+    protected void usage() {
+        System.err.println( "Usage:" );
+        System.err.println( "  java jena.schemagen [options ...]" );
+        System.err.println();
+        System.err.println( "Commonly used options include:" );
+        System.err.println( "   -i <input> the source document as a file or URL." );
+        System.err.println( "   -n <name> the name of the created Java class." );
+        System.err.println( "   -a <uri> the namespace URI of the source document." );
+        System.err.println( "   -o <file> the file to write the generated class into." );
+        System.err.println( "   -o <dir> the directory in which the generated Java class is created." );
+        System.err.println( "            By default, output goes to stdout." );
+        System.err.println( "   -e <encoding> the encoding of the input document (N3, RDF/XML, etc)." );
+        System.err.println( "   -c <config> a filename or URL for an RDF document containing " );
+        System.err.println( "               configuration parameters." );
+        System.err.println();
+        System.err.println( "Many other options are available. See the schemagen HOWTO in the " );
+        System.err.println( "Jena documentation for full details." );
+        System.exit( 1 );
+    }
+
+    /** Use the current replacements list to do the subs in the given string */
+    protected String substitute( String sIn ) {
+        String s = sIn;
+
+        for ( Replacement r : m_replacements )
+        {
+            s = r.pattern.matcher( s ).replaceAll( r.sub );
+        }
+
+        return s;
+    }
+
+    /** Add the appropriate indent to a buffer */
+    protected int indentTo( int i, StringBuffer buf ) {
+        int indent = i * m_indentStep;
+        for (int j = 0;  j < indent; j++) {
+            buf.append( ' ' );
+        }
+
+        return indent;
+    }
+
+    /** Write a blank line, with indent and newline */
+    protected void writeln( int indent ) {
+        writeln( indent, "" );
+    }
+
+    /** Write out the given string with n spaces of indent, with newline */
+    protected void writeln( int indent, String s ) {
+        write( indent, s );
+        m_output.print( m_nl );
+    }
+
+    /** Write out the given string with n spaces of indent */
+    protected void write( int indentLevel, String s ) {
+        for (int i = 0;  i < (m_indentStep * indentLevel);  i++) {
+            m_output.print( " " );
+        }
+
+        m_output.print( s );
+    }
+
+    /** Determine the list of imports to include in the file */
+    protected String getImports() {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "import org.apache.jena.rdf.model.*;" );
+        buf.append( m_nl );
+
+        if (useOntology()) {
+            buf.append( "import org.apache.jena.ontology.*;" );
+            buf.append( m_nl );
+        }
+
+        if (includeSource()) {
+            buf.append( "import java.io.ByteArrayInputStream;" );
+            buf.append( m_nl );
+        }
+
+        return buf.toString();
+    }
+
+    /** Determine the class name of the vocabulary from the URI */
+    protected String getClassName() {
+        // if a class name is given, just use that
+        if (m_options.hasClassnameOption()) {
+            return m_options.getClassnameOption();
+        }
+
+        // otherwise, we generate a name based on the URI
+        String uri = m_options.getInputOption().getURI();
+
+        // remove any suffixes
+        uri = (uri.endsWith( "#" )) ? uri.substring( 0, uri.length() - 1 ) : uri;
+        uri = (uri.endsWith( ".daml" )) ? uri.substring( 0, uri.length() - 5 ) : uri;
+        uri = (uri.endsWith( ".owl" )) ? uri.substring( 0, uri.length() - 4 ) : uri;
+        uri = (uri.endsWith( ".rdf" )) ? uri.substring( 0, uri.length() - 4 ) : uri;
+        uri = (uri.endsWith( ".rdfs" )) ? uri.substring( 0, uri.length() - 5 ) : uri;
+        uri = (uri.endsWith( ".n3" )) ? uri.substring( 0, uri.length() - 3 ) : uri;
+        uri = (uri.endsWith( ".xml" )) ? uri.substring( 0, uri.length() - 4 ) : uri;
+        uri = (uri.endsWith( ".ttl" )) ? uri.substring( 0, uri.length() - 4 ) : uri;
+
+        // now work back to the first non name character from the end
+        int i = uri.length() - 1;
+        for (; i > 0; i--) {
+            if (!Character.isUnicodeIdentifierPart( uri.charAt( i ) ) &&
+                uri.charAt( i ) != '-') {
+                i++;
+                break;
+            }
+        }
+
+        String name = uri.substring( i );
+
+        // optionally add name suffix
+        if (m_options.hasClassnameSuffixOption()) {
+            name = name + m_options.getClassnameSuffixOption();
+        }
+
+        // now we make the name into a legal Java identifier
+        return asLegalJavaID( name, true );
+    }
+
+    /** Answer true if we are using ontology terms in this vocabulary */
+    protected boolean useOntology() {
+        return m_options.hasOntologyOption();
+    }
+
+    /** Answer true if all comments are suppressed */
+    protected boolean noComments() {
+        return m_options.hasNoCommentsOption();
+    }
+
+    /** Answer true if ontology source code is to be included */
+    protected boolean includeSource() {
+        return m_options.hasIncludeSourceOption();
+    }
+
+    /** Converts to a legal Java identifier; capitalise first char if cap is true */
+    protected String asLegalJavaID( String s, boolean cap ) {
+        StringBuffer buf = new StringBuffer();
+        int i = 0;
+
+        // treat the first character specially - must be able to start a Java ID, may have to up-case
+        try {
+            for (; !Character.isJavaIdentifierStart( s.charAt( i )); i++) { /**/ }
+        }
+        catch (StringIndexOutOfBoundsException e) {
+            System.err.println( "Could not identify legal Java identifier start character in '" + s + "', replacing with __" );
+            return "__";
+        }
+        buf.append( cap ? Character.toUpperCase( s.charAt( i ) ) : s.charAt( i ) );
+
+        // copy the remaining characters - replace non-legal chars with '_'
+        for (++i; i < s.length(); i++) {
+            char c = s.charAt( i );
+            buf.append( Character.isJavaIdentifierPart( c ) ? c : '_' );
+        }
+
+        // check for illegal keyword
+        if (KEYWORD_LIST.contains( buf.toString() )) {
+            buf.append( '_' );
+        }
+
+        return buf.toString();
+    }
+
+    /** The opening class declaration */
+    protected void writeClassDeclaration() {
+        write( 0, "public class " );
+        write( 0, getClassName() );
+        write( 0, " " );
+
+        if (m_options.hasClassdecOption()) {
+            write( 0, m_options.getClassdecOption() );
+        }
+
+        writeln( 0, "{" );
+    }
+
+    /** The close of the class decoration */
+    protected void writeClassClose() {
+        writeln( 0, "}" );
+    }
+
+    /** Write the declarations at the head of the class */
+    protected void writeInitialDeclarations() {
+        writeModelDeclaration();
+        writeSource();
+        writeNamespace();
+        writeOntologyVersionInfo();
+
+        if (m_options.hasDeclarationsOption()) {
+            writeln( 0, m_options.getDeclarationsOption() );
+        }
+    }
+
+    /** Write the declaration of the model */
+    protected void writeModelDeclaration() {
+        if (useOntology()) {
+            String lang = "OWL";
+            if (m_options.hasLangRdfsOption()) {
+                lang = "RDFS";
+            }
+            writeln( 1, "/** <p>The ontology model that holds the vocabulary terms</p> */" );
+            writeln( 1, "private static OntModel m_model = ModelFactory.createOntologyModel( OntModelSpec." + lang + "_MEM, null );" );
+        }
+        else {
+            writeln( 1, "/** <p>The RDF model that holds the vocabulary terms</p> */" );
+            writeln( 1, "private static Model m_model = ModelFactory.createDefaultModel();" );
+        }
+
+        writeln( 1 );
+    }
+
+    /** Write the source code of the input model into the file itself */
+    protected void writeSource() {
+        if (includeSource()) {
+            // first save a copy of the source in compact form into a buffer
+            ByteArrayOutputStream bos = new ByteArrayOutputStream();
+            RDFWriter rw = m_source.getWriter( "Turtle" );
+            rw.setProperty( "objectLists", Boolean.FALSE.toString() );
+            rw.write( m_source, bos, null );
+            String output = bos.toString();
+
+            // now we embed each line of the source in the output
+            writeln( 1, "private static final String SOURCE = " );
+            boolean first = true;
+
+            StringTokenizer st = new StringTokenizer( output, "\n" );
+            while (st.hasMoreTokens()) {
+                String tok = st.nextToken();
+                if (tok.endsWith( "\r" )) {
+                    tok = tok.substring( 0, tok.length() - 1 );
+                }
+                write( 2, first ? "   " : " + " );
+                write( 0, "\"" );
+                write( 0, protectQuotes( tok ) );
+                writeln( 2, "\\n\"" );
+                first = false;
+            }
+
+            // then we reference the string constant when reading the source
+            // note that we avoid StringReader due to charset encoding issues
+            writeln( 1, ";" );
+            writeln( 0, "" );
+            writeln( 1, "/** Read the ontology definition into the source model */ " );
+            writeln( 1, "static { " );
+            writeln( 2, "m_model.read( new ByteArrayInputStream( SOURCE.getBytes() ), null, \"N3\" );" );
+            writeln( 1, "}" );
+            writeln( 0, "" );
+        }
+    }
+
+    /** Protect any double quotes in the given string so that it's a legal Java String */
+    private String protectQuotes( String s ) {
+        return s.replaceAll( "\\\\", "\\\\\\\\" ).replaceAll( "\"", "\\\\\"" );
+    }
+    
+    /** Write owl:versionInfo string if it exists **/
+    protected void writeOntologyVersionInfo() {
+        String versionInfo = getOntologyElementVersionInfo();
+        
+        if (null != versionInfo) {
+            writeln( 1, "/** <p>The ontology's owl:versionInfo as a string</p> */" );
+            writeln( 1, "public static final String VERSION_INFO = \"" + protectQuotes(versionInfo) + "\";" );
+            writeln( 1 );
+        }
+    }
+
+    /** Write the string and resource that represent the namespace */
+    protected void writeNamespace() {
+        String nsURI = determineNamespaceURI();
+
+        writeln( 1, "/** <p>The namespace of the vocabulary as a string</p> */" );
+        writeln( 1, "public static final String NS = \"" + nsURI + "\";" );
+        writeln( 1 );
+
+        writeln( 1, "/** <p>The namespace of the vocabulary as a string</p>" );
+        writeln( 1, " *  @see #NS */" );
+        writeln( 1, "public static String getURI() {return NS;}" );
+        writeln( 1 );
+
+        writeln( 1, "/** <p>The namespace of the vocabulary as a resource</p> */" );
+        writeln( 1, "public static final Resource NAMESPACE = m_model.createResource( NS );" );
+        writeln( 1 );
+    }
+
+
+    /** Determine what the namespace URI for this vocabulary is */
+    protected String determineNamespaceURI() {
+        // we have a sequence of strategies for determining the ontology namespace
+        String ns = getOptionNamespace();
+        if (ns == null) {
+            ns = getDefaultPrefixNamespace();
+        }
+        if (ns == null) {
+            ns = getOntologyElementNamespace();
+        }
+        if (ns == null) {
+            ns = guessNamespace();
+        }
+
+        // did we get one?
+        if (ns == null) {
+            abort( "Could not determine the base URI for the input vocabulary", null );
+        }
+
+        m_includeURI.add( ns );
+        return ns;
+    }
+
+    /** User has set namespace via a schemagen option */
+    protected String getOptionNamespace() {
+        return m_options.hasNamespaceOption() ? m_options.getNamespaceOption().getURI() : null;
+    }
+
+    /** Document has set an empty prefix for the model */
+    protected String getDefaultPrefixNamespace() {
+        // alternatively, the default namespace may be set in the prefix mapping read from the input document
+        String defaultNS = m_source.getNsPrefixURI( "" );
+        if (defaultNS == null) {
+            defaultNS = m_source.getBaseModel().getNsPrefixURI( "" );
+        }
+
+        return defaultNS;
+    }
+    
+    /** Document has an owl:Ontology or daml:Ontology element */
+    protected String getOntologyElementVersionInfo() {
+        String versionInfo = null;
+        
+        Resource ontologyClass = m_source.getProfile().ONTOLOGY();
+        if (null != ontologyClass) {
+            StmtIterator i = m_source.getBaseModel().listStatements( null, RDF.type, ontologyClass );
+            if (i.hasNext()) {
+                Resource ont = i.nextStatement().getSubject();
+                StmtIterator j = m_source.getBaseModel().listStatements( ont, OWL.versionInfo, (RDFNode)null );
+                if (j.hasNext()) {
+                    versionInfo = j.nextStatement().getObject().asLiteral().getLexicalForm();
+                    
+                    // check for ambiguous answers
+                    if (j.hasNext()) {
+                        System.err.println( "Warning: ambiguous owl:versionInfo - there are more than one owl:versionInfo statements." );
+                        System.err.println( "Picking first choice: " + versionInfo  + ". Other choices are:" );
+                        while (j.hasNext()) {
+                            System.err.print( " " );
+                            System.err.print( j.nextStatement().getObject().toString() );
+                        }
+                        System.err.println();
+                    }
+                }
+                
+                // check for ambiguous answers
+                if (i.hasNext()) {
+                    System.err.println( "Warning: ambiguous owl:versionInfo - there is more than one owl:Ontology element." );
+                    System.err.println( "Picking first choice: " + ont.getURI()  + ". Other choices are:" );
+                    while (i.hasNext()) {
+                        System.err.print( " " );
+                        System.err.print( i.nextStatement().getObject().toString() );
+                    }
+                    System.err.println();
+                }
+            }
+        }
+        
+        return versionInfo;
+    }
+
+    /** Document has an owl:Ontology or daml:Ontology element */
+    protected String getOntologyElementNamespace() {
+        // if we are using an ontology model, we can get the namespace URI from the ontology element
+        String uri = null;
+
+        StmtIterator i = m_source.getBaseModel()
+                                 .listStatements( null, RDF.type, m_source.getProfile().ONTOLOGY() );
+
+        if (i.hasNext()) {
+            Resource ont = i.nextStatement().getSubject();
+            uri = ont.getURI();
+
+            // ensure ends with namespace separator char
+            char ch = uri.charAt( uri.length() - 1 );
+            boolean endsWithNCNameCh = XMLChar.isNCName( ch );
+            uri = endsWithNCNameCh ? uri + "#" : uri;
+
+            // check for ambiguous answers
+            if (i.hasNext()) {
+                System.err.println( "Warning: ambiguous default namespace - there is more than one owl:Ontology element." );
+                System.err.println( "Picking first choice: " + uri  + ". Other choices are:" );
+                while (i.hasNext()) {
+                    System.err.print( " " );
+                    System.err.print( i.nextStatement().getString() );
+                }
+                System.err.println();
+                System.err.println( "Use the -a option to specify a particular namespace if required." );
+            }
+        }
+
+        return uri;
+    }
+
+    /** Guess the URI from the most prevalent URI */
+    protected String guessNamespace() {
+        Map<String,Integer> nsCount = new HashMap<>();
+
+        // count all of the namespaces used in the model
+        for (StmtIterator i = m_source.listStatements(); i.hasNext(); ) {
+            Statement s = i.next();
+            countNamespace( s.getSubject(), nsCount );
+            countNamespace( s.getPredicate(), nsCount );
+            if (s.getObject().isResource()) {
+                countNamespace( s.getResource(), nsCount );
+            }
+        }
+
+        // now find the maximal element
+        String ns = null;
+        int max = 0;
+        for ( String nsKey : nsCount.keySet() )
+        {
+            // we ignore the usual suspects
+            if ( !( OWL.getURI().equals( nsKey ) ||
+                RDF.getURI().equals( nsKey ) ||
+                RDFS.getURI().equals( nsKey ) ||
+                XSD.getURI().equals( nsKey ) ) )
+            {
+                // not an ignorable namespace
+                int count = nsCount.get( nsKey ).intValue();
+
+                if ( count > max )
+                {
+                    // highest count seen so far
+                    max = count;
+                    ns = nsKey;
+                }
+            }
+        }
+
+        return ns;
+    }
+
+    /** Record a use of the given namespace in the count map */
+    private void countNamespace( Resource r, Map<String,Integer> nsCount ) {
+        if (!r.isAnon()) {
+            String ns = r.getNameSpace();
+
+            // increment the count for this namespace
+            Integer count = nsCount.containsKey( ns ) ? (Integer) nsCount.get( ns ) : new Integer( 0 );
+            Integer count1 = new Integer( count.intValue() + 1 );
+
+            nsCount.put( ns, count1 );
+        }
+    }
+
+    /** Write the list of properties */
+    protected void writeProperties() {
+        if (m_options.hasNopropertiesOption()) {
+            return;
+        }
+
+        if (m_options.hasPropertySectionOption()) {
+            writeln( 0, m_options.getPropertySectionOption());
+        }
+
+        if (useOntology()) {
+            writeObjectProperties();
+            writeDatatypeProperties();
+            writeAnnotationProperties();
+
+            // we also write out the RDF properties, to mop up any props that are not stated as
+            // object, datatype or annotation properties
+            writeRDFProperties( true );
+        }
+        else {
+            writeRDFProperties( false );
+        }
+    }
+
+    /** Write any object properties in the vocabulary */
+    protected void writeObjectProperties() {
+        String template = m_options.hasPropTemplateOption() ?  m_options.getPropTemplateOption() : DEFAULT_TEMPLATE;
+
+        if (!m_options.hasLangRdfsOption()) {
+            for (Iterator<? extends RDFNode> i = sorted( m_source.listObjectProperties() ); i.hasNext(); ) {
+                writeValue( (Resource) i.next(), template, "ObjectProperty", "createObjectProperty", "_PROP" );
+            }
+        }
+    }
+
+    /** Write any datatype properties in the vocabulary */
+    protected void writeDatatypeProperties() {
+        String template = m_options.hasPropTemplateOption() ?  m_options.getPropTemplateOption() : DEFAULT_TEMPLATE;
+
+        if (!m_options.hasLangRdfsOption()) {
+            for (Iterator<? extends RDFNode> i = sorted( m_source.listDatatypeProperties() ); i.hasNext(); ) {
+                writeValue( (Resource) i.next(), template, "DatatypeProperty", "createDatatypeProperty", "_PROP" );
+            }
+        }
+    }
+
+    /** Write any annotation properties in the vocabulary */
+    protected void writeAnnotationProperties() {
+        String template = m_options.hasPropTemplateOption() ?  m_options.getPropTemplateOption() : DEFAULT_TEMPLATE;
+
+        if (!m_options.hasLangRdfsOption()) {
+            for (Iterator<? extends RDFNode> i = sorted( m_source.listAnnotationProperties() ); i.hasNext(); ) {
+                writeValue( (Resource) i.next(), template, "AnnotationProperty", "createAnnotationProperty", "_PROP" );
+            }
+        }
+    }
+
+    /** Write any vanilla RDF properties in the vocabulary */
+    protected void writeRDFProperties( boolean useOntProperty ) {
+        String template = m_options.hasPropTemplateOption() ?  m_options.getPropTemplateOption() : DEFAULT_TEMPLATE;
+        String propType = useOntProperty ? "OntProperty" : "Property";
+
+        // select the appropriate properties based on the language choice
+        Resource[] props;
+        if (m_options.hasLangOwlOption()) {
+            props = new Resource[] {OWL.ObjectProperty, OWL.DatatypeProperty, RDF.Property};
+        }
+        else {
+            props = new Resource[] {RDF.Property};
+        }
+
+        // collect the properties to be written
+        List<Resource> propertyResources = new ArrayList<>();
+        for ( Resource prop : props )
+        {
+            for ( StmtIterator i = m_source.listStatements( null, RDF.type, prop ); i.hasNext(); )
+            {
+                propertyResources.add( i.nextStatement().getSubject() );
+            }
+        }
+
+        // now write the properties
+        for (Iterator<? extends RDFNode> i = sorted( propertyResources ); i.hasNext(); ) {
+            writeValue( (Resource) i.next(), template, propType, "create" + propType, "_PROP" );
+        }
+    }
+
+    /** Write any classes in the vocabulary */
+    protected void writeClasses() {
+        if (m_options.hasNoclassesOption()) {
+            return;
+        }
+
+        if (m_options.hasClassSectionOption()) {
+            writeln( 0, m_options.getClassSectionOption());
+        }
+
+        if (useOntology()) {
+            writeOntClasses();
+        }
+        else {
+            writeRDFClasses();
+        }
+    }
+
+    /** Write classes as ontology terms */
+    protected void writeOntClasses() {
+        String template = m_options.hasClassTemplateOption() ?  m_options.getClassTemplateOption() : DEFAULT_TEMPLATE;
+
+        for (Iterator<? extends RDFNode> i = sorted( m_source.listClasses() ); i.hasNext(); ) {
+            writeValue( (Resource) i.next(), template, "OntClass", "createClass", "_CLASS" );
+        }
+    }
+
+    /** Write classes as vanilla RDF terms */
+    protected void writeRDFClasses() {
+        String template = m_options.hasClassTemplateOption() ?  m_options.getClassTemplateOption() : DEFAULT_TEMPLATE;
+
+        // make sure we're looking for the appropriate type of class
+        Resource cls = OWL.Class;
+        if (m_options.hasLangRdfsOption()) {
+            cls = RDFS.Class;
+        }
+
+        // collect the classes to list
+        List<Resource> classes = m_source.listStatements( null, RDF.type, cls ).mapWith( s -> s.getSubject()).toList();
+
+        for (Iterator<? extends RDFNode> i = sorted( classes ); i.hasNext(); ) {
+            writeValue( (Resource) i.next(), template, "Resource", "createResource", "_CLASS" );
+        }
+    }
+
+    /** Write any instances (individuals) in the vocabulary */
+    protected void writeIndividuals() {
+        if (m_options.hasNoindividualsOption()) {
+            return;
+        }
+
+        if (m_options.hasIndividualsSectionOption()) {
+            writeln( 0, m_options.getIndividualsSectionOption() );
+        }
+
+        if (useOntology()) {
+            writeOntIndividuals();
+        }
+        else {
+            writeRDFIndividuals();
+        }
+    }
+
+    /** Write individuals as ontology terms */
+    protected void writeOntIndividuals() {
+        String template = m_options.hasIndividualTemplateOption() ?  m_options.getIndividualTemplateOption() : DEFAULT_INDIVIDUAL_TEMPLATE;
+
+        for (Iterator<? extends RDFNode> i = selectIndividuals(); i.hasNext(); ) {
+            Individual ind = ((Resource) i.next()).as( Individual.class );
+
+            // do we have a local class resource
+            Resource cls = ind.getOntClass();
+            if (cls == null) { cls = OWL.Thing; }
+
+            String varName = m_resourcesToNames.get( cls );
+            String valType = (varName != null) ? varName : "m_model.createClass( \"" + cls.getURI() + "\" )";
+
+            // push the individuals type onto the stack
+            addReplacementPattern( "valtype", valType );
+            writeValue( ind, template, "Individual", "createIndividual", "_INSTANCE" );
+            pop( 1 );
+
+        }
+    }
+
+    /** Write individuals as vanilla RDF terms */
+    protected void writeRDFIndividuals() {
+        String template = m_options.hasIndividualTemplateOption() ?  m_options.getIndividualTemplateOption() : DEFAULT_RDFS_INDIVIDUAL_TEMPLATE;
+
+        for (Iterator<? extends RDFNode> i = selectIndividuals(); i.hasNext(); ) {
+            writeValue( (Resource) i.next(), template, "Resource", "createResource", "_INSTANCE" );
+        }
+    }
+
+    /** Answer an iterator over the individuals selected for output */
+    protected ExtendedIterator<? extends RDFNode> selectIndividuals() {
+        List<Resource> candidates = new ArrayList<>();
+        for (StmtIterator i = m_source.listStatements( null, RDF.type, (RDFNode) null ); i.hasNext(); ) {
+            Statement candidate = i.nextStatement();
+
+            if (candidate.getObject().isResource()) {
+                Resource candObj = candidate.getResource();
+                Resource candSubj = candidate.getSubject();
+
+                // ignore RDFS and OWL builtins
+                if (!candObj.isAnon()) {
+                    String candTypeURI = candObj.getURI();
+                    if (candTypeURI.startsWith( RDF.getURI() ) ||
+                        candTypeURI.startsWith( OWL.getURI() ) ||
+                        candTypeURI.startsWith( RDFS.getURI() )) {
+                        continue;
+                    }
+                }
+
+                // note that whether candSubj is included is tested later on by {@link #filter}
+                if (!candSubj.isAnon() && (isIncluded( candObj ) || isIncluded( candSubj )) && !candidates.contains( candSubj )) {
+                    candidates.add( candSubj );
+                }
+            }
+        }
+
+        return sorted( candidates );
+    }
+
+    /**
+     * Answer true if the given resource is accepted for presentation in the output, which
+     * is true iff it is a URI node, whose namespace is one of the accepted namespaces in
+     * {@link #m_includeURI}.
+     * @param r A resource to test
+     * @return True if the resource is to be included in the generated output
+     */
+    protected boolean isIncluded( Resource r ) {
+        boolean accepted = false;
+
+        if (!r.isAnon()) {
+            String uri = r.getURI();
+            for (Iterator<String> j = m_includeURI.iterator();  !accepted && j.hasNext(); ) {
+                accepted = uri.startsWith( j.next() );
+            }
+        }
+
+        return accepted;
+    }
+    
+    /** Write any datatypes in the vocabulary */
+    protected void writeDatatypes() {
+        if (m_options.hasNodatatypesOption()) {
+            return;
+        }
+
+        if (m_options.hasDatatypesSectionOption()) {
+            writeln( 0, m_options.getDatatypesSectionOption() );
+        }
+        
+        String template = m_options.hasDatatypeTemplateOption() ?  m_options.getDatatypeTemplateOption() : DEFAULT_TEMPLATE;
+        
+        // Cannot create a full RDFDatatype object since we don't know how to parse these custom types, but we can at least specify a Resource
+        for (Iterator<? extends RDFNode> i = selectDatatypes(); i.hasNext(); ) {
+            writeValue( (Resource) i.next(), template, "Resource", "createResource", "_DATATYPE" );
+        }
+    }
+    
+    /** Answer an iterator over the datatypes selected for output */
+    protected ExtendedIterator<? extends RDFNode> selectDatatypes() {
+        List<Resource> candidates = new ArrayList<>();
+        for (StmtIterator i = m_source.listStatements( null, RDF.type, RDFS.Datatype ); i.hasNext(); ) {
+            Statement candidate = i.nextStatement();
+
+            if (candidate.getObject().isResource()) {
+                Resource candSubj = candidate.getSubject();
+
+                // ignore XSD builtins
+                if (!candSubj.isAnon()) {
+                    String candTypeURI = candSubj.getURI();
+                    if (candTypeURI.startsWith( XSD.getURI() )) {
+                        continue;
+                    }
+                }
+
+                // note that whether candSubj is included is tested later on by {@link #filter}
+                if (!candSubj.isAnon() && !candidates.contains( candSubj )) {
+                    candidates.add( candSubj );
+                }
+            }
+        }
+
+        return sorted( candidates );
+    }
+
+    /** Write the value declaration out using the given template, optionally creating comments */
+    protected void writeValue( Resource r, String template, String valueClass, String creator, String disambiguator ) {
+        if (!filter( r )) {
+            if (!noComments()  &&  hasComment( r )) {
+                writeln( 1, formatComment( getComment( r ) ) );
+            }
+
+            // push the local bindings for the substitution onto the stack
+            addReplacementPattern( "valuri", r.getURI() );
+            addReplacementPattern( "valname", getValueName( r, disambiguator ));
+            addReplacementPattern( "valclass", valueClass );
+            addReplacementPattern( "valcreator", creator );
+
+            // write out the value
+            writeln( 1, substitute( template ) );
+            writeln( 1 );
+
+            // pop the local replacements off the stack
+            pop( 4 );
+        }
+    }
+
+    /** Answer true if the given resource has an rdf:comment */
+    protected boolean hasComment( Resource r ) {
+        return r.hasProperty( RDFS.comment ) ;
+    }
+
+    /** Answer all of the commentary on the given resource, as a string */
+    protected String getComment( Resource r ) {
+        StringBuffer comment = new StringBuffer();
+
+        // collect any RDFS or DAML comments attached to the node
+        for (NodeIterator ni = m_source.listObjectsOfProperty( r, RDFS.comment );  ni.hasNext(); ) {
+            RDFNode n = ni.nextNode();
+            if (n instanceof Literal) {
+                comment.append( ((Literal) n).getLexicalForm().trim() );
+            }
+            else {
+                System.err.println( "Warning: Comment on resource <" + r.getURI() + "> is not a literal: " + n );
+            }
+        }
+
+        return comment.toString();
+    }
+
+    /** Format the comment as Javadoc, and limit the line width */
+    protected String formatComment( String comment ) {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "/** <p>" );
+
+        boolean inSpace = false;
+        int pos = buf.length();
+        boolean singleLine = true;
+
+        // now format the comment by compacting whitespace and limiting the line length
+        // add the prefix to the start of each line
+        for (int i = 0;  i < comment.length();  i++ ) {
+            char c = comment.charAt( i );
+
+            // compress whitespace
+            if (Character.isWhitespace( c )) {
+                if (inSpace) {
+                    continue;       // more than one space is ignored
+                }
+                else {
+                    c = ' ';        // map all whitespace to 0x20
+                    inSpace = true;
+                }
+            }
+            else {
+                inSpace = false;
+            }
+
+            // escapes?
+            if (c == '\\') {
+                c = comment.charAt( ++i );
+
+                switch (c) {
+                    case 'n':
+                        buf.append( m_nl );
+                        pos = indentTo( 1, buf );
+                        buf.append( " *  " );
+                        pos += 3;
+                        singleLine = false;
+                        break;
+
+                    default:
+                        // add other escape sequences above
+                        break;
+                }
+            }
+            else if (c == '<') {
+                buf.append( "&lt;" );
+                pos += 4;
+            }
+            else if (c == '>') {
+                buf.append( "&gt;" );
+                pos += 4;
+            }
+            else if (c == '&') {
+                buf.append( "&amp;" );
+                pos += 5;
+            }
+            else {
+                // add the char
+                buf.append( c );
+                pos++;
+            }
+
+            // wrap any very long lines at 120 chars
+            if ((pos > COMMENT_LENGTH_LIMIT) && (inSpace)) {
+                buf.append( m_nl );
+                pos = indentTo( 1, buf );
+                buf.append( " *  " );
+                pos += 3;
+                singleLine = false;
+            }
+        }
+
+        buf.append( "</p>" );
+        buf.append( singleLine ? "" : m_nl );
+        indentTo( singleLine ? 0 : 1, buf );
+        buf.append( " */" );
+        return buf.toString();
+    }
+
+    /** Answer true if resource r <b>does not</b> show in output */
+    protected boolean filter( Resource r ) {
+        if (r.isAnon()) {
+            return true;
+        }
+
+        // if we've already processed this resource once, ignore it next time
+        if (m_resourcesToNames.containsKey( r )) {
+            return true;
+        }
+
+        // search the allowed URI's
+        for ( String uri : m_includeURI )
+        {
+            if ( r.getURI().startsWith( uri ) )
+            {
+                // in
+                return false;
+            }
+        }
+
+        // we allow individuals whose class is not in the included NS's, unless opt strict-individuals is true */
+        if (!m_options.hasStrictIndividualsOption()) {
+            for (StmtIterator j = r.listProperties( RDF.type ); j.hasNext(); ) {
+                // we search the rdf:types of this resource
+                Resource typeRes = j.nextStatement().getResource();
+
+                if (!typeRes.isAnon()) {
+                    String typeURI = typeRes.getURI();
+
+                    // for any type that is in a permitted NS
+                    for ( String uri : m_includeURI )
+                    {
+                        if ( typeURI.startsWith( uri ) )
+                        {
+                            // in
+                            return false;
+                        }
+                    }
+                }
+            }
+        }
+
+        // default is out
+        return true;
+    }
+
+    /** Answer the Java value name for the URI */
+    protected String getValueName( Resource r, String disambiguator ) {
+        // the id name is basically the local name of the resource, possibly in upper case
+        String name = m_options.hasUcNamesOption() ? getUCValueName( r ) : r.getLocalName();
+
+        // must be legal java
+        name = asLegalJavaID( name, false );
+
+        // must not clash with an existing name
+        int attempt = 0;
+        String baseName = name;
+        while (m_usedNames.contains( name )) {
+            name = (attempt == 0) ? (name + disambiguator) : (baseName + disambiguator + attempt);
+            attempt++;
+        }
+
+        // record this name so that we don't use it again (which will stop the vocabulary from compiling)
+        m_usedNames.add( name );
+
+        // record the mapping from resource to name
+        m_resourcesToNames.put( r, name );
+
+        return name;
+    }
+
+    /** Answer the local name of resource r mapped to upper case */
+    protected String getUCValueName( Resource r ) {
+        StringBuffer buf = new StringBuffer();
+        String localName = r.getLocalName();
+        char lastChar = 0;
+
+        for (int i = 0; i < localName.length(); i++) {
+            char c = localName.charAt(i);
+
+            if (Character.isLowerCase(lastChar) && Character.isUpperCase(c)) {
+                buf.append( '_' );
+            }
+            buf.append( Character.toUpperCase(c) );
+            lastChar = c;
+        }
+
+        return buf.toString();
+    }
+
+    /** Answer an iterator that contains the elements of the given list, but sorted by URI */
+    protected ExtendedIterator<? extends RDFNode> sorted( ExtendedIterator<? extends RDFNode> i ) {
+        return sorted( i.toList() );
+    }
+
+    /** Answer an iterator that contains the elements of the given iterator, but sorted by URI */
+    protected ExtendedIterator<? extends RDFNode> sorted( List<? extends RDFNode> members ) {
+        Collections.sort( members, new Comparator<RDFNode>() {
+            @Override
+            public int compare( RDFNode n0, RDFNode n1 ) {
+                if (n0.isLiteral() || n1.isLiteral()) {
+                    if (n0.isLiteral() && n1.isLiteral()) {
+                        // two literals
+                        Literal l0 = (Literal) n0;
+                        Literal l1 = (Literal) n1;
+                        return l0.getLexicalForm().compareTo( l1.getLexicalForm() );
+                    }
+                    else {
+                        return n0.isLiteral() ? -1 : 1;
+                    }
+                }
+                else {
+                    Resource r0 = (Resource) n0;
+                    Resource r1 = (Resource) n1;
+                    if (r0.isAnon() && r1.isAnon()) {
+                        // two anonID's - the order is important as long as its consistent
+                        return r0.getId().toString().compareTo( r1.getId().toString() );
+                    }
+                    else if (r0.isAnon()) {
+                        return -1;
+                    }
+                    else if (r1.isAnon()) {
+                        return 1;
+                    }
+                    else {
+                        // two named resources
+                        return r0.getURI().compareTo( r1.getURI() );
+                    }
+                }
+            }} );
+
+        return WrappedIterator.create( members.iterator() );
+    }
+
+    //==============================================================================
+    // Inner class definitions
+    //==============================================================================
+
+    public interface SchemagenOptions {
+        /* Constants for the various options we can set */
+
+        public enum OPT {
+            /** Select an alternative config file; use <code>-c &lt;filename&gt;</code> on command line */
+            CONFIG_FILE,
+
+            /** Turn off all comment output; use <code>--nocomments</code> on command line;  use <code>sgen:noComments</code> in config file */
+            NO_COMMENTS,
+
+            /** Nominate the URL of the input document; use <code>-i &lt;URL&gt;</code> on command line;  use <code>sgen:input</code> in config file */
+            INPUT,
+
+            /** Specify that the language of the source is DAML+OIL; use <code>--daml</code> on command line;  use <code>sgen:daml</code> in config file */
+            LANG_DAML,
+
+            /** Specify that the language of the source is OWL (the default); use <code>--owl</code> on command line;  use <code>sgen:owl</code> in config file */
+            LANG_OWL,
+
+            /** Specify that the language of the source is RDFS; use <code>--rdfs</code> on command line;  use <code>sgen:rdfs</code> in config file */
+            LANG_RDFS,
+
+            /** Specify that destination file; use <code>-o &lt;fileName&gt;</code> on command line;  use <code>sgen:output</code> in config file */
+            OUTPUT,
+
+            /** Specify the file header; use <code>--header "..."</code> on command line;  use <code>sgen:header</code> in config file */
+            HEADER,
+
+            /** Specify the file footer; use <code>--footer "..."</code> on command line;  use <code>sgen:footer</code> in config file */
+            FOOTER,
+
+            /** Specify the uri of the configuration root node; use <code>--root &lt;URL&gt;</code> on command line */
+            ROOT,
+
+            /** Specify the marker string for substitutions, default is '%'; use <code>-m "..."</code> on command line; use <code>sgen:marker</code> in config file */
+            MARKER,
+
+            /** Specify the packagename; use <code>--package &lt;packagename&gt;</code> on command line; use <code>sgen:package</code> in config file */
+            PACKAGENAME,
+
+            /** Use ontology terms in preference to vanilla RDF; use <code>--ontology</code> on command line; use <code>sgen:ontology</code> in config file */
+            ONTOLOGY,
+
+            /** The name of the generated class; use <code>-n &lt;classname&gt;</code> on command line; use <code>sgen:classname</code> in config file */
+            CLASSNAME,
+
+            /** Additional decoration for class header (such as implements); use <code>--classdec &lt;classname&gt;</code> on command line; use <code>sgen:classdec</code> in config file */
+            CLASSDEC,
+
+            /** The namespace URI for the vocabulary; use <code>-a &lt;uri&gt;</code> on command line; use <code>sgen:namespace</code> in config file */
+            NAMESPACE,
+
+            /** Additional declarations to add at the top of the class; use <code>--declarations &lt;...&gt;</code> on command line; use <code>sgen:declarations</code> in config file */
+            DECLARATIONS,
+
+            /** Section declaration for properties section; use <code>--propSection &lt;...&gt;</code> on command line; use <code>sgen:propSection</code> in config file */
+            PROPERTY_SECTION,
+
+            /** Section declaration for class section; use <code>--classSection &lt;...&gt;</code> on command line; use <code>sgen:classSection</code> in config file */
+            CLASS_SECTION,
+
+            /** Section declaration for individuals section; use <code>--individualsSection &lt;...&gt;</code> on command line; use <code>sgen:individualsSection</code> in config file */
+            INDIVIDUALS_SECTION,
+            
+            /** Section declaration for datatypes section; use <code>--datatypesSection &lt;...&gt;</code> on command line; use <code>sgen:datatypesSection</code> in config file */
+            DATATYPES_SECTION,
+
+            /** Option to suppress properties in vocab file; use <code>--noproperties &lt;...&gt;</code> on command line; use <code>sgen:noproperties</code> in config file */
+            NOPROPERTIES,
+
+            /** Option to suppress classes in vocab file; use <code>--noclasses &lt;...&gt;</code> on command line; use <code>sgen:noclasses</code> in config file */
+            NOCLASSES,
+
+            /** Option to suppress individuals in vocab file; use <code>--noindividuals &lt;...&gt;</code> on command line; use <code>sgen:noindividuals</code> in config file */
+            NOINDIVIDUALS,
+            
+            /** Option to suppress datatypes in vocab file; use <code>--nodatatypes &lt;...&gt;</code> on command line; use <code>sgen:nodatatypes</code> in config file */
+            NODATATYPES,
+
+            /** Option for no file header; use <code>--noheader &lt;...&gt;</code> on command line; use <code>sgen:noheader</code> in config file */
+            NOHEADER,
+
+            /** Template for writing out property declarations; use <code>--propTemplate &lt;...&gt;</code> on command line; use <code>sgen:propTemplate</code> in config file */
+            PROP_TEMPLATE,
+
+            /** Template for writing out class declarations; use <code>--classTemplate &lt;...&gt;</code> on command line; use <code>sgen:classTemplate</code> in config file */
+            CLASS_TEMPLATE,
+
+            /** Template for writing out individual declarations; use <code>--individualTemplate &lt;...&gt;</code> on command line; use <code>sgen:individualTemplate</code> in config file */
+            INDIVIDUAL_TEMPLATE,
+            
+            /** Template for writing out datatype declarations; use <code>--datatypeTemplate &lt;...&gt;</code> on command line; use <code>sgen:datatypeTemplate</code> in config file */
+            DATATYPE_TEMPLATE,
+
+            /** Option for mapping constant names to uppercase; use <code>--uppercase &lt;...&gt;</code> on command line; use <code>sgen:uppercase</code> in config file */
+            UC_NAMES,
+
+            /** Option for including non-local URI's in vocabulary; use <code>--include &lt;uri&gt;</code> on command line; use <code>sgen:include</code> in config file */
+            INCLUDE,
+
+            /** Option for adding a suffix to the generated class name; use <code>--classnamesuffix &lt;uri&gt;</code> on command line; use <code>sgen:classnamesuffix</code> in config file */
+            CLASSNAME_SUFFIX,
+
+            /** Option for the presentation syntax (encoding) of the file; use <code>-e <i>encoding</i></code> on command line; use <code>sgen:encoding</code> in config file */
+            ENCODING,
+
+            /** Option to show the usage message; use --help on command line */
+            HELP,
+
+            /** Option to generate an output file with DOS (\r\n) line endings. Default is Unix line endings. */
+            DOS,
+
+            /** Option to generate to force the model to perform inference, off by default. */
+            USE_INF,
+
+            /** Option to exclude instances of classes in the allowed namespaces, where the individuals themselves are in other namespaces; use <code>--strictIndividuals</code> on command line; use <code>sgen:strictIndividuals</code> in config file */
+            STRICT_INDIVIDUALS,
+
+            /** Option to include the ontology source code in the generated file */
+            INCLUDE_SOURCE,
+
+            /** Option to turn off strict checking in .a() */
+            NO_STRICT
+        }
+
+
+        public static final Object[][] m_optionDefinitions = new Object[][] {
+                {OPT.CONFIG_FILE,         new OptionDefinition( "-c", "configFile" ) },
+                {OPT.ROOT,                new OptionDefinition( "-r", "root" ) },
+                {OPT.NO_COMMENTS,         new OptionDefinition( "--nocomments", "noComments" ) },
+                {OPT.INPUT,               new OptionDefinition( "-i", "input" ) },
+                {OPT.LANG_DAML,           new OptionDefinition( "--daml", "daml" ) },
+                {OPT.LANG_OWL,            new OptionDefinition( "--owl", "owl" ) },
+                {OPT.LANG_RDFS,           new OptionDefinition( "--rdfs", "rdfs" ) },
+                {OPT.OUTPUT,              new OptionDefinition( "-o", "output" ) },
+                {OPT.HEADER,              new OptionDefinition( "--header", "header" ) },
+                {OPT.FOOTER,              new OptionDefinition( "--footer", "footer" ) },
+                {OPT.MARKER,              new OptionDefinition( "--marker", "marker" ) },
+                {OPT.PACKAGENAME,         new OptionDefinition( "--package", "package" ) },
+                {OPT.ONTOLOGY,            new OptionDefinition( "--ontology", "ontology" ) },
+                {OPT.CLASSNAME,           new OptionDefinition( "-n", "classname" ) },
+                {OPT.CLASSDEC,            new OptionDefinition( "--classdec", "classdec" ) },
+                {OPT.NAMESPACE,           new OptionDefinition( "-a", "namespace" ) },
+                {OPT.DECLARATIONS,        new OptionDefinition( "--declarations", "declarations" ) },
+                {OPT.PROPERTY_SECTION,    new OptionDefinition( "--propSection", "propSection" ) },
+                {OPT.CLASS_SECTION,       new OptionDefinition( "--classSection", "classSection" ) },
+                {OPT.INDIVIDUALS_SECTION, new OptionDefinition( "--individualsSection", "individualsSection" ) },
+                {OPT.DATATYPES_SECTION,   new OptionDefinition( "--datatypesSection", "datatypesSection" ) },
+                {OPT.NOPROPERTIES,        new OptionDefinition( "--noproperties", "noproperties" ) },
+                {OPT.NOCLASSES,           new OptionDefinition( "--noclasses", "noclasses" ) },
+                {OPT.NOINDIVIDUALS,       new OptionDefinition( "--noindividuals", "noindividuals" ) },
+                {OPT.NODATATYPES,         new OptionDefinition( "--nodatatypes", "nodatatypes" ) },
+                {OPT.PROP_TEMPLATE,       new OptionDefinition( "--propTemplate", "propTemplate" ) },
+                {OPT.CLASS_TEMPLATE,      new OptionDefinition( "--classTemplate", "classTemplate" ) },
+                {OPT.INDIVIDUAL_TEMPLATE, new OptionDefinition( "--individualTemplate", "individualTemplate" ) },
+                {OPT.DATATYPE_TEMPLATE,   new OptionDefinition( "--datatypeTemplate", "datatypeTemplate" ) },
+                {OPT.UC_NAMES,            new OptionDefinition( "--uppercase", "uppercase" ) },
+                {OPT.INCLUDE,             new OptionDefinition( "--include", "include" ) },
+                {OPT.CLASSNAME_SUFFIX,    new OptionDefinition( "--classnamesuffix", "classnamesuffix" )},
+                {OPT.NOHEADER,            new OptionDefinition( "--noheader", "noheader" )},
+                {OPT.ENCODING,            new OptionDefinition( "-e", "encoding" )},
+                {OPT.HELP,                new OptionDefinition( "--help", "help" )},
+                {OPT.DOS,                 new OptionDefinition( "--dos", "dos" )},
+                {OPT.USE_INF,             new OptionDefinition( "--inference", "inference" )},
+                {OPT.STRICT_INDIVIDUALS,  new OptionDefinition( "--strictIndividuals", "strictIndividuals" )},
+                {OPT.INCLUDE_SOURCE,      new OptionDefinition( "--includeSource", "includeSource" )},
+                {OPT.NO_STRICT,           new OptionDefinition( "--nostrict", "noStrict")},
+            };
+
+        public boolean hasConfigFileOption();
+        public String getConfigFileOption();
+        public boolean hasRootOption();
+        public String getRootOption();
+        public boolean hasNoCommentsOption();
+        public String getNoCommentsOption();
+        public boolean hasInputOption();
+        public Resource getInputOption();
+        public boolean hasLangOwlOption();
+        public String getLangOwlOption();
+        public boolean hasLangRdfsOption();
+        public String getLangRdfsOption();
+        public boolean hasOutputOption();
+        public String getOutputOption();
+        public boolean hasHeaderOption();
+        public String getHeaderOption();
+        public boolean hasFooterOption();
+        public String getFooterOption();
+        public boolean hasMarkerOption();
+        public String getMarkerOption();
+        public boolean hasPackagenameOption();
+        public String getPackagenameOption();
+        public boolean hasOntologyOption();
+        public String getOntologyOption();
+        public boolean hasClassnameOption();
+        public String getClassnameOption();
+        public boolean hasClassdecOption();
+        public String getClassdecOption();
+        public boolean hasNamespaceOption();
+        public Resource getNamespaceOption();
+        public boolean hasDeclarationsOption();
+        public String getDeclarationsOption();
+        public boolean hasPropertySectionOption();
+        public String getPropertySectionOption();
+        public boolean hasClassSectionOption();
+        public String getClassSectionOption();
+        public boolean hasIndividualsSectionOption();
+        public String getIndividualsSectionOption();
+        public boolean hasDatatypesSectionOption();
+        public String getDatatypesSectionOption();
+        public boolean hasNopropertiesOption();
+        public boolean hasNoclassesOption();
+        public boolean hasNoindividualsOption();
+        public boolean hasNodatatypesOption();
+        public boolean hasPropTemplateOption();
+        public String getPropTemplateOption();
+        public boolean hasClassTemplateOption();
+        public String getClassTemplateOption();
+        public boolean hasIndividualTemplateOption();
+        public String getIndividualTemplateOption();
+        public boolean hasDatatypeTemplateOption();
+        public String getDatatypeTemplateOption();
+        public boolean hasUcNamesOption();
+        public boolean hasIncludeOption();
+        public List<String> getIncludeOption();
+        public boolean hasClassnameSuffixOption();
+        public String getClassnameSuffixOption();
+        public boolean hasNoheaderOption();
+        public boolean hasEncodingOption();
+        public String getEncodingOption();
+        public boolean hasHelpOption();
+        public String getHelpOption();
+        public boolean hasDosOption();
+        public boolean hasUseInfOption();
+        public boolean hasStrictIndividualsOption();
+        public boolean hasIncludeSourceOption();
+        public boolean hasNoStrictOption();
+    }
+
+    public static class SchemagenOptionsImpl
+        implements SchemagenOptions
+    {
+        // Instance variables
+        /** The list of command line arguments */
+        private List<String> m_cmdLineArgs = new ArrayList<>();
+
+        /** The root of the options in the config file */
+        private Resource m_root;
+
+        /** The model that contains the configuration information */
+        private Model m_config = ModelFactory.createDefaultModel();
+
+        // Constructor
+
+        public SchemagenOptionsImpl( String[] args ) {
+            m_cmdLineArgs = Arrays.asList( args );
+
+            // check to see if there's a specified config file
+            String configURL = DEFAULT_CONFIG_URI;
+            if (hasConfigFileOption()) {
+                // check for protocol; add file: if not specified
+                configURL = SchemagenUtils.urlCheck( getConfigFileOption() );
+            }
+
+            // try to read the config URI
+            try {
+                FileManager.get().readModel( m_config, configURL );
+            }
+            catch (Exception e) {
+                // if the user left the default config URI in place, it's not an error to fail to read it
+                if (!configURL.equals( DEFAULT_CONFIG_URI )) {
+                    throw new SchemagenException( "Failed to read configuration from URL: " + configURL, e );
+                }
+            }
+
+            // ensure we have a root URI for the configuration model
+            determineConfigRoot();
+        }
+
+        /**
+         * Return the configuration model used to hold config information
+         * @return Model
+         */
+        protected Model getConfigModel() {
+            return m_config;
+        }
+
+        /**
+         * Return the root resource to which configuration information is attached
+         * @return Resource
+         */
+        protected Resource getConfigRoot() {
+            if (m_root == null) {
+                determineConfigRoot();
+            }
+            return m_root;
+        }
+
+        // Internal implementation methods
+
+        /** Determine the root resource in the configuration file */
+        protected void determineConfigRoot() {
+            if (hasValue( OPT.ROOT )) {
+                m_root = m_config.getResource( getStringValue( OPT.ROOT ) );
+            }
+            else {
+                // no specified root, we assume there is only one with type sgen:Config
+                StmtIterator i = m_config.listStatements( null, RDF.type, m_config.getResource( NS + "Config" ) );
+                if (i.hasNext()) {
+                    m_root = i.nextStatement().getSubject();
+                }
+                else {
+                    // no configuration root, so we invent one
+                    m_root = m_config.createResource();
+                }
+            }
+        }
+
+        /** Answer true if the given option is set to true */
+        protected boolean isTrue( OPT option ) {
+            return getOpt( option ).isTrue( m_cmdLineArgs, m_root );
+        }
+
+        /** Answer true if the given option has value */
+        protected boolean hasValue( OPT option ) {
+            return getOpt( option ).hasValue( m_cmdLineArgs, m_root );
+        }
+
+        /** Answer the value of the option or null */
+        protected RDFNode getValue( OPT option ) {
+            return getOpt( option ).getValue( m_cmdLineArgs, m_root );
+        }
+
+        /** Answer the String value of the option or null */
+        protected String getStringValue( OPT option ) {
+            return getOpt( option ).getStringValue( m_cmdLineArgs, m_root );
+        }
+
+        /** Answer true if the given option has a resource value */
+        protected boolean hasResourceValue( OPT option ) {
+            return getOpt( option ).hasResourceValue( m_cmdLineArgs, m_root );
+        }
+
+        /** Answer the value of the option or null */
+        protected Resource getResource( OPT option ) {
+            return getOpt( option ).getResource( m_cmdLineArgs, m_root );
+        }
+
+        /** Answer all values for the given options as Strings */
+        protected List<String> getAllValues( OPT option ) {
+            List<String> values = new ArrayList<>();
+            OptionDefinition opt = getOpt( option );
+
+            // look in the command line arguments
+            for (Iterator<String> i = m_cmdLineArgs.iterator(); i.hasNext(); ) {
+                String s = i.next();
+                if (s.equals( opt.m_cmdLineForm )) {
+                    // next iterator value is the arg value
+                    values.add( i.next() );
+                }
+            }
+
+            // now look in the config file
+            for (StmtIterator i = m_root.listProperties( opt.m_prop ); i.hasNext(); ) {
+                Statement s = i.nextStatement();
+
+                if (s.getObject() instanceof Literal) {
+                    values.add( s.getString() );
+                }
+                else {
+                    values.add( s.getResource().getURI() );
+                }
+            }
+
+            return values;
+        }
+
+        /** Answer the option object for the given option */
+        protected OptionDefinition getOpt( OPT option ) {
+            for ( Object[] m_optionDefinition : m_optionDefinitions )
+            {
+                if ( m_optionDefinition[0] == option )
+                {
+                    return (OptionDefinition) m_optionDefinition[1];
+                }
+            }
+
+            return null;
+        }
+
+        // External interface methods
+
+        @Override
+        public boolean hasConfigFileOption() { return hasValue( OPT.CONFIG_FILE ); }
+        @Override
+        public String getConfigFileOption() { return getStringValue( OPT.CONFIG_FILE ); }
+        @Override
+        public boolean hasRootOption() { return hasValue( OPT.ROOT ); }
+        @Override
+        public String getRootOption() { return getStringValue( OPT.ROOT ); }
+        @Override
+        public boolean hasNoCommentsOption() { return isTrue( OPT.NO_COMMENTS ); }
+        @Override
+        public String getNoCommentsOption() { return getStringValue( OPT.NO_COMMENTS ); }
+        @Override
+        public boolean hasInputOption() { return hasValue( OPT.INPUT ); }
+        @Override
+        public Resource getInputOption() { return getResource( OPT.INPUT ); }
+        @Override
+        public boolean hasLangOwlOption() { return isTrue( OPT.LANG_OWL ); }
+        @Override
+        public String getLangOwlOption() { return getStringValue( OPT.LANG_OWL ); }
+        @Override
+        public boolean hasLangRdfsOption() { return isTrue( OPT.LANG_RDFS ); }
+        @Override
+        public String getLangRdfsOption() { return getStringValue( OPT.LANG_RDFS ); }
+        @Override
+        public boolean hasOutputOption() { return hasValue( OPT.OUTPUT ); }
+        @Override
+        public String getOutputOption() { return getStringValue( OPT.OUTPUT ); }
+        @Override
+        public boolean hasHeaderOption() { return isTrue( OPT.HEADER ); }
+        @Override
+        public String getHeaderOption() { return getStringValue( OPT.HEADER ); }
+        @Override
+        public boolean hasFooterOption() { return isTrue( OPT.FOOTER ); }
+        @Override
+        public String getFooterOption() { return getStringValue( OPT.FOOTER ); }
+        @Override
+        public boolean hasMarkerOption() { return hasValue( OPT.MARKER ); }
+        @Override
+        public String getMarkerOption() { return getStringValue( OPT.MARKER ); }
+        @Override
+        public boolean hasPackagenameOption() { return hasValue( OPT.PACKAGENAME ); }
+        @Override
+        public String getPackagenameOption() { return getStringValue( OPT.PACKAGENAME ); }
+        @Override
+        public boolean hasOntologyOption() { return isTrue( OPT.ONTOLOGY ); }
+        @Override
+        public String getOntologyOption() { return getStringValue( OPT.ONTOLOGY ); }
+        @Override
+        public boolean hasClassnameOption() { return hasValue( OPT.CLASSNAME ); }
+        @Override
+        public String getClassnameOption() { return getStringValue( OPT.CLASSNAME ); }
+        @Override
+        public boolean hasClassdecOption() { return hasValue( OPT.CLASSDEC ); }
+        @Override
+        public String getClassdecOption() { return getStringValue( OPT.CLASSDEC ); }
+        @Override
+        public boolean hasNamespaceOption() { return hasValue( OPT.NAMESPACE ); }
+        @Override
+        public Resource getNamespaceOption() { return getResource( OPT.NAMESPACE ); }
+        @Override
+        public boolean hasDeclarationsOption() { return hasValue( OPT.DECLARATIONS ); }
+        @Override
+        public String getDeclarationsOption() { return getStringValue( OPT.DECLARATIONS ); }
+        @Override
+        public boolean hasPropertySectionOption() { return hasValue( OPT.PROPERTY_SECTION ); }
+        @Override
+        public String getPropertySectionOption() { return getStringValue( OPT.PROPERTY_SECTION ); }
+        @Override
+        public boolean hasClassSectionOption() { return hasValue( OPT.CLASS_SECTION ); }
+        @Override
+        public String getClassSectionOption() { return getStringValue( OPT.CLASS_SECTION ); }
+        @Override
+        public boolean hasIndividualsSectionOption() { return hasValue( OPT.INDIVIDUALS_SECTION ); }
+        @Override
+        public String getIndividualsSectionOption() { return getStringValue( OPT.INDIVIDUALS_SECTION ); }
+        @Override
+        public boolean hasDatatypesSectionOption() { return hasValue( OPT.DATATYPES_SECTION ); }
+        @Override
+        public String getDatatypesSectionOption() { return getStringValue( OPT.DATATYPES_SECTION ); }
+        @Override
+        public boolean hasNopropertiesOption() { return isTrue( OPT.NOPROPERTIES ); }
+        @Override
+        public boolean hasNoclassesOption() { return isTrue( OPT.NOCLASSES ); }
+        @Override
+        public boolean hasNoindividualsOption() { return isTrue( OPT.NOINDIVIDUALS ); }
+        @Override
+        public boolean hasNodatatypesOption() { return isTrue( OPT.NODATATYPES ); }
+        @Override
+        public boolean hasPropTemplateOption() { return hasValue( OPT.PROP_TEMPLATE ); }
+        @Override
+        public String getPropTemplateOption() { return getStringValue( OPT.PROP_TEMPLATE ); }
+        @Override
+        public boolean hasClassTemplateOption() { return hasValue( OPT.CLASS_TEMPLATE ); }
+        @Override
+        public String getClassTemplateOption() { return getStringValue( OPT.CLASS_TEMPLATE ); }
+        @Override
+        public boolean hasIndividualTemplateOption() { return hasValue( OPT.INDIVIDUAL_TEMPLATE ); }
+        @Override
+        public String getIndividualTemplateOption() { return getStringValue( OPT.INDIVIDUAL_TEMPLATE ); }
+        @Override
+        public boolean hasDatatypeTemplateOption() { return hasValue( OPT.DATATYPE_TEMPLATE ); }
+        @Override
+        public String getDatatypeTemplateOption() { return getStringValue( OPT.DATATYPE_TEMPLATE ); }
+        @Override
+        public boolean hasUcNamesOption() { return isTrue( OPT.UC_NAMES ); }
+        @Override
+        public boolean hasIncludeOption() { return hasValue( OPT.INCLUDE ); }
+        @Override
+        public List<String> getIncludeOption() { return getAllValues( OPT.INCLUDE ); }
+        @Override
+        public boolean hasClassnameSuffixOption() { return hasValue( OPT.CLASSNAME_SUFFIX ); }
+        @Override
+        public String getClassnameSuffixOption() { return getStringValue( OPT.CLASSNAME_SUFFIX ); }
+        @Override
+        public boolean hasNoheaderOption() { return isTrue( OPT.NOHEADER ); }
+        @Override
+        public boolean hasEncodingOption() { return hasValue( OPT.ENCODING ); }
+        @Override
+        public String getEncodingOption() { return getStringValue( OPT.ENCODING ); }
+        @Override
+        public boolean hasHelpOption() { return hasValue( OPT.HELP ); }
+        @Override
+        public String getHelpOption() { return getStringValue( OPT.HELP ); }
+        @Override
+        public boolean hasDosOption() { return isTrue( OPT.DOS ); }
+        @Override
+        public boolean hasUseInfOption() { return isTrue( OPT.USE_INF ); }
+        @Override
+        public boolean hasStrictIndividualsOption() { return isTrue( OPT.STRICT_INDIVIDUALS ); }
+        @Override
+        public boolean hasIncludeSourceOption() { return isTrue( OPT.INCLUDE_SOURCE ); }
+        @Override
+        public boolean hasNoStrictOption() { return isTrue( OPT.NO_STRICT ); }
+    }
+
+    /** An option that can be set either on the command line or in the RDF config */
+    public static class OptionDefinition
+    {
+        protected String m_cmdLineForm;
+        protected Property m_prop;
+
+        protected OptionDefinition( String cmdLineForm, String name ) {
+            m_cmdLineForm = cmdLineForm;
+            if (name != null) {
+                m_prop = ResourceFactory.createProperty( NS, name );
+            }
+        }
+
+        /**
+         * Return the RDF property that is used when configuring this option
+         * via a {@link Model}
+         * @return The declaration property, or null
+         */
+        public Property getDeclarationProperty() {
+            return m_prop;
+        }
+
+        /**
+         * Return the command line form of this option
+         * @return The command line form as a String
+         */
+        public String getCommandLineForm() {
+            return m_cmdLineForm;
+        }
+
+        /**
+         * Answer true if this option is set to true, either on the command line
+         * or in the config model
+         *
+         * @return boolean
+         */
+        protected boolean isTrue( List<String> cmdLineArgs, Resource confRoot ) {
+            if (cmdLineArgs.contains( m_cmdLineForm )) {
+                return true;
+            }
+
+            if (confRoot.hasProperty( m_prop )) {
+                return confRoot.getRequiredProperty( m_prop ).getBoolean();
+            }
+
+            return false;
+        }
+
+        /**
+         * Answer the string value of the parameter if set, or null otherwise. Note command line
+         * has precedence.
+         *
+         * @return String
+         */
+        protected String getStringValue( List<String> cmdLineArgs, Resource confRoot ) {
+            RDFNode n = getValue( cmdLineArgs, confRoot );
+            return (n == null) ? null : (n.isLiteral() ? n.asLiteral().getLexicalForm() : n.toString() );
+        }
+
+        /**
+         * Return the value of the parameter if set, or null otherwise. Note command line
+         * has precedence.
+         *
+         * @return The argument value as an RDFNode
+         */
+        protected RDFNode getValue( List<String> cmdLineArgs, Resource confRoot ) {
+            int index = cmdLineArgs.indexOf( m_cmdLineForm );
+
+            if (index >= 0) {
+                try {
+                    return ResourceFactory.createPlainLiteral( cmdLineArgs.get( index + 1 ) );
+                }
+                catch (IndexOutOfBoundsException e) {
+                    throw new SchemagenException( "Value for parameter " + m_cmdLineForm  + " not set! Aborting.", e );
+                }
+            }
+
+            if (m_prop != null && confRoot != null  &&  confRoot.hasProperty( m_prop )) {
+                return confRoot.getRequiredProperty( m_prop ).getObject();
+            }
+
+            // not set
+            return null;
+        }
+
+        /**
+         * Answer true if the parameter has a value at all.
+         *
+         * @return boolean
+         */
+        protected boolean hasValue( List<String> cmdLineArgs, Resource confRoot ) {
+            return getValue( cmdLineArgs, confRoot ) != null;
+        }
+
+
+        /**
+         * Answer the resource value of the parameter if set, or null otherwise.
+         *
+         * @return String
+         */
+        protected Resource getResource( List<String> cmdLineArgs, Resource confRoot ) {
+            int index = cmdLineArgs.indexOf( m_cmdLineForm );
+
+            if (index >= 0) {
+                try {
+                    return confRoot.getModel().getResource( cmdLineArgs.get( index + 1 ) );
+                }
+                catch (IndexOutOfBoundsException e) {
+                    System.err.println( "Value for parameter " + m_cmdLineForm  + " not set! Aborting.");
+                }
+            }
+
+            if (m_prop != null  &&  confRoot.hasProperty( m_prop )) {
+                return confRoot.getRequiredProperty( m_prop ).getResource();
+            }
+
+            // not set
+            return null;
+        }
+
+        /**
+         * Answer true if the parameter has a value at all.
+         *
+         * @return boolean
+         */
+        protected boolean hasResourceValue( List<String> cmdLineArgs, Resource confRoot ) {
+            return getResource( cmdLineArgs, confRoot ) != null;
+        }
+    }  // end inner class OptionDefinition
+
+
+    /** A pairing of pattern and substitution we want to apply to output */
+    protected class Replacement
+    {
+        protected String sub;
+        protected Pattern pattern;
+
+        protected Replacement( Pattern pattern, String sub) {
+            this.sub = sub;
+            this.pattern = pattern;
+        }
+    } // end inner class Replacement
+
+    /**
+     * <p>Schemagen runtime exception</p>
+     */
+    public static class SchemagenException
+        extends RuntimeException
+    {
+        public SchemagenException( String msg, Throwable cause ) {
+            super( msg, cause );
+        }
+    }
+
+    /** Utility method container */
+    public static class SchemagenUtils
+    {
+        /** Return a URI formed from the given string, unchanged if it's already a URI or
+         *  converted to a file URI otherwise.  If not recognisable as a URL, abort.
+         */
+        public static String urlCheck( String uriOrFile ) {
+            boolean legal = true;
+            String url = uriOrFile;
+
+            // is it a URI already?  to check, we make a URL and see what happens!
+            try {
+                new URL( url );
+            }
+            catch (MalformedURLException ignore) {
+                legal = false;
+            }
+
+            // if not a legal url, assume it's a file
+            if (!legal) {
+                legal = true;
+                String slash = System.getProperty( "file.separator" );
+                url = "file:" + (uriOrFile.startsWith( slash ) ? (slash + slash) : "") + uriOrFile;
+
+                try {
+                    new URL( url );
+                }
+                catch (MalformedURLException ignore) {
+                    legal = false;
+                }
+            }
+
+            if (!legal) {
+                throw new SchemagenException( "Could not parse " + uriOrFile + " as a legal URL or a file reference. Aborting.", null );
+            }
+
+            return url;
+        }
+    } /* End class SchemagenUtils */
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/sparql.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/sparql.java b/jena-cmds/src/main/java/jena/sparql.java
new file mode 100644
index 0000000..37c7839
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/sparql.java
@@ -0,0 +1,25 @@
+/*
+ * 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 jena;
+
+public class sparql {
+    public static void main(String[] args) {
+        arq.sparql.main(args);
+    }
+}


[13/20] jena git commit: JENA-1108 : jena-cmds module

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/cmd/CmdGeneral.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/CmdGeneral.java b/jena-cmds/src/main/java/jena/cmd/CmdGeneral.java
new file mode 100644
index 0000000..fc04397
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/CmdGeneral.java
@@ -0,0 +1,92 @@
+/*
+ * 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 jena.cmd;
+
+import java.io.PrintStream ;
+
+import org.apache.jena.atlas.io.IndentedWriter ;
+import jena.cmd.ArgModuleGeneral;
+import jena.cmd.CmdArgModule;
+import jena.cmd.ModGeneral;
+
+// Added usage + some common flags
+// This is the usual starting point for any sub 
+
+public abstract class CmdGeneral extends CmdArgModule
+{
+    protected ModGeneral modGeneral = new ModGeneral(this::printHelp) ;
+    protected ModVersion modVersion = new ModVersion(true) ;
+    
+    // Could be turned into a module but these are convenient as inherited flags
+    
+    protected CmdGeneral(String[] argv)
+    {
+        super(argv) ;
+        addModule(modGeneral) ;
+        addModule(modVersion) ;
+    }
+
+    @Override
+    public void addModule(ArgModuleGeneral argModule)
+    {
+        super.addModule(argModule) ;
+        argModule.registerWith(this) ;
+    }
+    
+    protected boolean isVerbose() { return modGeneral.verbose ; }
+    protected boolean isQuiet()   { return modGeneral.quiet ; }
+    protected boolean isDebug()   { return modGeneral.debug ; }
+    protected boolean help()      { return modGeneral.help ; }
+
+    final public void printHelp()
+    {
+        usage() ;
+        throw new TerminationException(0) ;
+    }
+
+    @Override
+    protected void processModulesAndArgs()
+    { 
+        if ( modVersion.getVersionFlag() )
+            modVersion.printVersionAndExit() ;
+    }
+    
+    private Usage usage = new Usage() ; 
+    
+    protected String cmdName = null ;
+
+    protected abstract String getSummary() ;
+
+    public void usage() { usage(System.err) ; }
+
+    public void usage(PrintStream pStr)
+    {
+        IndentedWriter out = new IndentedWriter(pStr) ;
+        out.println(getSummary()) ;
+        usage.output(out) ;
+    }
+    
+    public void add(ArgDecl argDecl, String argName, String msg)
+    {
+        add(argDecl) ;
+        getUsage().addUsage(argName, msg) ;
+    }
+
+    public Usage getUsage() { return usage ; }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/cmd/CmdLineArgs.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/CmdLineArgs.java b/jena-cmds/src/main/java/jena/cmd/CmdLineArgs.java
new file mode 100644
index 0000000..2ba515c
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/CmdLineArgs.java
@@ -0,0 +1,413 @@
+/*
+ * 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 jena.cmd;
+
+import static java.nio.file.Files.readAllBytes;
+
+import java.io.IOException;
+import java.nio.file.Paths;
+import java.util.ArrayList ;
+import java.util.Arrays ;
+import java.util.Collections ;
+import java.util.HashMap ;
+import java.util.Iterator ;
+import java.util.List ;
+import java.util.Map ;
+
+import org.apache.jena.atlas.logging.Log ;
+
+/**
+ * Command line, using the common named/positional arguments paradigm
+ * (also called options/arguments).
+ */
+public class CmdLineArgs extends CommandLineBase {
+    public CmdLineArgs(String[] args) {
+        super(args) ;
+    }
+
+    private boolean processedArgs = false ;
+    protected Map<String, ArgDecl> argMap = new HashMap<>() ;          // Map from string name to ArgDecl
+    protected Map<String, Arg> args = new HashMap<>() ;            // Name to Arg
+    protected List<String> positionals = new ArrayList<>() ;  // Positional arguments as strings.
+    
+    public void process() throws IllegalArgumentException
+    {
+        processedArgs = true ;
+        apply(new ArgProcessor()) ;
+    }
+    
+    // ---- Setting the ArgDecls
+
+    /** Add an argument to those to be accepted on the command line.
+     * @param argName Name
+     * @param hasValue True if the command takes a (string) value
+     * @return The CommandLine processor object
+     */
+
+    public CmdLineArgs add(String argName, boolean hasValue) {
+        return add(new ArgDecl(hasValue, argName)) ;
+    }
+
+    /** Add an argument to those to be accepted on the command line.
+     *  Argument order reflects ArgDecl.
+     * @param hasValue True if the command takes a (string) value
+     * @param argName Name
+     * @return The CommandLine processor object
+     */
+   
+    public CmdLineArgs add(boolean hasValue, String argName) {
+        return add(new ArgDecl(hasValue, argName)) ;
+    }
+
+    /** Add an argument object
+     * @param arg Argument to add
+     * @return The CommandLine processor object
+     */
+   
+    public CmdLineArgs add(ArgDecl arg) {
+        for (Iterator<String> iter = arg.names(); iter.hasNext();) {
+            String name = iter.next() ;
+            if ( argMap.containsKey(name) )
+                Log.warn(this, "Argument '" + name + "' already added") ;
+            argMap.put(name, arg) ;
+        }
+        return this ;
+    }
+    
+    /**
+     * Add a positional parameter
+     * @param value
+     * @return this object
+     */
+    public CmdLineArgs addPositional(String value) {
+        positionals.add(value) ;
+        return this ;
+    }
+    
+    /**
+     * Add a named argument which has no value.
+     * @param name
+     * @return this
+     */
+    public CmdLineArgs addArg(String name) {
+        return addArg(name, null) ;
+    }
+
+    /**
+     * Add a named argument/value pair
+     * @param name
+     * @param value
+     * @return this object
+     */
+    public CmdLineArgs addArg(String name, String value) {
+        if ( !args.containsKey(name) )
+            args.put(name, new Arg(name)) ;
+        Arg arg = args.get(name) ;
+        return addArgWorker(arg, value) ;
+    }
+
+    private CmdLineArgs addArgWorker(Arg arg, String value) {
+        ArgDecl argDecl = argMap.get(arg.getName()) ;
+
+        if ( !argDecl.takesValue() && value != null )
+            throw new IllegalArgumentException("No value for argument: " + arg.getName()) ;
+
+        if ( argDecl.takesValue() ) {
+            if ( value == null )
+                throw new IllegalArgumentException("No value for argument: " + arg.getName()) ;
+
+            arg.setValue(value) ;
+            arg.addValue(value) ;
+        }
+
+        return this ;
+    }
+
+    // ---- Indirection
+
+    static final String DefaultIndirectMarker = "@" ;
+    
+    public boolean matchesIndirect(String s) { return matchesIndirect(s, DefaultIndirectMarker) ; }
+    public boolean matchesIndirect(String s, String marker) { return s.startsWith(marker) ; }
+    
+    public String indirect(String s) { return indirect(s, DefaultIndirectMarker) ; }
+    
+    public String indirect(String s, String marker) {
+        if ( !matchesIndirect(s, marker) )
+            return s ;
+        s = s.substring(marker.length()) ;
+        try {
+			return new String(readAllBytes(Paths.get(s)));
+		} catch (IOException e) {
+			throw new CmdException("Could not read from: " + s, e);
+		}
+    }
+
+    // ---- Argument access
+    
+    /** Test whether an argument was seen. */
+
+    public boolean contains(ArgDecl argDecl)    { return getArg(argDecl) != null ; }
+    
+    /** Test whether an argument was seen. */
+
+    public boolean contains(String s)           { return getArg(s) != null ; }
+    
+    /** Test whether an argument was seen more than once */ 
+    public boolean containsMultiple(String s)   { return getValues(s).size() > 1 ; }
+    
+    /** Test whether an argument was seen more than once */ 
+    public boolean containsMultiple(ArgDecl argDecl) { return getValues(argDecl).size() > 1 ; }
+    
+    public boolean hasArgs() { return args.size() > 0 ; }
+    
+    /** Test whether the command line had a particular argument
+     * 
+     * @param argName
+     * @return this object
+     */
+    public boolean hasArg(String argName) { return getArg(argName) != null ; }
+
+    /** Test whether the command line had a particular argument
+     * 
+     * @param argDecl
+     * @return true or false
+     */
+    
+    public boolean hasArg(ArgDecl argDecl) { return getArg(argDecl) != null ; }
+
+    
+    /** Get the argument associated with the argument declaration.
+     *  Actually returns the LAST one seen
+     *  @param argDecl Argument declaration to find
+     *  @return Last argument that matched.
+     */
+    
+    public Arg getArg(ArgDecl argDecl) {
+        Arg arg = null ;
+        for ( Arg a : args.values() )
+        {
+            if ( argDecl.matches( a ) )
+            {
+                arg = a;
+            }
+        }
+        return arg ;
+    }
+    
+    /** Get the argument associated with the argument name.
+     *  Actually returns the LAST one seen
+     *  @param argName Argument name
+     *  @return Last argument that matched.
+     */
+    public Arg getArg(String argName) {
+        argName = ArgDecl.canonicalForm(argName) ;
+        return args.get(argName) ;
+    }
+    
+    /**
+     * Returns the value (a string) for an argument with a value - 
+     * returns null for no argument and no value.  
+     * @param argDecl
+     * @return String
+     */
+    public String getValue(ArgDecl argDecl) {
+        Arg arg = getArg(argDecl) ;
+        if ( arg == null )
+            return null ;
+        if ( arg.hasValue() )
+            return arg.getValue() ;
+        return null ;
+    }
+
+    /**
+     * Returns the value (a string) for an argument with a value - 
+     * returns null for no argument and no value.  
+     * @param argName
+     * @return String
+     */
+    public String getValue(String argName) {
+        Arg arg = getArg(argName) ;
+        if ( arg == null )
+            return null ;
+        return arg.getValue() ;
+    }
+    
+    /** Is the value something that looks like "true" or "yes"? */
+    public boolean hasValueOfTrue(ArgDecl argDecl) {
+        String x = getValue(argDecl) ;
+        if ( x == null )
+            return false ;
+        if ( x.equalsIgnoreCase("true") || x.equalsIgnoreCase("t") ||
+             x.equalsIgnoreCase("yes")  || x.equalsIgnoreCase("y") )
+            return true ;
+        return false ;
+    }
+
+    /** Is the value something that looks like "false" or "no"? */
+    public boolean hasValueOfFalse(ArgDecl argDecl) {
+        String x = getValue(argDecl) ;
+        if ( x == null )
+            return false ;
+        if ( x.equalsIgnoreCase("false") || x.equalsIgnoreCase("f") ||
+             x.equalsIgnoreCase("no") || x.equalsIgnoreCase("n") )
+            return true ;
+        return false ;
+    }
+    
+    /**
+     * Returns all the values (0 or more strings) for an argument. 
+     * @param argDecl
+     * @return List
+     */
+    public List<String> getValues(ArgDecl argDecl) {
+        Arg arg = getArg(argDecl) ;
+        if ( arg == null )
+            return new ArrayList<>() ;
+        return arg.getValues() ;
+    }
+
+    /**
+     * Returns all the values (0 or more strings) for an argument. 
+     * @param argName
+     * @return List
+     */
+    public List<String> getValues(String argName) {
+        Arg arg = getArg(argName) ;
+        if ( arg == null )
+            return new ArrayList<>() ;
+        return arg.getValues() ;
+    }
+    
+   // ---- Positional 
+    /** Get the i'th positional argument (indexed from 0)*/
+    public String getPositionalArg(int i) {
+        return positionals.get(i) ;
+    }
+
+    /** Return the number of positional arguments */  
+    public int getNumPositional() {
+        return positionals.size() ;
+    }
+
+    public boolean hasPositional() {
+        return positionals.size() > 0 ;
+    }
+
+    public List<String> getPositional() {
+        return positionals ;
+    }
+
+    /** Return the positional arguments or "-" to indicate stdin */
+    public List<String> getPositionalOrStdin() {
+        if ( !positionals.isEmpty() )
+            return Collections.unmodifiableList(positionals) ;
+        List<String> x = Arrays.asList("-") ;
+        return Collections.unmodifiableList(x) ;
+    }
+    
+    // ----
+    
+    /**
+     * Handle an unrecognised argument; default is to throw an exception
+     * @param argStr The string image of the unrecognised argument
+     */
+    protected void handleUnrecognizedArg( String argStr ) {
+        throw new CmdException("Unknown argument: "+argStr) ;
+    }
+    
+    @Override
+    public String toString() {
+        if ( !processedArgs )
+            return super.toString() ;
+        String str = "" ;
+        String sep = "" ;
+        for ( String k : args.keySet() )
+        {
+            Arg a = args.get( k );
+            str = str + sep + a;
+            sep = " ";
+        }
+        sep = " -- " ;
+        for ( String v : positionals )
+        {
+            str = str + sep + v;
+            sep = " ";
+        }
+        return str ;
+    }
+
+    // ---- Process arguments after low level parsing and after ArgDecls added.
+    class ArgProcessor implements ArgProc {
+        boolean nextArgProcessed      = false ;
+        boolean positionalArgsStarted = false ;
+
+        @Override
+        public void startArgs() {
+            nextArgProcessed = false ;
+            positionalArgsStarted = false ;
+        }
+
+        @Override
+        public void finishArgs() {}
+
+        @Override
+        public void arg(String argStr, int i) {
+            if ( nextArgProcessed ) {
+                nextArgProcessed = false ;
+                return ;
+            }
+
+            if ( positionalArgsStarted ) {
+                addPositional(argStr) ;
+                return ;
+            }
+
+            if ( argStr.equals("-") || argStr.equals("--") ) {
+                positionalArgsStarted = true ;
+                return ;
+            }
+
+            if ( !argStr.startsWith("-") ) {
+                // End of flags, start of positional arguments
+                positionalArgsStarted = true ;
+                addPositional(argStr) ;
+                return ;
+            }
+
+            argStr = ArgDecl.canonicalForm(argStr) ;
+            if ( !argMap.containsKey(argStr) ) {
+                handleUnrecognizedArg(argStr) ;
+                return ;
+            }
+
+            // Recognized flag
+            ArgDecl argDecl = argMap.get(argStr) ;
+
+            if ( argDecl.takesValue() ) {
+                String val = getArg(i + 1) ;
+                // Use first name as the canonical one.
+                String x = argDecl.getKeyName() ;
+                addArg(x, val) ;
+                nextArgProcessed = true ;
+            } else
+                addArg(argStr) ;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/cmd/CmdMain.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/CmdMain.java b/jena-cmds/src/main/java/jena/cmd/CmdMain.java
new file mode 100644
index 0000000..3caca21
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/CmdMain.java
@@ -0,0 +1,108 @@
+/*
+ * 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 jena.cmd;
+
+import org.apache.jena.atlas.logging.LogCtl ;
+
+/** Adds main()-like methods
+ * 
+ * Usage:
+ *    new YourCommand(args).mainAndExit()
+ *  which never returns and routes thing to System.exit.
+ *  or call
+ *     new YourCommand(args).mainMethod()
+ *  which should not call System.exit anywhere */
+
+public abstract class CmdMain extends CmdLineArgs
+{
+    // Do this very early so it happens before anything else
+    // gets a chance to create a logger.
+    static { LogCtl.setCmdLogging() ; }
+    
+    public CmdMain(String[] args)
+    {
+        super(args) ;
+    }
+
+    /** Run command - exit on failure */
+    public void mainRun()
+    { mainRun(false, true) ; }
+    
+    /** Run command - choose whether to exit on failure */
+    public void mainRun(boolean exitOnFailure)
+    { mainRun(exitOnFailure, true) ; }
+    
+    /** Run command - exit on success or failure */
+    public void mainAndExit()
+    { mainRun(true, true) ; }
+     
+    /** Run command */
+    public int mainRun(boolean exitOnSuccess, boolean exitOnFailure)
+    {
+        try { mainMethod() ; }
+        catch (TerminationException ex) { System.exit(ex.getCode()) ; }
+        catch (IllegalArgumentException ex)
+        {
+            ex.printStackTrace(System.err) ;
+            //System.err.println(ex.getMessage()) ;
+            if ( exitOnFailure ) System.exit(1) ;
+            return 1 ; 
+        }
+        catch (CmdException ex)
+        {
+            if ( ex.getMessage() != null && ex.getMessage().length() > 0 )
+                System.err.println(ex.getMessage()) ;
+            //ex.printStackTrace() ;
+            
+            if ( ex.getCause() != null )
+                ex.getCause().printStackTrace(System.err) ;
+            
+            if ( exitOnFailure ) System.exit(1) ;
+            return 1 ;
+        }
+        catch (Exception ex)
+        {
+            ex.printStackTrace(System.err) ;
+            if ( exitOnFailure ) System.exit(2) ;
+            return 2 ;
+        }
+        if ( exitOnSuccess ) 
+            System.exit(0) ;
+        return 0 ;
+    }
+
+    protected final void mainMethod()
+    {
+        process() ;
+        exec() ;
+    }
+    
+    protected abstract void exec() ;
+    
+    protected abstract String getCommandName() ;
+    
+    public void cmdError(String msg) { cmdError(msg, true) ;}
+    
+    public void cmdError(String msg, boolean exit)
+    {
+        System.err.println(msg) ;
+        if ( exit )
+            throw new TerminationException(5) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/cmd/CommandLineBase.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/CommandLineBase.java b/jena-cmds/src/main/java/jena/cmd/CommandLineBase.java
new file mode 100644
index 0000000..def345e
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/CommandLineBase.java
@@ -0,0 +1,136 @@
+/*
+ * 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 jena.cmd;
+
+import static java.util.stream.IntStream.range;
+
+import java.util.ArrayList ;
+import java.util.List ;
+
+/** 
+ * Incoming String[] to a list of argument/values + items.
+ */
+
+
+public class CommandLineBase {
+    private List<String> argList    = new ArrayList<>() ;
+    boolean              splitTerms = true ;
+
+    public CommandLineBase(String[] args) {
+        setArgs(args) ;
+    }
+
+    public CommandLineBase() {}
+    
+    public void setArgs(String[] argv)
+    { argList = processArgv(argv) ; }
+    
+    protected List<String> getArgList() { return argList ; }
+
+    protected String getArg(int i) {
+        if ( i < 0 || i >= argList.size() )
+            return null ;
+        return argList.get(i) ;
+    }
+
+    protected void apply(ArgProc a) {
+        a.startArgs() ; 
+        range(0, argList.size()).forEach(i -> a.arg(argList.get(i), i));
+        a.finishArgs() ;
+    }
+    
+    /** Process String[] to a list of tokens.
+     *  All "=" and ":" terms are split.
+     *  Make -flag/--flag consistent.
+     * @param argv The words of the command line.
+     */    
+    private List<String> processArgv(String[] argv) {
+        // Combine with processedArgs/process?
+        List<String> argList = new ArrayList<>() ;
+
+        boolean positional = false ;
+
+        for ( String anArgv : argv )
+        {
+            String argStr = anArgv;
+
+            if ( positional || !argStr.startsWith( "-" ) )
+            {
+                argList.add( argStr );
+                continue;
+            }
+
+            if ( argStr.equals( "-" ) || argStr.equals( "--" ) )
+            {
+                positional = true;
+                argList.add( "--" );
+                continue;
+            }
+
+            // Starts with a "-"
+            // Do not canonicalize positional arguments.
+            if ( !argStr.startsWith( "--" ) )
+            {
+                argStr = "-" + argStr;
+            }
+
+            if ( !splitTerms )
+            {
+                argList.add( argStr );
+                continue;
+            }
+
+            // If the flag has a "=" or :, it is long form --arg=value.
+            // Split and insert the arg
+            int j1 = argStr.indexOf( '=' );
+            int j2 = argStr.indexOf( ':' );
+            int j = -1;
+
+            if ( j1 > 0 && j2 > 0 )
+            {
+                j = Math.min( j1, j2 );
+            }
+            else
+            {
+                if ( j1 > 0 )
+                {
+                    j = j1;
+                }
+                if ( j2 > 0 )
+                {
+                    j = j2;
+                }
+            }
+
+            if ( j < 0 )
+            {
+                argList.add( argStr );
+                continue;
+            }
+
+            // Split it.
+            String argStr1 = argStr.substring( 0, j );
+            String argStr2 = argStr.substring( j + 1 );
+
+            argList.add( argStr1 );
+            argList.add( argStr2 );
+        }
+        return argList ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/cmd/ModBase.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/ModBase.java b/jena-cmds/src/main/java/jena/cmd/ModBase.java
new file mode 100644
index 0000000..3899608
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/ModBase.java
@@ -0,0 +1,23 @@
+/*
+ * 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 jena.cmd;
+
+public abstract class ModBase implements ArgModuleGeneral
+{
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/cmd/ModGeneral.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/ModGeneral.java b/jena-cmds/src/main/java/jena/cmd/ModGeneral.java
new file mode 100644
index 0000000..25e1dac
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/ModGeneral.java
@@ -0,0 +1,57 @@
+/*
+ * 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 jena.cmd;
+
+public class ModGeneral extends ModBase
+{
+    private Runnable helpFunction = null ;
+
+    public ModGeneral(Runnable helpFunction) { this.helpFunction = helpFunction ; }
+    
+    // Could be turned into a module but these are convenient as inherited flags 
+    private final ArgDecl argDeclHelp        = new ArgDecl(false, "help", "h");
+    private final ArgDecl argDeclVerbose     = new ArgDecl(false, "v", "verbose");
+    private final ArgDecl argDeclQuiet       = new ArgDecl(false, "q", "quiet");
+    private final ArgDecl argDeclDebug       = new ArgDecl(false, "debug");
+
+    protected boolean verbose = false ;
+    protected boolean quiet = false ;
+    public boolean debug = false ;
+    protected boolean help = false ;
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("General") ;
+        cmdLine.add(argDeclVerbose, "-v   --verbose", "Verbose") ;
+        cmdLine.add(argDeclQuiet, "-q   --quiet", "Run with minimal output") ;
+        cmdLine.add(argDeclDebug, "--debug", "Output information for debugging") ;
+        cmdLine.add(argDeclHelp, "--help", null) ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        verbose = cmdLine.contains(argDeclVerbose) || cmdLine.contains(argDeclDebug) ;
+        quiet   = cmdLine.contains(argDeclQuiet) ;
+        help = cmdLine.contains(argDeclHelp) ;
+        if ( help )
+            helpFunction.run() ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/cmd/ModVersion.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/ModVersion.java b/jena-cmds/src/main/java/jena/cmd/ModVersion.java
new file mode 100644
index 0000000..3b47fb5
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/ModVersion.java
@@ -0,0 +1,67 @@
+/*
+ * 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 jena.cmd;
+
+import org.apache.jena.atlas.io.IndentedWriter;
+import org.apache.jena.atlas.lib.Version ;
+
+public class ModVersion extends ModBase
+{
+    protected final ArgDecl versionDecl = new ArgDecl(ArgDecl.NoValue, "version") ;
+    protected boolean version = false ;
+    protected boolean printAndExit = false ;
+    
+    private Version versionMgr = new Version() ; 
+    
+    public ModVersion(boolean printAndExit)
+    {
+        this.printAndExit = printAndExit ;
+    }
+    
+    public void addClass(Class<?> c) { versionMgr.addClass(c) ; }
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.add(versionDecl, "--version", "Version information") ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        if ( cmdLine.contains(versionDecl) )
+            version = true ;
+        // The --version flag causes us to print and exit. 
+        if ( version && printAndExit )
+            printVersionAndExit() ;
+    }
+
+    public boolean getVersionFlag() { return version ; }
+    
+    public void printVersion()
+    {
+        versionMgr.print(IndentedWriter.stdout);
+    }  
+     
+    public void printVersionAndExit()
+    {
+        printVersion() ;
+        System.exit(0) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/cmd/TerminationException.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/TerminationException.java b/jena-cmds/src/main/java/jena/cmd/TerminationException.java
new file mode 100644
index 0000000..090fa48
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/TerminationException.java
@@ -0,0 +1,31 @@
+/*
+ * 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 jena.cmd;
+
+
+/** Exception used to indicate that the command should end now.
+ *  Use instead of System.exit so that a wrapper can catch (else a command server
+ *  wil exit wrongly). */
+
+public class TerminationException extends CmdException
+{
+    public int returnCode ;
+    public TerminationException(int rc) { super() ; this.returnCode = rc ; }
+    public int getCode() { return returnCode ; }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/cmd/Usage.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/Usage.java b/jena-cmds/src/main/java/jena/cmd/Usage.java
new file mode 100644
index 0000000..1331eb9
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/Usage.java
@@ -0,0 +1,102 @@
+/*
+ * 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 jena.cmd;
+
+import java.io.PrintStream ;
+import java.util.ArrayList ;
+import java.util.Collections ;
+import java.util.List ;
+
+import org.apache.jena.atlas.io.IndentedWriter ;
+
+public class Usage
+{
+    class Category
+    {
+        String desc ;
+        List<Entry> entries = new ArrayList<>() ;
+        Category(String desc) { this.desc = desc ; }
+    }
+    
+   class Entry
+   { String arg; String msg ;
+     Entry(String arg, String msg) { this.arg = arg ; this.msg = msg ; }
+   }
+   
+   List<Category> categories = new ArrayList<>() ;
+   public Usage()
+   {
+       // Start with an unnamed category
+       startCategory(null) ; 
+   }
+   
+   public void startCategory(String desc) 
+   {
+       categories.add(new Category(desc)) ;
+   }
+   
+   public void addUsage(String argName, String msg)
+   {
+       current().entries.add(new Entry(argName, msg)) ;
+   }
+   
+   
+   public void output(PrintStream out)
+   {
+       output(new IndentedWriter(out)) ;
+   }
+   
+   public void output(IndentedWriter out)
+   {
+       int INDENT1 = 2 ;
+       int INDENT2 = 4 ;
+       out.incIndent(INDENT1) ;
+   
+       List<Category> categories2 = new ArrayList<>(categories) ;
+       Collections.reverse(categories2) ;
+
+       for ( Category c : categories2 )
+       {
+           if ( c.desc != null )
+           {
+               out.println( c.desc );
+           }
+           out.incIndent( INDENT2 );
+           for ( final Entry e : c.entries )
+           {
+               out.print( e.arg );
+               if ( e.msg != null )
+               {
+                   out.pad( 20 );
+                   out.print( "   " );
+                   out.print( e.msg );
+               }
+               out.println();
+           }
+           out.decIndent( INDENT2 );
+       }
+       out.decIndent(INDENT1) ;
+       out.flush() ;
+   }
+   
+   private Category current()
+   {
+       return categories.get(categories.size()-1) ;
+   }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/cmd/package-info.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/cmd/package-info.java b/jena-cmds/src/main/java/jena/cmd/package-info.java
new file mode 100644
index 0000000..26000b5
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/cmd/package-info.java
@@ -0,0 +1,6 @@
+/**
+ * Contains framework components for CLI and command execution.
+ * 
+ * @author ajs6f
+ */
+package jena.cmd;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/package.html
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/package.html b/jena-cmds/src/main/java/jena/package.html
new file mode 100644
index 0000000..b0db285
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/package.html
@@ -0,0 +1,34 @@
+<!--
+    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.
+-->
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+</head>
+ <body>
+<p>A package for some Jena command-line programs, including
+<ul>
+<li>copying RDF data with representation conversion, eg XML to N3
+<li>comparing two RDF files for isomorphism (extended equality)
+<li>an interface to the ARP RDF parser
+<li>access to the RDQL interpreter
+<li>a schema-to-Java generator
+</ul>
+</p>
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/query.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/query.java b/jena-cmds/src/main/java/jena/query.java
new file mode 100644
index 0000000..a04e02f
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/query.java
@@ -0,0 +1,26 @@
+/*
+ * 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 jena;
+
+public class query {
+    // Call-through to arq command line application
+    public static void main(String... args) {
+        arq.query.main(args);
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/rdfcat.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/rdfcat.java b/jena-cmds/src/main/java/jena/rdfcat.java
new file mode 100644
index 0000000..c292d45
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/rdfcat.java
@@ -0,0 +1,1150 @@
+/*
+ * 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
+///////////////
+package jena;
+
+
+// Imports
+///////////////
+
+import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
+
+import java.io.OutputStream ;
+import java.util.* ;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.rdf.model.impl.RDFWriterFImpl ;
+import org.apache.jena.shared.NoWriterForLangException ;
+import org.apache.jena.system.JenaSystem ;
+import org.apache.jena.util.FileManager ;
+import org.apache.jena.util.FileUtils ;
+import org.apache.jena.vocabulary.OWL ;
+import org.apache.jena.vocabulary.RDFS ;
+
+
+/**
+ * <p>
+ * An RDF utility that takes its name from the Unix utility <em>cat</em>, and
+ * is used to generate serialisations of the contents of zero or more
+ * input model serialisations. <strong>Note</strong> In a change from previous
+ * versions, but to ensure compatability with standard argument handling
+ * practice, the input language options are <em>no longer sticky</em>. In
+ * previous versions, <code>rdfcat -n A B C</code> would ensure that A, B
+ * and C were all read as N3. From Jena 2.5.2 onwards, this requires:
+ * <code>rdfcat -n A -n B -n C</code>, or the use of the <code>-in</code>
+ * option.
+ * </p>
+ * <p>Synopsis:</p>
+ * <pre>
+ * java jena.rdfcat (options|input)*
+ * where options are:
+ *   -out N3  (aliases n, n3, ttl)
+ *   -out N-TRIPLE  (aliases t, ntriple)
+ *   -out RDF/XML  (aliases x, rdf, xml, rdfxml)
+ *   -out RDF/XML-ABBREV (default)
+ *   -in N3  (aliases n, n3, ttl)
+ *   -in N-TRIPLE  (aliases t, ntriple)
+ *   -in RDF/XML  (aliases x, rdf, xml, rdfxml)
+ *   -include
+ *   -noinclude (default)
+ *
+ * input is one of:
+ *   -n &lt;filename&gt; for n3 input  (aliases -n3, -N3, -ttl)
+ *   -x &lt;filename&gt; for rdf/xml input  (aliases -rdf, -xml, -rdfxml)
+ *   -t &lt;filename&gt; for n-triple input  (aliases -ntriple)
+ * or just a URL, a filename, or - for the standard input.
+ * </pre>
+ * <p>
+ * The default
+ * input language is RDF/XML, but the reader will try to guess the
+ * input language based on the file extension (e.g. N3 for file with a .n3
+ * file extension.
+ * </p>
+ * <p>The input language options set the language for the following file
+ * name only. So in the following example, input
+ * A is read as N3, inputs B, C and D are read as RDF/XML,
+ * while stdin is read as N-TRIPLE:</p>
+ * <pre>
+ * java jena.rdfcat -n A B C -t - -x D
+ * </pre>
+ * <p>To change the default input language for all files that do
+ * not have a specified language encoding, use the <code>-in</code> option.
+ * </p>
+ * <p>If the <code>include</code> option is set, the input files are scanned
+ * for <code>rdfs:seeAlso</code> and <code>owl:imports</code> statements, and
+ * the objects of these statements are read as well.  By default, <code>include</code>
+ * is off. If <code>include</code> is turned on, the normal behaviour is for
+ * the including statements (e.g <code>owl:imports</code> to be filtered
+ * from the output models. To leave such statements in place, use the <code>--nofilter</code>
+ * option.</p>
+ * <p>rdfcat uses the Jena {@link org.apache.jena.util.FileManager FileManager}
+ * to resolve input URI's to locations. This allows, for example, <code>http:</code>
+ * URI's to be re-directed to local <code>file:</code> locations, to avoid a
+ * network transaction.</p>
+ * <p>Examples:</p>
+ * <pre>
+ * Join two RDF/XML files together into a single model in RDF/XML-ABBREV:
+ * java jena.rdfcat in1 in2 &gt; out.rdf
+ *
+ * Convert a single RDF/XML file to N3:
+ * java jena.rdfcat in1 -out N3 &gt; out.n3
+ *
+ * Join two owl files one N3, one XML, and their imports, into a single NTRIPLE file:
+ * java jena.rdfcat -out NTRIPLE -include in1.owl -n in2.owl > out.ntriple
+ *
+ * Concatenate two N3-serving http URL's as N-TRIPLE
+ * java jena.rdfcat -in N3 -out N-TRIPLE http://example.com/a http://example.com/b
+ * </pre>
+ * <p>Note that, in a difference from the Unix utility <code>cat</code>, the order
+ * of input statements is not preserved. The output document is a merge of the
+ * input documents, and does not preserve any statement ordering from the input
+ * serialisations. Also, duplicate triples will be suppressed.</p>
+ */
+@Deprecated
+public class rdfcat
+{
+    static { setCmdLogging("jena-log4j.properties") ; }
+    
+    /** The merged model containing all of the inputs */
+    protected Model m_model = ModelFactory.createDefaultModel();
+
+    /** The output format to write to, defaults to RDF/XML-ABBREV */
+    protected String m_outputFormat = "RDF/XML-ABBREV";
+
+    /** The input format we're expecting for the next URL to be read - defaults to RDF/XML */
+    protected String m_inputFormat = "RDF/XML";
+
+    /** Flag to indicate whether we include owl:imports and rdfs:seeAlso */
+    protected boolean m_include = false;
+
+    /** List of URL's that have been loaded already, occurs check */
+    protected Set<String> m_seen = new HashSet<>();
+
+    /** Flag to control whether import/include statements are filtered from merged models */
+    protected boolean m_removeIncludeStatements = true;
+
+    /** Action queue */
+    protected List<RCAction> m_actionQ = new ArrayList<>();
+
+    // Allow testing to run silent.
+    public static boolean suppressDeprecationBanner = false ;
+    
+    // Constants
+    //////////////////////////////////
+
+    /** Argument setting expected input language to N3 */
+    public final ArgDecl IN_N3 = new ArgDecl( true, "n", "n3", "ttl", "N3",
+    		(arg,val) -> m_actionQ.add( new ReadAction( val, "N3") ) );
+
+    /** Argument setting expected input language to RDF/XML */
+    public final ArgDecl IN_RDF_XML = new ArgDecl( true, "x", "xml", "rdfxml", "rdf",
+    		(arg,val) -> m_actionQ.add( new ReadAction( val, "RDF/XML") ) );
+
+    /** Argument setting expected input language to NTRIPLE */
+    public final ArgDecl IN_NTRIPLE = new ArgDecl( true, "t", "ntriples", "ntriple", "n-triple", "n-triples",
+    		(arg,val) -> m_actionQ.add( new ReadAction( val, "N-TRIPLE" ) ) );    
+
+    /** Argument to set the output language */
+    public final ArgDecl OUT_LANG = new ArgDecl( true, "out", (arg,val) -> setOutput( val ) );
+
+    /** Argument to set the default input language */
+    public final ArgDecl IN_LANG = new ArgDecl( true, "in", (arg,val) -> expectInput( val ) );
+
+    /** Argument to turn include processing on */
+    public final ArgDecl INCLUDE = new ArgDecl( false, "include", (arg,val) -> setInclude( true ) );
+
+    /** Argument to turn include processing off */
+    public final ArgDecl NOINCLUDE = new ArgDecl( false, "noinclude", (arg,val) -> setInclude( false ) );
+
+    /** Argument to leave import/seeAlso statements in place in flattened models */
+    public final ArgDecl NOFILTER = new ArgDecl( false, "nofilter", (arg,val) -> setRemoveIncludeStatements( false ) );
+
+    /** Argument to show usage */
+    public final ArgDecl HELP = new ArgDecl( false, "help", (arg,val) -> usage() );
+    public final ArgDecl USAGE = new ArgDecl( false, "usage", (arg,val) -> usage() );
+
+    // Instance variables
+    //////////////////////////////////
+
+    /** The command line processor that handles the arguments */
+    protected CommandLine m_cmdLine = new RCCommandLine().add( IN_N3 )
+                                                         .add( IN_NTRIPLE )
+                                                         .add( IN_RDF_XML )
+                                                         .add( OUT_LANG )
+                                                         .add( IN_LANG )
+                                                         .add( INCLUDE )
+                                                         .add( NOINCLUDE )
+                                                         .add( NOFILTER )
+                                                         .add( HELP )
+                                                         .add( USAGE );
+
+    // Constructors
+    //////////////////////////////////
+
+    // External signature methods
+    //////////////////////////////////
+
+    public static void main( String... args ) {
+        new rdfcat().go( args );
+    }
+
+    // Internal implementation methods
+    //////////////////////////////////
+
+    /* main loop */
+    protected void go( String[] args ) {
+    	JenaSystem.init();
+        if ( ! suppressDeprecationBanner ) {
+            System.err.println("------------------------------------------------------------------");
+    		System.err.println("   DEPRECATED: Please use 'riot' instead.");
+    		System.err.println("     http://jena.apache.org/documentation/io/#command-line-tools");
+            System.err.println("------------------------------------------------------------------");
+    		System.err.println() ;
+        }
+    	
+        m_cmdLine.process( args );
+
+        // process any stored items
+        for (int i = 0; i < m_cmdLine.numItems(); i++) {
+            m_actionQ.add(  new ReadAction( m_cmdLine.getItem( i ), getExpectedInput() ) );
+        }
+        for ( RCAction aM_actionQ : m_actionQ )
+        {
+            aM_actionQ.run( this );
+        }
+
+        // generate the output
+        m_model.write( getOutputStream(), m_outputFormat );
+    }
+
+    /** Set the input language of next and subsequent reads */
+    protected void expectInput( String lang ) {
+        m_inputFormat = lang;
+    }
+
+    /** Answer the currently expected input format */
+    protected String getExpectedInput() {
+        return m_inputFormat;
+    }
+
+    /** Set the language to write the output model in */
+    protected void setOutput( String lang ) {
+        m_outputFormat = getCheckedLanguage( lang );
+    }
+
+    /**
+         Answer the full, checked, language name expanded from <code>shortName</code>.
+        The shortName is expanded according to the table of abbreviations [below].
+        It is then checked against RDFWriterFImpl's writer table [this is hacky but
+        at the moment it's the most available interface] and the NoWriter exception
+        trapped and replaced by the original IllegalArgument exception.
+    */
+    public static String getCheckedLanguage( String shortLang )
+        {
+        String fullLang = unabbreviate.get( shortLang );
+        String tryLang = (fullLang == null ? shortLang : fullLang);
+        try { new RDFWriterFImpl().getWriter( tryLang ); }
+        catch (NoWriterForLangException e)
+            { throw new IllegalArgumentException( "'" + shortLang + "' is not recognised as a legal output format" ); }
+        return tryLang;
+        }
+
+    /**
+        Map from abbreviated names to full names.
+    */
+    public static Map<String,String> unabbreviate = makeUnabbreviateMap();
+
+    /**
+        Construct the canonical abbreviation map.
+    */
+    protected static Map<String,String> makeUnabbreviateMap()
+        {
+        Map<String,String> result = new HashMap<>();
+        result.put( "x", "RDF/XML" );
+        result.put( "rdf", "RDF/XML" );
+        result.put( "rdfxml", "RDF/XML" );
+        result.put( "xml", "RDF/XML" );
+        result.put( "n3", "N3" );
+        result.put( "n", "N3" );
+        result.put( "ttl", "N3" );
+        result.put( "ntriples", "N-TRIPLE" );
+        result.put( "ntriple", "N-TRIPLE" );
+        result.put( "t", "N-TRIPLE" );
+        result.put( "owl", "RDF/XML-ABBREV" );
+        result.put( "abbrev", "RDF/XML-ABBREV" );
+        return result;
+        }
+
+    /** Set the flag to include owl:imports and rdf:seeAlso files in the output, default off */
+    protected void setInclude( boolean incl ) {
+        m_include = incl;
+    }
+
+    /** Set the flag to leave owl:imports and rdfs:seeAlso statements in place, rather than filter them */
+    protected void setRemoveIncludeStatements( boolean f ) {
+        m_removeIncludeStatements = f;
+    }
+
+    /* Take the string as an input file or URI, and
+     * try to read using the current default input syntax.
+     */
+    protected void readInput( String inputName ) {
+        List<IncludeQueueEntry> queue = new ArrayList<>();
+        queue.add( new IncludeQueueEntry( inputName, null ) );
+
+        while (!queue.isEmpty()) {
+            IncludeQueueEntry entry = queue.remove( 0 );
+            String in = entry.m_includeURI;
+
+            if (!m_seen.contains( in )) {
+                m_seen.add( in );
+                Model inModel = ModelFactory.createDefaultModel();
+
+                // check for stdin
+                if (in.equals( "-" )) {
+                    inModel.read( System.in, null, m_inputFormat );
+                }
+                else {
+                    // lang from extension overrides default set on command line
+                    String lang = FileUtils.guessLang( in, m_inputFormat );
+                    FileManager.get().readModel( inModel, in, lang );
+                }
+
+                // check for anything more that we need to read
+                if (m_include) {
+                    addIncludes( inModel, queue );
+                }
+
+                // merge the models
+                m_model.add( inModel );
+                m_model.setNsPrefixes( inModel );
+
+                // do we remove the include statement?
+                if (m_removeIncludeStatements && entry.m_includeStmt != null) {
+                    m_model.remove( entry.m_includeStmt );
+                }
+            }
+        }
+    }
+
+    /** Return the stream to which the output is written, defaults to stdout */
+    protected OutputStream getOutputStream() {
+        return System.out;
+    }
+
+    /** Add any additional models to include given the rdfs:seeAlso and
+     * owl:imports statements in the given model
+     */
+    protected void addIncludes( Model inModel, List<IncludeQueueEntry> queue ) {
+        // first collect any rdfs:seeAlso statements
+        StmtIterator i = inModel.listStatements( null, RDFS.seeAlso, (RDFNode) null );
+        while (i.hasNext()) {
+            Statement s = i.nextStatement();
+            queue.add( new IncludeQueueEntry( getURL( s.getObject() ), s ) );
+        }
+
+        // then any owl:imports
+        i = inModel.listStatements( null, OWL.imports, (RDFNode) null );
+        while (i.hasNext()) {
+            Statement s = i.nextStatement();
+            queue.add( new IncludeQueueEntry( getURL( s.getResource() ), s ) );
+        }
+    }
+
+    protected void usage() {
+    		System.err.println( "------------------------------------" );
+    		System.err.println( "DEPRECATED: Please use riot instead." );
+    		System.err.println( "------------------------------------\n" );
+        System.err.println( "Usage: java jena.rdfcat (option|input)*" );
+        System.err.println( "Concatenates the contents of zero or more input RDF documents." );
+        System.err.println( "Options: -out N3 | N-TRIPLE | RDF/XML | RDF/XML-ABBREV" );
+        System.err.println( "         -n  expect subsequent inputs in N3 syntax" );
+        System.err.println( "         -x  expect subsequent inputs in RDF/XML syntax" );
+        System.err.println( "         -t  expect subsequent inputs in N-TRIPLE syntax" );
+        System.err.println( "         -[no]include  include rdfs:seeAlso and owl:imports" );
+        System.err.println( "input can be filename, URL, or - for stdin" );
+        System.err.println( "Recognised aliases for -n are: -n3 -ttl or -N3" );
+        System.err.println( "Recognised aliases for -x are: -xml -rdf or -rdfxml" );
+        System.err.println( "Recognised aliases for -t are: -ntriple" );
+        System.err.println( "Output format aliases: x, xml or rdf for RDF/XML, n, n3 or ttl for N3, t or ntriple for N-TRIPLE" );
+        System.err.println( "See the Javadoc for jena.rdfcat for additional details." );
+
+
+        System.exit(0);
+    }
+
+    /** Answer a URL string from a resource or literal */
+    protected String getURL( RDFNode n ) {
+        return n.isLiteral() ? ((Literal) n).getLexicalForm() : ((Resource) n).getURI();
+    }
+
+    //==============================================================================
+    // Inner class definitions
+    //==============================================================================
+
+    /** Local extension to CommandLine to handle mixed arguments and values */
+    protected class RCCommandLine
+        extends CommandLine
+    {
+        /** Don't stop processing args on the first non-arg */
+        public boolean xendProcessing( String argStr ) {
+            return false;
+        }
+
+        /** Handle an unrecognised argument by assuming it's a URI to read */
+        @Override
+        public void handleUnrecognizedArg( String argStr ) {
+            if (argStr.equals("-") || !argStr.startsWith( "-" )) {
+                // queue this action for reading later
+                m_actionQ.add( new ReadAction( argStr, getExpectedInput() ) );
+            }
+            else {
+                System.err.println( "Unrecognised argument: " + argStr );
+                usage();
+            }
+        }
+
+        /** Hook to test whether this argument should be processed further
+         */
+        @Override
+        public boolean ignoreArgument( String argStr ) {
+            return !argStr.startsWith("-") || argStr.length() == 1;
+        }
+
+        /** Answer an iterator over the non-arg items from the command line */
+        public Iterator<String> getItems() {
+            return items.iterator();
+        }
+    }
+
+    /** Queue entry that contains both a URI to be included, and a statement that may be removed */
+    protected class IncludeQueueEntry
+    {
+        protected String m_includeURI;
+        protected Statement m_includeStmt;
+        protected IncludeQueueEntry( String includeURI, Statement includeStmt ) {
+            m_includeURI = includeURI;
+            m_includeStmt = includeStmt;
+        }
+    }
+
+    /** Simple action object for local processing queue */
+    protected interface RCAction {
+        public void run( rdfcat rc );
+    }
+
+    /** Action to set the output format */
+    protected class ReadAction
+        implements RCAction
+    {
+        private String m_lang;
+        private String m_uri;
+        protected ReadAction( String uri, String lang ) {
+            m_lang = lang;
+            m_uri = uri;
+        }
+
+        /** perform the action of reading a uri */
+        @Override
+        public void run( rdfcat rc ) {
+            String l = rc.getExpectedInput();
+            if (m_lang != null) {
+                // if an input lang was given, use that
+                rc.expectInput( m_lang );
+            }
+            rc.readInput( m_uri );
+
+            // put the lang back to default
+            rc.expectInput( l );
+        }
+    }
+    
+    /**
+     * Command line argument processing based on a trigger model.
+     * An action is called whenever an argument is encountered. Example:
+     * <CODE>
+     * public static void main (String[] args)
+     * {
+     *  CommandLine cl = new CommandLine() ;
+     *  cl.add(false, "verbose")
+     *    .add(true, "--file") ;
+     *  cl.process(args) ;
+     *
+     *  for ( Iterator iter = cl.args() ; iter.hasNext() ; )
+     *  ...
+     * }
+     * </CODE>
+     * A gloabl hook is provided to inspect arguments just before the
+     * action.  Tracing is enabled by setting this to a suitable function
+     * such as that provided by trace():
+     * <CODE>
+     *  cl.setHook(cl.trace()) ;
+     * </CODE>
+     *
+     * <ul>
+     * <li>Neutral as to whether options have - or --</li>
+     * <li>Does not allow multiple single letter options to be concatenated.</li>
+     * <li>Options may be ended with - or --</li>
+     * <li>Arguments with values can use "="</li>
+     * </ul>
+     */
+
+
+    static class CommandLine
+    {
+        /* Extra processor called before the registered one when set.
+         * Used for tracing.
+         */
+        protected BiConsumer<String,String> argHook = null ;
+        protected String usage = null ;
+        protected Map<String, ArgDecl> argMap = new HashMap<>() ;
+        protected Map<String, Arg> args = new HashMap<>() ;
+        //protected boolean ignoreUnknown = false ;
+
+        // Rest of the items found on the command line
+        String indirectionMarker = "@" ;
+        protected boolean allowItemIndirect = false ;   // Allow @ to mean contents of file
+        boolean ignoreIndirectionMarker = false ;       // Allow comand line items to have leading @ but strip it.
+        protected List<String> items = new ArrayList<>() ;
+
+
+        /** Creates new CommandLine */
+        public CommandLine()
+        {
+        }
+
+        /** Set the global argument handler.  Called on every valid argument.
+         * @param argHandler Handler
+         */
+        public void setHook(BiConsumer<String, String> argHandler) { argHook = argHandler ; }
+
+        public void setUsage(String usageMessage) { usage = usageMessage ; }
+
+        public boolean hasArgs() { return args.size() > 0 ; }
+        public boolean hasItems() { return items.size() > 0 ; }
+
+        public Iterator<Arg> args() { return args.values().iterator() ; }
+//        public Map args() { return args ; }
+//        public List items() { return items ; }
+
+        public int numArgs() { return args.size() ; }
+        public int numItems() { return items.size() ; }
+        public void pushItem(String s) { items.add(s) ; }
+
+        public boolean isIndirectItem(int i)
+        { return allowItemIndirect && items.get(i).startsWith(indirectionMarker) ; }
+
+        public String getItem(int i)
+        {
+            return getItem(i, allowItemIndirect) ;
+        }
+
+        public String getItem(int i, boolean withIndirect)
+        {
+            if ( i < 0 || i >= items.size() )
+                return null ;
+
+
+            String item = items.get(i) ;
+
+            if ( withIndirect && item.startsWith(indirectionMarker) )
+            {
+                item = item.substring(1) ;
+                try { item = FileUtils.readWholeFileAsUTF8(item) ; }
+                catch (Exception ex)
+                { throw new IllegalArgumentException("Failed to read '"+item+"': "+ex.getMessage()) ; }
+            }
+            return item ;
+        }
+
+
+        /** Process a set of command line arguments.
+         * @param argv The words of the command line.
+         * @throws IllegalArgumentException Throw when something is wrong (no value found, action fails).
+         */
+        public void process(String[] argv) throws java.lang.IllegalArgumentException
+        {
+            List<String> argList = new ArrayList<>() ;
+            argList.addAll(Arrays.asList(argv)) ;
+
+            int i = 0 ;
+            for ( ; i < argList.size() ; i++ )
+            {
+                String argStr = argList.get(i) ;
+                if (endProcessing(argStr))
+                    break ;
+                
+                if ( ignoreArgument(argStr) )
+                    continue ;
+
+                // If the flag has a "=" or :, it is long form --arg=value.
+                // Split and insert the arg
+                int j1 = argStr.indexOf('=') ;
+                int j2 = argStr.indexOf(':') ;
+                int j = Integer.MAX_VALUE ;
+
+                if ( j1 > 0 && j1 < j )
+                    j = j1 ;
+                if ( j2 > 0 && j2 < j )
+                    j = j2 ;
+
+                if ( j != Integer.MAX_VALUE )
+                {
+                    String a2 = argStr.substring(j+1) ;
+                    argList.add(i+1,a2) ;
+                    argStr = argStr.substring(0,j) ;
+                }
+
+                argStr = ArgDecl.canonicalForm(argStr) ;
+                String val = null ;
+
+                if ( argMap.containsKey(argStr) )
+                {
+                    if ( ! args.containsKey(argStr))
+                        args.put(argStr, new Arg(argStr)) ;
+
+                    Arg arg = args.get(argStr) ;
+                    ArgDecl argDecl = argMap.get(argStr) ;
+
+                    if ( argDecl.takesValue() )
+                    {
+                        if ( i == (argList.size()-1) )
+                            throw new IllegalArgumentException("No value for argument: "+arg.getName()) ;
+                        i++ ;
+                        val = argList.get(i) ;
+                        arg.setValue(val) ;
+                        arg.addValue(val) ;
+                    }
+
+                    // Global hook
+                    if ( argHook != null )
+                        argHook.accept(argStr, val) ;
+
+                    argDecl.trigger(arg) ;
+                }
+                else
+                    handleUnrecognizedArg( argList.get(i) );
+//                    if ( ! getIgnoreUnknown() )
+//                        // Not recognized
+//                        throw new IllegalArgumentException("Unknown argument: "+argStr) ;
+            }
+
+            // Remainder.
+            if ( i < argList.size() )
+            {
+                if ( argList.get(i).equals("-") || argList.get(i).equals("--") )
+                    i++ ;
+                for ( ; i < argList.size() ; i++ )
+                {
+                    String item = argList.get(i) ;
+                    items.add(item) ;
+                }
+            }
+        }
+
+        /** Hook to test whether this argument should be processed further
+         */
+        public boolean ignoreArgument( String argStr )
+        { return false ; }
+        
+        /** Answer true if this argument terminates argument processing for the rest
+         * of the command line. Default is to stop just before the first arg that
+         * does not start with "-", or is "-" or "--".
+         */
+        public boolean endProcessing( String argStr )
+        {
+            return ! argStr.startsWith("-") || argStr.equals("--") || argStr.equals("-");
+        }
+
+        /**
+         * Handle an unrecognised argument; default is to throw an exception
+         * @param argStr The string image of the unrecognised argument
+         */
+        public void handleUnrecognizedArg( String argStr ) {
+            throw new IllegalArgumentException("Unknown argument: "+argStr) ;
+        }
+
+
+        /** Test whether an argument was seen.
+         */
+
+        public boolean contains(ArgDecl argDecl) { return getArg(argDecl) != null ; }
+
+        /** Test whether an argument was seen.
+         */
+
+        public boolean contains(String s) { return getArg(s) != null ; }
+
+
+        /** Test whether the command line had a particular argument
+         *
+         * @param argName
+         */
+        public boolean hasArg(String argName) { return getArg(argName) != null ; }
+
+        /** Test whether the command line had a particular argument
+         *
+         * @param argDecl
+         */
+
+        public boolean hasArg(ArgDecl argDecl) { return getArg(argDecl) != null ; }
+
+
+        /** Get the argument associated with the argument declaration.
+         *  Actually returns the LAST one seen
+         *  @param argDecl Argument declaration to find
+         *  @return Last argument that matched.
+         */
+
+        public Arg getArg(ArgDecl argDecl)
+        {
+            Arg arg = null ;
+            for ( Arg a : args.values() )
+            {
+                if ( argDecl.matches( a ) )
+                {
+                    arg = a;
+                }
+            }
+            return arg ;
+        }
+
+        /** Get the argument associated with the arguement name.
+         *  Actually returns the LAST one seen
+         *  @param arg Argument declaration to find
+         *  @return Arg - Last argument that matched.
+         */
+
+        public Arg getArg(String arg)
+        {
+            arg = ArgDecl.canonicalForm(arg) ;
+            return args.get(arg) ;
+        }
+
+        /**
+         * Returns the value (a string) for an argument with a value -
+         * returns null for no argument and no value.
+         * @param argDecl
+         * @return String
+         */
+        public String getValue(ArgDecl argDecl)
+        {
+            Arg arg = getArg(argDecl) ;
+            if ( arg == null )
+                return null ;
+            if ( arg.hasValue())
+                return arg.getValue() ;
+            return null ;
+        }
+
+        /**
+         * Returns the value (a string) for an argument with a value -
+         * returns null for no argument and no value.
+         * @param argName
+         * @return String
+         */
+        public String getValue(String argName)
+        {
+            Arg arg = getArg(argName) ;
+            if ( arg == null )
+                return null ;
+            return arg.getValue() ;
+        }
+
+        /**
+         * Returns all the values (0 or more strings) for an argument.
+         * @param argDecl
+         * @return List
+         */
+        public List<String> getValues(ArgDecl argDecl)
+        {
+            Arg arg = getArg(argDecl) ;
+            if ( arg == null )
+                return null ;
+            return arg.getValues() ;
+        }
+
+        /**
+         * Returns all the values (0 or more strings) for an argument.
+         * @param argName
+         * @return List
+         */
+        public List<String> getValues(String argName)
+        {
+            Arg arg = getArg(argName) ;
+            if ( arg == null )
+                return null ;
+            return arg.getValues() ;
+        }
+
+
+
+        /** Add an argument to those to be accepted on the command line.
+         * @param argName Name
+         * @param hasValue True if the command takes a (string) value
+         * @return The CommandLine processor object
+         */
+
+        public CommandLine add(String argName, boolean hasValue)
+        {
+            return add(new ArgDecl(hasValue, argName)) ;
+        }
+
+        /** Add an argument to those to be accepted on the command line.
+         *  Argument order reflects ArgDecl.
+         * @param hasValue True if the command takes a (string) value
+         * @param argName Name
+         * @return The CommandLine processor object
+         */
+
+        public CommandLine add(boolean hasValue, String argName)
+        {
+            return add(new ArgDecl(hasValue, argName)) ;
+        }
+
+        /** Add an argument object
+         * @param arg Argument to add
+         * @return The CommandLine processor object
+         */
+
+        public CommandLine add(ArgDecl arg)
+        {
+            for ( Iterator<String> iter = arg.names() ; iter.hasNext() ; )
+                argMap.put(iter.next(), arg) ;
+            return this ;
+        }
+
+//        public boolean getIgnoreUnknown() { return ignoreUnknown ; }
+//        public void setIgnoreUnknown(boolean ign) { ignoreUnknown = ign ; }
+
+        /**
+         * @return Returns whether items starting "@" have the value of named file.
+         */
+        public boolean allowItemIndirect()
+        {
+            return allowItemIndirect ;
+        }
+
+        /**
+         * @param allowItemIndirect Set whether items starting "@" have the value of named file.
+
+         */
+        public void setAllowItemIndirect(boolean allowItemIndirect)
+        {
+            this.allowItemIndirect = allowItemIndirect ;
+        }
+
+        /**
+         * @return Returns the ignoreIndirectionMarker.
+         */
+        public boolean isIgnoreIndirectionMarker()
+        {
+            return ignoreIndirectionMarker ;
+        }
+
+        /**
+         * @return Returns the indirectionMarker.
+         */
+        public String getIndirectionMarker()
+        {
+            return indirectionMarker ;
+        }
+
+        /**
+         * @param indirectionMarker The indirectionMarker to set.
+         */
+        public void setIndirectionMarker(String indirectionMarker)
+        {
+            this.indirectionMarker = indirectionMarker ;
+        }
+
+        /**
+         * @param ignoreIndirectionMarker The ignoreIndirectionMarker to set.
+         */
+        public void setIgnoreIndirectionMarker(boolean ignoreIndirectionMarker)
+        {
+            this.ignoreIndirectionMarker = ignoreIndirectionMarker ;
+        }
+
+	    	public BiConsumer<String, String> trace() {
+	    		return (arg, val) -> {
+	    			System.err.println("Seen: " + arg + (val != null ? " = " + val : ""));
+	    		};
+	    	}
+
+    }
+    
+    /** A command line argument that has been foundspecification.
+	 */
+	static class Arg
+	{
+	    String name ;
+	    String value ;
+	    List<String> values = new ArrayList<>() ;
+	    
+	    Arg() { name = null ; value = null ; }
+	    
+	    Arg(String _name) { this() ; setName(_name) ; }
+	    
+	    Arg(String _name, String _value) { this() ; setName(_name) ; setValue(_value) ; }
+	    
+	    void setName(String n) { name = n ; }
+	    
+	    void setValue(String v) { value = v ; }
+	    void addValue(String v) { values.add(v) ; }
+	    
+	    public String getName() { return name ; }
+	    public String getValue() { return value; }
+	    public List<String> getValues() { return values; }
+	    
+	    public boolean hasValue() { return value != null ; }
+	    
+	    public boolean matches(ArgDecl decl)
+	    {
+	        return decl.getNames().contains(name) ;
+	    }
+	    
+	}
+    
+    /** A command line argument specification.
+	 */
+	static class ArgDecl
+	{
+	    boolean takesValue ;
+	    Set<String> names = new HashSet<>() ;
+	    boolean takesArg = false ;
+		List<BiConsumer<String, String>> argHooks = new ArrayList<>() ;
+	    public static final boolean HasValue = true ;
+	    public static final boolean NoValue = false ;
+
+	    /** Create a declaration for a command argument.
+	     *
+	     * @param hasValue  Does it take a value or not?
+	     */
+
+	    public ArgDecl(boolean hasValue)
+	    {
+	        takesValue = hasValue ;
+	    }
+
+	    /** Create a declaration for a command argument.
+	     *
+	     * @param hasValue  Does it take a value or not?
+	     * @param name      Name of argument
+	     */
+
+	    public ArgDecl(boolean hasValue, String name)
+	    {
+	        this(hasValue) ;
+	        addName(name) ;
+	    }
+
+	    /** Create a declaration for a command argument.
+	     *
+	     * @param hasValue  Does it take a value or not?
+	     * @param name      Name of argument
+	     * @param handler   BiConsumer<String, String>
+	     */
+
+	    public ArgDecl(boolean hasValue, String name, BiConsumer<String, String> handler)
+	    {
+	        this(hasValue) ;
+	        addName(name) ;
+	        addHook( handler );
+	    }
+
+	    /** Create a declaration for a command argument.
+	     *
+	     * @param hasValue  Does it take a value or not?
+	     * @param name1      Name of argument
+	     * @param name2      Name of argument
+	     */
+
+	    public ArgDecl(boolean hasValue, String name1, String name2)
+	    {
+	        this(hasValue) ;
+	        addName(name1) ;
+	        addName(name2) ;
+	    }
+
+	    /** Create a declaration for a command argument.
+	     *
+	     * @param hasValue  Does it take a value or not?
+	     * @param name1      Name of argument
+	     * @param name2      Name of argument
+	     * @param handler   BiConsumer<String, String>
+	     */
+
+	    public ArgDecl(boolean hasValue, String name1, String name2, BiConsumer<String, String> handler)
+	    {
+	        this(hasValue) ;
+	        addName(name1) ;
+	        addName(name2) ;
+	        addHook( handler );
+	    }
+
+	    /** Create a declaration for a command argument.
+	     *
+	     * @param hasValue  Does it take a value or not?
+	     * @param name1      Name of argument
+	     * @param name2      Name of argument
+	     * @param name3      Name of argument
+	     */
+
+	    public ArgDecl(boolean hasValue, String name1, String name2, String name3)
+	    {
+	        this(hasValue) ;
+	        addName(name1) ;
+	        addName(name2) ;
+	        addName(name3) ;
+	    }
+
+	    /** Create a declaration for a command argument.
+	     *
+	     * @param hasValue  Does it take a value or not?
+	     * @param name1      Name of argument
+	     * @param name2      Name of argument
+	     * @param name3      Name of argument
+	     * @param handler   BiConsumer<String, String>
+	     */
+
+	    public ArgDecl(boolean hasValue, String name1, String name2, String name3, BiConsumer<String, String> handler)
+	    {
+	        this(hasValue) ;
+	        addName(name1) ;
+	        addName(name2) ;
+	        addName(name3) ;
+	        addHook( handler );
+	    }
+
+	    /** Create a declaration for a command argument.
+	     *
+	     * @param hasValue  Does it take a value or not?
+	     * @param name1      Name of argument
+	     * @param name2      Name of argument
+	     * @param name3      Name of argument
+	     * @param name4      Name of argument
+	     */
+
+	    public ArgDecl(boolean hasValue, String name1, String name2, String name3, String name4)
+	    {
+	        this(hasValue) ;
+	        addName(name1) ;
+	        addName(name2) ;
+	        addName(name3) ;
+	        addName(name4) ;
+	    }
+
+	    /** Create a declaration for a command argument.
+	     *
+	     * @param hasValue  Does it take a value or not?
+	     * @param name1      Name of argument
+	     * @param name2      Name of argument
+	     * @param name3      Name of argument
+	     * @param name4      Name of argument
+	     * @param handler    BiConsumer<String, String>
+	     */
+
+	    public ArgDecl(boolean hasValue, String name1, String name2, String name3, String name4, BiConsumer<String, String> handler)
+	    {
+	        this(hasValue) ;
+	        addName(name1) ;
+	        addName(name2) ;
+	        addName(name3) ;
+	        addName(name4) ;
+	        addHook( handler );
+	    }
+
+	    /** Create a declaration for a command argument.
+	     *
+	     * @param hasValue  Does it take a value or not?
+	     * @param name1      Name of argument
+	     * @param name2      Name of argument
+	     * @param name3      Name of argument
+	     * @param name4      Name of argument
+	     * @param name5      Name of argument
+	     * @param handler    BiConsumer<String, String>
+	     */
+
+	    public ArgDecl(boolean hasValue, String name1, String name2, String name3, String name4, String name5, BiConsumer<String, String> handler)
+	    {
+	        this(hasValue) ;
+	        addName(name1) ;
+	        addName(name2) ;
+	        addName(name3) ;
+	        addName(name4) ;
+	        addName(name5) ;
+	        addHook( handler );
+	    }
+
+	    public void addName(String name)
+	    {
+	        name = canonicalForm(name) ;
+	        names.add(name) ;
+	    }
+
+	    public Set<String> getNames() { return names ; }
+	    public Iterator<String> names() { return names.iterator() ; }
+
+	    // Callback model
+
+	    public void addHook(BiConsumer<String, String> argHandler)
+	    {
+	        argHooks.add(argHandler) ;
+	    }
+
+	    protected void trigger(Arg arg)
+	    {
+			argHooks.forEach(action -> action.accept( arg.getName(), arg.getValue() ));
+	    }
+
+	    public boolean takesValue() { return takesValue ; }
+
+	    public boolean matches(Arg a)
+	    {
+	        for ( String n : names )
+	        {
+	            if ( a.getName().equals( n ) )
+	            {
+	                return true;
+	            }
+	        }
+	        return false ;
+	    }
+
+	    public boolean matches(String arg)
+	    {
+	        arg = canonicalForm(arg) ;
+	        return names.contains(arg) ;
+	    }
+
+	    static String canonicalForm(String str)
+	    {
+	        if ( str.startsWith("--") )
+	            return str.substring(2) ;
+
+	        if ( str.startsWith("-") )
+	            return str.substring(1) ;
+
+	        return str ;
+	    }
+	}
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/rdfcompare.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/rdfcompare.java b/jena-cmds/src/main/java/jena/rdfcompare.java
new file mode 100644
index 0000000..95cc602
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/rdfcompare.java
@@ -0,0 +1,131 @@
+/*
+ * 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 jena;
+
+import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
+
+import java.net.URL;
+import java.io.FileInputStream;
+
+import org.apache.jena.rdf.model.* ;
+
+/** A program which read two RDF models and determines if they are the same.
+ *
+ *  <p>This program will read two RDF models, in a variety of languages,
+ *     and compare them.  Input can be read either from a URL or from a file.
+ *     The program writes its results to the standard output stream and sets
+ *     its exit code to 0 if the models are equal, to 1 if they are not and
+ *     to -1 if it encounters an error.</p>
+ *
+ *  <p></p>
+ *
+ *  <pre>java jena.rdfcompare model1 model2 [lang1 [lang2]]
+ *
+ *       model1 and model2 can be file names or URL's
+ *       lang1 and lang2 specify the language of the input and can be:
+ *           RDF/XML
+ *           N-TRIPLE
+ *           N3
+ *  </pre>
+ */
+public class rdfcompare extends java.lang.Object {
+
+    static { setCmdLogging(); }
+
+    /**
+    * @param args the command line arguments
+    */
+    public static void main (String ... args) {
+        if (args.length < 2 || args.length > 6) {
+            usage();
+            System.exit(-1);
+        }
+        
+        String in1 = args[0];
+        String in2 = args[1];
+        String lang1 = "RDF/XML";
+        if (args.length >= 3) {
+            lang1 = args[2];
+        } 
+        String lang2 = "N-TRIPLE";
+        if (args.length >= 4) {
+            lang2 = args[3];
+        }
+        String base1 = null;
+        if (args.length >= 5) {
+            base1 = args[4];
+        }
+        String base2 = base1;
+        if (args.length >= 6) {
+            base2 = args[5];
+        }
+        
+        System.out.println(in1 + " " + in2 + " " + lang1 + " " + lang2 + " " + base1 + " " + base2);
+        try {
+            Model m1 = ModelFactory.createDefaultModel();
+            Model m2 = ModelFactory.createDefaultModel();
+        
+            read(m1, in1, lang1, base1);
+            read(m2, in2, lang2, base2);
+        
+            if (m1.isIsomorphicWith(m2)) {
+                System.out.println("models are equal");
+                System.out.println();
+                System.exit(0);
+            } else {
+                System.out.println("models are unequal");
+                System.out.println();
+                System.exit(1);
+            }
+        } catch (Exception e) {
+            System.err.println("Unhandled exception:");
+            System.err.println("    " + e.toString());
+            System.exit(-1);
+        }
+    }
+    
+    protected static void usage() {
+        System.err.println("usage:");
+        System.err.println(
+            "    java jena.rdfcompare source1 source2 [lang1 [lang2 [base1 [base2]]]]");
+        System.err.println();
+        System.err.println("    source1 and source2 can be URL's or filenames");
+        System.err.println("    lang1 and lang2 can take values:");
+        System.err.println("      RDF/XML");
+        System.err.println("      N-TRIPLE");
+        System.err.println("      N3");
+        System.err.println("    lang1 defaults to RDF/XML, lang2 to N-TRIPLE");
+        System.err.println("    base1 and base2 are URIs");
+        System.err.println("    base1 defaults to null");
+        System.err.println("    base2 defaults to base1");
+        System.err.println("    If no base URIs are specified Jena determines the base URI based on the input source");
+        
+        System.err.println();
+    }
+    
+    protected static void read(Model model, String in, String lang, String base) 
+      throws java.io.FileNotFoundException {
+        try {
+            URL url = new URL(in);
+            model.read(in, base, lang);
+        } catch (java.net.MalformedURLException e) {
+            model.read(new FileInputStream(in), base, lang);
+        }
+    }
+}


[02/20] jena git commit: JENA-1108: Command line tools for TDB bulkloader2

Posted by an...@apache.org.
JENA-1108: Command line tools for TDB bulkloader2


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

Branch: refs/heads/master
Commit: cda5c7cd5804033379f09a3732a55791acd14a60
Parents: 498b226
Author: Andy Seaborne <an...@apache.org>
Authored: Sun Jan 3 11:46:34 2016 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Jan 5 12:31:35 2016 +0000

----------------------------------------------------------------------
 apache-jena/bin/tdbloader2common                |   3 +-
 apache-jena/pom.xml                             |  20 +++
 jena-cmds/pom.xml                               |  84 +++++++++++
 .../src/main/java/tdb/CmdNodeTableBuilder.java  | 132 -----------------
 .../src/main/java/tdb/CmdRewriteIndex.java      | 147 -------------------
 .../java/tdb/bulkloader2/CmdIndexBuild.java     |  53 +++++++
 .../main/java/tdb/bulkloader2/CmdIndexCopy.java |  45 ++++++
 .../tdb/bulkloader2/CmdNodeTableBuilder.java    | 125 ++++++++++++++++
 .../java/tdb/bulkloader2/CmdRewriteIndex.java   |  61 ++++++++
 jena-fuseki2/jena-fuseki-core/pom.xml           |  17 ++-
 jena-maven-tools/pom.xml                        |   2 +-
 .../tdb/store/bulkloader2/CmdIndexBuild.java    | 126 ----------------
 .../tdb/store/bulkloader2/CmdIndexCopy.java     | 115 ---------------
 .../tdb/store/bulkloader2/ProcIndexBuild.java   | 104 +++++++++++++
 .../tdb/store/bulkloader2/ProcIndexCopy.java    | 102 +++++++++++++
 .../store/bulkloader2/ProcNodeTableBuilder.java |   8 +-
 .../tdb/store/bulkloader2/ProcRewriteIndex.java | 102 +++++++++++++
 pom.xml                                         |  37 +++--
 18 files changed, 732 insertions(+), 551 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/apache-jena/bin/tdbloader2common
----------------------------------------------------------------------
diff --git a/apache-jena/bin/tdbloader2common b/apache-jena/bin/tdbloader2common
index 807ac1d..136471d 100644
--- a/apache-jena/bin/tdbloader2common
+++ b/apache-jena/bin/tdbloader2common
@@ -211,4 +211,5 @@ function makeAbsolute() {
 #DATE="+%Y-%m-%dT%H:%M:%S%:z"
 DATE="+%H:%M:%S"
 
-PKG=org.apache.jena.tdb.store.bulkloader2
+# Package for the command wrappers.
+PKG=tdb.bulkloader2

http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/apache-jena/pom.xml
----------------------------------------------------------------------
diff --git a/apache-jena/pom.xml b/apache-jena/pom.xml
index 885db04..4bbc6e8 100644
--- a/apache-jena/pom.xml
+++ b/apache-jena/pom.xml
@@ -117,6 +117,26 @@
       <classifier>javadoc</classifier>
     </dependency>
 
+    <dependency>
+      <groupId>org.apache.jena</groupId>
+      <artifactId>jena-cmds</artifactId>
+      <version>3.1.0-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.jena</groupId>
+      <artifactId>jena-cmds</artifactId>
+      <version>3.1.0-SNAPSHOT</version>
+      <classifier>sources</classifier>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.jena</groupId>
+      <artifactId>jena-cmds</artifactId>
+      <version>3.1.0-SNAPSHOT</version>
+      <classifier>javadoc</classifier>
+    </dependency>
+
   </dependencies>
 
   <build>

http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/jena-cmds/pom.xml
----------------------------------------------------------------------
diff --git a/jena-cmds/pom.xml b/jena-cmds/pom.xml
index 1bb3d20..738213b 100644
--- a/jena-cmds/pom.xml
+++ b/jena-cmds/pom.xml
@@ -113,5 +113,89 @@
     </dependency>
 
   </dependencies>
+  <build>
+    <resources>
+      <resource>
+	    <filtering>true</filtering>
+        <directory>src/main/resources</directory>
+	    <includes>
+	      <include>org/apache/jena/arq/arq-properties.xml</include>
+	    </includes>
+      </resource>
+      <resource>
+        <filtering>false</filtering>
+        <directory>src/main/resources</directory>
+        <excludes>
+          <exclude>org/apache/jena/arq/arq-properties.xml</exclude>
+        </excludes>
+      </resource>
+    </resources>
+
+    <plugins>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+      </plugin>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <includes>
+            <include>**/TS_*.java</include>
+          </includes>
+        </configuration>
+      </plugin>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-source-plugin</artifactId>
+
+        <executions>
+          <execution>
+            <id>attach-sources</id>
+            <goals>
+              <goal>jar-no-fork</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>attach-sources-test</id>
+            <goals>
+              <goal>test-jar-no-fork</goal>
+            </goals>
+          </execution>
+        </executions>
+
+      </plugin>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>test-jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <configuration>
+          <version>true</version>
+          <show>public</show>
+          <quiet>true</quiet>
+          <encoding>UTF-8</encoding>
+          <windowtitle>Apache Jena ARQ</windowtitle>
+          <doctitle>Apache Jena ARQ ${project.version}</doctitle>
+          <bottom>Licenced under the Apache License, Version 2.0</bottom>
+        </configuration>
+      </plugin>
+
+    </plugins>
+  </build>
   
 </project>

http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/jena-cmds/src/main/java/tdb/CmdNodeTableBuilder.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/CmdNodeTableBuilder.java b/jena-cmds/src/main/java/tdb/CmdNodeTableBuilder.java
deleted file mode 100644
index 5dc0371..0000000
--- a/jena-cmds/src/main/java/tdb/CmdNodeTableBuilder.java
+++ /dev/null
@@ -1,132 +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 tdb;
-
-import java.util.Arrays ;
-import java.util.List ;
-import java.util.Objects ;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdException;
-import jena.cmd.CmdGeneral;
-import org.apache.jena.atlas.lib.FileOps ;
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFLanguages ;
-import org.apache.jena.system.JenaSystem ;
-import org.apache.jena.tdb.base.file.Location ;
-import org.apache.jena.tdb.setup.DatasetBuilderStd ;
-import org.apache.jena.tdb.store.bulkloader2.ProcNodeTableBuilder ;
-import tdb.cmdline.CmdTDB ;
-
-/** Build node table - write triples/quads as text file */
-public class CmdNodeTableBuilder extends CmdGeneral
-{
-    static { LogCtl.setLog4j() ; }
-    static { JenaSystem.init(); }
-    
-
-    private static ArgDecl argLocation      = new ArgDecl(ArgDecl.HasValue, "loc", "location") ;
-    private static ArgDecl argTriplesOut    = new ArgDecl(ArgDecl.HasValue, "triples") ;
-    private static ArgDecl argQuadsOut      = new ArgDecl(ArgDecl.HasValue, "quads") ;
-    private static ArgDecl argNoStats       = new ArgDecl(ArgDecl.NoValue, "nostats") ;
-    
-    private String locationString ;
-    private String dataFileTriples ;
-    private String dataFileQuads ;
-    private List<String> datafiles ;
-    private Location location ;
-    private boolean collectStats = true ;
-    
-    public static void main(String...argv)
-    {
-        System.err.println("CmdNodeTableBuilder");
-        CmdTDB.init() ;
-        DatasetBuilderStd.setOptimizerWarningFlag(false) ;
-        new CmdNodeTableBuilder(argv).mainRun() ;
-    }
-    
-    public CmdNodeTableBuilder(String...argv)
-    {
-        super(argv) ;
-        super.add(argLocation,      "--loc",        "Location") ;
-        super.add(argTriplesOut,    "--triples",    "Output file for triples") ;
-        super.add(argQuadsOut,      "--quads",      "Output file for quads") ;
-        super.add(argNoStats,       "--nostats",    "Don't collect stats") ;
-    }
-        
-    @Override
-    protected void processModulesAndArgs()
-    {
-        if ( !super.contains(argLocation) ) throw new CmdException("Required: --loc DIR") ;
-//        if ( !super.contains(argTriplesOut) ) throw new CmdException("Required: --triples FILE") ;
-//        if ( !super.contains(argQuadsOut) ) throw new CmdException("Required: --quads FILE") ;
-        
-        locationString   = super.getValue(argLocation) ;
-        location = Location.create(locationString) ;
-
-        dataFileTriples  = super.getValue(argTriplesOut) ;
-        if ( dataFileTriples == null )
-            dataFileTriples = location.getPath("triples", "tmp") ;
-        
-        dataFileQuads    = super.getValue(argQuadsOut) ;
-        if ( dataFileQuads == null )
-            dataFileQuads = location.getPath("quads", "tmp") ;
-        
-        if ( Objects.equals(dataFileTriples, dataFileQuads) )
-            cmdError("Triples and Quads work files are the same") ;
-        
-        if ( super.contains(argNoStats) )
-            collectStats = false ;
-        
-        //datafiles  = getPositionalOrStdin() ;
-        datafiles  = getPositional() ;
-        if ( datafiles.isEmpty() )
-            datafiles = Arrays.asList("-") ;
-        
-        // ---- Checking.
-        for( String filename : datafiles)
-        {
-            Lang lang = RDFLanguages.filenameToLang(filename, RDFLanguages.NQUADS) ;
-            if ( lang == null )
-                // Does not happen due to default above.
-                cmdError("File suffix not recognized: " +filename) ;
-            if ( ! filename.equals("-") && ! FileOps.exists(filename) )
-                cmdError("File does not exist: "+filename) ;
-        }
-    }
-    
-    @Override
-    protected void exec()
-    {
-        ProcNodeTableBuilder.execInner(location, dataFileTriples, dataFileQuads, datafiles, collectStats); 
-    }
-    
- @Override
-    protected String getSummary()
-    {
-        return getCommandName()+" --loc=DIR [--triples=tmpFile1] [--quads=tmpFile2] FILE ..." ;
-    }
-
-    @Override
-    protected String getCommandName()
-    {
-        return this.getClass().getName() ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/jena-cmds/src/main/java/tdb/CmdRewriteIndex.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/CmdRewriteIndex.java b/jena-cmds/src/main/java/tdb/CmdRewriteIndex.java
deleted file mode 100644
index 0c4a6fa..0000000
--- a/jena-cmds/src/main/java/tdb/CmdRewriteIndex.java
+++ /dev/null
@@ -1,147 +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 tdb;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.lib.FileOps ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.tdb.base.block.BlockMgr ;
-import org.apache.jena.tdb.base.block.BlockMgrFactory ;
-import org.apache.jena.tdb.base.file.FileSet ;
-import org.apache.jena.tdb.base.file.Location ;
-import org.apache.jena.tdb.base.record.Record ;
-import org.apache.jena.tdb.base.record.RecordFactory ;
-import org.apache.jena.tdb.index.RangeIndex ;
-import org.apache.jena.tdb.index.SetupIndex ;
-import org.apache.jena.tdb.index.bplustree.BPlusTree ;
-import org.apache.jena.tdb.index.bplustree.BPlusTreeParams ;
-import org.apache.jena.tdb.index.bplustree.BPlusTreeRewriter ;
-import org.apache.jena.tdb.sys.Names ;
-import org.apache.jena.tdb.sys.SystemTDB ;
-
-/** Rewrite one index */
-public class CmdRewriteIndex
-{
-    public static void main(String...argv)
-    {
-        // Usage: srcLocation dstLocation indexName
-        if ( argv.length != 3 )
-        {
-            System.err.println("Usage: "+Lib.classShortName(CmdRewriteIndex.class)+" SrcLocation DstLocation IndexName") ;
-            System.exit(1) ;
-        }
-        
-        Location srcLoc = Location.create(argv[0]) ;
-        Location dstLoc = Location.create(argv[1]) ;
-        String indexName = argv[2] ;
-        
-        if ( ! FileOps.exists(argv[1]) )
-        {
-            System.err.println("Destination directory does not exist") ;
-            System.exit(1) ;
-        }
-        
-        if ( FileOps.exists(dstLoc.getPath(indexName, Names.bptExtTree)) )
-        {
-            System.err.println("Destination contains an index of that name") ;
-            System.exit(1) ;
-        }
-        
-        // To current directory ....
-        FileSet destination = new FileSet(dstLoc, indexName) ;
-        // Check existance
-        
-//        FileOps.deleteSilent(destination.filename(Names.bptExt1)) ;
-//        FileOps.deleteSilent(destination.filename(Names.bptExt2)) ;
-        //FileSet destination = new FileSet(Location.mem(), destIndex) ;
-        
-        int readCacheSize = 0 ;
-        int writeCacheSize = -1 ;
-        
-        int dftKeyLength ;
-        int dftValueLength ;
-        
-        if ( indexName.length() == 3 )
-        {
-            dftKeyLength = SystemTDB.LenIndexTripleRecord ;
-            dftValueLength = 0 ;
-        }
-        else if ( indexName.length() == 4 )
-        {
-            dftKeyLength = SystemTDB.LenIndexQuadRecord ;
-            dftValueLength = 0 ;
-        }
-//        else if ( srcIndex.equals("node2id") )
-//        { }
-//      java -cp "$CP" -server -Xmx1000M bpt.CmdRewriteIndex "$@"  else if ( srcIndex.equals("prefixIdx") )
-//        {}
-//        else if ( srcIndex.equals("prefix2id") )
-//        {}
-        else
-        {
-            System.err.printf("Can't determine record size for %s\n",indexName) ;
-            return ;
-        }
-        
-        RecordFactory recordFactory = null ;
-        BPlusTreeParams bptParams = null ;
-        BlockMgr blkMgrNodes ;
-        BlockMgr blkMgrRecords ;
-        int blockSize = SystemTDB.BlockSize ;
-        
-        RangeIndex rangeIndex = SetupIndex.makeRangeIndex(srcLoc, indexName, blockSize, dftKeyLength, dftValueLength, readCacheSize, writeCacheSize) ;
-        BPlusTree bpt = (BPlusTree)rangeIndex ;
-        bptParams = bpt.getParams() ;
-        recordFactory = bpt.getRecordFactory() ;
-
-        int blockSizeNodes = blockSize ;
-        int blockSizeRecords = blockSize ;
-
-        blkMgrNodes = BlockMgrFactory.create(destination, Names.bptExtTree, blockSizeNodes, readCacheSize, writeCacheSize) ;
-        blkMgrRecords = BlockMgrFactory.create(destination, Names.bptExtRecords, blockSizeRecords, readCacheSize, writeCacheSize) ;
-
-        Iterator<Record>  iterator = bpt.iterator() ;
-            
-//            // Fakery.
-//            blkMgrNodes = BlockMgrFactory.create(destination, Names.bptExt1, blockSize, readCacheSize, writeCacheSize) ;
-//            blkMgrRecords = BlockMgrFactory.create(destination, Names.bptExt2, blockSize, readCacheSize, writeCacheSize) ;
-//            recordFactory = new RecordFactory(dftKeyLength, dftValueLength) ;
-//            bptParams = new BPlusTreeParams(3, recordFactory) ;
-//            List<Record> data = TestBPlusTreeRewriter.createData(10, recordFactory) ;
-//            iterator = data.iterator() ;
-        
-        //System.out.println("Rewrite: "+srcLoc+" "+indexName+" --> "+destination) ;
-        
-        BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(iterator, 
-                                                             bptParams, recordFactory,
-                                                             blkMgrNodes, blkMgrRecords) ;
-        if ( bpt2 == null )
-            return ;
-//        
-//        Iterator<Record> iter = bpt2.iterator() ;
-//        for ( ; iter.hasNext() ; )
-//        {
-//            Record r = iter.next() ;
-//            System.out.println(r) ;
-//        }
-
-        bpt2.close() ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/jena-cmds/src/main/java/tdb/bulkloader2/CmdIndexBuild.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/bulkloader2/CmdIndexBuild.java b/jena-cmds/src/main/java/tdb/bulkloader2/CmdIndexBuild.java
new file mode 100644
index 0000000..57c2de4
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/bulkloader2/CmdIndexBuild.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 tdb.bulkloader2;
+
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.system.JenaSystem ;
+import org.apache.jena.tdb.store.bulkloader2.ProcIndexBuild ;
+
+public class CmdIndexBuild {
+    static {
+        LogCtl.setLog4j();
+        JenaSystem.init();
+    }
+    
+    public static void main(String... argv) {
+        // DATA IN S/P/O columns but sorted by index order.
+
+        if ( argv.length != 3 ) {
+            System.err.println("Usage: Location Index dataFile");
+            System.exit(1);
+        }
+
+        String locationStr = argv[0];
+        String indexName = argv[1];
+        
+//        if ( ! Arrays.asList(Names.tripleIndexes).contains(indexName) &&
+//            ! Arrays.asList(Names.quadIndexes).contains(indexName) )
+//        {
+//            System.err.println("Index name not recognized: "+indexName) ;
+//            System.exit(1) ;
+//        }
+            
+        String dataFile = argv[2] ;
+        ProcIndexBuild.exec(locationStr, indexName, dataFile);
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/jena-cmds/src/main/java/tdb/bulkloader2/CmdIndexCopy.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/bulkloader2/CmdIndexCopy.java b/jena-cmds/src/main/java/tdb/bulkloader2/CmdIndexCopy.java
new file mode 100644
index 0000000..9ea62b8d
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/bulkloader2/CmdIndexCopy.java
@@ -0,0 +1,45 @@
+/*
+ * 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 tdb.bulkloader2;
+
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.system.JenaSystem ;
+import org.apache.jena.tdb.store.bulkloader2.ProcIndexCopy ;
+
+public class CmdIndexCopy 
+{
+    static {
+        LogCtl.setLog4j();
+        JenaSystem.init();
+    }
+
+    public static void main(String... argv) {
+        if ( argv.length != 4 ) {
+            System.err.println("Usage: Location1 Index1 Location2 Index2");
+            System.exit(1);
+        }
+
+        String locationStr1 = argv[0] ;
+        String indexName1 = argv[1] ;
+        String locationStr2 = argv[2] ;
+        String indexName2 = argv[3] ;
+        ProcIndexCopy.exec(locationStr1, indexName1, locationStr2, indexName2);
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/jena-cmds/src/main/java/tdb/bulkloader2/CmdNodeTableBuilder.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/bulkloader2/CmdNodeTableBuilder.java b/jena-cmds/src/main/java/tdb/bulkloader2/CmdNodeTableBuilder.java
new file mode 100644
index 0000000..bb56b70
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/bulkloader2/CmdNodeTableBuilder.java
@@ -0,0 +1,125 @@
+/*
+ * 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 tdb.bulkloader2;
+
+import java.util.Arrays ;
+import java.util.List ;
+import java.util.Objects ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral;
+import org.apache.jena.atlas.lib.FileOps ;
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFLanguages ;
+import org.apache.jena.system.JenaSystem ;
+import org.apache.jena.tdb.base.file.Location ;
+import org.apache.jena.tdb.setup.DatasetBuilderStd ;
+import org.apache.jena.tdb.store.bulkloader2.ProcNodeTableBuilder ;
+import tdb.cmdline.CmdTDB ;
+
+/** Build node table - write triples/quads as text file */
+public class CmdNodeTableBuilder extends CmdGeneral
+{
+    static {
+        LogCtl.setLog4j();
+        JenaSystem.init();
+    }
+
+    private static ArgDecl argLocation   = new ArgDecl(ArgDecl.HasValue, "loc", "location");
+    private static ArgDecl argTriplesOut = new ArgDecl(ArgDecl.HasValue, "triples");
+    private static ArgDecl argQuadsOut   = new ArgDecl(ArgDecl.HasValue, "quads");
+    private static ArgDecl argNoStats    = new ArgDecl(ArgDecl.NoValue, "nostats");
+
+    private String         locationString;
+    private String         dataFileTriples;
+    private String         dataFileQuads;
+    private List<String>   datafiles;
+    private Location       location;
+    private boolean        collectStats  = true;
+
+    public static void main(String... argv) {
+        CmdTDB.init();
+        DatasetBuilderStd.setOptimizerWarningFlag(false);
+        new CmdNodeTableBuilder(argv).mainRun();
+    }
+
+    public CmdNodeTableBuilder(String... argv) {
+        super(argv);
+        super.add(argLocation, "--loc", "Location");
+        super.add(argTriplesOut, "--triples", "Output file for triples");
+        super.add(argQuadsOut, "--quads", "Output file for quads");
+        super.add(argNoStats, "--nostats", "Don't collect stats");
+    }
+        
+    @Override
+    protected void processModulesAndArgs() {
+        if ( !super.contains(argLocation) ) throw new CmdException("Required: --loc DIR") ;
+//        if ( !super.contains(argTriplesOut) ) throw new CmdException("Required: --triples FILE") ;
+//        if ( !super.contains(argQuadsOut) ) throw new CmdException("Required: --quads FILE") ;
+        
+        locationString   = super.getValue(argLocation) ;
+        location = Location.create(locationString) ;
+
+        dataFileTriples  = super.getValue(argTriplesOut) ;
+        if ( dataFileTriples == null )
+            dataFileTriples = location.getPath("triples", "tmp") ;
+        
+        dataFileQuads    = super.getValue(argQuadsOut) ;
+        if ( dataFileQuads == null )
+            dataFileQuads = location.getPath("quads", "tmp") ;
+        
+        if ( Objects.equals(dataFileTriples, dataFileQuads) )
+            cmdError("Triples and Quads work files are the same") ;
+        
+        if ( super.contains(argNoStats) )
+            collectStats = false ;
+        
+        //datafiles  = getPositionalOrStdin() ;
+        datafiles  = getPositional() ;
+        if ( datafiles.isEmpty() )
+            datafiles = Arrays.asList("-") ;
+        
+        // ---- Checking.
+        for ( String filename : datafiles ) {
+            Lang lang = RDFLanguages.filenameToLang(filename, RDFLanguages.NQUADS);
+            if ( lang == null )
+                               // Does not happen due to default above.
+                               cmdError("File suffix not recognized: " + filename);
+            if ( !filename.equals("-") && !FileOps.exists(filename) )
+                cmdError("File does not exist: " + filename);
+        }
+    }
+
+    @Override
+    protected void exec() {
+        ProcNodeTableBuilder.exec(location, dataFileTriples, dataFileQuads, datafiles, collectStats);
+    }
+
+    @Override
+    protected String getSummary() {
+        return getCommandName() + " --loc=DIR [--triples=tmpFile1] [--quads=tmpFile2] FILE ...";
+    }
+
+    @Override
+    protected String getCommandName() {
+        return this.getClass().getName();
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/jena-cmds/src/main/java/tdb/bulkloader2/CmdRewriteIndex.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/tdb/bulkloader2/CmdRewriteIndex.java b/jena-cmds/src/main/java/tdb/bulkloader2/CmdRewriteIndex.java
new file mode 100644
index 0000000..43bc29c
--- /dev/null
+++ b/jena-cmds/src/main/java/tdb/bulkloader2/CmdRewriteIndex.java
@@ -0,0 +1,61 @@
+/*
+ * 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 tdb.bulkloader2;
+
+import org.apache.jena.atlas.lib.FileOps ;
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.system.JenaSystem ;
+import org.apache.jena.tdb.base.file.Location ;
+import org.apache.jena.tdb.store.bulkloader2.ProcRewriteIndex ;
+import org.apache.jena.tdb.sys.Names ;
+
+/** Rewrite one index */
+public class CmdRewriteIndex
+{
+    static {
+        LogCtl.setLog4j();
+        JenaSystem.init();
+    }
+
+    public static void main(String...argv)
+    {
+        // Usage: srcLocation dstLocation indexName
+        if ( argv.length != 3 ) {
+            System.err.println("Usage: " + Lib.classShortName(CmdRewriteIndex.class) + " SrcLocation DstLocation IndexName");
+            System.exit(1);
+        }
+
+        Location srcLoc = Location.create(argv[0]);
+        Location dstLoc = Location.create(argv[1]);
+        String indexName = argv[2];
+
+        if ( !FileOps.exists(argv[1]) ) {
+            System.err.println("Destination directory does not exist");
+            System.exit(1);
+        }
+
+        if ( FileOps.exists(dstLoc.getPath(indexName, Names.bptExtTree)) ) {
+            System.err.println("Destination contains an index of that name");
+            System.exit(1);
+        }
+
+        ProcRewriteIndex.exec(srcLoc, dstLoc, indexName);
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/jena-fuseki2/jena-fuseki-core/pom.xml
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/pom.xml b/jena-fuseki2/jena-fuseki-core/pom.xml
index ba8314b..e500114 100644
--- a/jena-fuseki2/jena-fuseki-core/pom.xml
+++ b/jena-fuseki2/jena-fuseki-core/pom.xml
@@ -48,21 +48,20 @@
 
     <dependency>
       <groupId>org.apache.jena</groupId>
-      <artifactId>jena-arq</artifactId>
+      <artifactId>apache-jena-libs</artifactId>
       <version>3.1.0-SNAPSHOT</version>
+      <type>pom</type>
     </dependency>
 
-    <dependency>
+      <dependency>
       <groupId>org.apache.jena</groupId>
-      <artifactId>jena-arq</artifactId>
+      <artifactId>jena-cmds</artifactId>
       <version>3.1.0-SNAPSHOT</version>
-      <classifier>tests</classifier>
-      <scope>test</scope>
     </dependency>
 
     <dependency>
       <groupId>org.apache.jena</groupId>
-      <artifactId>jena-base</artifactId>
+      <artifactId>jena-arq</artifactId>
       <version>3.1.0-SNAPSHOT</version>
       <classifier>tests</classifier>
       <scope>test</scope>
@@ -70,8 +69,10 @@
 
     <dependency>
       <groupId>org.apache.jena</groupId>
-      <artifactId>jena-tdb</artifactId>
+      <artifactId>jena-base</artifactId>
       <version>3.1.0-SNAPSHOT</version>
+      <classifier>tests</classifier>
+      <scope>test</scope>
     </dependency>
 
     <dependency>
@@ -218,7 +219,7 @@
       </plugin>
 
       <plugin>
-	<!-- Include the test jar for mebedded usein testing (eg. jena-jdbc-driver-remote) -->
+	    <!-- Include the test jar for mebedded usein testing (eg. jena-jdbc-driver-remote) -->
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-jar-plugin</artifactId>
         <executions>

http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/jena-maven-tools/pom.xml
----------------------------------------------------------------------
diff --git a/jena-maven-tools/pom.xml b/jena-maven-tools/pom.xml
index fb32f94..26b8bd7 100644
--- a/jena-maven-tools/pom.xml
+++ b/jena-maven-tools/pom.xml
@@ -187,7 +187,7 @@ limitations under the License.
     </dependency>
     <dependency>
       <groupId>org.apache.jena</groupId>
-      <artifactId>jena-core</artifactId>
+      <artifactId>jena-cmds</artifactId>
       <version>3.1.0-SNAPSHOT</version>
     </dependency>
     <dependency>

http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexBuild.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexBuild.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexBuild.java
deleted file mode 100644
index e5a8f6e..0000000
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexBuild.java
+++ /dev/null
@@ -1,126 +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.tdb.store.bulkloader2;
-
-import java.io.InputStream ;
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.AtlasException ;
-import org.apache.jena.atlas.io.IO ;
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.apache.jena.tdb.base.block.BlockMgr ;
-import org.apache.jena.tdb.base.block.BlockMgrFactory ;
-import org.apache.jena.tdb.base.file.FileSet ;
-import org.apache.jena.tdb.base.file.Location ;
-import org.apache.jena.tdb.base.record.Record ;
-import org.apache.jena.tdb.base.record.RecordFactory ;
-import org.apache.jena.tdb.index.bplustree.BPlusTree ;
-import org.apache.jena.tdb.index.bplustree.BPlusTreeParams ;
-import org.apache.jena.tdb.index.bplustree.BPlusTreeRewriter ;
-import org.apache.jena.tdb.lib.ColumnMap ;
-import org.apache.jena.tdb.sys.Names ;
-import org.apache.jena.tdb.sys.SystemTDB ;
-
-/** From a file of records, build a (packed) index */ 
-public class CmdIndexBuild
-{
-    static { LogCtl.setLog4j() ; }
-    
-    public static void main(String...argv)
-    {
-        // DATA IN S/P/O columns but sorted by index order.
-
-        if ( argv.length != 3 ) {
-            System.err.println("Usage: Location Index dataFile");
-            System.exit(1);
-        }
-
-        String locationStr = argv[0];
-        String indexName = argv[1];
-        
-//        if ( ! Arrays.asList(Names.tripleIndexes).contains(indexName) &&
-//            ! Arrays.asList(Names.quadIndexes).contains(indexName) )
-//        {
-//            System.err.println("Index name not recognized: "+indexName) ;
-//            System.exit(1) ;
-//        }
-            
-        String dataFile = argv[2] ;
-        
-        // Argument processing
-        
-        Location location = Location.create(locationStr) ;
-        
-        //InputStream input = System.in ;
-        InputStream input = IO.openFile(dataFile) ;
-        
-        int keyLength = SystemTDB.SizeOfNodeId * indexName.length() ;
-        int valueLength = 0 ;
-        
-        // The name is the order.
-        String primary = indexName ;  
-        
-        // Scope for optimization:
-        // Null column map => no churn.
-        // Do record -> record copy, not Tuple, Tuple copy.
-
-        String primaryOrder;
-        int dftKeyLength;
-        int dftValueLength;
-        int tupleLength = indexName.length();
-
-        if ( tupleLength == 3 ) {
-            primaryOrder = Names.primaryIndexTriples;
-            dftKeyLength = SystemTDB.LenIndexTripleRecord;
-            dftValueLength = 0;
-        } else if ( tupleLength == 4 ) {
-            primaryOrder = Names.primaryIndexQuads;
-            dftKeyLength = SystemTDB.LenIndexQuadRecord;
-            dftValueLength = 0;
-        } else {
-            throw new AtlasException("Index name: " + indexName);
-        }
-
-        ColumnMap colMap = new ColumnMap(primaryOrder, indexName) ;
-
-        // -1? Write only.
-        // Also flush cache every so often => block writes (but not sequential so boring).
-        int readCacheSize = 10;
-        int writeCacheSize = 100;
-
-        int blockSize = SystemTDB.BlockSize;
-        RecordFactory recordFactory = new RecordFactory(dftKeyLength, dftValueLength);
-
-        int order = BPlusTreeParams.calcOrder(blockSize, recordFactory);
-        BPlusTreeParams bptParams = new BPlusTreeParams(order, recordFactory);
-
-        int blockSizeNodes = blockSize;
-        int blockSizeRecords = blockSize;
-
-        FileSet destination = new FileSet(location, indexName);
-
-        BlockMgr blkMgrNodes = BlockMgrFactory.create(destination, Names.bptExtTree, blockSizeNodes, readCacheSize, writeCacheSize);
-        BlockMgr blkMgrRecords = BlockMgrFactory.create(destination, Names.bptExtRecords, blockSizeRecords, readCacheSize, writeCacheSize);
-
-        int rowBlock = 1000;
-        Iterator<Record> iter = new RecordsFromInput(input, tupleLength, colMap, rowBlock);
-        BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(iter, bptParams, recordFactory, blkMgrNodes, blkMgrRecords);
-        bpt2.close();
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexCopy.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexCopy.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexCopy.java
deleted file mode 100644
index 14609d5..0000000
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/CmdIndexCopy.java
+++ /dev/null
@@ -1,115 +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.tdb.store.bulkloader2;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.lib.DateTimeUtils ;
-import org.apache.jena.atlas.lib.tuple.Tuple ;
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.apache.jena.atlas.logging.ProgressLogger ;
-import org.apache.jena.tdb.base.file.Location ;
-import org.apache.jena.tdb.setup.Build ;
-import org.apache.jena.tdb.store.NodeId ;
-import org.apache.jena.tdb.store.tupletable.TupleIndex ;
-import org.apache.jena.tdb.sys.SystemTDB ;
-import org.slf4j.Logger ;
-import org.slf4j.LoggerFactory ;
-
-/** Copy one index to another, probably with a different key order */
-public class CmdIndexCopy
-{
-    static { LogCtl.setLog4j() ; }
-    private static Logger log = LoggerFactory.getLogger(CmdIndexCopy.class) ;
-    
-    static long tickQuantum = 100*1000 ;
-    static int superTick = 10 ;
-    
-    public static void main(String...argv)
-    {
-        // Ideas:
-        // Copy to buffer, sort, write in sequential clumps.
-        // Profile code for hotspots
-        
-        // Maybe be worth opening the data file (the leaves) as a regular, 
-        // non-memory mapped file as we read it through once, in natural order,
-        // and it may be laid out in increasing block order on-disk, e.g. repacked
-        // and in increasing order with occassional oddities if SPO from the bulk loader.
-
-        if ( argv.length != 4 ) {
-            System.err.println("Usage: Location1 Index1 Location2 Index2");
-            System.exit(1);
-        }
-        
-        String locationStr1 = argv[0] ;
-        String indexName1 = argv[1] ;
-        String locationStr2 = argv[2] ;
-        String indexName2 = argv[3] ;
-        
-        // Argument processing
-        
-        Location location1 = Location.create(locationStr1) ;
-        Location location2 = Location.create(locationStr2) ;
-        
-        int keyLength = SystemTDB.SizeOfNodeId * indexName1.length() ;
-        int valueLength = 0 ;
-        
-        // The name is the order.
-        String primary = "SPO" ;
-        
-        String indexOrder = indexName2 ;
-        String label = indexName1+" => "+indexName2 ;
-        
-        TupleIndex index1 = Build.openTupleIndex(location1, indexName1, primary, indexName1, 10, 10, keyLength, valueLength) ;      
-        TupleIndex index2 = Build.openTupleIndex(location2, indexName2, primary, indexOrder, 10, 10, keyLength, valueLength) ;
-        tupleIndexCopy(index1, index2, label) ;
-        index1.close() ;
-        index2.close() ;
-    }
-
-    private static void tupleIndexCopy(TupleIndex index1, TupleIndex index2, String label) {
-        ProgressLogger monitor = new ProgressLogger(log, label, tickQuantum, superTick);
-        monitor.start();
-
-        Iterator<Tuple<NodeId>> iter1 = index1.all();
-
-        long counter = 0;
-        for ( ; iter1.hasNext() ; ) {
-            counter++;
-            Tuple<NodeId> tuple = iter1.next();
-            index2.add(tuple);
-            monitor.tick();
-        }
-
-        index2.sync();
-        long time = monitor.finish();
-        float elapsedSecs = time / 1000F;
-
-        float rate = (elapsedSecs != 0) ? counter / elapsedSecs : 0;
-
-        print("Total: %,d records : %,.2f seconds : %,.2f records/sec [%s]", counter, elapsedSecs, rate, DateTimeUtils.nowAsString());
-    }
-
-    static private void print(String fmt, Object... args) {
-        if ( log != null && log.isInfoEnabled() ) {
-            String str = String.format(fmt, args);
-            log.info(str);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcIndexBuild.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcIndexBuild.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcIndexBuild.java
new file mode 100644
index 0000000..1a51313
--- /dev/null
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcIndexBuild.java
@@ -0,0 +1,104 @@
+/*
+ * 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.tdb.store.bulkloader2;
+
+import java.io.InputStream ;
+import java.util.Iterator ;
+
+import org.apache.jena.atlas.AtlasException ;
+import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.tdb.base.block.BlockMgr ;
+import org.apache.jena.tdb.base.block.BlockMgrFactory ;
+import org.apache.jena.tdb.base.file.FileSet ;
+import org.apache.jena.tdb.base.file.Location ;
+import org.apache.jena.tdb.base.record.Record ;
+import org.apache.jena.tdb.base.record.RecordFactory ;
+import org.apache.jena.tdb.index.bplustree.BPlusTree ;
+import org.apache.jena.tdb.index.bplustree.BPlusTreeParams ;
+import org.apache.jena.tdb.index.bplustree.BPlusTreeRewriter ;
+import org.apache.jena.tdb.lib.ColumnMap ;
+import org.apache.jena.tdb.sys.Names ;
+import org.apache.jena.tdb.sys.SystemTDB ;
+
+/** From a file of records, build a (packed) index */ 
+public class ProcIndexBuild
+{
+    public static void exec(String locationStr, String indexName, String dataFile) {
+        
+        // Argument processing
+        
+        Location location = Location.create(locationStr) ;
+        
+        //InputStream input = System.in ;
+        InputStream input = IO.openFile(dataFile) ;
+        
+        int keyLength = SystemTDB.SizeOfNodeId * indexName.length() ;
+        int valueLength = 0 ;
+        
+        // The name is the order.
+        String primary = indexName ;  
+        
+        // Scope for optimization:
+        // Null column map => no churn.
+        // Do record -> record copy, not Tuple, Tuple copy.
+
+        String primaryOrder;
+        int dftKeyLength;
+        int dftValueLength;
+        int tupleLength = indexName.length();
+
+        if ( tupleLength == 3 ) {
+            primaryOrder = Names.primaryIndexTriples;
+            dftKeyLength = SystemTDB.LenIndexTripleRecord;
+            dftValueLength = 0;
+        } else if ( tupleLength == 4 ) {
+            primaryOrder = Names.primaryIndexQuads;
+            dftKeyLength = SystemTDB.LenIndexQuadRecord;
+            dftValueLength = 0;
+        } else {
+            throw new AtlasException("Index name: " + indexName);
+        }
+
+        ColumnMap colMap = new ColumnMap(primaryOrder, indexName) ;
+
+        // -1? Write only.
+        // Also flush cache every so often => block writes (but not sequential so boring).
+        int readCacheSize = 10;
+        int writeCacheSize = 100;
+
+        int blockSize = SystemTDB.BlockSize;
+        RecordFactory recordFactory = new RecordFactory(dftKeyLength, dftValueLength);
+
+        int order = BPlusTreeParams.calcOrder(blockSize, recordFactory);
+        BPlusTreeParams bptParams = new BPlusTreeParams(order, recordFactory);
+
+        int blockSizeNodes = blockSize;
+        int blockSizeRecords = blockSize;
+
+        FileSet destination = new FileSet(location, indexName);
+
+        BlockMgr blkMgrNodes = BlockMgrFactory.create(destination, Names.bptExtTree, blockSizeNodes, readCacheSize, writeCacheSize);
+        BlockMgr blkMgrRecords = BlockMgrFactory.create(destination, Names.bptExtRecords, blockSizeRecords, readCacheSize, writeCacheSize);
+
+        int rowBlock = 1000;
+        Iterator<Record> iter = new RecordsFromInput(input, tupleLength, colMap, rowBlock);
+        BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(iter, bptParams, recordFactory, blkMgrNodes, blkMgrRecords);
+        bpt2.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcIndexCopy.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcIndexCopy.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcIndexCopy.java
new file mode 100644
index 0000000..831dd3c
--- /dev/null
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcIndexCopy.java
@@ -0,0 +1,102 @@
+/*
+ * 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.tdb.store.bulkloader2;
+
+import java.util.Iterator ;
+
+import org.apache.jena.atlas.lib.DateTimeUtils ;
+import org.apache.jena.atlas.lib.tuple.Tuple ;
+import org.apache.jena.atlas.logging.ProgressLogger ;
+import org.apache.jena.tdb.base.file.Location ;
+import org.apache.jena.tdb.setup.Build ;
+import org.apache.jena.tdb.store.NodeId ;
+import org.apache.jena.tdb.store.tupletable.TupleIndex ;
+import org.apache.jena.tdb.sys.SystemTDB ;
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
+
+/** Copy one index to another, probably with a different key order */
+public class ProcIndexCopy
+{
+    private static Logger log = LoggerFactory.getLogger(ProcIndexCopy.class) ;
+    
+    static long tickQuantum = 100*1000 ;
+    static int superTick = 10 ;
+    
+    // Ideas:
+    // Copy to buffer, sort, write in sequential clumps.
+    // Profile code for hotspots
+
+    // Maybe be worth opening the data file (the leaves) as a regular, 
+    // non-memory mapped file as we read it through once, in natural order,
+    // and it may be laid out in increasing block order on-disk, e.g. repacked
+    // and in increasing order with occassional oddities if SPO from the bulk loader.
+
+    public static void exec(String locationStr1, String indexName1, String locationStr2, String indexName2) {
+        // Argument processing
+        
+        Location location1 = Location.create(locationStr1) ;
+        Location location2 = Location.create(locationStr2) ;
+        
+        int keyLength = SystemTDB.SizeOfNodeId * indexName1.length() ;
+        int valueLength = 0 ;
+        
+        // The name is the order.
+        String primary = "SPO" ;
+        
+        String indexOrder = indexName2 ;
+        String label = indexName1+" => "+indexName2 ;
+        
+        TupleIndex index1 = Build.openTupleIndex(location1, indexName1, primary, indexName1, 10, 10, keyLength, valueLength) ;      
+        TupleIndex index2 = Build.openTupleIndex(location2, indexName2, primary, indexOrder, 10, 10, keyLength, valueLength) ;
+        tupleIndexCopy(index1, index2, label) ;
+        index1.close() ;
+        index2.close() ;
+    }
+
+    private static void tupleIndexCopy(TupleIndex index1, TupleIndex index2, String label) {
+        ProgressLogger monitor = new ProgressLogger(log, label, tickQuantum, superTick);
+        monitor.start();
+
+        Iterator<Tuple<NodeId>> iter1 = index1.all();
+
+        long counter = 0;
+        for ( ; iter1.hasNext() ; ) {
+            counter++;
+            Tuple<NodeId> tuple = iter1.next();
+            index2.add(tuple);
+            monitor.tick();
+        }
+
+        index2.sync();
+        long time = monitor.finish();
+        float elapsedSecs = time / 1000F;
+
+        float rate = (elapsedSecs != 0) ? counter / elapsedSecs : 0;
+
+        print("Total: %,d records : %,.2f seconds : %,.2f records/sec [%s]", counter, elapsedSecs, rate, DateTimeUtils.nowAsString());
+    }
+
+    static private void print(String fmt, Object... args) {
+        if ( log != null && log.isInfoEnabled() ) {
+            String str = String.format(fmt, args);
+            log.info(str);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcNodeTableBuilder.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcNodeTableBuilder.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcNodeTableBuilder.java
index 816d27f..d906651 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcNodeTableBuilder.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcNodeTableBuilder.java
@@ -48,11 +48,9 @@ import org.slf4j.Logger ;
 public class ProcNodeTableBuilder {
     private static Logger cmdLog = TDB.logLoader ;
     
-    public static void execInner(Location location,
-                                    String dataFileTriples,
-                                    String dataFileQuads,
-                                    List<String> datafiles,
-                                    boolean collectStats) {
+    public static void exec(Location location,
+                            String dataFileTriples, String dataFileQuads,
+                            List<String> datafiles, boolean collectStats) {
         // This formats the location correctly.
         // But we're not really interested in it all.
         DatasetGraphTDB dsg = DatasetBuilderStd.create(location) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcRewriteIndex.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcRewriteIndex.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcRewriteIndex.java
new file mode 100644
index 0000000..2da82a6
--- /dev/null
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcRewriteIndex.java
@@ -0,0 +1,102 @@
+/*
+ * 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.tdb.store.bulkloader2;
+
+import java.util.Iterator ;
+
+import org.apache.jena.tdb.base.block.BlockMgr ;
+import org.apache.jena.tdb.base.block.BlockMgrFactory ;
+import org.apache.jena.tdb.base.file.FileSet ;
+import org.apache.jena.tdb.base.file.Location ;
+import org.apache.jena.tdb.base.record.Record ;
+import org.apache.jena.tdb.base.record.RecordFactory ;
+import org.apache.jena.tdb.index.RangeIndex ;
+import org.apache.jena.tdb.index.SetupIndex ;
+import org.apache.jena.tdb.index.bplustree.BPlusTree ;
+import org.apache.jena.tdb.index.bplustree.BPlusTreeParams ;
+import org.apache.jena.tdb.index.bplustree.BPlusTreeRewriter ;
+import org.apache.jena.tdb.sys.Names ;
+import org.apache.jena.tdb.sys.SystemTDB ;
+
+public class ProcRewriteIndex {
+    public static void exec(Location srcLoc, Location dstLoc, String indexName) 
+    {
+        FileSet destination = new FileSet(dstLoc, indexName) ;
+        int readCacheSize = 0 ;
+        int writeCacheSize = -1 ;
+        
+        int dftKeyLength ;
+        int dftValueLength ;
+        
+        if ( indexName.length() == 3 ) {
+            dftKeyLength = SystemTDB.LenIndexTripleRecord;
+            dftValueLength = 0;
+        } else if ( indexName.length() == 4 ) {
+            dftKeyLength = SystemTDB.LenIndexQuadRecord;
+            dftValueLength = 0;
+        } else {
+            System.err.printf("Can't determine record size for %s\n", indexName);
+            return;
+        }
+
+        RecordFactory recordFactory = null ;
+        BPlusTreeParams bptParams = null ;
+        BlockMgr blkMgrNodes ;
+        BlockMgr blkMgrRecords ;
+        int blockSize = SystemTDB.BlockSize ;
+        
+        RangeIndex rangeIndex = SetupIndex.makeRangeIndex(srcLoc, indexName, blockSize, dftKeyLength, dftValueLength, readCacheSize, writeCacheSize) ;
+        BPlusTree bpt = (BPlusTree)rangeIndex ;
+        bptParams = bpt.getParams() ;
+        recordFactory = bpt.getRecordFactory() ;
+
+        int blockSizeNodes = blockSize ;
+        int blockSizeRecords = blockSize ;
+
+        blkMgrNodes = BlockMgrFactory.create(destination, Names.bptExtTree, blockSizeNodes, readCacheSize, writeCacheSize) ;
+        blkMgrRecords = BlockMgrFactory.create(destination, Names.bptExtRecords, blockSizeRecords, readCacheSize, writeCacheSize) ;
+
+        Iterator<Record>  iterator = bpt.iterator() ;
+            
+//            // Fakery.
+//            blkMgrNodes = BlockMgrFactory.create(destination, Names.bptExt1, blockSize, readCacheSize, writeCacheSize) ;
+//            blkMgrRecords = BlockMgrFactory.create(destination, Names.bptExt2, blockSize, readCacheSize, writeCacheSize) ;
+//            recordFactory = new RecordFactory(dftKeyLength, dftValueLength) ;
+//            bptParams = new BPlusTreeParams(3, recordFactory) ;
+//            List<Record> data = TestBPlusTreeRewriter.createData(10, recordFactory) ;
+//            iterator = data.iterator() ;
+        
+        //System.out.println("Rewrite: "+srcLoc+" "+indexName+" --> "+destination) ;
+        
+        BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(iterator, 
+                                                             bptParams, recordFactory,
+                                                             blkMgrNodes, blkMgrRecords) ;
+        if ( bpt2 == null )
+            return ;
+//        
+//        Iterator<Record> iter = bpt2.iterator() ;
+//        for ( ; iter.hasNext() ; )
+//        {
+//            Record r = iter.next() ;
+//            System.out.println(r) ;
+//        }
+
+        bpt2.close() ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/cda5c7cd/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 1b2c7ad..dcc85fe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,7 +15,9 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" 
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
 
   <name>Apache Jena</name>
@@ -56,27 +58,28 @@
   <profiles>
     <profile>
       <!--
-        This is the dev profile, typically used locally with "mvn clean install".
-        It only builds the common modules and
-        does not build SDB nor the slow-to-test JDBC module.
+          This is the dev profile, typically used locally with 
+          "mvn clean install -Pdev".
+          It only builds the moduels shipped in apache-jena binaries.
       -->
       <id>dev</id>
       <!-- The maven artifacts of the basic modules -->
       <modules>
         <module>jena-parent</module>
-	<!-- <module>jena-shared-guava</module> -->
-	<!-- <module>jena-iri</module> -->
-	<module>jena-base</module>
+	    <!-- <module>jena-shared-guava</module> -->
+	    <!-- <module>jena-iri</module> -->
+	    <module>jena-base</module>
 
-	<module>jena-core</module>
+	    <module>jena-core</module>
         <module>jena-arq</module>
         <module>jena-tdb</module> 
-	<module>apache-jena-libs</module>
+	    <module>apache-jena-libs</module>
+        <module>jena-cmds</module>
 
         <!--<module>jena-fuseki1</module>-->
-	<module>jena-fuseki2</module>
+	    <module>jena-fuseki2</module>
 
-	<module>jena-permissions</module>
+	    <module>jena-permissions</module>
 
         <!-- Slow to build - exclude from dev build -->
         <!-- <module>jena-jdbc</module>           -->
@@ -84,14 +87,14 @@
         <!-- <module>apache-jena-libs</module>    -->
         <!-- <module>apache-jena</module>         -->
         <!-- <module>jena-elephas</module> -->
-	<!-- <module>jena-extras</module> -->
+	    <!-- <module>jena-extras</module> -->
       </modules>
     </profile>
 
     <profile>
       <!--
-        This is the complete profile, it builds everything including slow
-        building modules and the distribution packages.
+          This is the complete profile, it builds everything including slow
+          building modules and the distribution packages.
       -->
       <id>complete</id>
       <activation>
@@ -111,20 +114,22 @@
         <module>jena-arq</module>
         <module>jena-tdb</module>
         <module>apache-jena-libs</module>
+	    <module>jena-cmds</module>
 
         <module>jena-text</module>
         <module>jena-spatial</module>
         <module>jena-csv</module>
 
-	<module>jena-sdb</module>
+	    <module>jena-sdb</module>
 
         <module>jena-fuseki1</module>
         <module>jena-fuseki2</module>
-	<module>jena-permissions</module>
+	    <module>jena-permissions</module>
 
         <module>jena-jdbc</module>
         <module>jena-maven-tools</module>
         <module>jena-elephas</module>
+
         <module>apache-jena</module>
         <module>apache-jena-osgi</module>
 


[04/20] jena git commit: JENA-1108 : jena-cmds module

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcNodeTableBuilder.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcNodeTableBuilder.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcNodeTableBuilder.java
new file mode 100644
index 0000000..816d27f
--- /dev/null
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/store/bulkloader2/ProcNodeTableBuilder.java
@@ -0,0 +1,211 @@
+/*
+ * 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.tdb.store.bulkloader2;
+
+import java.io.FileNotFoundException ;
+import java.io.FileOutputStream ;
+import java.io.OutputStream ;
+import java.util.List ;
+
+import org.apache.jena.atlas.AtlasException ;
+import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.lib.DateTimeUtils ;
+import org.apache.jena.atlas.logging.ProgressLogger ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.riot.RDFDataMgr ;
+import org.apache.jena.sparql.core.Quad ;
+import org.apache.jena.tdb.TDB ;
+import org.apache.jena.tdb.base.file.Location ;
+import org.apache.jena.tdb.setup.DatasetBuilderStd ;
+import org.apache.jena.tdb.solver.stats.Stats ;
+import org.apache.jena.tdb.solver.stats.StatsCollectorNodeId ;
+import org.apache.jena.tdb.store.DatasetGraphTDB ;
+import org.apache.jena.tdb.store.NodeId ;
+import org.apache.jena.tdb.store.bulkloader.BulkLoader ;
+import org.apache.jena.tdb.store.bulkloader.BulkStreamRDF ;
+import org.apache.jena.tdb.store.nodetable.NodeTable ;
+import org.apache.jena.tdb.store.nodetupletable.NodeTupleTable ;
+import org.apache.jena.tdb.sys.Names ;
+import org.slf4j.Logger ;
+
+public class ProcNodeTableBuilder {
+    private static Logger cmdLog = TDB.logLoader ;
+    
+    public static void execInner(Location location,
+                                    String dataFileTriples,
+                                    String dataFileQuads,
+                                    List<String> datafiles,
+                                    boolean collectStats) {
+        // This formats the location correctly.
+        // But we're not really interested in it all.
+        DatasetGraphTDB dsg = DatasetBuilderStd.create(location) ;
+        
+        // so close indexes and the prefix table.
+        dsg.getTripleTable().getNodeTupleTable().getTupleTable().close();
+        dsg.getQuadTable().getNodeTupleTable().getTupleTable().close();
+        
+        ProgressLogger monitor = new ProgressLogger(cmdLog, "Data", BulkLoader.DataTickPoint, BulkLoader.superTick) ;
+        OutputStream outputTriples = null ;
+        OutputStream outputQuads = null ;
+        
+        try { 
+            outputTriples = new FileOutputStream(dataFileTriples) ; 
+            outputQuads = new FileOutputStream(dataFileQuads) ;
+        }
+        catch (FileNotFoundException e) { throw new AtlasException(e) ; }
+        
+        NodeTableBuilder sink = new NodeTableBuilder(dsg, monitor, outputTriples, outputQuads, collectStats) ; 
+        monitor.start() ;
+        sink.startBulk() ;
+        for( String filename : datafiles) {
+            if ( datafiles.size() > 0 )
+                cmdLog.info("Load: "+filename+" -- "+DateTimeUtils.nowAsString()) ;
+            RDFDataMgr.parse(sink, filename) ;
+        }
+        sink.finishBulk() ;
+        IO.close(outputTriples) ;
+        IO.close(outputQuads) ;
+        
+        // ---- Stats
+        
+        // See Stats class.
+        if ( ! location.isMem() && sink.getCollector() != null )
+            Stats.write(dsg.getLocation().getPath(Names.optStats), sink.getCollector().results()) ;
+        
+        // ---- Monitor
+        long time = monitor.finish() ;
+
+        long total = monitor.getTicks() ;
+        float elapsedSecs = time/1000F ;
+        float rate = (elapsedSecs!=0) ? total/elapsedSecs : 0 ;
+        String str =  String.format("Total: %,d tuples : %,.2f seconds : %,.2f tuples/sec [%s]", total, elapsedSecs, rate, DateTimeUtils.nowAsString()) ;
+        cmdLog.info(str) ;
+    }
+
+    static class NodeTableBuilder implements BulkStreamRDF
+    {
+        private DatasetGraphTDB dsg ;
+        private NodeTable nodeTable ;
+        private WriteRows writerTriples ;
+        private WriteRows writerQuads ;
+        private ProgressLogger monitor ;
+        private StatsCollectorNodeId stats ;
+
+        NodeTableBuilder(DatasetGraphTDB dsg, ProgressLogger monitor, OutputStream outputTriples, OutputStream outputQuads, boolean collectStats)
+        {
+            this.dsg = dsg ;
+            this.monitor = monitor ;
+            NodeTupleTable ntt = dsg.getTripleTable().getNodeTupleTable() ; 
+            this.nodeTable = ntt.getNodeTable() ;
+            this.writerTriples = new WriteRows(outputTriples, 3, 20000) ; 
+            this.writerQuads = new WriteRows(outputQuads, 4, 20000) ; 
+            if ( collectStats )
+                this.stats = new StatsCollectorNodeId(nodeTable) ;
+        }
+        
+        @Override
+        public void startBulk()
+        {}
+
+        @Override
+        public void start()
+        {}
+
+        @Override
+        public void finish()
+        {}
+
+        @Override
+        public void finishBulk()
+        {
+            writerTriples.flush() ;
+            writerQuads.flush() ;
+            nodeTable.sync() ;
+            dsg.getPrefixes().sync() ;
+        }
+            
+        @Override
+        public void triple(Triple triple)
+        {
+            Node s = triple.getSubject() ;
+            Node p = triple.getPredicate() ;
+            Node o = triple.getObject() ;
+            process(Quad.tripleInQuad,s,p,o);
+        }
+
+        @Override
+        public void quad(Quad quad)
+        {
+            Node s = quad.getSubject() ;
+            Node p = quad.getPredicate() ;
+            Node o = quad.getObject() ;
+            Node g = null ;
+            // Union graph?!
+            if ( ! quad.isTriple() && ! quad.isDefaultGraph() )
+                g = quad.getGraph() ;
+            process(g,s,p,o);
+        }
+
+       
+        private void process(Node g, Node s, Node p, Node o)
+        {
+            NodeId sId = nodeTable.getAllocateNodeId(s) ; 
+            NodeId pId = nodeTable.getAllocateNodeId(p) ;
+            NodeId oId = nodeTable.getAllocateNodeId(o) ;
+            
+            if ( g != null )
+            {
+                NodeId gId = nodeTable.getAllocateNodeId(g) ;
+                writerQuads.write(gId.getId()) ;
+                writerQuads.write(sId.getId()) ;
+                writerQuads.write(pId.getId()) ;
+                writerQuads.write(oId.getId()) ;
+                writerQuads.endOfRow() ;
+                if ( stats != null )
+                    stats.record(gId, sId, pId, oId) ;
+            }
+            else
+            {
+                writerTriples.write(sId.getId()) ;
+                writerTriples.write(pId.getId()) ;
+                writerTriples.write(oId.getId()) ;
+                writerTriples.endOfRow() ;
+                if ( stats != null )
+                    stats.record(null, sId, pId, oId) ;
+            }
+            monitor.tick() ;
+        }
+
+        public StatsCollectorNodeId getCollector() { return stats ; }
+
+        @Override
+        public void base(String base)
+        {}
+
+        @Override
+        public void prefix(String prefix, String iri)
+        {
+            dsg.getPrefixes().getPrefixMapping().setNsPrefix(prefix, iri) ;
+        }
+    }
+
+   
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/CmdRewriteIndex.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/CmdRewriteIndex.java b/jena-tdb/src/main/java/tdb/CmdRewriteIndex.java
deleted file mode 100644
index 0c4a6fa..0000000
--- a/jena-tdb/src/main/java/tdb/CmdRewriteIndex.java
+++ /dev/null
@@ -1,147 +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 tdb;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.lib.FileOps ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.tdb.base.block.BlockMgr ;
-import org.apache.jena.tdb.base.block.BlockMgrFactory ;
-import org.apache.jena.tdb.base.file.FileSet ;
-import org.apache.jena.tdb.base.file.Location ;
-import org.apache.jena.tdb.base.record.Record ;
-import org.apache.jena.tdb.base.record.RecordFactory ;
-import org.apache.jena.tdb.index.RangeIndex ;
-import org.apache.jena.tdb.index.SetupIndex ;
-import org.apache.jena.tdb.index.bplustree.BPlusTree ;
-import org.apache.jena.tdb.index.bplustree.BPlusTreeParams ;
-import org.apache.jena.tdb.index.bplustree.BPlusTreeRewriter ;
-import org.apache.jena.tdb.sys.Names ;
-import org.apache.jena.tdb.sys.SystemTDB ;
-
-/** Rewrite one index */
-public class CmdRewriteIndex
-{
-    public static void main(String...argv)
-    {
-        // Usage: srcLocation dstLocation indexName
-        if ( argv.length != 3 )
-        {
-            System.err.println("Usage: "+Lib.classShortName(CmdRewriteIndex.class)+" SrcLocation DstLocation IndexName") ;
-            System.exit(1) ;
-        }
-        
-        Location srcLoc = Location.create(argv[0]) ;
-        Location dstLoc = Location.create(argv[1]) ;
-        String indexName = argv[2] ;
-        
-        if ( ! FileOps.exists(argv[1]) )
-        {
-            System.err.println("Destination directory does not exist") ;
-            System.exit(1) ;
-        }
-        
-        if ( FileOps.exists(dstLoc.getPath(indexName, Names.bptExtTree)) )
-        {
-            System.err.println("Destination contains an index of that name") ;
-            System.exit(1) ;
-        }
-        
-        // To current directory ....
-        FileSet destination = new FileSet(dstLoc, indexName) ;
-        // Check existance
-        
-//        FileOps.deleteSilent(destination.filename(Names.bptExt1)) ;
-//        FileOps.deleteSilent(destination.filename(Names.bptExt2)) ;
-        //FileSet destination = new FileSet(Location.mem(), destIndex) ;
-        
-        int readCacheSize = 0 ;
-        int writeCacheSize = -1 ;
-        
-        int dftKeyLength ;
-        int dftValueLength ;
-        
-        if ( indexName.length() == 3 )
-        {
-            dftKeyLength = SystemTDB.LenIndexTripleRecord ;
-            dftValueLength = 0 ;
-        }
-        else if ( indexName.length() == 4 )
-        {
-            dftKeyLength = SystemTDB.LenIndexQuadRecord ;
-            dftValueLength = 0 ;
-        }
-//        else if ( srcIndex.equals("node2id") )
-//        { }
-//      java -cp "$CP" -server -Xmx1000M bpt.CmdRewriteIndex "$@"  else if ( srcIndex.equals("prefixIdx") )
-//        {}
-//        else if ( srcIndex.equals("prefix2id") )
-//        {}
-        else
-        {
-            System.err.printf("Can't determine record size for %s\n",indexName) ;
-            return ;
-        }
-        
-        RecordFactory recordFactory = null ;
-        BPlusTreeParams bptParams = null ;
-        BlockMgr blkMgrNodes ;
-        BlockMgr blkMgrRecords ;
-        int blockSize = SystemTDB.BlockSize ;
-        
-        RangeIndex rangeIndex = SetupIndex.makeRangeIndex(srcLoc, indexName, blockSize, dftKeyLength, dftValueLength, readCacheSize, writeCacheSize) ;
-        BPlusTree bpt = (BPlusTree)rangeIndex ;
-        bptParams = bpt.getParams() ;
-        recordFactory = bpt.getRecordFactory() ;
-
-        int blockSizeNodes = blockSize ;
-        int blockSizeRecords = blockSize ;
-
-        blkMgrNodes = BlockMgrFactory.create(destination, Names.bptExtTree, blockSizeNodes, readCacheSize, writeCacheSize) ;
-        blkMgrRecords = BlockMgrFactory.create(destination, Names.bptExtRecords, blockSizeRecords, readCacheSize, writeCacheSize) ;
-
-        Iterator<Record>  iterator = bpt.iterator() ;
-            
-//            // Fakery.
-//            blkMgrNodes = BlockMgrFactory.create(destination, Names.bptExt1, blockSize, readCacheSize, writeCacheSize) ;
-//            blkMgrRecords = BlockMgrFactory.create(destination, Names.bptExt2, blockSize, readCacheSize, writeCacheSize) ;
-//            recordFactory = new RecordFactory(dftKeyLength, dftValueLength) ;
-//            bptParams = new BPlusTreeParams(3, recordFactory) ;
-//            List<Record> data = TestBPlusTreeRewriter.createData(10, recordFactory) ;
-//            iterator = data.iterator() ;
-        
-        //System.out.println("Rewrite: "+srcLoc+" "+indexName+" --> "+destination) ;
-        
-        BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(iterator, 
-                                                             bptParams, recordFactory,
-                                                             blkMgrNodes, blkMgrRecords) ;
-        if ( bpt2 == null )
-            return ;
-//        
-//        Iterator<Record> iter = bpt2.iterator() ;
-//        for ( ; iter.hasNext() ; )
-//        {
-//            Record r = iter.next() ;
-//            System.out.println(r) ;
-//        }
-
-        bpt2.close() ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/cmdline/CmdSub.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/cmdline/CmdSub.java b/jena-tdb/src/main/java/tdb/cmdline/CmdSub.java
deleted file mode 100644
index fb7bbd0..0000000
--- a/jena-tdb/src/main/java/tdb/cmdline/CmdSub.java
+++ /dev/null
@@ -1,77 +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 tdb.cmdline;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import jena.cmd.CmdException;
-
-
-public class CmdSub
-{
-    public interface Exec { public void exec(String[] argv) ; }
-    Map<String, Exec> dispatch = new HashMap<>() ;
-    
-    String subCmd ;
-    String args[] ;
-    
-    public CmdSub(String ...argv)
-    {
-        subCmd = subCommand(argv) ;
-        args = cmdline(argv) ;
-    }
-    
-    protected void exec()
-    {
-        Exec exec = dispatch.get(subCmd) ;
-        if ( exec == null )
-            throw new CmdException("No subcommand: "+subCmd) ;
-        exec.exec(args) ;
-    }
-
-    protected static String[] cmdline(String ... argv)
-    {
-        String [] a = new String[argv.length-1] ;
-        System.arraycopy(argv, 1, a, 0, argv.length-1) ;
-        return a ; 
-    }
-
-    protected static String subCommand(String ... argv)
-    {
-        if ( argv.length == 0 )
-            throw new CmdException("Missing subcommand") ;
-
-        String subCmd = argv[0] ;
-        if ( subCmd.startsWith("-") )
-            throw new CmdException("Argument found where subcommand expected") ;
-        return subCmd ;
-    }
-    
-    protected void addSubCommand(String subCmdName, Exec exec)
-    {
-        dispatch.put(subCmdName, exec) ;
-    }
-    
-    protected Collection<String> subCommandNames()
-    {
-        return dispatch.keySet() ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/cmdline/CmdTDB.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/cmdline/CmdTDB.java b/jena-tdb/src/main/java/tdb/cmdline/CmdTDB.java
deleted file mode 100644
index 12ceeda..0000000
--- a/jena-tdb/src/main/java/tdb/cmdline/CmdTDB.java
+++ /dev/null
@@ -1,87 +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 tdb.cmdline;
-
-import org.apache.jena.Jena ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.apache.jena.query.ARQ ;
-import org.apache.jena.query.Dataset ;
-import org.apache.jena.sparql.core.DatasetGraph ;
-import org.apache.jena.system.JenaSystem ;
-import org.apache.jena.tdb.TDB ;
-import org.apache.jena.tdb.base.file.Location ;
-import org.apache.jena.tdb.setup.DatasetBuilderStd ;
-import org.apache.jena.tdb.store.DatasetGraphTDB ;
-import org.apache.jena.tdb.sys.TDBInternal ;
-import arq.cmdline.CmdARQ ;
-
-public abstract class CmdTDB extends CmdARQ
-{
-    protected final ModTDBDataset tdbDatasetAssembler   = new ModTDBDataset() ;
-
-    private static boolean initialized = false ;
-    
-    protected CmdTDB(String[] argv) {
-        super(argv) ;
-        init() ;
-        super.addModule(tdbDatasetAssembler) ;
-        super.modVersion.addClass(Jena.class) ;
-        super.modVersion.addClass(ARQ.class) ;
-        super.modVersion.addClass(TDB.class) ;
-    }
-
-    public static synchronized void init() {
-        // In case called from elsewhere.
-        JenaSystem.init() ;
-        if (initialized)
-            return ;
-        // attempt once.
-        initialized = true ;
-        LogCtl.setCmdLogging() ;
-        DatasetBuilderStd.setOptimizerWarningFlag(false) ;
-    }
-
-    @Override
-    protected void processModulesAndArgs() {
-        super.processModulesAndArgs() ;
-    }
-
-    protected Location getLocation() {
-        return tdbDatasetAssembler.getLocation() ;
-    }
-
-    protected DatasetGraph getDatasetGraph() {
-        return getDataset().asDatasetGraph() ;
-    }
-
-    protected DatasetGraphTDB getDatasetGraphTDB() {
-        DatasetGraph dsg = getDatasetGraph() ;
-        return TDBInternal.getBaseDatasetGraphTDB(dsg) ;
-    }
-
-    protected Dataset getDataset() {
-        return tdbDatasetAssembler.getDataset() ;
-    }
-
-    @Override
-    protected String getCommandName() {
-        return Lib.className(this) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/cmdline/CmdTDBGraph.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/cmdline/CmdTDBGraph.java b/jena-tdb/src/main/java/tdb/cmdline/CmdTDBGraph.java
deleted file mode 100644
index c261831..0000000
--- a/jena-tdb/src/main/java/tdb/cmdline/CmdTDBGraph.java
+++ /dev/null
@@ -1,81 +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 tdb.cmdline;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdException;
-
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.query.Dataset ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.tdb.store.GraphTDB ;
-
-public abstract class CmdTDBGraph extends CmdTDB
-{
-    private static final ArgDecl argNamedGraph          = new ArgDecl(ArgDecl.HasValue, "graph") ;
-    protected String graphName = null ;
-    
-    protected CmdTDBGraph(String[] argv)
-    {
-        super(argv) ;
-        super.add(argNamedGraph, "--graph=IRI", "Act on a named graph") ;
-    }
-    
-    @Override
-    protected void processModulesAndArgs()
-    {
-        super.processModulesAndArgs() ;
-        if ( contains(argNamedGraph) )
-            graphName = getValue(argNamedGraph) ; 
-    }
-    
-    protected Model getModel()
-    {
-        Dataset ds = tdbDatasetAssembler.getDataset() ;
-        
-        if ( graphName != null )
-        {
-            Model m = ds.getNamedModel(graphName) ;
-            if ( m == null )
-                throw new CmdException("No such named graph (is this a TDB dataset?)") ;
-            return m ;
-        }
-        else
-            return ds.getDefaultModel() ;
-    }
-    
-    public Node getGraphName()  { return graphName == null ? null : NodeFactory.createURI(graphName) ; } 
-    
-    protected GraphTDB getGraph()
-    {
-        if ( graphName != null )
-            return (GraphTDB)tdbDatasetAssembler.getDataset().getNamedModel(graphName).getGraph() ;
-        else
-            return (GraphTDB)tdbDatasetAssembler.getDataset().getDefaultModel().getGraph() ;
-    }
-    
-    @Override
-    protected String getCommandName()
-    {
-        return Lib.className(this) ;
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/cmdline/ModLocation.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/cmdline/ModLocation.java b/jena-tdb/src/main/java/tdb/cmdline/ModLocation.java
deleted file mode 100644
index 387dba0..0000000
--- a/jena-tdb/src/main/java/tdb/cmdline/ModLocation.java
+++ /dev/null
@@ -1,56 +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 tdb.cmdline;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdGeneral;
-import jena.cmd.ModBase;
-
-import org.apache.jena.tdb.base.file.Location ;
-
-public class ModLocation extends ModBase
-{
-    public ModLocation() {}
-    
-    protected final ArgDecl locationDecl = new ArgDecl(ArgDecl.HasValue, "location", "loc") ;
-    protected Location location = null ;
-    
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        cmdLine.getUsage().startCategory("Location") ;
-        cmdLine.add(locationDecl, "--loc=DIR", "Location (a directory)") ;
-    }
-    
-    public void checkCommandLine(CmdArgModule cmdLine)
-    {}
-
-    @Override
-    public void processArgs(CmdArgModule cmdLine)
-    {
-        if ( cmdLine.contains(locationDecl) )
-        {
-            String dir = cmdLine.getValue(locationDecl) ;
-            location = Location.create(dir) ;
-        }
-    }
-    
-    public Location getLocation() { return location ; }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/cmdline/ModModel.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/cmdline/ModModel.java b/jena-tdb/src/main/java/tdb/cmdline/ModModel.java
deleted file mode 100644
index 4b04471..0000000
--- a/jena-tdb/src/main/java/tdb/cmdline/ModModel.java
+++ /dev/null
@@ -1,66 +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 tdb.cmdline;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdGeneral;
-import jena.cmd.ModBase;
-
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.util.FileManager ;
-
-/** Name a model */
-public class ModModel extends ModBase
-{
-    protected ArgDecl modelArgDecl = null ;
-    private Model model = null ;
-    
-    //public ModModel() { this("model") ; }
-    public ModModel(String argName, String ... altNames)
-    {
-        modelArgDecl = new ArgDecl(ArgDecl.HasValue, argName) ;
-        for ( String x : altNames )
-            modelArgDecl.addName(x) ;
-    }
-
-    public ArgDecl getArg() 
-    {
-        return modelArgDecl ;
-    }
-    
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        cmdLine.add(modelArgDecl, "--"+modelArgDecl.getKeyName()+"=filename", "Filename for a model") ;
-    }
-
-    @Override
-    public void processArgs(CmdArgModule cmdLine)
-    {
-        if ( cmdLine.contains(modelArgDecl) )
-        {
-            String filename = cmdLine.getValue(modelArgDecl) ;
-            model = FileManager.get().loadModel(filename) ;
-        }
-    }
-    
-    public Model getModel() { return model ; }
-    
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/cmdline/ModTDBAssembler.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/cmdline/ModTDBAssembler.java b/jena-tdb/src/main/java/tdb/cmdline/ModTDBAssembler.java
deleted file mode 100644
index a4cb52a..0000000
--- a/jena-tdb/src/main/java/tdb/cmdline/ModTDBAssembler.java
+++ /dev/null
@@ -1,90 +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 tdb.cmdline;
-
-import java.io.File;
-
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdException;
-import jena.cmd.CmdGeneral;
-
-import org.apache.jena.tdb.base.file.Location ;
-
-import arq.cmdline.ModAssembler;
-
-/**  Extends ModAssembler to include --tdb.
- *   Defaulting to "tdb.ttl" is done in ModTDBDataset because it interacts
- *   with --location
- */  
-public class ModTDBAssembler extends ModAssembler
-{
-    private ModLocation modLocation     =  new ModLocation() ;
-
-    public static final String defaultAssemblerFile = "tdb.ttl" ;
-    protected boolean useDefaultAssemblerFile = false ;
-    
-    public ModTDBAssembler()
-    { 
-        super() ;
-        ModAssembler.assemblerDescDecl.addName("tdb") ;
-    }
-    
-    @Override
-    public void processArgs(CmdArgModule cmdLine)
-    {
-        int count = 0 ;
-
-        modLocation.processArgs(cmdLine) ;
-        super.processArgs(cmdLine) ;
-        if ( super.getAssemblerFile() != null ) count++ ;
-        if ( modLocation.getLocation() != null ) count++ ;    
-        
-        if ( count == 0 )
-        {
-            useDefaultAssemblerFile = true ;
-            // throw new CmdException("No assembler file and no location") ;
-        }
-            
-        if ( count > 1 )
-            throw new CmdException("Only one of an assembler file and a location") ;
-    }
-   
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        super.registerWith(cmdLine) ;
-        cmdLine.addModule(modLocation) ;
-        //cmdLine.getUsage().startCategory("Dataset") ;
-        cmdLine.getUsage().addUsage("--tdb=", "Assembler description file") ;
-    }
- 
-    public Location getLocation() { return modLocation.getLocation() ; }
-    
-    @Override
-    public String getAssemblerFile()
-    {
-        if ( useDefaultAssemblerFile )
-        {
-            File f = new File(defaultAssemblerFile) ;
-            if ( f.exists() )
-                return defaultAssemblerFile ; 
-        }
-        return super.getAssemblerFile() ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/cmdline/ModTDBDataset.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/cmdline/ModTDBDataset.java b/jena-tdb/src/main/java/tdb/cmdline/ModTDBDataset.java
deleted file mode 100644
index 5255fce..0000000
--- a/jena-tdb/src/main/java/tdb/cmdline/ModTDBDataset.java
+++ /dev/null
@@ -1,139 +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 tdb.cmdline;
-
-import java.util.ArrayList ;
-import java.util.List ;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdException;
-import jena.cmd.CmdGeneral;
-
-import org.apache.jena.atlas.logging.Log ;
-import org.apache.jena.query.* ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.riot.RDFDataMgr ;
-import org.apache.jena.shared.JenaException ;
-import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
-import org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab ;
-import org.apache.jena.tdb.TDBFactory ;
-import org.apache.jena.tdb.assembler.VocabTDB ;
-import org.apache.jena.tdb.base.file.Location ;
-import org.apache.jena.tdb.transaction.DatasetGraphTransaction ;
-import org.apache.jena.util.FileManager ;
-
-import arq.cmdline.ModDataset ;
-
-public class ModTDBDataset extends ModDataset
-{
-    // Mixes assembler, location and "tdb"
-    // Can make a single model or a dataset
-    
-    private ArgDecl argMem                  = new ArgDecl(ArgDecl.HasValue, "mem", "data") ;
-    private ModTDBAssembler modAssembler    = new ModTDBAssembler() ;
-    private String inMemFile                = null ;
-    
-    public ModTDBDataset() {}
-    
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        cmdLine.add(argMem, "--mem=FILE", "Execute on an in-memory TDB database (for testing)") ;
-        cmdLine.addModule(modAssembler) ;
-    }
-
-    @Override
-    public void processArgs(CmdArgModule cmdLine)
-    {
-        inMemFile = cmdLine.getValue(argMem) ;
-        modAssembler.processArgs(cmdLine) ;
-    }        
-
-    @Override
-    public Dataset createDataset()
-    {
-        if ( inMemFile != null )
-        {
-            Dataset ds = TDBFactory.createDataset() ;
-            RDFDataMgr.read(ds, inMemFile) ;
-            return ds ;
-            
-        }
-        
-        if (  modAssembler.getAssemblerFile() != null )
-        {
-            Dataset thing = null ;
-            // Two variants: plain dataset with a TDB graph or a TDB dataset.
-            try {
-                thing = (Dataset)AssemblerUtils.build( modAssembler.getAssemblerFile(), VocabTDB.tDatasetTDB) ;
-                if ( thing != null && ! ( thing.asDatasetGraph() instanceof DatasetGraphTransaction ) )
-                        Log.warn(this, "Unexpected: Not a TDB dataset for type DatasetTDB");
-                
-                if ( thing == null )
-                    // Should use assembler inheritance but how do we assert the subclass relationship in a program?
-                    thing = (Dataset)AssemblerUtils.build( modAssembler.getAssemblerFile(), DatasetAssemblerVocab.tDataset) ;
-            }
-            catch (JenaException ex)    { throw ex ; }
-            catch (Exception ex)
-            { throw new CmdException("Error creating", ex) ; }
-            return thing ;
-        }
-        
-        if ( modAssembler.getLocation() == null )
-            throw new CmdException("No assembler file nor location provided") ;
-        
-        // No assembler - use location to find a database.
-        Dataset ds = TDBFactory.createDataset(modAssembler.getLocation()) ;
-        return ds ;
-    }
-    
-    public Location getLocation()
-    {
-        List<String> x = locations() ;
-        if ( x.size() == 0 )
-            return null ;
-        return Location.create(x.get(0)) ;
-    }
-    
-    public List<String> locations()
-    {
-        List<String> locations = new ArrayList<>() ;
-        
-        if ( modAssembler.getLocation() != null )
-            locations.add(modAssembler.getLocation().getDirectoryPath()) ;
-
-        // Extract the location from the assember file.
-        if ( modAssembler.getAssemblerFile() != null )
-        {
-            // Find and clear all locations
-            Model m = FileManager.get().loadModel(modAssembler.getAssemblerFile()) ;
-            Query query = QueryFactory.create("PREFIX tdb:     <http://jena.hpl.hp.com/2008/tdb#> SELECT ?dir { [] tdb:location ?dir FILTER (isURI(?dir)) }") ;
-            try(QueryExecution qExec = QueryExecutionFactory.create(query, m)) {
-                for (ResultSet rs = qExec.execSelect() ; rs.hasNext() ; )
-                {
-                    String x = rs.nextSolution().getResource("dir").getURI() ;
-                    locations.add(x) ;
-                }
-            }
-        }
-        
-        return locations ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/tdbbackup.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/tdbbackup.java b/jena-tdb/src/main/java/tdb/tdbbackup.java
deleted file mode 100644
index 06724d9..0000000
--- a/jena-tdb/src/main/java/tdb/tdbbackup.java
+++ /dev/null
@@ -1,49 +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 tdb;
-
-import org.apache.jena.tdb.TDBBackup ;
-import tdb.cmdline.CmdTDB ;
-
-public class tdbbackup extends CmdTDB
-{
-    static public void main(String... argv)
-    { 
-        CmdTDB.init() ;
-        new tdbdump(argv).mainRun() ;
-    }
-
-    protected tdbbackup(String[] argv)
-    {
-        super(argv) ;
-    }
-    
-    @Override
-    protected String getSummary()
-    {
-        return getCommandName()+" : Write N-Quads to stdout" ;
-    }
-
-    @Override
-    protected void exec()
-    {
-        TDBBackup.backup(getLocation(), System.out) ;
-    }
-}
-

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/tdbconfig.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/tdbconfig.java b/jena-tdb/src/main/java/tdb/tdbconfig.java
deleted file mode 100644
index 99aea15..0000000
--- a/jena-tdb/src/main/java/tdb/tdbconfig.java
+++ /dev/null
@@ -1,250 +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 tdb;
-
-
-import java.util.List ;
-import java.util.Map ;
-
-import jena.cmd.ModVersion;
-
-import org.apache.jena.atlas.io.IndentedWriter ;
-import org.apache.jena.atlas.lib.DateTimeUtils ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.shared.PrefixMapping ;
-import org.apache.jena.sparql.core.DatasetPrefixStorage ;
-import org.apache.jena.tdb.TDB ;
-import org.apache.jena.tdb.base.file.FileFactory ;
-import org.apache.jena.tdb.base.file.Location ;
-import org.apache.jena.tdb.base.objectfile.StringFile ;
-import org.apache.jena.tdb.setup.Build ;
-import org.apache.jena.tdb.solver.stats.Stats ;
-import org.apache.jena.tdb.solver.stats.StatsResults ;
-import org.apache.jena.tdb.store.DatasetGraphTDB ;
-import org.apache.jena.tdb.sys.DatasetControlNone ;
-
-import tdb.cmdline.CmdSub ;
-import tdb.cmdline.CmdTDB ;
-import tdb.cmdline.CmdTDBGraph ;
-import arq.cmdline.CmdARQ ;
-
-/** Tools to manage a TDB store.  Subcommand based. */
-public class tdbconfig extends CmdSub
-{
-    static final String CMD_CLEAN       = "clean" ;
-    static final String CMD_HELP        = "help" ;
-    static final String CMD_STATS       = "stats" ;
-    static final String CMD_NODES       = "nodes" ;
-    static final String CMD_INFO        = "info" ;
-    static final String CMD_PREFIXES    = "prefixes" ;
-    
-    static public void main(String... argv)
-    {
-        CmdTDB.init() ;
-        new tdbconfig(argv).exec();
-    }
-
-    protected tdbconfig(String[] argv)
-    {
-        super(argv) ;
-//        super.addSubCommand(CMD_CLEAN, new Exec()
-//          { @Override public void exec(String[] argv) { new tdbclean(argv).main() ; } }) ;
-        
-        super.addSubCommand(CMD_HELP, new Exec()
-        { /*@Override*/ @Override
-        public void exec(String[] argv) { new SubHelp(argv).mainRun() ; } }) ;
-        
-        super.addSubCommand(CMD_STATS, new Exec()
-        { /*@Override*/ @Override
-        public void exec(String[] argv) { new SubStats(argv).mainRun() ; } }) ;
-        
-        super.addSubCommand(CMD_NODES, new Exec()
-        { /*@Override*/ @Override
-        public void exec(String[] argv) { new SubNodes(argv).mainRun() ; } }) ;
-        
-        super.addSubCommand(CMD_INFO, new Exec()
-        { /*@Override*/ @Override
-        public void exec(String[] argv) { new SubInfo(argv).mainRun() ; } }) ;
-        
-        super.addSubCommand(CMD_PREFIXES, new Exec()
-        { /*@Override*/ @Override
-        public void exec(String[] argv) { new SubPrefixes(argv).mainRun() ; } }) ;
-
-        
-    }
-    
-    static class SubPrefixes extends CmdTDB
-    {
-        public SubPrefixes(String ... argv)
-        {
-            super(argv) ;
-            //super.addModule(modSymbol) ;
-        }
-
-        @Override
-        protected String getSummary()
-        {
-            return "tdbconfig prefixes" ;
-        }
-
-        @Override
-        protected void exec()
-        {
-            Location location = getLocation() ;
-            DatasetPrefixStorage prefixes = Build.makePrefixes(location, new DatasetControlNone()) ;
-            for ( String gn : prefixes.graphNames() )
-            {
-                System.out.println("Graph: "+gn) ;
-                PrefixMapping pmap = prefixes.getPrefixMapping(gn) ;
-                Map<String, String> x = pmap.getNsPrefixMap() ;
-                for ( String k : x.keySet() )
-                    System.out.printf("  %-10s %s\n", k+":", x.get(k)) ;
-            }
-        }
-    }
-    
-    // Subcommand : help
-    class SubHelp extends CmdARQ
-    {
-        public SubHelp(String ... argv)
-        {
-            super(argv) ;
-            //super.addModule(modSymbol) ;
-        }
-        
-        @Override
-        protected String getSummary()
-        {
-            return null ;
-        }
-
-        @Override
-        protected void exec()
-        {
-            IndentedWriter out = IndentedWriter.stdout ;
-            out.println("Sub-commands:") ;
-            out.incIndent() ;
-
-            for ( String name : subCommandNames() )
-            {
-                out.println(name) ; 
-            }
-            out.decIndent() ;
-            out.flush() ;
-        }
-
-        @Override
-        protected String getCommandName()
-        {
-            return "tdbconfig help" ;
-        }
-    }
-    
-    static class SubStats extends CmdTDBGraph
-    {
-        public SubStats(String ... argv)
-        {
-            super(argv) ;
-            //super.addModule(modSymbol) ;
-        }
-        
-        @Override
-        protected String getSummary()
-        {
-            return "tdbconfig stats" ;
-        }
-
-        @Override
-        protected void exec()
-        {
-            DatasetGraphTDB dsg = getDatasetGraphTDB() ;
-            Node gn = getGraphName() ;
-            StatsResults results = tdbstats.stats(dsg, gn) ;
-            Stats.write(System.out, results) ;
-        }
-
-        @Override
-        protected String getCommandName()
-        {
-            return "tdbconfig stats" ;
-        }
-    }
-    
-    static class SubNodes extends CmdTDB
-    {
-        public SubNodes(String ... argv)
-        {
-            super(argv) ;
-        }
-        
-        @Override
-        protected String getSummary()
-        {
-            return "tdbconfig nodes" ;
-        }
-
-        @Override
-        protected void exec()
-        {
-            List<String> args = positionals ;
-            for ( String x : args )
-            {
-                System.out.println("**** Object File: "+x) ;
-                StringFile objs = FileFactory.createStringFileDisk(x) ;
-                objs.dump() ;
-            }
-        }
-
-        @Override
-        protected String getCommandName()
-        {
-            return "tdbconfig nodes" ;
-        }
-    }
-
-    static class SubInfo extends CmdTDB
-    {
-        public SubInfo(String ... argv)
-        {
-            super(argv) ;
-        }
-        
-        @Override
-        protected String getSummary()
-        {
-            return "tdbconfig info" ;
-        }
-
-        @Override
-        protected void exec()
-        {
-            System.out.println("-- "+DateTimeUtils.nowAsString()+" --") ;
-            ModVersion v = new ModVersion(true) ;
-            v.addClass(TDB.class) ;
-            v.printVersionAndExit() ;
-        }
-
-        @Override
-        protected String getCommandName()
-        {
-            return "tdbconfig info" ;
-        }
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/tdbdump.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/tdbdump.java b/jena-tdb/src/main/java/tdb/tdbdump.java
deleted file mode 100644
index 093ae9e..0000000
--- a/jena-tdb/src/main/java/tdb/tdbdump.java
+++ /dev/null
@@ -1,51 +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 tdb;
-
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFDataMgr ;
-import org.apache.jena.sparql.core.DatasetGraph ;
-import tdb.cmdline.CmdTDB ;
-
-public class tdbdump extends CmdTDB
-{
-    static public void main(String... argv)
-    { 
-        CmdTDB.init() ;
-        new tdbdump(argv).mainRun() ;
-    }
-
-    protected tdbdump(String[] argv)
-    {
-        super(argv) ;
-    }
-    
-    @Override
-    protected String getSummary()
-    {
-        return getCommandName()+" : Write N-Quads to stdout" ;
-    }
-
-    @Override
-    protected void exec()
-    {
-        DatasetGraph dsg = super.getDatasetGraphTDB() ;
-        RDFDataMgr.write(System.out, dsg, Lang.NQUADS) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/tdbloader.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/tdbloader.java b/jena-tdb/src/main/java/tdb/tdbloader.java
deleted file mode 100644
index 37ba0e4..0000000
--- a/jena-tdb/src/main/java/tdb/tdbloader.java
+++ /dev/null
@@ -1,138 +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 tdb ;
-
-import java.util.List ;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdException;
-
-import org.apache.jena.query.ARQ ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFLanguages ;
-import org.apache.jena.tdb.TDB ;
-import org.apache.jena.tdb.TDBLoader ;
-import org.apache.jena.tdb.store.GraphTDB ;
-
-import tdb.cmdline.CmdTDB ;
-import tdb.cmdline.CmdTDBGraph ;
-
-public class tdbloader extends CmdTDBGraph {
-    // private static final ArgDecl argParallel = new ArgDecl(ArgDecl.NoValue, "parallel") ;
-    // private static final ArgDecl argIncremental = new ArgDecl(ArgDecl.NoValue, "incr", "incremental") ;
-    private static final ArgDecl argNoStats = new ArgDecl(ArgDecl.NoValue, "nostats") ;
-    private static final ArgDecl argStats = new ArgDecl(ArgDecl.HasValue,  "stats") ;
-
-    private boolean showProgress  = true ;
-    private boolean generateStats  = true ;
-    // private boolean doInParallel = false ;
-    // private boolean doIncremental = false ;
-
-    static public void main(String... argv) {
-        CmdTDB.init() ;
-        TDB.setOptimizerWarningFlag(false) ;
-        new tdbloader(argv).mainRun() ;
-    }
-
-    protected tdbloader(String[] argv) {
-        super(argv) ;
-//        super.getUsage().startCategory("Stats") ;
-        super.add(argNoStats, "--nostats", "Switch off statistics gathering") ;
-        super.add(argStats) ;   // Hidden argument
-        // super.add(argParallel, "--parallel",
-        // "Do rebuilding of secondary indexes in a parallel") ;
-        // super.add(argIncremental, "--incremental",
-        // "Do an incremental load (keep indexes during data load)") ;
-        // super.add(argStats, "--stats",
-        // "Generate statistics while loading (new graph only)") ;
-        // addModule(modRDFS) ;
-    }
-
-    @Override
-    protected void processModulesAndArgs() {
-        super.processModulesAndArgs() ;
-        // doInParallel = super.contains(argParallel) ;
-        // doIncremental = super.contains(argIncremental) ;
-    }
-
-    @Override
-    protected String getSummary() {
-        return getCommandName() + " [--desc DATASET | -loc DIR] FILE ..." ;
-    }
-
-    @Override
-    protected void exec() {
-        if ( isVerbose() ) {
-            System.out.println("Java maximum memory: " + Runtime.getRuntime().maxMemory()) ;
-            System.out.println(ARQ.getContext()) ;
-        }
-        if ( isVerbose() )
-            showProgress = true ;
-        if ( isQuiet() )
-            showProgress = false ;
-        if ( super.contains(argStats) ) {
-            if ( ! hasValueOfTrue(argStats) && ! hasValueOfFalse(argStats) )
-                throw new CmdException("Not a boolean value: "+getValue(argStats)) ;
-            generateStats = super.hasValueOfTrue(argStats) ;
-        }
-
-        if ( super.contains(argNoStats))
-            generateStats = false ;
-        
-        List<String> urls = getPositional() ;
-        if ( urls.size() == 0 )
-            urls.add("-") ;
-
-        if ( graphName == null ) {
-            loadQuads(urls) ;
-            return ;
-        }
-        
-        // There's a --graph.
-        // Check/warn that there are no quads formats mentioned
-        // (RIOT will take the default graph from quads).  
-        
-        for ( String url : urls ) {
-            Lang lang = RDFLanguages.filenameToLang(url) ;
-            if ( lang != null && RDFLanguages.isQuads(lang) ) {
-                System.err.println("Warning: Quads format given - only the default graph is loaded into the graph for --graph") ;
-                break ;
-            }
-        }
-        
-        loadNamedGraph(urls) ;
-    }
-
-//    void loadDefaultGraph(List<String> urls) {
-//        GraphTDB graph = getGraph() ;
-//        TDBLoader.load(graph, urls, showProgress) ;
-//        return ;
-//    }
-
-    void loadNamedGraph(List<String> urls) {
-        GraphTDB graph = getGraph() ;
-        TDBLoader.load(graph, urls, showProgress) ;
-        return ;
-    }
-
-    void loadQuads(List<String> urls) {
-        TDBLoader.load(getDatasetGraphTDB(), urls, showProgress, generateStats) ;
-        return ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/tdbnode.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/tdbnode.java b/jena-tdb/src/main/java/tdb/tdbnode.java
deleted file mode 100644
index 391c628..0000000
--- a/jena-tdb/src/main/java/tdb/tdbnode.java
+++ /dev/null
@@ -1,84 +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 tdb;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.lib.Bytes ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.tdb.lib.NodeLib ;
-import org.apache.jena.tdb.store.DatasetGraphTDB ;
-import org.apache.jena.tdb.store.Hash ;
-import org.apache.jena.tdb.store.NodeId ;
-import org.apache.jena.tdb.store.nodetable.NodeTable ;
-import org.apache.jena.tdb.sys.SystemTDB ;
-import tdb.cmdline.CmdTDB ;
-
-public class tdbnode extends CmdTDB
-{
-    // Debugging tool.
-    static public void main(String... argv)
-    { 
-        CmdTDB.init() ;
-        new tdbnode(argv).mainRun() ;
-    }
-
-    protected tdbnode(String[] argv)
-    {
-        super(argv) ;
-    }
-
-    @Override
-    protected String getSummary()
-    {
-        return getCommandName()+" NodeId ..." ;
-    }
-
-    @Override
-    protected void exec()
-    {
-        DatasetGraphTDB dsg = getDatasetGraphTDB() ;
-        NodeTable nodeTable = dsg.getTripleTable().getNodeTupleTable().getNodeTable() ;
-        Iterator<String> iter = super.getPositional().iterator() ;
-        if ( ! iter.hasNext() )
-        {
-            System.err.println("No node ids") ;
-            return ;
-        }
-        
-        for ( ; iter.hasNext() ; )
-        {
-            String id = iter.next() ;
-            try {
-                long x = Long.parseLong(id) ;
-                NodeId nodeId = new NodeId(x) ;
-                Node n = nodeTable.getNodeForNodeId(nodeId) ;
-                //System.out.printf("%s [%d] => %s\n", id, x, n) ;
-
-                Hash h = new Hash(SystemTDB.LenNodeHash) ;
-                NodeLib.setHash(h, n) ;
-                String str = Bytes.asHex(h.getBytes()) ;
-                System.out.printf("%s %08d 0x%s # %s\n", id, x, str, n) ;
-            } catch (Exception ex)
-            {
-                System.out.println("Failed to decode: "+id) ;
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/tdbquery.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/tdbquery.java b/jena-tdb/src/main/java/tdb/tdbquery.java
deleted file mode 100644
index 82ee3de..0000000
--- a/jena-tdb/src/main/java/tdb/tdbquery.java
+++ /dev/null
@@ -1,60 +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 tdb;
-
-import org.apache.jena.tdb.TDB ;
-import tdb.cmdline.CmdTDB ;
-import tdb.cmdline.ModTDBDataset ;
-import arq.cmdline.ModDataset ;
-
-
-public class tdbquery extends arq.query
-{
-    // Inherits from arq.query so is not a CmdTDB.  Mixins for Java!
-    public static void main(String...argv)
-    {
-        CmdTDB.init() ;
-        new tdbquery(argv).mainRun() ;
-    }
-    
-    public tdbquery(String[] argv)
-    {
-        super(argv) ;
-        // Because this inherits from an ARQ command
-        super.modVersion.addClass(TDB.class) ;
-    }
-
-    @Override
-    protected String getSummary() 
-    { 
-        return getCommandName()+" --loc=<path> --query=<query>" ; 
-    }
-    
-    @Override
-    protected void processModulesAndArgs()
-    {
-        super.processModulesAndArgs() ;
-    }
-    
-    @Override
-    protected ModDataset setModDataset()
-    {
-        return new ModTDBDataset() ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/tdbrecovery.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/tdbrecovery.java b/jena-tdb/src/main/java/tdb/tdbrecovery.java
deleted file mode 100644
index 2621115..0000000
--- a/jena-tdb/src/main/java/tdb/tdbrecovery.java
+++ /dev/null
@@ -1,54 +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 tdb;
-
-import org.apache.jena.tdb.TDB ;
-import org.apache.jena.tdb.store.DatasetGraphTDB ;
-import org.apache.jena.tdb.transaction.JournalControl ;
-import tdb.cmdline.CmdTDB ;
-
-public class tdbrecovery extends CmdTDB
-{
-    static public void main(String... argv)
-    { 
-        CmdTDB.init() ;
-        TDB.setOptimizerWarningFlag(false) ;
-        new tdbrecovery(argv).mainRun() ;
-    }
-
-    protected tdbrecovery(String[] argv)
-    {
-        super(argv) ;
-    }
-
-    @Override
-    protected String getSummary()
-    {
-        return getCommandName()+" --loc DIRECTORY\nRun database journal recovery." ;
-    }
-
-    @Override
-    protected void exec()
-    {
-        DatasetGraphTDB dsg = super.getDatasetGraphTDB() ;
-        // Just creating the DSG does a recovery so this is not (currently) necessary:
-        // This may change (not immediately recovering on start up).
-        JournalControl.recovery(dsg) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/tdbreorder.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/tdbreorder.java b/jena-tdb/src/main/java/tdb/tdbreorder.java
deleted file mode 100644
index 8d9984a..0000000
--- a/jena-tdb/src/main/java/tdb/tdbreorder.java
+++ /dev/null
@@ -1,124 +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 tdb;
-
-import org.apache.jena.atlas.io.IndentedWriter ;
-import org.apache.jena.atlas.lib.FileOps ;
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.shared.PrefixMapping ;
-import org.apache.jena.shared.impl.PrefixMappingImpl ;
-import org.apache.jena.sparql.algebra.Op ;
-import org.apache.jena.sparql.algebra.op.OpBGP ;
-import org.apache.jena.sparql.algebra.op.OpQuadPattern ;
-import org.apache.jena.sparql.core.BasicPattern ;
-import org.apache.jena.sparql.engine.optimizer.StatsMatcher ;
-import org.apache.jena.sparql.engine.optimizer.reorder.ReorderLib ;
-import org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation ;
-import org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformationSubstitution ;
-import org.apache.jena.sparql.serializer.SerializationContext ;
-import org.apache.jena.sparql.sse.SSE ;
-import org.apache.jena.sparql.sse.writers.WriterNode ;
-import org.apache.jena.tdb.sys.Names ;
-
-public class tdbreorder
-{
-    public static void main(String... args) {
-        if ( args.length != 2 ) {
-            System.err.println("Usage: PATTERN STATS") ;
-            System.exit(1) ;
-        }
-        LogCtl.enable(StatsMatcher.class) ;
-        LogCtl.enable(ReorderTransformationSubstitution.class) ;
-        
-        if ( args.length != 2 )
-        {
-            System.err.println("Usage: op stats") ; 
-            System.exit(1) ;
-        }
-            
-        String pattern = args[0] ;
-        String statsFile = args[1] ;
-        
-        Op op = SSE.readOp(pattern) ;
-
-        BasicPattern bgp ;
-        if ( op instanceof OpQuadPattern ) {
-            bgp = ((OpQuadPattern)op).getBasicPattern() ;
-        } else if ( op instanceof OpBGP ) {
-            bgp = ((OpBGP)op).getPattern() ;
-        }
-        else {
-            System.err.println("Not a quad or triple pattern") ;
-            System.exit(2) ;
-            bgp = null ;
-        }
-        
-        ReorderTransformation reorder = chooseReorder(statsFile) ;
-        //ReorderTransformation reorder = ReorderLib.fixed() ;
-        BasicPattern bgp2 = reorder.reorder(bgp) ;
-     
-        System.out.println() ;
-        
-        print(bgp) ;
-        System.out.println() ;
-        System.out.println(" ======== >>>>>>>>") ;
-        print(bgp2) ;
-        System.out.println() ;
-    }
-    
-    private static void print(BasicPattern bgp) {
-        IndentedWriter out = IndentedWriter.stdout;
-        
-        PrefixMapping pmap = new PrefixMappingImpl() ;
-        pmap.setNsPrefixes(SSE.defaultPrefixMapWrite) ;
-//        pmap.setNsPrefix("ppi", "http://landregistry.data.gov.uk/def/ppi/") ;
-//        pmap.setNsPrefix("common", "http://landregistry.data.gov.uk/def/common/") ;
-        
-        SerializationContext sCxt = SSE.sCxt(pmap) ;
-        
-        boolean first = true ;
-        for ( Triple t : bgp )
-        {
-            if ( !first )
-                out.print("\n") ;
-            else
-                first = false ;
-            // Adds (triple ...)
-            // SSE.write(buff.getIndentedWriter(), t) ;
-            out.print("(") ;
-            WriterNode.outputPlain(out, t, sCxt) ;
-            out.print(")") ;
-        }
-        out.flush();
-        
-    }
-    private static ReorderTransformation chooseReorder(String filename)
-    {
-        if ( filename.equals(Names.optFixed) )
-            return ReorderLib.fixed() ;
-        if ( filename.equals(Names.optNone) )
-            return ReorderLib.identity() ;
-        if ( FileOps.exists(filename) )
-            return ReorderLib.weighted(filename) ;
-        else
-            throw new RuntimeException("No such file: "+filename) ;
-    }
-}
-

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/tdbstats.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/tdbstats.java b/jena-tdb/src/main/java/tdb/tdbstats.java
deleted file mode 100644
index 115c487..0000000
--- a/jena-tdb/src/main/java/tdb/tdbstats.java
+++ /dev/null
@@ -1,103 +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 tdb;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.lib.tuple.Tuple ;
-import org.apache.jena.atlas.logging.Log ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.sparql.core.Quad ;
-import org.apache.jena.tdb.solver.SolverLib ;
-import org.apache.jena.tdb.solver.stats.Stats ;
-import org.apache.jena.tdb.solver.stats.StatsCollectorNodeId ;
-import org.apache.jena.tdb.solver.stats.StatsResults ;
-import org.apache.jena.tdb.store.DatasetGraphTDB ;
-import org.apache.jena.tdb.store.NodeId ;
-import org.apache.jena.tdb.store.nodetable.NodeTable ;
-import org.apache.jena.tdb.store.nodetupletable.NodeTupleTable ;
-import tdb.cmdline.CmdTDB ;
-import tdb.cmdline.CmdTDBGraph ;
-
-public class tdbstats extends CmdTDBGraph
-{
-    // tdbconfig?
-    static public void main(String... argv)
-    { 
-        CmdTDB.init() ;
-        new tdbstats(argv).mainRun() ;
-    }
-
-    protected tdbstats(String[] argv)
-    {
-        super(argv) ;
-    }
-    
-    @Override
-    protected String getSummary()
-    {
-        return null ;
-    }
-    
-    public static StatsResults stats(DatasetGraphTDB dsg, Node gn)
-    {
-        NodeTable nt = dsg.getTripleTable().getNodeTupleTable().getNodeTable() ;
-        StatsCollectorNodeId stats = new StatsCollectorNodeId(nt) ;
-        
-        if ( gn == null )
-        {
-            Iterator<Tuple<NodeId>> iter = dsg.getTripleTable().getNodeTupleTable().findAll() ;
-            for ( ; iter.hasNext(); )
-            {
-                Tuple<NodeId> t = iter.next() ;
-                stats.record(null, t.get(0), t.get(1), t.get(2)) ;
-            }
-        } else {
-            // If the union graph, then we need to scan all quads but with uniqueness.
-            boolean unionGraph = Quad.isUnionGraph(gn) ;
-            NodeId gnid = null ;
-            if ( ! unionGraph )
-            {
-                gnid = nt.getNodeIdForNode(gn) ;
-                if ( NodeId.isDoesNotExist(gnid) )
-                Log.warn(tdbstats.class, "No such graph: "+gn) ;
-            }
-                
-            NodeTupleTable ntt = dsg.getQuadTable().getNodeTupleTable() ;
-            Iterator<Tuple<NodeId>> iter = unionGraph
-                ? SolverLib.unionGraph(ntt)
-                : ntt.find(gnid, null, null, null) ;
-            for ( ; iter.hasNext(); )
-            {
-                Tuple<NodeId> t = iter.next() ;
-                stats.record(t.get(0), t.get(1), t.get(2), t.get(3)) ;
-            }
-        }
-        return stats.results() ;
-    }
-
-    @Override
-    protected void exec()
-    {
-        DatasetGraphTDB dsg = getDatasetGraphTDB() ;
-        Node gn = getGraphName() ;
-        StatsResults results = stats(dsg, gn) ;
-        Stats.write(System.out, results) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/tdbupdate.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/tdbupdate.java b/jena-tdb/src/main/java/tdb/tdbupdate.java
deleted file mode 100644
index 464ec2e..0000000
--- a/jena-tdb/src/main/java/tdb/tdbupdate.java
+++ /dev/null
@@ -1,61 +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 tdb;
-
-import arq.cmdline.ModDataset ;
-import jena.cmd.CmdException ;
-import org.apache.jena.sparql.core.DatasetGraph ;
-import org.apache.jena.tdb.TDB ;
-import org.apache.jena.tdb.transaction.TransactionManager ;
-import tdb.cmdline.CmdTDB ;
-import tdb.cmdline.ModTDBDataset ;
-
-public class tdbupdate extends arq.update
-{
-    // Inherits from arq.update so is not a CmdTDB.  Mixins for Java!
-    public static void main(String...argv)
- {
-        CmdTDB.init();
-        // Do everything with flushing transactions.
-        TransactionManager.QueueBatchSize = 0;
-        new tdbupdate(argv).mainRun();
-    }
-
-    public tdbupdate(String[] argv) {
-        super(argv);
-        // Because this inherits from an ARQ command
-        CmdTDB.init();
-        super.modVersion.addClass(TDB.class);
-    }
-
-    @Override
-    protected void processModulesAndArgs() {
-        super.processModulesAndArgs();
-    }
-
-    @Override
-    protected ModDataset setModeDataset() {
-        return new ModTDBDataset();
-    }
-    
-    @Override
-    protected DatasetGraph dealWithNoDataset() {
-        throw new CmdException("No dataset provided") ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/tools/dumpbpt.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/tools/dumpbpt.java b/jena-tdb/src/main/java/tdb/tools/dumpbpt.java
deleted file mode 100644
index 269150e..0000000
--- a/jena-tdb/src/main/java/tdb/tools/dumpbpt.java
+++ /dev/null
@@ -1,178 +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 tdb.tools ;
-
-import java.io.PrintStream ;
-import java.util.Arrays ;
-import java.util.Iterator ;
-import java.util.List ;
-
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.lib.tuple.Tuple ;
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.apache.jena.tdb.base.file.Location ;
-import org.apache.jena.tdb.base.record.Record ;
-import org.apache.jena.tdb.base.record.RecordFactory ;
-import org.apache.jena.tdb.index.IndexFactory ;
-import org.apache.jena.tdb.index.RangeIndex ;
-import org.apache.jena.tdb.index.bplustree.BPlusTree ;
-import org.apache.jena.tdb.lib.ColumnMap ;
-import org.apache.jena.tdb.store.NodeId ;
-import org.apache.jena.tdb.store.tupletable.TupleIndex ;
-import org.apache.jena.tdb.store.tupletable.TupleIndexRecord ;
-import org.apache.jena.tdb.sys.Names ;
-import org.apache.jena.tdb.sys.SystemTDB ;
-
-import arq.cmdline.CmdARQ;
-import tdb.cmdline.ModLocation ;
-
-public class dumpbpt extends CmdARQ {
-    ModLocation modLocation = new ModLocation() ;
-
-    static public void main(String... argv) {
-        LogCtl.setLog4j() ;
-        new dumpbpt(argv).mainRun() ;
-    }
-
-    protected dumpbpt(String[] argv) {
-        super(argv) ;
-        super.addModule(modLocation) ;
-    }
-
-    @Override
-    protected void processModulesAndArgs() {
-        if ( modVersion.getVersionFlag() )
-            modVersion.printVersionAndExit() ;
-        if ( modLocation.getLocation() == null )
-            cmdError("Location required") ;
-        if ( super.getPositional().size() == 0 )
-            cmdError("No index specified") ;
-    }
-
-    @Override
-    protected String getSummary() {
-        return getCommandName() + " --loc=DIR IndexName" ;
-    }
-
-    @Override
-    protected String getCommandName() {
-        return Lib.className(this) ;
-    }
-
-    @Override
-    protected void exec() {
-        List<String> tripleIndexes = Arrays.asList(Names.tripleIndexes) ;
-        List<String> quadIndexes = Arrays.asList(Names.quadIndexes) ;
-        Location loc = modLocation.getLocation() ;
-
-        // The name is the order.
-        for ( String indexName : super.getPositional() ) {
-            String primary ;
-            if ( indexName.length() == 3 ) {
-                primary = Names.primaryIndexTriples ;
-            } else if ( indexName.length() == 4 ) {
-                primary = Names.primaryIndexQuads ;
-            } else {
-                cmdError("Wrong length: " + indexName) ;
-                primary = null ;
-            }
-
-            int keySubLen = SystemTDB.SizeOfNodeId ;
-            int keyUnitLen = indexName.length() ;
-            int keyLength = keySubLen * keyUnitLen ;
-            int valueLength = 0 ;
-
-            RecordFactory rf = new RecordFactory(keyLength, valueLength) ;
-            RangeIndex rIndex = IndexFactory.buildRangeIndex(loc, indexName, rf) ;
-            BPlusTree bpt = (BPlusTree)rIndex ;
-
-            if ( false ) {
-                System.out.println("---- Index structure") ;
-                bpt.dump() ;
-            }
-            if ( true ) {
-                System.out.println("---- Index contents") ;
-                Iterator<Record> iter = bpt.iterator() ;
-                if ( !iter.hasNext() )
-                    System.out.println("<<Empty>>") ;
-
-                for ( ; iter.hasNext() ; ) {
-                    Record r = iter.next() ;
-                    printRecord("", System.out, r, keyUnitLen) ;
-                }
-            }
-
-            // Check.
-            Iterator<Record> iterCheck = bpt.iterator() ;
-            Record r1 = null ;
-            int i = 0 ;
-            for ( ; iterCheck.hasNext() ; ) {
-                Record r2 = iterCheck.next() ;
-                i++ ;
-
-                if ( r1 != null ) {
-                    if ( !Record.keyLT(r1, r2) ) {
-                        System.err.println("key error@ " + i) ;
-                        printRecord("  ", System.err, r1, keyUnitLen) ;
-                        printRecord("  ", System.err, r2, keyUnitLen) ;
-                    }
-                }
-                r1 = r2 ;
-            }
-
-            if ( false ) {
-                // Dump in tuple order.
-                TupleIndex tupleIndex = new TupleIndexRecord(primary.length(), new ColumnMap(primary, indexName), indexName,
-                                                             rIndex.getRecordFactory(), rIndex) ;
-                if ( true ) {
-                    System.out.println("---- Tuple contents") ;
-                    Iterator<Tuple<NodeId>> iter2 = tupleIndex.all() ;
-                    if ( !iter2.hasNext() )
-                        System.out.println("<<Empty>>") ;
-
-                    for ( ; iter2.hasNext() ; ) {
-                        Tuple<NodeId> row = iter2.next() ;
-                        System.out.println(row) ;
-                    }
-                }
-            }
-        }
-    }
-
-    private static void printRecord(String label, PrintStream out, Record r, int keyUnitLen) {
-        // out.println(r) ;
-
-        int keySubLen = r.getKey().length / keyUnitLen ;
-        if ( label != null )
-            out.print(label) ;
-        for ( int i = 0 ; i < keyUnitLen ; i++ ) {
-            if ( i != 0 )
-                out.print(" ") ;
-
-            // Print in chunks
-            int k = i * keySubLen ;
-            for ( int j = k ; j < k + keySubLen ; j++ )
-                out.printf("%02x", r.getKey()[j]) ;
-
-            // long x = Bytes.getLong(r.getKey(), i*SystemTDB.SizeOfNodeId) ;
-            // System.out.printf("%016x", x) ;
-        }
-        out.println() ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-tdb/src/main/java/tdb/tools/dumpnodetable.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/tdb/tools/dumpnodetable.java b/jena-tdb/src/main/java/tdb/tools/dumpnodetable.java
deleted file mode 100644
index 31f6309..0000000
--- a/jena-tdb/src/main/java/tdb/tools/dumpnodetable.java
+++ /dev/null
@@ -1,182 +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 tdb.tools ;
-
-import java.io.OutputStream ;
-import java.util.Arrays ;
-import java.util.Iterator ;
-import java.util.List ;
-
-import org.apache.jena.atlas.io.IndentedWriter ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.lib.Pair ;
-import org.apache.jena.atlas.logging.Log ;
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Node_Literal ;
-import org.apache.jena.sparql.util.FmtUtils ;
-import org.apache.jena.tdb.StoreConnection ;
-import org.apache.jena.tdb.base.file.Location ;
-import org.apache.jena.tdb.setup.Build ;
-import org.apache.jena.tdb.store.DatasetGraphTDB ;
-import org.apache.jena.tdb.store.NodeId ;
-import org.apache.jena.tdb.store.nodetable.NodeTable ;
-import org.apache.jena.tdb.sys.Names ;
-import org.apache.jena.tdb.sys.SystemTDB ;
-
-import arq.cmdline.CmdARQ;
-import tdb.cmdline.ModLocation ;
-
-public class dumpnodetable extends CmdARQ {
-    ModLocation modLocation = new ModLocation() ;
-
-    static public void main(String... argv) {
-        LogCtl.setLog4j() ;
-        new dumpnodetable(argv).mainRun() ;
-    }
-
-    @Override
-    protected void exec() {
-        List<String> tripleIndexes = Arrays.asList(Names.tripleIndexes) ;
-        List<String> quadIndexes = Arrays.asList(Names.quadIndexes) ;
-        Location loc = modLocation.getLocation() ;
-
-        StoreConnection sConn = StoreConnection.make(loc) ;
-        DatasetGraphTDB dsg = sConn.getBaseDataset() ;
-        NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable() ;
-        dump(System.out, nodeTable) ;
-    }
-
-    protected dumpnodetable(String[] argv) {
-        super(argv) ;
-        super.addModule(modLocation) ;
-    }
-
-    public static void dumpNodes(OutputStream w, String location) {
-        dump(w, location, Names.indexNode2Id, SystemTDB.Node2NodeIdCacheSize, Names.indexId2Node, SystemTDB.NodeId2NodeCacheSize,
-             SystemTDB.NodeMissCacheSize) ;
-    }
-
-    public static void dumpPrefixes(OutputStream w, String location) {
-        dump(w, location, Names.prefixNode2Id, 100, Names.prefixId2Node, 100, 10) ;
-    }
-
-    public static void dump(OutputStream w, String location, String indexNode2Id, int node2NodeIdCacheSize, String indexId2Node,
-                            int nodeId2NodeCacheSize, //
-
-                            int sizeNodeMissCacheSize) {
-        NodeTable nodeTable = Build.makeNodeTable(Location.create(location), indexNode2Id, node2NodeIdCacheSize, indexId2Node,
-                                                  nodeId2NodeCacheSize, sizeNodeMissCacheSize) ;
-    }
-
-    public static void dump(OutputStream w, NodeTable nodeTable) {
-        // Better to hack the indexes?
-        Iterator<Pair<NodeId, Node>> iter = nodeTable.all() ;
-        long count = 0 ;
-        try (IndentedWriter iw = new IndentedWriter(w)) {
-            for ( ; iter.hasNext() ; ) {
-                Pair<NodeId, Node> pair = iter.next() ;
-                iw.print(pair.car().toString()) ;
-                iw.print(" : ") ;
-                // iw.print(pair.cdr()) ;
-                Node n = pair.cdr() ;
-                String $ = stringForNode(n) ;
-                iw.print($) ;
-                iw.println() ;
-                count++ ;
-            }
-            iw.println() ;
-            iw.printf("Total: " + count) ;
-            iw.println() ;
-            iw.flush() ;
-        }
-    }
-
-    private static String stringForNode(Node n) {
-        if ( n == null )
-            return "<<null>>" ;
-
-        if ( n.isBlank() )
-            return "_:" + n.getBlankNodeLabel() ;
-
-        if ( n.isLiteral() )
-            return stringForLiteral((Node_Literal)n) ;
-
-        if ( n.isURI() ) {
-            String uri = n.getURI() ;
-            return stringForURI(uri) ;
-        }
-
-        if ( n.isVariable() )
-            return "?" + n.getName() ;
-
-        if ( n.equals(Node.ANY) )
-            return "ANY" ;
-
-        Log.warn(FmtUtils.class, "Failed to turn a node into a string: " + n) ;
-        return n.toString() ;
-    }
-
-    public static String stringForURI(String uri) {
-        return "<" + uri + ">" ;
-    }
-
-    public static String stringForLiteral(Node_Literal literal) {
-        String datatype = literal.getLiteralDatatypeURI() ;
-        String lang = literal.getLiteralLanguage() ;
-        String s = literal.getLiteralLexicalForm() ;
-
-        StringBuilder sbuff = new StringBuilder() ;
-        sbuff.append("\"") ;
-        FmtUtils.stringEsc(sbuff, s, true) ;
-        sbuff.append("\"") ;
-
-        // Format the language tag
-        if ( lang != null && lang.length() > 0 ) {
-            sbuff.append("@") ;
-            sbuff.append(lang) ;
-        }
-
-        if ( datatype != null ) {
-            sbuff.append("^^") ;
-            sbuff.append(stringForURI(datatype)) ;
-        }
-
-        return sbuff.toString() ;
-    }
-
-    @Override
-    protected void processModulesAndArgs() {
-        if ( modVersion.getVersionFlag() )
-            modVersion.printVersionAndExit() ;
-        if ( modLocation.getLocation() == null )
-            cmdError("Location required") ;
-    }
-
-    @Override
-    protected String getSummary() {
-        return getCommandName() + " --loc=DIR IndexName" ;
-    }
-
-    @Override
-    protected String getCommandName() {
-        return Lib.className(this) ;
-    }
-
-}


[18/20] jena git commit: JENA-1108 : jena-cmds module

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModResultsIn.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModResultsIn.java b/jena-arq/src/main/java/arq/cmdline/ModResultsIn.java
deleted file mode 100644
index c560767..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModResultsIn.java
+++ /dev/null
@@ -1,138 +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 arq.cmdline;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdGeneral;
-import jena.cmd.ModBase;
-import jena.cmd.TerminationException;
-
-import org.apache.jena.query.ResultSet ;
-import org.apache.jena.query.ResultSetFactory ;
-import org.apache.jena.shared.NotFoundException ;
-import org.apache.jena.sparql.ARQInternalErrorException ;
-import org.apache.jena.sparql.resultset.ResultsFormat ;
-
-public class ModResultsIn extends ModBase
-{
-    protected final ArgDecl resultsInputFmtDecl = new ArgDecl(ArgDecl.HasValue, "in") ;
-    protected final ArgDecl fileDecl = new ArgDecl(ArgDecl.HasValue, "file") ;
-
-    private ResultsFormat inputFormat = ResultsFormat.FMT_TEXT ;
-    private String resultsFilename = null ;
-    private ResultSet resultSet = null ;
-    
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        cmdLine.getUsage().startCategory("Results") ;
-        cmdLine.add(fileDecl,
-                    "--file",
-                    "Input file") ;
-        cmdLine.add(resultsInputFmtDecl,
-                    "--in",
-                    "Results format (XML, JSON; RDF serialization)") ;  
-    }
-
-    @Override
-    public void processArgs(CmdArgModule cmdline) throws IllegalArgumentException
-    {
-        // Input file.
-        if ( cmdline.contains(fileDecl) )
-            resultsFilename = cmdline.getValue(fileDecl) ;
-        
-        if ( cmdline.getNumPositional() == 0 && resultsFilename == null )
-            cmdline.cmdError("No results file") ;
-
-        if ( cmdline.getNumPositional() > 1 )
-            cmdline.cmdError("Only one result set file allowed") ;
-            
-        if ( cmdline.getNumPositional() == 1 && resultsFilename != null )
-            cmdline.cmdError("Either result set file or --file - not both") ;
-
-        if ( resultsFilename == null )
-            // One positional argument.
-            resultsFilename = cmdline.getPositionalArg(0) ;
-        
-        // Guess format
-        if ( resultsFilename != null )
-            inputFormat = ResultsFormat.guessSyntax(resultsFilename) ;
-
-        // Set format
-        if ( cmdline.contains(resultsInputFmtDecl) )
-        {
-            String rFmt = cmdline.getValue(resultsInputFmtDecl) ;
-            inputFormat = ResultsFormat.lookup(rFmt) ;
-            if ( inputFormat == null )
-                cmdline.cmdError("Unrecognized output format: "+rFmt) ;
-        }
-    }
-    
-    public void checkCommandLine(CmdArgModule cmdLine)
-    {}
-    
-    
-    public ResultSet getResultSet()
-    {
-        if ( resultSet != null )
-            return resultSet ;
-        
-        if ( resultsFilename == null )
-        {
-            System.err.println("No result file name" ) ;
-            throw new TerminationException(1) ;
-        }
-
-        try
-        {
-            if ( resultsFilename.equals("-") )
-                return ResultSetFactory.load(System.in, inputFormat) ;
-            ResultSet rs = ResultSetFactory.load(resultsFilename, inputFormat) ;
-            if ( rs == null )
-            {
-                System.err.println("Failed to read the result set") ;
-                throw new TerminationException(9) ;
-            }
-            resultSet = rs ;
-            return resultSet ;
-        }
-        catch (NotFoundException ex)
-        {
-            System.err.println("File not found: "+resultsFilename) ;
-            throw new TerminationException(9) ;
-        }
-        catch (ARQInternalErrorException intEx)
-        {
-            System.err.println(intEx.getMessage()) ;
-            if ( intEx.getCause() != null )
-            {
-                System.err.println("Cause:") ;
-                intEx.getCause().printStackTrace(System.err) ;
-                System.err.println() ;
-            }
-            intEx.printStackTrace(System.err) ;
-            throw new TerminationException(99) ;
-        }
-    }
-
-    
-    public ResultsFormat getInputFormat() { return inputFormat ; }
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModResultsOut.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModResultsOut.java b/jena-arq/src/main/java/arq/cmdline/ModResultsOut.java
deleted file mode 100644
index 938be5f..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModResultsOut.java
+++ /dev/null
@@ -1,70 +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 arq.cmdline;
-
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdGeneral;
-import jena.cmd.ModBase;
-
-import org.apache.jena.query.ResultSet ;
-import org.apache.jena.sparql.core.Prologue ;
-import org.apache.jena.sparql.resultset.ResultsFormat ;
-import org.apache.jena.sparql.util.QueryExecUtils ;
-
-public class ModResultsOut extends ModBase
-{
-    protected final 
-    ArgDecl resultsFmtDecl = new ArgDecl(ArgDecl.HasValue, "results", "out", "rfmt") ;
-
-    private ResultsFormat resultsFormat = ResultsFormat.FMT_UNKNOWN ;
-    
-    @Override
-    public void processArgs(CmdArgModule cmdline) throws IllegalArgumentException
-    {
-        if ( cmdline.contains(resultsFmtDecl) )
-        {
-            String rFmt = cmdline.getValue(resultsFmtDecl) ;
-            resultsFormat = ResultsFormat.lookup(rFmt) ;
-            if ( resultsFormat == null )
-                cmdline.cmdError("Unrecognized output format: "+rFmt) ;
-        }
-    }
-    
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        cmdLine.getUsage().startCategory("Results") ;
-        cmdLine.add(resultsFmtDecl,
-                    "--results=",
-                    "Results format (Result set: text, XML, JSON, CSV, TSV; Graph: RDF serialization)") ;  
-    }
-
-    public void checkCommandLine(CmdArgModule cmdLine)
-    {}
-
-    public void printResultSet(ResultSet resultSet, Prologue prologue)
-    {
-        QueryExecUtils.outputResultSet(resultSet, prologue, resultsFormat) ;
-    }
-    
-    public ResultsFormat getResultsFormat() { return resultsFormat ; }
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModSymbol.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModSymbol.java b/jena-arq/src/main/java/arq/cmdline/ModSymbol.java
deleted file mode 100644
index b465644..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModSymbol.java
+++ /dev/null
@@ -1,26 +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 arq.cmdline;
-
-/** Set Context items
- *  @deprecated Use ModContext.
- */
-@Deprecated
-public class ModSymbol extends ModContext {
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/cmdline/ModTime.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModTime.java b/jena-arq/src/main/java/arq/cmdline/ModTime.java
deleted file mode 100644
index 03a2096..0000000
--- a/jena-arq/src/main/java/arq/cmdline/ModTime.java
+++ /dev/null
@@ -1,73 +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 arq.cmdline;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdGeneral;
-import jena.cmd.ModBase;
-
-import org.apache.jena.atlas.lib.Timer ;
-
-
-public class ModTime extends ModBase
-{
-
-    protected final ArgDecl timeDecl = new ArgDecl(ArgDecl.NoValue, "time") ;
-    
-    protected Timer timer = new Timer() ;
-    
-    private boolean timing = false ;
-    
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        cmdLine.getUsage().startCategory("Time") ;
-        cmdLine.add(timeDecl, "--time", "Time the operation") ;
-    }
-    
-    public void checkCommandLine(CmdArgModule cmdLine)
-    {}
-
-    @Override
-    public void processArgs(CmdArgModule cmdLine)
-    {
-        timing = cmdLine.contains(timeDecl) ;
-    }
-    
-    public boolean timingEnabled() { return timing ; }
-    
-    public void setTimingEnabled(boolean timingEnabled) { timing = timingEnabled ; }
-    
-    public void startTimer()
-    { timer.startTimer() ; } 
-    
-    public long endTimer()
-    { return timer.endTimer() ; } 
-    
-    public long readTimer() 
-    { return timer.readTimer() ; }
-    
-    public long getTimeInterval()
-    { return timer.getTimeInterval() ; }
-    
-    public String timeStr(long timeInterval)
-    { return Timer.timeStr(timeInterval) ; }
-    
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/iri.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/iri.java b/jena-arq/src/main/java/arq/iri.java
deleted file mode 100644
index 2d5232c..0000000
--- a/jena-arq/src/main/java/arq/iri.java
+++ /dev/null
@@ -1,57 +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 arq;
-
-import java.util.Iterator ;
-
-
-import org.apache.jena.iri.IRI ;
-import org.apache.jena.iri.IRIFactory ;
-import org.apache.jena.iri.Violation ;
-import org.apache.jena.riot.system.IRIResolver ;
-
-public class iri
-{
-
-    public static void main(String[] args)
-    {
-        //IRIFactory iriFactory = IRIFactory.iriImplementation() ;
-        IRIFactory iriFactory = IRIResolver.iriFactory ;
-        
-        boolean first = true ;
-        for ( String iriStr : args )
-        {
-            if ( ! first )
-                System.out.println() ;
-            first = false ;
-            
-            IRI iri = iriFactory.create(iriStr) ;
-            System.out.println(iriStr + " ==> "+iri) ;
-            if ( iri.isRelative() )
-                System.out.println("Relative: "+iri.isRelative()) ;
-
-            Iterator<Violation> vIter = iri.violations(true) ;
-            for ( ; vIter.hasNext() ; )
-            {
-                System.out.println(vIter.next().getShortMessage()) ;
-            }
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/juuid.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/juuid.java b/jena-arq/src/main/java/arq/juuid.java
deleted file mode 100644
index ccd6fd1..0000000
--- a/jena-arq/src/main/java/arq/juuid.java
+++ /dev/null
@@ -1,173 +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 arq;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdArgModule;
-import jena.cmd.CmdGeneral;
-import jena.cmd.ModBase;
-
-import org.apache.jena.shared.uuid.* ;
-
-public class juuid extends CmdGeneral
-{
-    ModJUUID modJUUID = new ModJUUID() ;
-    int number = 1 ;
-    boolean resetEachTime = false ;
-    int uuidType = 0 ;
-    boolean asURN = false ;
-    boolean asURI = false ;
-    boolean asPlain = false ;
-
-    public static void main (String [] argv)
-    {
-        new juuid(argv).mainAndExit() ;
-    }
-    
-    private juuid(String argv[])
-    {
-        super(argv) ;
-        super.addModule(modJUUID) ;
-    }
-
-    @Override
-    protected String getSummary()
-    {
-        return getCommandName()+" [--num=N] [--reset] [--type={1|4}]" ;
-    }
-
-    @Override
-    protected void exec()
-    {
-        if ( uuidType == UUID_V1.version )
-            JenaUUID.setFactory(new UUID_V1_Gen()) ;
-        if ( uuidType == UUID_V4.version )
-            JenaUUID.setFactory(new UUID_V4_Gen()) ;
-
-        for ( int i = 0 ; i < number ; i++ )
-        {
-            if ( resetEachTime && i != 0)
-                JenaUUID.reset() ;
-            JenaUUID uuid = JenaUUID.generate() ;
-            String str = null ;
-            if ( asURN )
-                str = uuid.asURN() ; 
-            else if ( asURI )
-                str = uuid.asURI() ; 
-            else if ( asPlain )
-                str = uuid.asString() ; 
-            if ( str == null )
-                str = uuid.asString() ;
-            System.out.println(str) ;
-        }
-    }
-
-    @Override
-    protected String getCommandName()
-    {
-        return "uuid" ;
-    }
-
-    @Override
-    protected void processModulesAndArgs()
-    {
-        
-    }
-    
-    static ArgDecl argDeclNum      = new ArgDecl(ArgDecl.HasValue,  "num", "n") ;
-    static ArgDecl argDeclReset    = new ArgDecl(ArgDecl.NoValue,   "reset") ;
-    static ArgDecl argDeclGen      = new ArgDecl(ArgDecl.HasValue,  "gen", "scheme", "type", "ver") ;
-    static ArgDecl argDeclURN      = new ArgDecl(ArgDecl.NoValue,   "urn") ;
-    static ArgDecl argDeclURI      = new ArgDecl(ArgDecl.NoValue,   "uri") ;
-    static ArgDecl argDeclPlain    = new ArgDecl(ArgDecl.NoValue,   "plain") ;
-
-    class ModJUUID extends ModBase
-    {
-        @Override
-        public void registerWith(CmdGeneral cmdLine)
-        {
-            cmdLine.add(argDeclNum) ;
-            cmdLine.add(argDeclReset) ;
-            cmdLine.add(argDeclGen) ;
-            cmdLine.add(argDeclURN) ;
-            cmdLine.add(argDeclURI) ;
-            cmdLine.add(argDeclPlain) ;
-        }
-        
-        @Override
-        public void processArgs(CmdArgModule cmdLine)
-        {
-            String numStr = null ;
-            
-            if ( getNumPositional() > 1)
-                cmdError("Too many positional arguments") ;
-            
-            if ( cmdLine.contains(argDeclNum) )
-            {
-                if ( getNumPositional() != 0 )
-                    cmdError("--num and positional arguments don't go together") ;
-                numStr = getValue(argDeclNum) ;
-            }
-            
-            if ( numStr == null && cmdLine.getNumPositional() == 1 )
-                numStr = cmdLine.getPositionalArg(0) ;
-            
-            if ( numStr != null )
-            {
-                try
-                {
-                    number = Integer.parseInt(numStr) ;
-                    if ( number < 0 || number > 10000 )
-                        cmdLine.cmdError("Number out of range:" + numStr);
-                }
-                catch (NumberFormatException e)
-                {
-                    cmdLine.cmdError("Bad argument: " + numStr);
-                }
-            }
-
-            resetEachTime = cmdLine.contains(argDeclReset) ;
-            
-            if ( contains(argDeclGen) ) 
-            {
-                String s = getValue(argDeclGen) ;
-                if ( s.equalsIgnoreCase("time") || s.equalsIgnoreCase("1"))
-                    uuidType = UUID_V1.version ;
-                else if ( s.equalsIgnoreCase("random") || s.equalsIgnoreCase("rand") || s.equalsIgnoreCase("4"))
-                    uuidType = UUID_V4.version ;
-                else
-                    cmdError("Unrecognized UUID scheme: "+s) ;
-            }
-            
-            if ( contains(argDeclURN) || contains(argDeclURI) || contains(argDeclPlain) )
-            {
-                asURN = contains(argDeclURN) ;
-                asURI = contains(argDeclURI) ;
-                asPlain = contains(argDeclPlain) ;
-            }
-            else
-            {
-                // Defaults
-                asURN = true ;
-                asURI = false ;
-                asPlain = false ;
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/load.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/load.java b/jena-arq/src/main/java/arq/load.java
deleted file mode 100644
index b5d75c8..0000000
--- a/jena-arq/src/main/java/arq/load.java
+++ /dev/null
@@ -1,120 +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 arq;
-
-import java.util.Iterator ;
-import java.util.List ;
-
-import arq.cmdline.CmdUpdate ;
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdException;
-import org.apache.jena.atlas.io.IndentedWriter ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.sparql.core.DatasetGraph ;
-import org.apache.jena.sparql.modify.request.UpdateLoad ;
-import org.apache.jena.sparql.sse.SSE ;
-import org.apache.jena.sparql.util.graph.GraphLoadMonitor ;
-import org.apache.jena.update.UpdateExecutionFactory ;
-import org.apache.jena.update.UpdateRequest ;
-
-public class load extends CmdUpdate
-{
-    static private final ArgDecl graphNameArg = new ArgDecl(ArgDecl.HasValue, "--graph") ;
-    static private final ArgDecl dumpArg = new ArgDecl(ArgDecl.NoValue, "--dump") ;
-    
-    String graphName = null ;
-    List<String> loadFiles = null ;
-    boolean dump = false ;
-    
-    public static void main (String... argv)
-    { new load(argv).mainRun() ; }
-    
-    protected load(String[] argv)
-    {
-        super(argv) ;
-        super.add(graphNameArg, "--graph=IRI", "Graph IRI (loads default graph if absent)") ;
-        super.add(dumpArg, "--dump", "Dump the resulting graph store") ;
-    }
-
-    @Override
-    protected void processModulesAndArgs()
-    {
-        if ( containsMultiple(graphNameArg) )
-            throw new CmdException("At most one --graph allowed") ;
-        
-        graphName = getValue(graphNameArg) ;
-        loadFiles = super.getPositional() ;
-        dump = contains(dumpArg) ;
-        super.processModulesAndArgs() ;
-    }
-    
-    @Override
-    protected String getCommandName() { return Lib.className(this) ; }
-    
-    @Override
-    protected String getSummary() { return getCommandName()+" --desc=assembler [--dump] --update=<request file>" ; }
-
-    @Override
-    protected void execUpdate(DatasetGraph graphStore)
-    {
-        if ( loadFiles.size() == 0 )
-            throw new CmdException("Nothing to do") ;
-        
-        UpdateRequest req = new UpdateRequest() ;
-        for ( String filename : loadFiles )
-        {
-            UpdateLoad loadReq = new UpdateLoad( filename, graphName );
-            req.add( loadReq );
-        }
-        
-        if ( true )
-        {
-            // Need a better way
-            monitor(graphStore.getDefaultGraph()) ;
-            for ( Iterator<Node> iter = graphStore.listGraphNodes() ; iter.hasNext() ; )
-            {
-                Graph g = graphStore.getGraph(iter.next()) ;
-                monitor(g) ;
-            }
-        }
-        
-        UpdateExecutionFactory.create(req, graphStore).execute() ;
-        
-        if ( dump )
-        {
-            IndentedWriter out = IndentedWriter.stdout ;
-            SSE.write(graphStore) ;
-            out.flush();
-        }
-    }
-
-    private void monitor(Graph graph)
-    {
-        GraphLoadMonitor m = new GraphLoadMonitor(20000,false) ;
-        //m.setSummaryLabel(getCommandName()) ;
-        graph.getEventManager().register(m)  ;
-    }
-    
-    @Override
-    protected DatasetGraph dealWithNoDataset() {
-        throw new CmdException("No dataset provided") ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/qexpr.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/qexpr.java b/jena-arq/src/main/java/arq/qexpr.java
deleted file mode 100644
index 2408907..0000000
--- a/jena-arq/src/main/java/arq/qexpr.java
+++ /dev/null
@@ -1,223 +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 arq;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdException;
-import jena.cmd.CmdLineArgs;
-import jena.cmd.TerminationException;
-
-import org.apache.jena.Jena ;
-import org.apache.jena.atlas.io.IndentedWriter ;
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.query.ARQ ;
-import org.apache.jena.query.QueryParseException ;
-import org.apache.jena.riot.out.NodeFmtLib ;
-import org.apache.jena.shared.PrefixMapping ;
-import org.apache.jena.sparql.ARQConstants ;
-import org.apache.jena.sparql.core.Prologue ;
-import org.apache.jena.sparql.engine.ExecutionContext ;
-import org.apache.jena.sparql.expr.Expr ;
-import org.apache.jena.sparql.expr.ExprEvalException ;
-import org.apache.jena.sparql.expr.ExprLib ;
-import org.apache.jena.sparql.expr.NodeValue ;
-import org.apache.jena.sparql.function.FunctionEnv ;
-import org.apache.jena.sparql.sse.WriterSSE ;
-import org.apache.jena.sparql.util.ExprUtils ;
-import org.apache.jena.sparql.util.NodeFactoryExtra ;
-
-/** A program to execute expressions from the command line. */
-
-public class qexpr
-{
-    // TODO Convert to extends CmdArgModule 
-    static { LogCtl.setCmdLogging(); }
-
-    public static void main (String... argv)
-    {
-        try {
-            main2(argv) ;
-        }
-        catch (TerminationException ex) { System.exit(ex.getCode()) ; }
-        catch (CmdException ex)
-        {
-            System.err.println(ex.getMessage()) ;
-            if ( ex.getCause() != null )
-                ex.getCause().printStackTrace(System.err) ;
-        }
-        
-    }
-    
-    public static void execAndReturn(String... argv)
-    {
-        try {
-            main2(argv) ;
-        }
-        catch (TerminationException ex) { return ; }
-        catch (CmdException ex)
-        {
-            System.err.println(ex.getMessage()) ;
-            if ( ex.getCause() != null )
-                ex.getCause().printStackTrace(System.err) ;
-        }
-    }
-        
-    public static void main2(String... argv)
-    {
-        
-        CmdLineArgs cl = new CmdLineArgs(argv) ;
-        
-        ArgDecl helpDecl = new ArgDecl(ArgDecl.NoValue, "h", "help") ;
-        cl.add(helpDecl) ;
-        
-        ArgDecl verboseDecl = new ArgDecl(ArgDecl.NoValue, "v", "verbose") ;
-        cl.add(verboseDecl) ;
-        
-        ArgDecl versionDecl = new ArgDecl(ArgDecl.NoValue, "ver", "version", "V") ;
-        cl.add(versionDecl) ;
-        
-        ArgDecl quietDecl = new ArgDecl(ArgDecl.NoValue, "q", "quiet") ;
-        cl.add(quietDecl) ;
-
-        ArgDecl reduceDecl =  new ArgDecl(ArgDecl.NoValue, "reduce", "fold", "simplify" ) ;
-        cl.add(reduceDecl) ;
-
-        ArgDecl strictDecl =  new ArgDecl(ArgDecl.NoValue, "strict") ;
-        cl.add(strictDecl) ;
-        
-        ArgDecl printDecl =  new ArgDecl(ArgDecl.HasValue, "print") ;
-        cl.add(printDecl) ;
-
-        try {
-            cl.process() ;
-        } catch (IllegalArgumentException ex)
-        {
-            System.err.println(ex.getMessage()) ;
-            usage(System.err) ;
-            throw new CmdException() ;
-        }
-
-        if ( cl.contains(helpDecl) )
-        {
-            usage() ;
-            throw new TerminationException(0) ;
-        }
-        
-        if ( cl.contains(versionDecl) )
-        {
-            System.out.println("ARQ Version: "+ARQ.VERSION+" (Jena: "+Jena.VERSION+")") ;
-            throw new TerminationException(0) ;
-        }
- 
-        // ==== General things
-        boolean verbose = cl.contains(verboseDecl) ;
-        boolean quiet = cl.contains(quietDecl) ;
-
-        if ( cl.contains(strictDecl) )
-            ARQ.setStrictMode() ;
-        
-        boolean actionCopySubstitute = cl.contains(reduceDecl) ;
-        boolean actionPrintPrefix = false ;
-        boolean actionPrintSPARQL = false ; 
-        boolean actionPrint = cl.contains(printDecl) ;
-
-        for ( String v : cl.getValues( printDecl ) )
-        {
-            if ( v.equalsIgnoreCase( "prefix" ) || v.equalsIgnoreCase( "op" ) )
-            {
-                actionPrintPrefix = true;
-            }
-            else if ( v.equalsIgnoreCase( "expr" ) )
-            {
-                actionPrintSPARQL = true;
-            }
-            else
-            {
-                System.err.println( "Unknown print form: " + v );
-                throw new TerminationException( 0 );
-            }
-        }
-
-        // ==== Do it
-        
-        for ( int i = 0 ; i < cl.getNumPositional() ; i++ )
-        {
-            String exprStr = cl.getPositionalArg(i) ;
-            exprStr = cl.indirect(exprStr) ;
-            
-            try {
-                PrefixMapping pmap = PrefixMapping.Factory.create()  ;
-                pmap.setNsPrefixes(ARQConstants.getGlobalPrefixMap()) ;
-                pmap.setNsPrefix("", "http://example/") ;
-                pmap.setNsPrefix("ex", "http://example/ns#") ;
-//              Node n = asNode() ;
-//              return makeNode(n) ;
-
-                Expr expr = ExprUtils.parse(exprStr, pmap) ;
-                if ( verbose )
-                    System.out.print(expr.toString()+" => ") ;
-                
-                if ( actionPrint )
-                {
-                    if ( actionPrintSPARQL )
-                        System.out.println(ExprUtils.fmtSPARQL(expr)) ;
-                    if ( actionPrintPrefix )
-                        WriterSSE.out(IndentedWriter.stdout, expr, new Prologue(pmap)) ;
-                    continue ;
-                }
-                
-                try {
-                    if ( actionCopySubstitute )
-                    {
-                        Expr e = ExprLib.foldConstants(expr) ;
-                        System.out.println(e) ;
-                    }
-                    else
-                    {
-                        // Default action
-                        ARQ.getContext().set(ARQConstants.sysCurrentTime, NodeFactoryExtra.nowAsDateTime()) ;
-                        FunctionEnv env = new ExecutionContext(ARQ.getContext(), null, null, null) ; 
-                        NodeValue r = expr.eval(null, env) ;
-                        //System.out.println(r.asQuotedString()) ;
-                        Node n = r.asNode() ;
-                        String s = NodeFmtLib.displayStr(n) ;
-                        System.out.println(s) ;
-                    }
-                } catch (ExprEvalException ex)
-                {
-                    System.out.println("Exception: "+ex.getMessage()) ;
-                    throw new TerminationException(2) ;
-                }
-            } catch (QueryParseException ex)
-            {
-                System.err.println("Parse error: "+ex.getMessage()) ;
-                throw new TerminationException(2) ;
-            }
-        }
-    }
-    
-    static void usage() { usage(System.out) ; }
-    
-    static void usage(java.io.PrintStream out)
-    {
-        out.println("Usage: [--print=[prefix|expr]] expression") ;
-    }
-
- }

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/qparse.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/qparse.java b/jena-arq/src/main/java/arq/qparse.java
deleted file mode 100644
index 749ab66..0000000
--- a/jena-arq/src/main/java/arq/qparse.java
+++ /dev/null
@@ -1,269 +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 arq;
-
-import java.io.PrintStream ;
-import java.util.Iterator ;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdException;
-
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.apache.jena.query.* ;
-import org.apache.jena.shared.JenaException ;
-import org.apache.jena.sparql.ARQInternalErrorException ;
-import org.apache.jena.sparql.core.QueryCheckException ;
-import org.apache.jena.sparql.lang.ParserBase ;
-import org.apache.jena.sparql.resultset.ResultSetException ;
-import org.apache.jena.sparql.util.QueryOutputUtils ;
-import org.apache.jena.sparql.util.QueryUtils ;
-
-import arq.cmdline.CmdARQ ;
-import arq.cmdline.ModEngine ;
-import arq.cmdline.ModQueryIn ;
-import arq.cmdline.ModQueryOut ;
-
-/** A program to parse and print a query. */
-
-public class qparse extends CmdARQ
-{
-    protected ModQueryIn    modQuery        = new ModQueryIn(Syntax.syntaxSPARQL_11) ;
-    protected ModQueryOut   modOutput       = new ModQueryOut() ; 
-    protected ModEngine     modEngine       = new ModEngine() ;
-    protected final ArgDecl argDeclPrint    = new ArgDecl(ArgDecl.HasValue, "print") ;
-    protected final ArgDecl argDeclOpt      = new ArgDecl(ArgDecl.NoValue, "opt", "optimize") ;
-    protected final ArgDecl argDeclExplain  = new ArgDecl(ArgDecl.NoValue, "explain") ;
-    
-    protected boolean printNone             = false ;
-    protected boolean printQuery            = false ;
-    protected boolean printOp               = false ;
-    protected boolean printOpt              = false ;
-    protected boolean printQuad             = false ;
-    protected boolean printQuadOpt          = false ;
-    protected boolean printPlan             = false ;
-    
-    public static void main(String... argv)
-    {
-        new qparse(argv).mainRun() ;
-    }
-    
-    public qparse(String[] argv)
-    {
-        super(argv) ;
-        super.addModule(modQuery) ;
-        super.addModule(modOutput) ;
-        super.addModule(modEngine) ;
-        super.getUsage().startCategory(null) ;
-        super.add(argDeclPrint, "--print", "Print in various forms [query, op, quad, plan]") ;
-        super.add(argDeclExplain, "--explain", "Print with algebra-level optimization") ;
-        super.add(argDeclOpt, "--opt", "[deprecated]") ; 
-    }
-    
-    @Override
-    protected void processModulesAndArgs()
-    {
-        super.processModulesAndArgs() ;
-        
-        if ( contains(argDeclOpt) )
-            printOpt = true ;
-        if ( contains(argDeclExplain) )
-        {
-            printQuery = true ;
-            printOpt = true ;
-        }
-
-        for ( String arg : getValues( argDeclPrint ) )
-        {
-            if ( arg.equalsIgnoreCase( "query" ) )
-            {
-                printQuery = true;
-            }
-            else if ( arg.equalsIgnoreCase( "op" ) ||
-                arg.equalsIgnoreCase( "alg" ) ||
-                arg.equalsIgnoreCase( "algebra" ) )
-            {
-                printOp = true;
-            }
-            else if ( arg.equalsIgnoreCase( "quad" ) )
-            {
-                printQuad = true;
-            }
-            else if ( arg.equalsIgnoreCase( "quads" ) )
-            {
-                printQuad = true;
-            }
-            else if ( arg.equalsIgnoreCase( "plan" ) )
-            {
-                printPlan = true;
-            }
-            else if ( arg.equalsIgnoreCase( "opt" ) )
-            {
-                printOpt = true;
-            }
-            else if ( arg.equalsIgnoreCase( "optquad" ) )
-            {
-                printQuadOpt = true;
-            }
-            else if ( arg.equalsIgnoreCase( "quadopt" ) )
-            {
-                printQuadOpt = true;
-            }
-            else if ( arg.equalsIgnoreCase( "none" ) )
-            {
-                printNone = true;
-            }
-            else
-            {
-                throw new CmdException(
-                    "Not a recognized print form: " + arg + " : Choices are: query, op, quad, opt, optquad" );
-            }
-        }
-        
-        if ( ! printQuery && ! printOp && ! printQuad && ! printPlan && ! printOpt && ! printQuadOpt && ! printNone )
-            printQuery = true ;
-    }
-
-    static String usage = qparse.class.getName()+" [--in syntax] [--out syntax] [--print=FORM] [\"query\"] | --query <file>" ;
-    
-    @Override
-    protected String getSummary()
-    {
-        return usage ;
-    }
-    
-    static final String divider = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" ;
-    //static final String divider = "" ;
-    boolean needDivider = false ;
-    private void divider()
-    {
-        if ( needDivider ) System.out.println(divider) ;
-        needDivider = true ;
-    }
-    
-    @Override
-    protected void exec()
-    {
-        try{
-            Query query = modQuery.getQuery() ;
-            try {
-                LogCtl.disable(ParserBase.ParserLoggerName) ;
-                QueryUtils.checkQuery(query, true) ;
-            } catch (QueryCheckException ex)
-            {
-                System.err.println() ;
-                System.err.println("**** Check failure: "+ex.getMessage()) ;
-                if ( ex.getCause() != null )
-                    ex.getCause().printStackTrace(System.err) ;
-            }
-            finally { LogCtl.set(ParserBase.ParserLoggerName, "INFO") ; }
-
-            
-            // Print the query out in some syntax
-            if ( printQuery )
-            { divider() ; modOutput.output(query) ; }
-
-            // Print internal forms.
-            if ( printOp )
-            { divider() ; modOutput.outputOp(query, false) ; }
-            
-            if ( printQuad )
-            { divider() ; modOutput.outputQuad(query, false) ; }
-            
-            if ( printOpt )
-            { divider() ; modOutput.outputOp(query, true) ; }
-            
-            if ( printQuadOpt )
-            { divider() ; modOutput.outputQuad(query, true) ; }
-            
-            if ( printPlan )
-            { 
-                divider() ;
-                // This forces internal query initialization - must be after QueryUtils.checkQuery
-                QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.createGeneral()) ;
-                QueryOutputUtils.printPlan(query, qExec) ; 
-            }
-        }
-        catch (ARQInternalErrorException intEx)
-        {
-            System.err.println(intEx.getMessage()) ;
-            if ( intEx.getCause() != null )
-            {
-                System.err.println("Cause:") ;
-                intEx.getCause().printStackTrace(System.err) ;
-                System.err.println() ;
-            }
-            intEx.printStackTrace(System.err) ;
-        }
-        catch (ResultSetException ex)
-        {
-            System.err.println(ex.getMessage()) ;
-            ex.printStackTrace(System.err) ;
-        }
-        catch (QueryException qEx)
-        {
-            //System.err.println(qEx.getMessage()) ;
-            throw new CmdException("Query Exeception", qEx) ;
-        }
-        catch (JenaException ex) { 
-            ex.printStackTrace() ;
-            throw ex ; } 
-        catch (CmdException ex) { throw ex ; } 
-        catch (Exception ex)
-        {
-            throw new CmdException("Exception", ex) ;
-        }
-    }
-
-    @Override
-    protected String getCommandName() { return Lib.className(this) ; }
-
-//    static String usage = qparse.class.getName()+
-//            " [--in syntax] [--out syntax] [\"query\" | --query <file>\n"+
-//            "  where syntax is one of ARQ, SPARQL\n" +
-//            "Other options: \n"+
-//            "  --num on|off   Line number ('on' by default)\n"+
-//            "  -n             Same as --num=off\n"+
-//            "  --base URI     Set the base URI for resolving relative URIs\n"+
-//            "  --plain        No pretty printing\n"+
-//            "  --parse        Parse only - don't print\n"+
-//            "  ---planning    Turn planning on/off\n"+
-//            "  --show X       Show internal structure (X = query or plan)\n" ;
-    
-    static void writeSyntaxes(String msg, PrintStream out)
-    {
-        if ( msg != null )
-            out.println(msg) ;
-        for ( Iterator<String> iter = Syntax.querySyntaxNames.keys() ; iter.hasNext() ; )
-        {
-            String k = iter.next() ;
-            Syntax v = Syntax.lookup(k) ;
-            k = padOut(k,10) ;
-            out.println("  "+k+"  "+v) ;
-        }
-    }
-    // printf ... java 1.5 .. mutter,mutter
-    static String padOut(String x, int len)
-    {
-        StringBuilder r = new StringBuilder(x) ;
-        for ( int i = x.length() ; i <= len ; i++ )
-            r.append(" ") ;
-        return r.toString() ; 
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/query.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/query.java b/jena-arq/src/main/java/arq/query.java
deleted file mode 100644
index 9a9ed5f..0000000
--- a/jena-arq/src/main/java/arq/query.java
+++ /dev/null
@@ -1,257 +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 arq;
-
-import arq.cmdline.* ;
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdException;
-import jena.cmd.TerminationException;
-import org.apache.jena.atlas.io.IndentedWriter ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.apache.jena.query.* ;
-import org.apache.jena.riot.RiotException ;
-import org.apache.jena.riot.RiotNotFoundException ;
-import org.apache.jena.riot.SysRIOT ;
-import org.apache.jena.shared.JenaException ;
-import org.apache.jena.sparql.ARQInternalErrorException ;
-import org.apache.jena.sparql.mgt.Explain ;
-import org.apache.jena.sparql.resultset.ResultSetException ;
-import org.apache.jena.sparql.resultset.ResultsFormat ;
-import org.apache.jena.sparql.util.QueryExecUtils ;
-
-public class query extends CmdARQ
-{
-    private ArgDecl argRepeat   = new ArgDecl(ArgDecl.HasValue, "repeat") ;
-    private ArgDecl argExplain  = new ArgDecl(ArgDecl.NoValue, "explain") ;
-    private ArgDecl argOptimize = new ArgDecl(ArgDecl.HasValue, "opt", "optimize") ;
-
-    protected int repeatCount = 1 ; 
-    protected int warmupCount = 0 ;
-    protected boolean queryOptimization = true ;
-    
-    protected ModTime       modTime =     new ModTime() ;
-    protected ModQueryIn    modQuery =    null;
-    protected ModDataset    modDataset =  null ;
-    protected ModResultsOut modResults =  new ModResultsOut() ;
-    protected ModEngine     modEngine =   new ModEngine() ;
-    
-    public static void main (String... argv)
-    {
-        new query(argv).mainRun() ;
-    }
-    
-    public query(String[] argv)
-    {
-        super(argv) ;
-        modQuery = new ModQueryIn(getDefaultSyntax()) ; 
-        modDataset = setModDataset() ;
-       
-        super.addModule(modQuery) ;
-        super.addModule(modResults) ;
-        super.addModule(modDataset) ;
-        super.addModule(modEngine) ;
-        super.addModule(modTime) ;
-
-        super.getUsage().startCategory("Control") ;
-        super.add(argExplain,  "--explain", "Explain and log query execution") ;
-        super.add(argRepeat,   "--repeat=N or N,M", "Do N times or N warmup and then M times (use for timing to overcome start up costs of Java)");
-        super.add(argOptimize, "--optimize=", "Turn the query optimizer on or off (default: on)") ;
-    }
-
-    /** Default syntax used when the syntax can not be determined from the command name or file extension
-     *  The order of determination is:
-     *  <ul>
-     *  <li>Explicitly given --syntax</li>
-     *  <li>File extension</li>
-     *  <li>Command default</li>
-     *  <li>System default</li>
-     *  </ul>
-     *  
-     */
-    protected Syntax getDefaultSyntax()     { return Syntax.defaultQuerySyntax ; }
-
-    @Override
-    protected void processModulesAndArgs()
-    {
-        super.processModulesAndArgs() ;
-        if ( contains(argRepeat) )
-        {
-            String[] x = getValue(argRepeat).split(",") ;
-            if ( x.length == 1 )
-            {
-                try { repeatCount = Integer.parseInt(x[0]) ; }
-                catch (NumberFormatException ex)
-                { throw new CmdException("Can't parse "+x[0]+" in arg "+getValue(argRepeat)+" as an integer") ; }
-                
-            }
-            else if ( x.length == 2 )
-            {
-                try { warmupCount = Integer.parseInt(x[0]) ; }
-                catch (NumberFormatException ex)
-                { throw new CmdException("Can't parse "+x[0]+" in arg "+getValue(argRepeat)+" as an integer") ; }
-                try { repeatCount = Integer.parseInt(x[1]) ; }
-                catch (NumberFormatException ex)
-                { throw new CmdException("Can't parse "+x[1]+" in arg "+getValue(argRepeat)+" as an integer") ; }
-            }
-            else
-                throw new CmdException("Wrong format for repeat count: "+getValue(argRepeat)) ;
-        }
-        if ( isVerbose() )
-            ARQ.getContext().setTrue(ARQ.symLogExec) ;
-        
-        if ( hasArg(argExplain) )
-            ARQ.setExecutionLogging(Explain.InfoLevel.ALL) ;
-        
-        if ( hasArg(argOptimize) )
-        {
-            String x1 = getValue(argOptimize) ;
-            if ( hasValueOfTrue(argOptimize) || x1.equalsIgnoreCase("on") || x1.equalsIgnoreCase("yes") ) 
-                queryOptimization = true ;
-            else if ( hasValueOfFalse(argOptimize) || x1.equalsIgnoreCase("off") || x1.equalsIgnoreCase("no") )
-                queryOptimization = false ;
-            else throw new CmdException("Optimization flag must be true/false/on/off/yes/no. Found: "+getValue(argOptimize)) ;
-        }
-    }
-    
-    protected ModDataset setModDataset()
-    {
-        return new ModDatasetGeneralAssembler() ;
-    }
-    
-    @Override
-    protected void exec()
-    {
-        if ( ! queryOptimization )
-            ARQ.getContext().setFalse(ARQ.optimization) ;
-        if ( cmdStrictMode )
-            ARQ.getContext().setFalse(ARQ.optimization) ;
-        
-        // Warm up.
-        for ( int i = 0 ; i < warmupCount ; i++ )
-        {
-            queryExec(false, ResultsFormat.FMT_NONE) ;
-        }
-        
-        for ( int i = 0 ; i < repeatCount ; i++ )
-            queryExec(modTime.timingEnabled(),  modResults.getResultsFormat()) ;
-        
-        if ( modTime.timingEnabled() && repeatCount > 1 )
-        {
-            long avg = totalTime/repeatCount ;
-            String avgStr = modTime.timeStr(avg) ;
-            System.err.println("Total time: "+modTime.timeStr(totalTime)+" sec for repeat count of "+repeatCount+ " : average: "+avgStr) ;
-        }
-    }
-
-    @Override
-    protected String getCommandName() { return Lib.className(this) ; }
-    
-    @Override
-    protected String getSummary() { return getCommandName()+" --data=<file> --query=<query>" ; }
-    
-    protected Dataset getDataset()  { 
-        try {
-            Dataset ds = modDataset.getDataset();
-            if ( ds == null )
-                ds = dealWithNoDataset();
-            return ds;
-        }
-        catch (RiotNotFoundException ex) {
-            System.err.println("Failed to load data: " + ex.getMessage());
-            throw new TerminationException(1);
-        }
-        catch (RiotException ex) {
-            System.err.println("Failed to load data");
-            throw new TerminationException(1);
-        }
-    }
-    
-    protected Dataset dealWithNoDataset()  {
-        return DatasetFactory.create() ;
-        //throw new CmdException("No dataset provided") ; 
-    }
-    
-    protected long totalTime = 0 ;
-    protected void queryExec(boolean timed, ResultsFormat fmt)
-    {
-        try{
-            Query query = modQuery.getQuery() ;
-            if ( isVerbose() )
-            {
-                IndentedWriter out = new IndentedWriter(System.out, true) ;
-                query.serialize(out) ;
-                out.flush() ;
-                System.out.println();
-            }
-            
-            if ( isQuiet() )
-                LogCtl.setError(SysRIOT.riotLoggerName) ;
-            Dataset dataset = getDataset() ;
-            modTime.startTimer() ;
-            QueryExecution qe = QueryExecutionFactory.create(query, dataset) ;
-            // Check there is a dataset
-            
-            if ( dataset == null && ! query.hasDatasetDescription() )
-            {
-                System.err.println("Dataset not specified in query nor provided on command line.");
-                throw new TerminationException(1) ;
-            }
-            try { QueryExecUtils.executeQuery(query, qe, fmt) ; } 
-            catch (QueryCancelledException ex) { 
-                System.out.flush() ;
-                System.err.println("Query timed out") ;
-            }
-            
-            long time = modTime.endTimer() ;
-            if ( timed )
-            {
-                totalTime += time ;
-                System.err.println("Time: "+modTime.timeStr(time)+" sec") ;
-            }
-            qe.close() ;
-        }
-        catch (ARQInternalErrorException intEx)
-        {
-            System.err.println(intEx.getMessage()) ;
-            if ( intEx.getCause() != null )
-            {
-                System.err.println("Cause:") ;
-                intEx.getCause().printStackTrace(System.err) ;
-                System.err.println() ;
-            }
-            intEx.printStackTrace(System.err) ;
-        }
-        catch (ResultSetException ex)
-        {
-            System.err.println(ex.getMessage()) ;
-            ex.printStackTrace(System.err) ;
-        }
-        catch (QueryException qEx)
-        {
-            //System.err.println(qEx.getMessage()) ;
-            throw new CmdException("Query Exeception", qEx) ;
-        }
-        catch (JenaException | CmdException ex) { throw ex ; }
-        catch (Exception ex)
-        {
-            throw new CmdException("Exception", ex) ;
-        }
-    }    
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/rdfdiff.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/rdfdiff.java b/jena-arq/src/main/java/arq/rdfdiff.java
deleted file mode 100644
index 78a51bb..0000000
--- a/jena-arq/src/main/java/arq/rdfdiff.java
+++ /dev/null
@@ -1,312 +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 arq;
-
-import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-import java.io.FileInputStream;
-
-import org.apache.jena.rdf.model.*;
-import org.apache.jena.sparql.util.Closure;
-
-/**
- * A program which read two RDF models and provides a basic triple level diff
- *
- * <p>
- * This program will read two RDF models, in a variety of languages, and compare
- * them providing a basic triple level diff output. Since blank nodes are a
- * complicating factor diffs for blank node containing portions of the graph are
- * reported in terms of sub-graphs rather than individual triples.
- * </p>
- * <p>
- * Input can be read either from a URL or from a file. The program writes its
- * results to the standard output stream and sets its exit code to 0 if the
- * models are equal, to 1 if they are not and to -1 if it encounters an error.
- * </p>
- *
- * <p>
- * </p>
- *
- * <pre>
- * java jena.rdfcompare model1 model2 [lang1 [lang2]]
- *
- *       model1 and model2 can be file names or URL's
- *       lang1 and lang2 specify the language of the input and can be:
- *           RDF/XML
- *           N-TRIPLE
- *           N3
- * </pre>
- */
-public class rdfdiff extends java.lang.Object {
-
-    static {
-        setCmdLogging();
-    }
-
-    /**
-     * @param args
-     *            the command line arguments
-     */
-    public static void main(String... args) {
-        if (args.length < 2 || args.length > 6) {
-            usage();
-            System.exit(-1);
-        }
-
-        String in1 = args[0];
-        String in2 = args[1];
-        String lang1 = "RDF/XML";
-        if (args.length >= 3) {
-            lang1 = args[2];
-        }
-        String lang2 = "N-TRIPLE";
-        if (args.length >= 4) {
-            lang2 = args[3];
-        }
-        String base1 = null;
-        if (args.length >= 5) {
-            base1 = args[4];
-        }
-        String base2 = base1;
-        if (args.length >= 6) {
-            base2 = args[5];
-        }
-
-        System.out.println(in1 + " " + in2 + " " + lang1 + " " + lang2 + " " + base1 + " " + base2);
-        try {
-            Model m1 = ModelFactory.createDefaultModel();
-            Model m2 = ModelFactory.createDefaultModel();
-
-            read(m1, in1, lang1, base1);
-            read(m2, in2, lang2, base2);
-
-            if (m1.isIsomorphicWith(m2)) {
-                System.out.println("models are equal");
-                System.out.println();
-                System.exit(0);
-            } else {
-                System.out.println("models are unequal");
-                System.out.println();
-
-                if (m1.size() != m2.size()) {
-                    System.out.println(String.format("< %,d triples", m1.size()));
-                    System.out.println(String.format("> %,d triples", m2.size()));
-                }
-
-                // Calculate differences
-                Map<AnonId, Model> m1SubGraphs = new HashMap<>();
-                StmtIterator iter = m1.listStatements();
-                while (iter.hasNext()) {
-                    Statement stmt = iter.next();
-                    if (stmt.asTriple().isConcrete()) {
-                        if (!m2.contains(stmt)) {
-                            System.out.print("< ");
-                            System.out.println(stmt.toString());
-                        }
-                    } else {
-                        // Handle blank nodes via sub-graphs
-                        addToSubGraph(stmt, m1SubGraphs);
-                    }
-                }
-
-                Map<AnonId, Model> m2SubGraphs = new HashMap<>();
-                iter = m2.listStatements();
-                while (iter.hasNext()) {
-                    Statement stmt = iter.next();
-                    if (stmt.asTriple().isConcrete()) {
-                        if (!m1.contains(stmt)) {
-                            System.out.print("> ");
-                            System.out.println(stmt.toString());
-                        }
-                    } else {
-                        // Handle blank nodes via sub-graphs
-                        addToSubGraph(stmt, m2SubGraphs);
-                    }
-                }
-
-                // Compute sub-graph differences
-
-                // Reduce to sets
-                Set<Model> m1SubGraphSet = new TreeSet<>(new ModelReferenceComparator());
-                m1SubGraphSet.addAll(m1SubGraphs.values());
-                Set<Model> m2SubGraphSet = new TreeSet<>(new ModelReferenceComparator());
-                m2SubGraphSet.addAll(m2SubGraphs.values());
-
-                if (m1SubGraphSet.size() != m2SubGraphSet.size()) {
-                    System.out.println("< " + m1SubGraphs.size() + " sub-graphs");
-                    System.out.println("> " + m2SubGraphs.size() + " sub-graphs");
-                }
-                if (m1SubGraphSet.size() > 0) {
-                    diffSubGraphs(m1SubGraphSet, m2SubGraphSet, "< ");
-                }
-                if (m2SubGraphSet.size() > 0) {
-                    diffSubGraphs(m2SubGraphSet, m1SubGraphSet, "> ");
-                }
-
-                System.exit(1);
-            }
-        } catch (Exception e) {
-            System.err.println("Unhandled exception:");
-            System.err.println("    " + e.toString());
-            System.exit(-1);
-        }
-    }
-
-    private static void diffSubGraphs(Set<Model> m1SubGraphSet, Set<Model> m2SubGraphSet, String prefix) {
-        for (Model subGraph : m1SubGraphSet) {
-            // Find candidate matches
-            List<Model> candidates = new ArrayList<>();
-            for (Model subGraphCandidate : m2SubGraphSet) {
-                if (subGraph.size() == subGraphCandidate.size()) {
-                    candidates.add(subGraph);
-                }
-            }
-
-            if (candidates.size() == 0) {
-                // No match
-                printNonMatchingSubGraph(prefix, subGraph);
-            } else if (candidates.size() == 1) {
-                // Precisely 1 candidate
-                if (!subGraph.isIsomorphicWith(candidates.get(0))) {
-                    printNonMatchingSubGraph(prefix, subGraph);
-                } else {
-                    m2SubGraphSet.remove(candidates.get(0));
-                }
-            } else {
-                // Multiple candidates
-                boolean matched = false;
-                for (Model subGraphCandidate : candidates) {
-                    if (subGraph.isIsomorphicWith(subGraphCandidate)) {
-                        // Found a match
-                        matched = true;
-                        m2SubGraphSet.remove(subGraphCandidate);
-                        break;
-                    }
-                }
-
-                if (!matched) {
-                    // Didn't find a match
-                    printNonMatchingSubGraph(prefix, subGraph);
-                }
-            }
-        }
-    }
-
-    private static void printNonMatchingSubGraph(String prefix, Model subGraph) {
-        StmtIterator sIter = subGraph.listStatements();
-        while (sIter.hasNext()) {
-            System.out.print(prefix);
-            System.out.println(sIter.next().toString());
-        }
-    }
-
-    private static void addToSubGraph(Statement stmt, Map<AnonId, Model> subGraphs) {
-        Set<AnonId> ids = new HashSet<>();
-
-        addToIdList(stmt, ids);
-
-        // Here we take a copy of the IDs
-        Model subGraph = null;
-        for (AnonId id : ids) {
-            if (!subGraphs.containsKey(id)) {
-                subGraph = Closure.closure(stmt);
-                subGraph.add(stmt);
-                break;
-            }
-        }
-
-        // May already have built the sub-graph that includes this statement
-        if (subGraph == null)
-            return;
-
-        // Find any further IDs that occur in the sub-graph
-        StmtIterator sIter = subGraph.listStatements();
-        while (sIter.hasNext()) {
-            addToIdList(sIter.next(), ids);
-        }
-
-        // Associate the sub-graph with all mentioned blank node IDs
-        for (AnonId id : ids) {
-            if (subGraphs.containsKey(id))
-                throw new IllegalStateException(String.format("ID %s occurs in multiple sub-graphs", id));
-            subGraphs.put(id, subGraph);
-        }
-    }
-
-    private static void addToIdList(Statement stmt, Set<AnonId> ids) {
-        if (stmt.getSubject().isAnon()) {
-            ids.add(stmt.getSubject().getId());
-        }
-        if (stmt.getObject().isAnon()) {
-            ids.add(stmt.getObject().asResource().getId());
-        }
-    }
-
-    protected static void usage() {
-        System.err.println("usage:");
-        System.err.println("    java jena.rdfdiff source1 source2 [lang1 [lang2 [base1 [base2]]]]");
-        System.err.println();
-        System.err.println("    source1 and source2 can be URL's or filenames");
-        System.err.println("    lang1 and lang2 can take values:");
-        System.err.println("      RDF/XML");
-        System.err.println("      N-TRIPLE");
-        System.err.println("      N3");
-        System.err.println("    lang1 defaults to RDF/XML, lang2 to N-TRIPLE");
-        System.err.println("    base1 and base2 are URIs");
-        System.err.println("    base1 defaults to null");
-        System.err.println("    base2 defaults to base1");
-        System.err.println("    If no base URIs are specified Jena determines the base URI based on the input source");
-
-        System.err.println();
-    }
-
-    protected static void read(Model model, String in, String lang, String base) throws java.io.FileNotFoundException {
-        try {
-            URL url = new URL(in);
-            model.read(in, base, lang);
-        } catch (java.net.MalformedURLException e) {
-            model.read(new FileInputStream(in), base, lang);
-        }
-    }
-
-    private static class ModelReferenceComparator implements Comparator<Model> {
-
-        @Override
-        public int compare(Model o1, Model o2) {
-            if (o1 == o2)
-                return 0;
-            int h1 = System.identityHashCode(o1);
-            int h2 = System.identityHashCode(o2);
-
-            if (h1 == h2)
-                return 0;
-            return h1 < h2 ? -1 : 1;
-        }
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/rset.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/rset.java b/jena-arq/src/main/java/arq/rset.java
deleted file mode 100644
index b1cbc3e..0000000
--- a/jena-arq/src/main/java/arq/rset.java
+++ /dev/null
@@ -1,73 +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 arq;
-
-import org.apache.jena.query.ResultSet ;
-import arq.cmdline.CmdARQ ;
-import arq.cmdline.ModResultsIn ;
-import arq.cmdline.ModResultsOut ;
-
-/** Read and write result sets */
-
-public class rset extends CmdARQ
-{
-    ModResultsIn modInput    = new ModResultsIn() ;
-    ModResultsOut modOutput  = new ModResultsOut() ;
-    
-    static String usage = rset.class.getName()+
-            " [--in syntax] [--out syntax] [--file FILE | FILE ]" ; 
-
-    public static void main(String... argv)
-    {
-        new rset(argv).mainRun() ;
-    }
-
-    public rset(String[] argv)
-    {
-        super(argv) ;
-        super.addModule(modInput) ;
-        super.addModule(modOutput) ;
-    }
-            
-    @Override
-    protected void processModulesAndArgs()
-    {
-        super.processModulesAndArgs() ;
-    }
-
-    @Override
-    protected String getSummary()
-    {
-        return usage ;
-    }
-
-    @Override
-    protected void exec()
-    {
-        ResultSet rs = modInput.getResultSet() ;
-        modOutput.printResultSet(rs, null) ;
-    }
-
-    @Override
-    protected String getCommandName()
-    {
-        return "rset" ;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/rsparql.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/rsparql.java b/jena-arq/src/main/java/arq/rsparql.java
deleted file mode 100644
index bf87dfd..0000000
--- a/jena-arq/src/main/java/arq/rsparql.java
+++ /dev/null
@@ -1,95 +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 arq;
-
-import jena.cmd.CmdException;
-
-import org.apache.jena.query.Query ;
-import org.apache.jena.query.QueryExecution ;
-import org.apache.jena.query.QueryExecutionFactory ;
-import org.apache.jena.query.Syntax ;
-import org.apache.jena.sparql.engine.http.HttpQuery ;
-import org.apache.jena.sparql.engine.http.QueryExceptionHTTP ;
-import org.apache.jena.sparql.util.QueryExecUtils ;
-
-import arq.cmdline.CmdARQ ;
-import arq.cmdline.ModQueryIn ;
-import arq.cmdline.ModRemote ;
-import arq.cmdline.ModResultsOut ;
-
-public class rsparql extends CmdARQ
-{
-    protected ModQueryIn    modQuery =      new ModQueryIn(Syntax.syntaxSPARQL_11) ;
-    protected ModRemote     modRemote =     new ModRemote() ;
-    protected ModResultsOut modResults =    new ModResultsOut() ;
-
-    public static void main (String... argv)
-    {
-        new rsparql(argv).mainRun() ;
-    }
-
-
-    public rsparql(String[] argv)
-    {
-        super(argv) ;
-        super.addModule(modRemote) ;
-        super.addModule(modQuery) ;
-        super.addModule(modResults) ;
-    }
-    
-    
-    @Override
-    protected void processModulesAndArgs()
-    {
-        super.processModulesAndArgs() ;
-        if ( modRemote.getServiceURL() == null )
-            throw new CmdException("No SPARQL endpoint specificied") ;
-    }
-    
-    @Override
-    protected void exec()
-    {
-        Query query = modQuery.getQuery() ;
-
-        try {
-            String serviceURL = modRemote.getServiceURL() ;
-            QueryExecution qe = QueryExecutionFactory.sparqlService(serviceURL, query) ;
-            if ( modRemote.usePost() )
-                HttpQuery.urlLimit = 0 ;
-
-            QueryExecUtils.executeQuery(query, qe, modResults.getResultsFormat()) ;
-        } catch (QueryExceptionHTTP ex)
-        {
-            throw new CmdException("HTTP Exeception", ex) ;
-        }
-        catch (Exception ex)
-        {
-            System.out.flush() ;
-            ex.printStackTrace(System.err) ;
-        }
-    }
-
-
-    @Override
-    protected String getSummary()
-    {
-        return null ;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/rupdate.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/rupdate.java b/jena-arq/src/main/java/arq/rupdate.java
deleted file mode 100644
index 8ef988c..0000000
--- a/jena-arq/src/main/java/arq/rupdate.java
+++ /dev/null
@@ -1,98 +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 arq;
-
-import java.util.List ;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdException;
-
-import org.apache.jena.update.UpdateExecutionFactory ;
-import org.apache.jena.update.UpdateFactory ;
-import org.apache.jena.update.UpdateProcessor ;
-import org.apache.jena.update.UpdateRequest ;
-
-import arq.cmdline.CmdARQ ;
-import arq.cmdline.ModRemote ;
-
-public class rupdate extends CmdARQ
-{
-    static final ArgDecl updateArg = new ArgDecl(ArgDecl.HasValue, "update", "file") ;
-    
-    protected ModRemote     modRemote =     new ModRemote() ;
-
-    List<String> requestFiles = null ;
-
-    public static void main(String[] argv)
-    {
-        new rupdate(argv).mainRun() ;
-    }
-
-    protected rupdate(String[] argv)
-    {
-        super(argv) ;
-        super.add(updateArg, "--update=FILE", "Update commands to execute") ;
-        super.addModule(modRemote) ;
-    }
-
-    @Override
-    protected void processModulesAndArgs()
-    {
-        requestFiles = getValues(updateArg) ;   // ????
-        super.processModulesAndArgs() ;
-    }
-    
-    
-    @Override
-    protected String getSummary()
-    {
-        return getCommandName()+" --service=URL --update=<request file>" ;
-    }
-
-    @Override
-    protected void exec()
-    {
-        if ( modRemote.getServiceURL() == null )
-        {
-            throw new CmdException("No endpoint given") ;
-        }
-        String endpoint = modRemote.getServiceURL() ;
-
-        for ( String filename : requestFiles )
-        {
-            UpdateRequest req = UpdateFactory.read( filename );
-            exec( endpoint, req );
-        }
-
-        for ( String requestString : super.getPositional() )
-        {
-            requestString = indirect( requestString );
-            UpdateRequest req = UpdateFactory.create( requestString );
-            exec( endpoint, req );
-        }
-    }
-
-    private void exec(String endpoint, UpdateRequest req) 
-    {
-        UpdateProcessor proc = UpdateExecutionFactory.createRemote(req, endpoint) ;
-        proc.execute() ;
-    }
-
-}
-

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/sparql.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/sparql.java b/jena-arq/src/main/java/arq/sparql.java
deleted file mode 100644
index d42ba7f..0000000
--- a/jena-arq/src/main/java/arq/sparql.java
+++ /dev/null
@@ -1,37 +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 arq;
-
-import org.apache.jena.query.Syntax ;
-
-/** A program to execute queries from the command line in SPARQL mode. */
-
-public class sparql extends query
-{
-    public static void main (String... argv) {
-        new sparql(argv).mainRun() ;
-    }
-    
-    public sparql(String[] argv) {
-        super(argv) ; 
-    }
-
-    @Override
-    protected Syntax getDefaultSyntax()     { return Syntax.syntaxSPARQL_11 ; } 
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/sse.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/sse.java b/jena-arq/src/main/java/arq/sse.java
deleted file mode 100644
index 95a769e..0000000
--- a/jena-arq/src/main/java/arq/sse.java
+++ /dev/null
@@ -1,108 +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 arq;
-
-import jena.cmd.ArgDecl;
-import jena.cmd.TerminationException;
-
-import org.apache.jena.atlas.io.IndentedWriter ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.shared.PrefixMapping ;
-import org.apache.jena.sparql.serializer.SerializationContext ;
-import org.apache.jena.sparql.sse.Item ;
-import org.apache.jena.sparql.sse.ItemWriter ;
-import org.apache.jena.sparql.sse.SSE ;
-
-import arq.cmdline.CmdARQ_SSE ;
-
-public class sse extends CmdARQ_SSE
-{
-    protected final ArgDecl numberDecl      = new ArgDecl(ArgDecl.HasValue, "num", "number") ;
-    protected final ArgDecl noPrintDecl     = new ArgDecl(ArgDecl.NoValue, "n") ;
-    protected final ArgDecl noResolveDecl   = new ArgDecl(ArgDecl.NoValue, "raw") ;
-
-    private boolean         print       = true ;
-    private boolean         structural  = true ;
-    private boolean         lineNumbers = false ;
-
-    public static void main (String... argv)
-    {
-        new sse(argv).mainRun() ;
-    }
-
-    public sse(String[] argv)
-    {
-        super(argv) ;
-        super.add(noPrintDecl,      "-n",               "Don't print the expression") ;
-        super.add(numberDecl,       "--num [on|off]",   "Numbers") ;
-        super.add(noResolveDecl,    "--raw", "Don't handle base or prefix names specially") ;
-    }
-
-    @Override
-    protected void processModulesAndArgs()
-    {
-        super.processModulesAndArgs() ;
-        print = !contains(noPrintDecl) ;
-        if ( contains(numberDecl) )
-            lineNumbers = getValue(numberDecl).equalsIgnoreCase("on") ;
-        
-        if ( contains(noResolveDecl) )
-            SSE.setUseResolver(false) ;
-    }
-
-    @Override
-    protected String getCommandName() { return Lib.className(this) ; }
-
-    @Override
-    protected String getSummary() { return getCommandName() ; }
-
-    static final String divider = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" ;
-    //static final String divider = "" ;
-
-    boolean needDivider = false ;
-    private void divider()
-    {
-        if ( needDivider ) System.out.println(divider) ;
-        needDivider = true ;
-    }
-
-    @Override
-    protected void exec(Item item)
-    {
-        if ( ! print )
-            return ;
-        
-        if ( item == null )
-        {
-            System.err.println("No expression") ;
-            throw new TerminationException(9) ;
-        }
-        divider() ;
-        IndentedWriter out = new IndentedWriter(System.out, lineNumbers) ;
-        
-        // Need to check if used.
-        //PrefixMapping pmap = SSE.getDefaultPrefixMapWrite() ;
-        PrefixMapping pmap = null ;
-        SerializationContext sCxt = new SerializationContext(pmap) ;
-        ItemWriter.write(out, item, sCxt) ;
-        //item.output(out) ;
-        out.ensureStartOfLine() ;
-        out.flush();
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/sse_exec.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/sse_exec.java b/jena-arq/src/main/java/arq/sse_exec.java
deleted file mode 100644
index 3b5f49c..0000000
--- a/jena-arq/src/main/java/arq/sse_exec.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 arq;
-
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.sparql.sse.Item ;
-import org.apache.jena.sparql.sse.builders.BuilderExec ;
-import arq.cmdline.CmdARQ_SSE ;
-
-public class sse_exec extends CmdARQ_SSE
-{
-    
-    public static void main (String... argv)
-    {
-        new sse_exec(argv).mainRun() ;
-    }
-    
-    public sse_exec(String[] argv)
-    {
-        super(argv) ;
-    }
-    
-    @Override
-    protected String getCommandName() { return Lib.className(this) ; }
-    
-    @Override
-    protected String getSummary() { return getCommandName()+" [--file<file> | string]" ; }
-
-    @Override
-    protected void exec(Item item)
-    {
-        BuilderExec.exec(item) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/sse_expr.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/sse_expr.java b/jena-arq/src/main/java/arq/sse_expr.java
deleted file mode 100644
index 9339d53..0000000
--- a/jena-arq/src/main/java/arq/sse_expr.java
+++ /dev/null
@@ -1,24 +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 arq;
-
-public class sse_expr
-{
-
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/main/java/arq/sse_query.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/sse_query.java b/jena-arq/src/main/java/arq/sse_query.java
deleted file mode 100644
index c5d8c7f..0000000
--- a/jena-arq/src/main/java/arq/sse_query.java
+++ /dev/null
@@ -1,162 +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 arq;
-
-
-import jena.cmd.ArgDecl;
-import jena.cmd.CmdException;
-import jena.cmd.TerminationException;
-
-import org.apache.jena.atlas.io.IndentedWriter ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.query.Dataset ;
-import org.apache.jena.query.DatasetFactory ;
-import org.apache.jena.sparql.algebra.Algebra ;
-import org.apache.jena.sparql.algebra.Op ;
-import org.apache.jena.sparql.core.DatasetGraph ;
-import org.apache.jena.sparql.engine.Plan ;
-import org.apache.jena.sparql.engine.PlanOp ;
-import org.apache.jena.sparql.engine.QueryIterator ;
-import org.apache.jena.sparql.util.QueryExecUtils ;
-
-import arq.cmdline.CmdARQ ;
-import arq.cmdline.ModAlgebra ;
-import arq.cmdline.ModDataset ;
-import arq.cmdline.ModDatasetGeneralAssembler ;
-import arq.cmdline.ModEngine ;
-import arq.cmdline.ModResultsOut ;
-import arq.cmdline.ModTime ;
-
-public class sse_query extends CmdARQ
-{
-    // Merging with qparse/sparql
-    // 1 - split those two into Query and QueryExecution parts
-    // 2 - This is then calls on the QueryExecution parts
-    // 3 - Printing plan - uses a verbose prefix setting.  Scan to see what's in use.
-    //      WriterOp.reducePrologue(prologue, op) => prologue.
-    
-    protected final ArgDecl printDecl  = new ArgDecl(ArgDecl.HasValue, "print") ;
-    
-    ModAlgebra    modAlgebra =  new ModAlgebra() ;
-    ModDataset    modDataset =  new ModDatasetGeneralAssembler() ;
-    ModResultsOut modResults =  new ModResultsOut() ;
-    ModTime       modTime =     new ModTime() ;
-    ModEngine     modEngine =   new ModEngine() ;
-
-    boolean printOp      = false ;
-    boolean printPlan    = false ;
-    
-    public static void main (String... argv)
-    {
-        new sse_query(argv).mainRun() ;
-    }
-    
-    public sse_query(String[] argv)
-    {
-        super(argv) ;
-        super.add(printDecl, "--print=op/plan",  "Print details") ;
-        super.addModule(modAlgebra) ;
-        super.addModule(modResults) ;
-        super.addModule(modDataset) ;
-        super.addModule(modTime) ;
-        super.addModule(modEngine) ;
-    }
-
-    @Override
-    protected void processModulesAndArgs()
-    {
-        super.processModulesAndArgs() ;
-
-        for (String arg : getValues(printDecl))
-        {
-            if ( arg.equalsIgnoreCase("op") ||
-                      arg.equalsIgnoreCase("alg") || 
-                      arg.equalsIgnoreCase("algebra") ) { printOp = true ; }
-            else if ( arg.equalsIgnoreCase("plan"))     { printPlan = true ; }
-            else
-                throw new CmdException("Not a recognized print form: "+arg+" : Choices are: query, op, quad") ;
-        }
-        
-    }
-    
-    @Override
-    protected String getCommandName() { return Lib.className(this) ; }
-    
-    @Override
-    protected String getSummary() { return getCommandName()+" --data=<file> --query=<query>" ; }
-
-    static final String divider = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" ;
-    //static final String divider = "" ;
-    boolean needDivider = false ;
-    private void divider()
-    {
-        if ( needDivider ) System.out.println(divider) ;
-        needDivider = true ;
-    }
-    
-    @Override
-    protected void exec()
-    {
-        Op op = modAlgebra.getOp() ;
-
-        if ( op == null )
-        {
-            System.err.println("No query expression to execute") ;
-            throw new TerminationException(9) ;
-        }
-
-        Dataset dataset = modDataset.getDataset() ;
-        // Check there is a dataset.
-        if ( dataset == null )
-            dataset = DatasetFactory.createGeneral() ;
-
-        modTime.startTimer() ;
-        DatasetGraph dsg = dataset.asDatasetGraph() ;
-
-        if ( printOp || printPlan )
-        {
-            if ( printOp )
-            {
-                divider() ;
-                IndentedWriter out = new IndentedWriter(System.out, true) ;
-                op.output(out) ;
-                out.flush();
-            }
-
-            if ( printPlan )
-            {
-                QueryIterator qIter = Algebra.exec(op, dsg) ;
-                Plan plan = new PlanOp(op, null, qIter) ;
-                divider() ;
-                IndentedWriter out = new IndentedWriter(System.out, false) ;
-                plan.output(out) ;
-                out.flush();
-            }
-            //return ;
-        }
-
-        // Do not optimize.  Execute as-is.
-        QueryExecUtils.execute(op, dsg, modResults.getResultsFormat()) ;
-
-        long time = modTime.endTimer() ;
-        if ( modTime.timingEnabled() )
-            System.out.println("Time: "+modTime.timeStr(time)) ;
-    }    
-
-}


[16/20] jena git commit: JENA-1108 : jena-cmds module

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-arq/src/test/java/riotcmd/rdflangtest.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/riotcmd/rdflangtest.java b/jena-arq/src/test/java/riotcmd/rdflangtest.java
deleted file mode 100644
index 1f5af3b..0000000
--- a/jena-arq/src/test/java/riotcmd/rdflangtest.java
+++ /dev/null
@@ -1,213 +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 riotcmd;
-
-import arq.cmdline.ModEngine ;
-import arq.cmdline.ModContext ;
-import jena.cmd.ArgDecl ;
-import jena.cmd.CmdException ;
-import jena.cmd.CmdGeneral ;
-import jena.cmd.TerminationException ;
-import junit.framework.TestSuite ;
-import org.apache.jena.atlas.legacy.BaseTest2 ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.query.ARQ ;
-import org.apache.jena.rdf.model.Literal ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.rdf.model.Resource ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFDataMgr ;
-import org.apache.jena.riot.langsuite.FactoryTestRiot ;
-import org.apache.jena.riot.langsuite.VocabLangRDF ;
-import org.apache.jena.sparql.expr.E_Function ;
-import org.apache.jena.sparql.expr.NodeValue ;
-import org.apache.jena.sparql.junit.EarlReport ;
-import org.apache.jena.sparql.junit.SimpleTestRunner ;
-import org.apache.jena.sparql.util.NodeFactoryExtra ;
-import org.apache.jena.sparql.vocabulary.DOAP ;
-import org.apache.jena.sparql.vocabulary.FOAF ;
-import org.apache.jena.system.JenaSystem ;
-import org.apache.jena.vocabulary.DC ;
-import org.apache.jena.vocabulary.DCTerms ;
-import org.apache.jena.vocabulary.RDF ;
-
-/** A program to execute RDF language test suites
- * 
- * <pre>
- * Usage: 
- *   [--all]
- *   <i>testManifest</i>
- *   [ --query <i>query</i> --data <i>data</i> --result <i>result</i> ] -- run one test
- * </pre>
- */
-
-public class rdflangtest extends CmdGeneral
-{
-    static { JenaSystem.init() ; }
-    protected ModContext modContext     = new ModContext() ;
-    protected ArgDecl  strictDecl       = new ArgDecl(ArgDecl.NoValue, "strict") ;
-    protected boolean  cmdStrictMode    = false ; 
-
-    //protected ArgDecl allDecl =    new ArgDecl(ArgDecl.NoValue, "all") ;
-    protected ArgDecl earlDecl          = new ArgDecl(ArgDecl.NoValue, "earl") ;
-    
-    protected boolean createEarlReport = false;
-    
-    public static void main (String... argv)
-    {
-        try { new rdflangtest(argv).mainRun() ; }
-        catch (TerminationException ex) { System.exit(ex.getCode()) ; }
-    }
-    
-    public rdflangtest(String[] argv)
-    {
-        super(argv) ;
-        super.add(strictDecl, "--strict", "Operate in strict mode (no extensions of any kind)") ;
-        super.modVersion.addClass(ARQ.class) ;
-        //add(allDecl, "--all", "run all tests") ;
-        getUsage().startCategory("Tests (execute test manifest)") ;
-        getUsage().addUsage("<manifest>", "run the tests specified in the given manifest") ;
-        add(earlDecl, "--earl", "create EARL report") ;
-        addModule(modContext) ;
-    }
-    
-    protected ModEngine setModEngine()
-    {
-        return new ModEngine() ;
-    }
-    
-    @Override
-    protected String getCommandName() { return Lib.className(this) ; }
-    
-    @Override
-    protected String getSummary() { return getCommandName()+" <manifest>" ; }
-    
-    @Override
-    protected void processModulesAndArgs()
-    {
-        if ( ! hasPositional() )
-            throw new CmdException("No manifest file") ;
-        createEarlReport = contains(earlDecl) ;
-    }
-    
-    @Override
-    protected void exec()
-    {
-        // Paradoxical naming - the boolean is a visibility flag.
-        BaseTest2.setTestLogging() ;
-        
-//        if ( contains(strictDecl) ) {
-//            // Always done in test setups.
-//            cmdStrictMode = true ;
-//            // Which will apply to reading the manifest!
-//            ARQ.setStrictMode() ;
-//            SysRIOT.setStrictMode(true) ;
-//        }
-        
-        NodeValue.VerboseWarnings = false ;
-        E_Function.WarnOnUnknownFunction = false ;
-        
-        for ( String fn : getPositional() )
-            exec1(fn) ;
-    }
-    
-    protected void exec1(String manifest)
-    {
-        if ( createEarlReport )
-            oneManifestEarl(manifest) ;
-        else
-            oneManifest(manifest) ;
-    }
-
-    static void oneManifest(String testManifest)
-    {
-        TestSuite suite = FactoryTestRiot.make(testManifest, null, null) ;
-
-        //junit.textui.TestRunner.run(suite) ;
-        SimpleTestRunner.runAndReport(suite) ;
-    }
-    
-    static String name =  "Apache Jena RIOT" ;
-    static String releaseName =  "RIOT" ;
-    //static String version = RIOT.getVersion() ;  // Can be "development"
-    static String version = null ;
-    static String homepage = "http://jena.apache.org/" ;
-    static String systemURI = "http://jena.apache.org/#riot" ;  // Null for bNode.
-
-    static void oneManifestEarl(String testManifest)
-    {
-        EarlReport report = new EarlReport(systemURI, name, version, homepage) ;
-        FactoryTestRiot.report = report ;
-        TestSuite suite = FactoryTestRiot.make(testManifest, null, null) ;
-        SimpleTestRunner.runSilent(suite) ;
-
-        Model model = report.getModel() ;
-        model.setNsPrefix("rdft", VocabLangRDF.getURI()) ;
-        model.setNsPrefix("turtletest", "http://www.w3.org/2013/TurtleTests/manifest.ttl#") ;
-        insertMetaOld(report) ;
-        RDFDataMgr.write(System.out, model, Lang.TURTLE) ;
-    }
-    
-    static void insertMeta(EarlReport report) {
-        Model model = report.getModel() ;
-        // We add the meta by hand separatly for better layout later 
-    }
-    
-    //OLD meta.
-    static void insertMetaOld(EarlReport report) {
-        Model model = report.getModel() ;
-        /*
-        <> foaf:primaryTopic <http://jena.apache.org/#riot> ;
-            dc:issued "..."^^xsd:dateTime;
-            foaf:maker who.
-        */
-        
-        // Update the EARL report. 
-        Resource jena = model.createResource()
-                    .addProperty(FOAF.homepage, model.createResource("http://jena.apache.org/")) ;
-        
-        // ARQ is part of Jena.
-        Resource arq = report.getSystem()
-                        .addProperty(DCTerms.isPartOf, jena) ;
-        
-        // Andy wrote the test software (updates the thing being tested as well as they are the same). 
-        Resource who = model.createResource(FOAF.Person)
-                                .addProperty(FOAF.name, "Andy Seaborne")
-                                .addProperty(FOAF.homepage, 
-                                             model.createResource("http://people.apache.org/~andy")) ;
-        
-        Resource reporter = report.getReporter() ;
-        reporter.addProperty(DC.creator, who) ;
-
-        Resource system = report.getSystem() ;
-        system.addProperty(RDF.type, DOAP.Project) ;
-        system.addProperty(DOAP.name, name) ;
-        system.addProperty(DOAP.homepage, homepage) ;
-        system.addProperty(DOAP.maintainer, who) ;
-        
-        Resource release = model.createResource(DOAP.Version) ;
-        system.addProperty(DOAP.release, release) ;
-        
-        Node today_node = NodeFactoryExtra.todayAsDate() ;
-        Literal today = model.createTypedLiteral(today_node.getLiteralLexicalForm(), today_node.getLiteralDatatype()) ;
-        release.addProperty(DOAP.created, today) ;
-        release.addProperty(DOAP.name, releaseName) ;      // Again
-    }
- }

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-base/src/main/java/jena/cmd/Arg.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/jena/cmd/Arg.java b/jena-base/src/main/java/jena/cmd/Arg.java
deleted file mode 100644
index d7fb8c9..0000000
--- a/jena-base/src/main/java/jena/cmd/Arg.java
+++ /dev/null
@@ -1,69 +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 jena.cmd;
-
-import java.util.ArrayList ;
-import java.util.List ;
-
-public class Arg
-{
-    String name ;
-    String value ;                                      // Last seen
-    List<String> values = new ArrayList<>() ;     // All seen
-    
-    Arg() { name = null ; value = null ; }
-    
-    public Arg(String _name) { this() ; setName(_name) ; }
-    
-    Arg(String _name, String _value) { this() ; setName(_name) ; setValue(_value) ; }
-    
-    void setName(String n) { name = n ; }
-    
-    public void setValue(String v) { value = v ; }
-    public void addValue(String v) { values.add(v) ; }
-    
-    public String getName() { return name ; }
-    public String getValue() { return value; }
-    public List<String> getValues() { return values; }
-    
-    public boolean hasValue() { return value != null ; }
-    
-    public boolean matches(ArgDecl decl)
-    {
-        return decl.getNames().contains(name) ;
-    }
-    
-    @Override
-    public String toString()
-    {
-        String base = (( name.length() == 1 )?"-":"--") + name ;
-        if ( getValues().size() == 0 )
-            return base ;
-
-        String str = "" ;
-        String sep = "" ;
-
-        for ( String v : getValues() )
-        {
-            str = str + sep + base + "=" + v;
-            sep = " ";
-        }
-        return str ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-base/src/main/java/jena/cmd/ArgDecl.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/jena/cmd/ArgDecl.java b/jena-base/src/main/java/jena/cmd/ArgDecl.java
deleted file mode 100644
index c3781e2..0000000
--- a/jena-base/src/main/java/jena/cmd/ArgDecl.java
+++ /dev/null
@@ -1,93 +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 jena.cmd;
-
-import static java.util.Arrays.asList;
-
-import java.util.ArrayList ;
-import java.util.Iterator ;
-import java.util.List ;
-
-/** A command line argument specification. */
-public class ArgDecl
-{
-    boolean takesValue ;
-    
-    List<String> names = new ArrayList<>() ;
-	
-    public static final boolean HasValue = true ;
-    public static final boolean NoValue = false ;
-
-   /** Create a declaration for a command argument.
-    *
-    * @param hasValue  Does it take a value or not?
-    */
-   public ArgDecl(boolean hasValue)
-   {
-       takesValue = hasValue ;
-   }
-
-   /** Create a declaration for a command argument.
-    *
-    * @param hasValue  Does it take a value or not?
-    * @param names     Names of arguments
-    */
-   public ArgDecl(boolean hasValue, String... names)
-   {
-       this(hasValue) ;
-       asList(names).forEach(this::addName);
-   }
-   
-    public void addName(String name)
-    {
-        name = canonicalForm(name) ;
-        if ( ! names.contains(name))
-            names.add(name) ;
-    }
-    
-    public String getKeyName() { return names.get(0) ; }
-    
-    public List<String> getNames() { return names ; }
-    public Iterator<String> names() { return names.iterator() ; }
-    
-    public boolean takesValue() { return takesValue ; }
-    
-    public boolean matches(Arg a)
-    {
-    	 	String name = a.getName();
-    		return names.stream().anyMatch(name::equals);
-    }
-    
-    public boolean matches(String arg)
-    {
-        arg = canonicalForm(arg) ;
-        return names.contains(arg) ;
-    }
-    
-    public static String canonicalForm(String str)
-    {
-        if ( str.startsWith("--") )
-            return str.substring(2) ;
-        
-        if ( str.startsWith("-") )
-            return str.substring(1) ;
-        
-        return str ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-base/src/main/java/jena/cmd/ArgModule.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/jena/cmd/ArgModule.java b/jena-base/src/main/java/jena/cmd/ArgModule.java
deleted file mode 100644
index 82194de..0000000
--- a/jena-base/src/main/java/jena/cmd/ArgModule.java
+++ /dev/null
@@ -1,26 +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 jena.cmd;
-
-public interface ArgModule
-{
-    // Argument processing phase
-    public void processArgs(CmdArgModule cmdLine) ;
-}
-

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-base/src/main/java/jena/cmd/ArgModuleGeneral.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/jena/cmd/ArgModuleGeneral.java b/jena-base/src/main/java/jena/cmd/ArgModuleGeneral.java
deleted file mode 100644
index d6f09fa..0000000
--- a/jena-base/src/main/java/jena/cmd/ArgModuleGeneral.java
+++ /dev/null
@@ -1,25 +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 jena.cmd;
-
-public interface ArgModuleGeneral extends ArgModule
-{
-    // Registration phase for usage messages
-    public abstract void registerWith(CmdGeneral cmdLine) ;
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-base/src/main/java/jena/cmd/ArgProc.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/jena/cmd/ArgProc.java b/jena-base/src/main/java/jena/cmd/ArgProc.java
deleted file mode 100644
index 51989e7..0000000
--- a/jena-base/src/main/java/jena/cmd/ArgProc.java
+++ /dev/null
@@ -1,27 +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 jena.cmd;
-
-
-public interface ArgProc {
-
-    void startArgs() ;
-    void finishArgs() ;
-    void arg(String arg, int i) ;
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-base/src/main/java/jena/cmd/CmdArgModule.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/jena/cmd/CmdArgModule.java b/jena-base/src/main/java/jena/cmd/CmdArgModule.java
deleted file mode 100644
index c3279dc..0000000
--- a/jena-base/src/main/java/jena/cmd/CmdArgModule.java
+++ /dev/null
@@ -1,70 +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 jena.cmd;
-
-import java.util.ArrayList ;
-import java.util.List ;
-
-import jena.cmd.ArgModuleGeneral;
-
-public abstract class CmdArgModule extends CmdMain
-{
-    List<ArgModuleGeneral> modules = new ArrayList<>() ;
-    
-    protected CmdArgModule(String[] argv)
-    {
-        super(argv) ;
-    }
-    
-    protected void addModule(ArgModuleGeneral argModule)
-    {
-        modules.add(argModule) ;
-    }
-
-    @Override
-    final
-    public void process()
-    {
-        super.process() ;
-        forEach(new Action(){
-            @Override
-            public void action(CmdArgModule controller, ArgModuleGeneral module)
-            { 
-                module.processArgs(controller) ;
-            }
-        } ) ;
-        processModulesAndArgs() ;
-    }
-    
-    abstract
-    protected void processModulesAndArgs() ;
-    
-    private void forEach(Action action)
-    {
-        for ( ArgModuleGeneral am : modules )
-        {
-            action.action( this, am );
-        }
-    }
-                    
-    interface Action
-    {
-        public void action(CmdArgModule controller, ArgModuleGeneral module) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-base/src/main/java/jena/cmd/CmdException.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/jena/cmd/CmdException.java b/jena-base/src/main/java/jena/cmd/CmdException.java
deleted file mode 100644
index df952af..0000000
--- a/jena-base/src/main/java/jena/cmd/CmdException.java
+++ /dev/null
@@ -1,30 +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 jena.cmd;
-
-/**
- * Indicate that something went wrong - while executing the command or processing the request.
- */
-
-public class CmdException extends RuntimeException
-{
-    public CmdException()                             { super() ; }
-    public CmdException(String msg)                   { super(msg) ; }
-    public CmdException(String msg, Throwable cause)  { super(msg, cause) ; }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-base/src/main/java/jena/cmd/CmdGeneral.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/jena/cmd/CmdGeneral.java b/jena-base/src/main/java/jena/cmd/CmdGeneral.java
deleted file mode 100644
index fc04397..0000000
--- a/jena-base/src/main/java/jena/cmd/CmdGeneral.java
+++ /dev/null
@@ -1,92 +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 jena.cmd;
-
-import java.io.PrintStream ;
-
-import org.apache.jena.atlas.io.IndentedWriter ;
-import jena.cmd.ArgModuleGeneral;
-import jena.cmd.CmdArgModule;
-import jena.cmd.ModGeneral;
-
-// Added usage + some common flags
-// This is the usual starting point for any sub 
-
-public abstract class CmdGeneral extends CmdArgModule
-{
-    protected ModGeneral modGeneral = new ModGeneral(this::printHelp) ;
-    protected ModVersion modVersion = new ModVersion(true) ;
-    
-    // Could be turned into a module but these are convenient as inherited flags
-    
-    protected CmdGeneral(String[] argv)
-    {
-        super(argv) ;
-        addModule(modGeneral) ;
-        addModule(modVersion) ;
-    }
-
-    @Override
-    public void addModule(ArgModuleGeneral argModule)
-    {
-        super.addModule(argModule) ;
-        argModule.registerWith(this) ;
-    }
-    
-    protected boolean isVerbose() { return modGeneral.verbose ; }
-    protected boolean isQuiet()   { return modGeneral.quiet ; }
-    protected boolean isDebug()   { return modGeneral.debug ; }
-    protected boolean help()      { return modGeneral.help ; }
-
-    final public void printHelp()
-    {
-        usage() ;
-        throw new TerminationException(0) ;
-    }
-
-    @Override
-    protected void processModulesAndArgs()
-    { 
-        if ( modVersion.getVersionFlag() )
-            modVersion.printVersionAndExit() ;
-    }
-    
-    private Usage usage = new Usage() ; 
-    
-    protected String cmdName = null ;
-
-    protected abstract String getSummary() ;
-
-    public void usage() { usage(System.err) ; }
-
-    public void usage(PrintStream pStr)
-    {
-        IndentedWriter out = new IndentedWriter(pStr) ;
-        out.println(getSummary()) ;
-        usage.output(out) ;
-    }
-    
-    public void add(ArgDecl argDecl, String argName, String msg)
-    {
-        add(argDecl) ;
-        getUsage().addUsage(argName, msg) ;
-    }
-
-    public Usage getUsage() { return usage ; }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-base/src/main/java/jena/cmd/CmdLineArgs.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/jena/cmd/CmdLineArgs.java b/jena-base/src/main/java/jena/cmd/CmdLineArgs.java
deleted file mode 100644
index 2ba515c..0000000
--- a/jena-base/src/main/java/jena/cmd/CmdLineArgs.java
+++ /dev/null
@@ -1,413 +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 jena.cmd;
-
-import static java.nio.file.Files.readAllBytes;
-
-import java.io.IOException;
-import java.nio.file.Paths;
-import java.util.ArrayList ;
-import java.util.Arrays ;
-import java.util.Collections ;
-import java.util.HashMap ;
-import java.util.Iterator ;
-import java.util.List ;
-import java.util.Map ;
-
-import org.apache.jena.atlas.logging.Log ;
-
-/**
- * Command line, using the common named/positional arguments paradigm
- * (also called options/arguments).
- */
-public class CmdLineArgs extends CommandLineBase {
-    public CmdLineArgs(String[] args) {
-        super(args) ;
-    }
-
-    private boolean processedArgs = false ;
-    protected Map<String, ArgDecl> argMap = new HashMap<>() ;          // Map from string name to ArgDecl
-    protected Map<String, Arg> args = new HashMap<>() ;            // Name to Arg
-    protected List<String> positionals = new ArrayList<>() ;  // Positional arguments as strings.
-    
-    public void process() throws IllegalArgumentException
-    {
-        processedArgs = true ;
-        apply(new ArgProcessor()) ;
-    }
-    
-    // ---- Setting the ArgDecls
-
-    /** Add an argument to those to be accepted on the command line.
-     * @param argName Name
-     * @param hasValue True if the command takes a (string) value
-     * @return The CommandLine processor object
-     */
-
-    public CmdLineArgs add(String argName, boolean hasValue) {
-        return add(new ArgDecl(hasValue, argName)) ;
-    }
-
-    /** Add an argument to those to be accepted on the command line.
-     *  Argument order reflects ArgDecl.
-     * @param hasValue True if the command takes a (string) value
-     * @param argName Name
-     * @return The CommandLine processor object
-     */
-   
-    public CmdLineArgs add(boolean hasValue, String argName) {
-        return add(new ArgDecl(hasValue, argName)) ;
-    }
-
-    /** Add an argument object
-     * @param arg Argument to add
-     * @return The CommandLine processor object
-     */
-   
-    public CmdLineArgs add(ArgDecl arg) {
-        for (Iterator<String> iter = arg.names(); iter.hasNext();) {
-            String name = iter.next() ;
-            if ( argMap.containsKey(name) )
-                Log.warn(this, "Argument '" + name + "' already added") ;
-            argMap.put(name, arg) ;
-        }
-        return this ;
-    }
-    
-    /**
-     * Add a positional parameter
-     * @param value
-     * @return this object
-     */
-    public CmdLineArgs addPositional(String value) {
-        positionals.add(value) ;
-        return this ;
-    }
-    
-    /**
-     * Add a named argument which has no value.
-     * @param name
-     * @return this
-     */
-    public CmdLineArgs addArg(String name) {
-        return addArg(name, null) ;
-    }
-
-    /**
-     * Add a named argument/value pair
-     * @param name
-     * @param value
-     * @return this object
-     */
-    public CmdLineArgs addArg(String name, String value) {
-        if ( !args.containsKey(name) )
-            args.put(name, new Arg(name)) ;
-        Arg arg = args.get(name) ;
-        return addArgWorker(arg, value) ;
-    }
-
-    private CmdLineArgs addArgWorker(Arg arg, String value) {
-        ArgDecl argDecl = argMap.get(arg.getName()) ;
-
-        if ( !argDecl.takesValue() && value != null )
-            throw new IllegalArgumentException("No value for argument: " + arg.getName()) ;
-
-        if ( argDecl.takesValue() ) {
-            if ( value == null )
-                throw new IllegalArgumentException("No value for argument: " + arg.getName()) ;
-
-            arg.setValue(value) ;
-            arg.addValue(value) ;
-        }
-
-        return this ;
-    }
-
-    // ---- Indirection
-
-    static final String DefaultIndirectMarker = "@" ;
-    
-    public boolean matchesIndirect(String s) { return matchesIndirect(s, DefaultIndirectMarker) ; }
-    public boolean matchesIndirect(String s, String marker) { return s.startsWith(marker) ; }
-    
-    public String indirect(String s) { return indirect(s, DefaultIndirectMarker) ; }
-    
-    public String indirect(String s, String marker) {
-        if ( !matchesIndirect(s, marker) )
-            return s ;
-        s = s.substring(marker.length()) ;
-        try {
-			return new String(readAllBytes(Paths.get(s)));
-		} catch (IOException e) {
-			throw new CmdException("Could not read from: " + s, e);
-		}
-    }
-
-    // ---- Argument access
-    
-    /** Test whether an argument was seen. */
-
-    public boolean contains(ArgDecl argDecl)    { return getArg(argDecl) != null ; }
-    
-    /** Test whether an argument was seen. */
-
-    public boolean contains(String s)           { return getArg(s) != null ; }
-    
-    /** Test whether an argument was seen more than once */ 
-    public boolean containsMultiple(String s)   { return getValues(s).size() > 1 ; }
-    
-    /** Test whether an argument was seen more than once */ 
-    public boolean containsMultiple(ArgDecl argDecl) { return getValues(argDecl).size() > 1 ; }
-    
-    public boolean hasArgs() { return args.size() > 0 ; }
-    
-    /** Test whether the command line had a particular argument
-     * 
-     * @param argName
-     * @return this object
-     */
-    public boolean hasArg(String argName) { return getArg(argName) != null ; }
-
-    /** Test whether the command line had a particular argument
-     * 
-     * @param argDecl
-     * @return true or false
-     */
-    
-    public boolean hasArg(ArgDecl argDecl) { return getArg(argDecl) != null ; }
-
-    
-    /** Get the argument associated with the argument declaration.
-     *  Actually returns the LAST one seen
-     *  @param argDecl Argument declaration to find
-     *  @return Last argument that matched.
-     */
-    
-    public Arg getArg(ArgDecl argDecl) {
-        Arg arg = null ;
-        for ( Arg a : args.values() )
-        {
-            if ( argDecl.matches( a ) )
-            {
-                arg = a;
-            }
-        }
-        return arg ;
-    }
-    
-    /** Get the argument associated with the argument name.
-     *  Actually returns the LAST one seen
-     *  @param argName Argument name
-     *  @return Last argument that matched.
-     */
-    public Arg getArg(String argName) {
-        argName = ArgDecl.canonicalForm(argName) ;
-        return args.get(argName) ;
-    }
-    
-    /**
-     * Returns the value (a string) for an argument with a value - 
-     * returns null for no argument and no value.  
-     * @param argDecl
-     * @return String
-     */
-    public String getValue(ArgDecl argDecl) {
-        Arg arg = getArg(argDecl) ;
-        if ( arg == null )
-            return null ;
-        if ( arg.hasValue() )
-            return arg.getValue() ;
-        return null ;
-    }
-
-    /**
-     * Returns the value (a string) for an argument with a value - 
-     * returns null for no argument and no value.  
-     * @param argName
-     * @return String
-     */
-    public String getValue(String argName) {
-        Arg arg = getArg(argName) ;
-        if ( arg == null )
-            return null ;
-        return arg.getValue() ;
-    }
-    
-    /** Is the value something that looks like "true" or "yes"? */
-    public boolean hasValueOfTrue(ArgDecl argDecl) {
-        String x = getValue(argDecl) ;
-        if ( x == null )
-            return false ;
-        if ( x.equalsIgnoreCase("true") || x.equalsIgnoreCase("t") ||
-             x.equalsIgnoreCase("yes")  || x.equalsIgnoreCase("y") )
-            return true ;
-        return false ;
-    }
-
-    /** Is the value something that looks like "false" or "no"? */
-    public boolean hasValueOfFalse(ArgDecl argDecl) {
-        String x = getValue(argDecl) ;
-        if ( x == null )
-            return false ;
-        if ( x.equalsIgnoreCase("false") || x.equalsIgnoreCase("f") ||
-             x.equalsIgnoreCase("no") || x.equalsIgnoreCase("n") )
-            return true ;
-        return false ;
-    }
-    
-    /**
-     * Returns all the values (0 or more strings) for an argument. 
-     * @param argDecl
-     * @return List
-     */
-    public List<String> getValues(ArgDecl argDecl) {
-        Arg arg = getArg(argDecl) ;
-        if ( arg == null )
-            return new ArrayList<>() ;
-        return arg.getValues() ;
-    }
-
-    /**
-     * Returns all the values (0 or more strings) for an argument. 
-     * @param argName
-     * @return List
-     */
-    public List<String> getValues(String argName) {
-        Arg arg = getArg(argName) ;
-        if ( arg == null )
-            return new ArrayList<>() ;
-        return arg.getValues() ;
-    }
-    
-   // ---- Positional 
-    /** Get the i'th positional argument (indexed from 0)*/
-    public String getPositionalArg(int i) {
-        return positionals.get(i) ;
-    }
-
-    /** Return the number of positional arguments */  
-    public int getNumPositional() {
-        return positionals.size() ;
-    }
-
-    public boolean hasPositional() {
-        return positionals.size() > 0 ;
-    }
-
-    public List<String> getPositional() {
-        return positionals ;
-    }
-
-    /** Return the positional arguments or "-" to indicate stdin */
-    public List<String> getPositionalOrStdin() {
-        if ( !positionals.isEmpty() )
-            return Collections.unmodifiableList(positionals) ;
-        List<String> x = Arrays.asList("-") ;
-        return Collections.unmodifiableList(x) ;
-    }
-    
-    // ----
-    
-    /**
-     * Handle an unrecognised argument; default is to throw an exception
-     * @param argStr The string image of the unrecognised argument
-     */
-    protected void handleUnrecognizedArg( String argStr ) {
-        throw new CmdException("Unknown argument: "+argStr) ;
-    }
-    
-    @Override
-    public String toString() {
-        if ( !processedArgs )
-            return super.toString() ;
-        String str = "" ;
-        String sep = "" ;
-        for ( String k : args.keySet() )
-        {
-            Arg a = args.get( k );
-            str = str + sep + a;
-            sep = " ";
-        }
-        sep = " -- " ;
-        for ( String v : positionals )
-        {
-            str = str + sep + v;
-            sep = " ";
-        }
-        return str ;
-    }
-
-    // ---- Process arguments after low level parsing and after ArgDecls added.
-    class ArgProcessor implements ArgProc {
-        boolean nextArgProcessed      = false ;
-        boolean positionalArgsStarted = false ;
-
-        @Override
-        public void startArgs() {
-            nextArgProcessed = false ;
-            positionalArgsStarted = false ;
-        }
-
-        @Override
-        public void finishArgs() {}
-
-        @Override
-        public void arg(String argStr, int i) {
-            if ( nextArgProcessed ) {
-                nextArgProcessed = false ;
-                return ;
-            }
-
-            if ( positionalArgsStarted ) {
-                addPositional(argStr) ;
-                return ;
-            }
-
-            if ( argStr.equals("-") || argStr.equals("--") ) {
-                positionalArgsStarted = true ;
-                return ;
-            }
-
-            if ( !argStr.startsWith("-") ) {
-                // End of flags, start of positional arguments
-                positionalArgsStarted = true ;
-                addPositional(argStr) ;
-                return ;
-            }
-
-            argStr = ArgDecl.canonicalForm(argStr) ;
-            if ( !argMap.containsKey(argStr) ) {
-                handleUnrecognizedArg(argStr) ;
-                return ;
-            }
-
-            // Recognized flag
-            ArgDecl argDecl = argMap.get(argStr) ;
-
-            if ( argDecl.takesValue() ) {
-                String val = getArg(i + 1) ;
-                // Use first name as the canonical one.
-                String x = argDecl.getKeyName() ;
-                addArg(x, val) ;
-                nextArgProcessed = true ;
-            } else
-                addArg(argStr) ;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-base/src/main/java/jena/cmd/CmdMain.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/jena/cmd/CmdMain.java b/jena-base/src/main/java/jena/cmd/CmdMain.java
deleted file mode 100644
index 3caca21..0000000
--- a/jena-base/src/main/java/jena/cmd/CmdMain.java
+++ /dev/null
@@ -1,108 +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 jena.cmd;
-
-import org.apache.jena.atlas.logging.LogCtl ;
-
-/** Adds main()-like methods
- * 
- * Usage:
- *    new YourCommand(args).mainAndExit()
- *  which never returns and routes thing to System.exit.
- *  or call
- *     new YourCommand(args).mainMethod()
- *  which should not call System.exit anywhere */
-
-public abstract class CmdMain extends CmdLineArgs
-{
-    // Do this very early so it happens before anything else
-    // gets a chance to create a logger.
-    static { LogCtl.setCmdLogging() ; }
-    
-    public CmdMain(String[] args)
-    {
-        super(args) ;
-    }
-
-    /** Run command - exit on failure */
-    public void mainRun()
-    { mainRun(false, true) ; }
-    
-    /** Run command - choose whether to exit on failure */
-    public void mainRun(boolean exitOnFailure)
-    { mainRun(exitOnFailure, true) ; }
-    
-    /** Run command - exit on success or failure */
-    public void mainAndExit()
-    { mainRun(true, true) ; }
-     
-    /** Run command */
-    public int mainRun(boolean exitOnSuccess, boolean exitOnFailure)
-    {
-        try { mainMethod() ; }
-        catch (TerminationException ex) { System.exit(ex.getCode()) ; }
-        catch (IllegalArgumentException ex)
-        {
-            ex.printStackTrace(System.err) ;
-            //System.err.println(ex.getMessage()) ;
-            if ( exitOnFailure ) System.exit(1) ;
-            return 1 ; 
-        }
-        catch (CmdException ex)
-        {
-            if ( ex.getMessage() != null && ex.getMessage().length() > 0 )
-                System.err.println(ex.getMessage()) ;
-            //ex.printStackTrace() ;
-            
-            if ( ex.getCause() != null )
-                ex.getCause().printStackTrace(System.err) ;
-            
-            if ( exitOnFailure ) System.exit(1) ;
-            return 1 ;
-        }
-        catch (Exception ex)
-        {
-            ex.printStackTrace(System.err) ;
-            if ( exitOnFailure ) System.exit(2) ;
-            return 2 ;
-        }
-        if ( exitOnSuccess ) 
-            System.exit(0) ;
-        return 0 ;
-    }
-
-    protected final void mainMethod()
-    {
-        process() ;
-        exec() ;
-    }
-    
-    protected abstract void exec() ;
-    
-    protected abstract String getCommandName() ;
-    
-    public void cmdError(String msg) { cmdError(msg, true) ;}
-    
-    public void cmdError(String msg, boolean exit)
-    {
-        System.err.println(msg) ;
-        if ( exit )
-            throw new TerminationException(5) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-base/src/main/java/jena/cmd/CommandLineBase.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/jena/cmd/CommandLineBase.java b/jena-base/src/main/java/jena/cmd/CommandLineBase.java
deleted file mode 100644
index def345e..0000000
--- a/jena-base/src/main/java/jena/cmd/CommandLineBase.java
+++ /dev/null
@@ -1,136 +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 jena.cmd;
-
-import static java.util.stream.IntStream.range;
-
-import java.util.ArrayList ;
-import java.util.List ;
-
-/** 
- * Incoming String[] to a list of argument/values + items.
- */
-
-
-public class CommandLineBase {
-    private List<String> argList    = new ArrayList<>() ;
-    boolean              splitTerms = true ;
-
-    public CommandLineBase(String[] args) {
-        setArgs(args) ;
-    }
-
-    public CommandLineBase() {}
-    
-    public void setArgs(String[] argv)
-    { argList = processArgv(argv) ; }
-    
-    protected List<String> getArgList() { return argList ; }
-
-    protected String getArg(int i) {
-        if ( i < 0 || i >= argList.size() )
-            return null ;
-        return argList.get(i) ;
-    }
-
-    protected void apply(ArgProc a) {
-        a.startArgs() ; 
-        range(0, argList.size()).forEach(i -> a.arg(argList.get(i), i));
-        a.finishArgs() ;
-    }
-    
-    /** Process String[] to a list of tokens.
-     *  All "=" and ":" terms are split.
-     *  Make -flag/--flag consistent.
-     * @param argv The words of the command line.
-     */    
-    private List<String> processArgv(String[] argv) {
-        // Combine with processedArgs/process?
-        List<String> argList = new ArrayList<>() ;
-
-        boolean positional = false ;
-
-        for ( String anArgv : argv )
-        {
-            String argStr = anArgv;
-
-            if ( positional || !argStr.startsWith( "-" ) )
-            {
-                argList.add( argStr );
-                continue;
-            }
-
-            if ( argStr.equals( "-" ) || argStr.equals( "--" ) )
-            {
-                positional = true;
-                argList.add( "--" );
-                continue;
-            }
-
-            // Starts with a "-"
-            // Do not canonicalize positional arguments.
-            if ( !argStr.startsWith( "--" ) )
-            {
-                argStr = "-" + argStr;
-            }
-
-            if ( !splitTerms )
-            {
-                argList.add( argStr );
-                continue;
-            }
-
-            // If the flag has a "=" or :, it is long form --arg=value.
-            // Split and insert the arg
-            int j1 = argStr.indexOf( '=' );
-            int j2 = argStr.indexOf( ':' );
-            int j = -1;
-
-            if ( j1 > 0 && j2 > 0 )
-            {
-                j = Math.min( j1, j2 );
-            }
-            else
-            {
-                if ( j1 > 0 )
-                {
-                    j = j1;
-                }
-                if ( j2 > 0 )
-                {
-                    j = j2;
-                }
-            }
-
-            if ( j < 0 )
-            {
-                argList.add( argStr );
-                continue;
-            }
-
-            // Split it.
-            String argStr1 = argStr.substring( 0, j );
-            String argStr2 = argStr.substring( j + 1 );
-
-            argList.add( argStr1 );
-            argList.add( argStr2 );
-        }
-        return argList ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-base/src/main/java/jena/cmd/ModBase.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/jena/cmd/ModBase.java b/jena-base/src/main/java/jena/cmd/ModBase.java
deleted file mode 100644
index 3899608..0000000
--- a/jena-base/src/main/java/jena/cmd/ModBase.java
+++ /dev/null
@@ -1,23 +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 jena.cmd;
-
-public abstract class ModBase implements ArgModuleGeneral
-{
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-base/src/main/java/jena/cmd/ModGeneral.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/jena/cmd/ModGeneral.java b/jena-base/src/main/java/jena/cmd/ModGeneral.java
deleted file mode 100644
index 25e1dac..0000000
--- a/jena-base/src/main/java/jena/cmd/ModGeneral.java
+++ /dev/null
@@ -1,57 +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 jena.cmd;
-
-public class ModGeneral extends ModBase
-{
-    private Runnable helpFunction = null ;
-
-    public ModGeneral(Runnable helpFunction) { this.helpFunction = helpFunction ; }
-    
-    // Could be turned into a module but these are convenient as inherited flags 
-    private final ArgDecl argDeclHelp        = new ArgDecl(false, "help", "h");
-    private final ArgDecl argDeclVerbose     = new ArgDecl(false, "v", "verbose");
-    private final ArgDecl argDeclQuiet       = new ArgDecl(false, "q", "quiet");
-    private final ArgDecl argDeclDebug       = new ArgDecl(false, "debug");
-
-    protected boolean verbose = false ;
-    protected boolean quiet = false ;
-    public boolean debug = false ;
-    protected boolean help = false ;
-    
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        cmdLine.getUsage().startCategory("General") ;
-        cmdLine.add(argDeclVerbose, "-v   --verbose", "Verbose") ;
-        cmdLine.add(argDeclQuiet, "-q   --quiet", "Run with minimal output") ;
-        cmdLine.add(argDeclDebug, "--debug", "Output information for debugging") ;
-        cmdLine.add(argDeclHelp, "--help", null) ;
-    }
-
-    @Override
-    public void processArgs(CmdArgModule cmdLine)
-    {
-        verbose = cmdLine.contains(argDeclVerbose) || cmdLine.contains(argDeclDebug) ;
-        quiet   = cmdLine.contains(argDeclQuiet) ;
-        help = cmdLine.contains(argDeclHelp) ;
-        if ( help )
-            helpFunction.run() ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-base/src/main/java/jena/cmd/ModVersion.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/jena/cmd/ModVersion.java b/jena-base/src/main/java/jena/cmd/ModVersion.java
deleted file mode 100644
index 3b47fb5..0000000
--- a/jena-base/src/main/java/jena/cmd/ModVersion.java
+++ /dev/null
@@ -1,67 +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 jena.cmd;
-
-import org.apache.jena.atlas.io.IndentedWriter;
-import org.apache.jena.atlas.lib.Version ;
-
-public class ModVersion extends ModBase
-{
-    protected final ArgDecl versionDecl = new ArgDecl(ArgDecl.NoValue, "version") ;
-    protected boolean version = false ;
-    protected boolean printAndExit = false ;
-    
-    private Version versionMgr = new Version() ; 
-    
-    public ModVersion(boolean printAndExit)
-    {
-        this.printAndExit = printAndExit ;
-    }
-    
-    public void addClass(Class<?> c) { versionMgr.addClass(c) ; }
-    
-    @Override
-    public void registerWith(CmdGeneral cmdLine)
-    {
-        cmdLine.add(versionDecl, "--version", "Version information") ;
-    }
-
-    @Override
-    public void processArgs(CmdArgModule cmdLine)
-    {
-        if ( cmdLine.contains(versionDecl) )
-            version = true ;
-        // The --version flag causes us to print and exit. 
-        if ( version && printAndExit )
-            printVersionAndExit() ;
-    }
-
-    public boolean getVersionFlag() { return version ; }
-    
-    public void printVersion()
-    {
-        versionMgr.print(IndentedWriter.stdout);
-    }  
-     
-    public void printVersionAndExit()
-    {
-        printVersion() ;
-        System.exit(0) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-base/src/main/java/jena/cmd/TerminationException.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/jena/cmd/TerminationException.java b/jena-base/src/main/java/jena/cmd/TerminationException.java
deleted file mode 100644
index 090fa48..0000000
--- a/jena-base/src/main/java/jena/cmd/TerminationException.java
+++ /dev/null
@@ -1,31 +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 jena.cmd;
-
-
-/** Exception used to indicate that the command should end now.
- *  Use instead of System.exit so that a wrapper can catch (else a command server
- *  wil exit wrongly). */
-
-public class TerminationException extends CmdException
-{
-    public int returnCode ;
-    public TerminationException(int rc) { super() ; this.returnCode = rc ; }
-    public int getCode() { return returnCode ; }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-base/src/main/java/jena/cmd/Usage.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/jena/cmd/Usage.java b/jena-base/src/main/java/jena/cmd/Usage.java
deleted file mode 100644
index 1331eb9..0000000
--- a/jena-base/src/main/java/jena/cmd/Usage.java
+++ /dev/null
@@ -1,102 +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 jena.cmd;
-
-import java.io.PrintStream ;
-import java.util.ArrayList ;
-import java.util.Collections ;
-import java.util.List ;
-
-import org.apache.jena.atlas.io.IndentedWriter ;
-
-public class Usage
-{
-    class Category
-    {
-        String desc ;
-        List<Entry> entries = new ArrayList<>() ;
-        Category(String desc) { this.desc = desc ; }
-    }
-    
-   class Entry
-   { String arg; String msg ;
-     Entry(String arg, String msg) { this.arg = arg ; this.msg = msg ; }
-   }
-   
-   List<Category> categories = new ArrayList<>() ;
-   public Usage()
-   {
-       // Start with an unnamed category
-       startCategory(null) ; 
-   }
-   
-   public void startCategory(String desc) 
-   {
-       categories.add(new Category(desc)) ;
-   }
-   
-   public void addUsage(String argName, String msg)
-   {
-       current().entries.add(new Entry(argName, msg)) ;
-   }
-   
-   
-   public void output(PrintStream out)
-   {
-       output(new IndentedWriter(out)) ;
-   }
-   
-   public void output(IndentedWriter out)
-   {
-       int INDENT1 = 2 ;
-       int INDENT2 = 4 ;
-       out.incIndent(INDENT1) ;
-   
-       List<Category> categories2 = new ArrayList<>(categories) ;
-       Collections.reverse(categories2) ;
-
-       for ( Category c : categories2 )
-       {
-           if ( c.desc != null )
-           {
-               out.println( c.desc );
-           }
-           out.incIndent( INDENT2 );
-           for ( final Entry e : c.entries )
-           {
-               out.print( e.arg );
-               if ( e.msg != null )
-               {
-                   out.pad( 20 );
-                   out.print( "   " );
-                   out.print( e.msg );
-               }
-               out.println();
-           }
-           out.decIndent( INDENT2 );
-       }
-       out.decIndent(INDENT1) ;
-       out.flush() ;
-   }
-   
-   private Category current()
-   {
-       return categories.get(categories.size()-1) ;
-   }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-base/src/main/java/jena/cmd/package-info.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/jena/cmd/package-info.java b/jena-base/src/main/java/jena/cmd/package-info.java
deleted file mode 100644
index 26000b5..0000000
--- a/jena-base/src/main/java/jena/cmd/package-info.java
+++ /dev/null
@@ -1,6 +0,0 @@
-/**
- * Contains framework components for CLI and command execution.
- * 
- * @author ajs6f
- */
-package jena.cmd;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/pom.xml
----------------------------------------------------------------------
diff --git a/jena-cmds/pom.xml b/jena-cmds/pom.xml
new file mode 100644
index 0000000..1bb3d20
--- /dev/null
+++ b/jena-cmds/pom.xml
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+   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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" 
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.jena</groupId>
+    <artifactId>jena-parent</artifactId>
+    <version>16-SNAPSHOT</version>
+    <relativePath>../jena-parent</relativePath>
+  </parent> 
+
+  <name>Apache Jena - Command line tools</name>
+  <artifactId>jena-cmds</artifactId>
+  <version>3.1.0-SNAPSHOT</version>
+
+  <description>Command line tools</description>
+
+  <packaging>jar</packaging>
+  
+  <url>http://jena.apache.org/</url>
+
+  <repositories>
+    <repository>
+      <id>apache.snapshots</id>
+      <name>Apache Snapshot Repository</name>
+      <url>http://repository.apache.org/snapshots</url>
+      <releases>
+        <enabled>false</enabled>
+      </releases>
+    </repository>
+  </repositories>
+
+  <organization>
+    <name>Apache Jena</name>
+    <url>http://jena.apache.org/</url>
+  </organization>
+
+  <licenses>
+    <license>
+      <name>Apache 2.0 License</name>
+      <url>http://www.apache.org/licenses/LICENSE-2.0</url>
+    </license>
+  </licenses>
+
+  <properties>
+    <maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ssZ</maven.build.timestamp.format>
+    <build.time.xsd>${maven.build.timestamp}</build.time.xsd>  
+  </properties>
+  
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.jena</groupId>
+      <artifactId>apache-jena-libs</artifactId>
+      <version>3.1.0-SNAPSHOT</version>
+      <type>pom</type>
+    </dependency>
+
+    <!-- Command Logging -->
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>${ver.slf4j}</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>${ver.slf4j}</version>
+    </dependency>
+
+    <!-- Testing -->
+
+    <dependency>
+      <groupId>org.apache.jena</groupId>
+      <artifactId>jena-arq</artifactId>
+      <version>3.1.0-SNAPSHOT</version>
+      <classifier>tests</classifier>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.jena</groupId>
+      <artifactId>jena-core</artifactId>
+      <version>3.1.0-SNAPSHOT</version>
+      <classifier>tests</classifier>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.jena</groupId>
+      <artifactId>jena-base</artifactId>
+      <version>3.1.0-SNAPSHOT</version>
+      <classifier>tests</classifier>
+      <scope>test</scope>
+    </dependency>
+
+  </dependencies>
+  
+</project>

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/arq.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/arq.java b/jena-cmds/src/main/java/arq/arq.java
new file mode 100644
index 0000000..5fc9c6c
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/arq.java
@@ -0,0 +1,37 @@
+/*
+ * 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 arq;
+
+import org.apache.jena.query.Syntax ;
+
+/** A program to execute queries from the command line in ARQ mode. */
+
+public class arq extends query
+{
+    public static void main (String... argv) {
+        new arq(argv).mainRun() ;
+    }
+    
+    public arq(String[] argv) {
+        super(argv) ; 
+    }
+
+    @Override
+    protected Syntax getDefaultSyntax()     { return Syntax.syntaxARQ ; } 
+ }

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/bindings.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/bindings.java b/jena-cmds/src/main/java/arq/bindings.java
new file mode 100644
index 0000000..f9d3b2c
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/bindings.java
@@ -0,0 +1,42 @@
+/*
+ * 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 arq;
+
+import java.io.InputStream ;
+import java.io.OutputStream ;
+
+import org.apache.jena.sparql.engine.binding.BindingInputStream ;
+import org.apache.jena.sparql.engine.binding.BindingOutputStream ;
+
+/** Simple command for testing bindings */
+public class bindings
+{
+    public static void main(String[] args)
+    {
+        InputStream in = System.in ;
+        OutputStream out = System.out ;
+        
+        BindingInputStream input = new BindingInputStream(in) ;
+        BindingOutputStream output = new BindingOutputStream(out) ;
+        
+        for ( ; input.hasNext() ; )
+            output.send(input.next()) ;
+        output.flush() ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/CmdARQ.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/CmdARQ.java b/jena-cmds/src/main/java/arq/cmdline/CmdARQ.java
new file mode 100644
index 0000000..d6fb553
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/CmdARQ.java
@@ -0,0 +1,65 @@
+/*
+ * 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 arq.cmdline;
+
+import jena.cmd.ArgDecl ;
+import jena.cmd.CmdGeneral ;
+import org.apache.jena.Jena ;
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.query.ARQ ;
+import org.apache.jena.riot.RIOT ;
+import org.apache.jena.sparql.engine.iterator.QueryIteratorBase ;
+import org.apache.jena.system.JenaSystem ;
+
+public abstract class CmdARQ extends CmdGeneral
+{
+	static { JenaSystem.init() ; }
+
+    protected ModContext modContext = new ModContext() ;
+    ArgDecl  strictDecl = new ArgDecl(ArgDecl.NoValue, "strict") ;
+    
+    protected boolean cmdStrictMode = false ; 
+    
+    protected CmdARQ(String[] argv)
+    {
+        super(argv) ;
+        modVersion.addClass(Jena.class) ;
+        modVersion.addClass(ARQ.class) ;
+        modVersion.addClass(RIOT.class) ;
+        super.add(strictDecl, "--strict", "Operate in strict SPARQL mode (no extensions of any kind)") ; 
+        addModule(modContext) ;
+    }
+    
+    @Override
+    protected void processModulesAndArgs()
+    {
+        super.processModulesAndArgs();
+        if ( super.contains(strictDecl) ) 
+            ARQ.setStrictMode() ;
+        cmdStrictMode = super.contains(strictDecl) ;
+        if ( modGeneral.debug )
+            QueryIteratorBase.traceIterators = true ;
+    }
+    
+    @Override
+    protected String getCommandName()
+    {
+        return Lib.className(this) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/CmdARQ_SSE.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/CmdARQ_SSE.java b/jena-cmds/src/main/java/arq/cmdline/CmdARQ_SSE.java
new file mode 100644
index 0000000..7834a12
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/CmdARQ_SSE.java
@@ -0,0 +1,45 @@
+/*
+ * 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 arq.cmdline;
+
+import org.apache.jena.sparql.sse.Item ;
+
+/** Root of read an SSE file and do something */
+public abstract class CmdARQ_SSE extends CmdARQ
+{
+    protected ModItem modItem = new ModItem() ; 
+    
+    public CmdARQ_SSE(String[] argv)
+    {
+        super(argv) ;
+        super.addModule(modItem) ;
+    }
+    
+    @Override
+    protected String getSummary() { return getCommandName()+" [--file<file> | string]" ; }
+
+    @Override
+    final protected void exec()
+    {
+        Item item = modItem.getItem() ;
+        exec(item) ;
+    }
+    
+    protected abstract void exec(Item item) ;
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/CmdUpdate.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/CmdUpdate.java b/jena-cmds/src/main/java/arq/cmdline/CmdUpdate.java
new file mode 100644
index 0000000..9ff706c
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/CmdUpdate.java
@@ -0,0 +1,63 @@
+/*
+ * 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 arq.cmdline;
+
+import org.apache.jena.query.Syntax ;
+import org.apache.jena.rdf.model.ModelFactory ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+
+public abstract class CmdUpdate extends CmdARQ
+{
+    protected ModDataset modDataset = null ;
+    protected Syntax updateSyntax = Syntax.defaultUpdateSyntax ;
+
+    protected CmdUpdate(String[] argv)
+    {
+        super(argv) ;
+        modDataset = setModeDataset() ;
+        addModule(modDataset) ;
+    }
+    
+    protected ModDataset setModeDataset() {
+        return new ModDatasetGeneralAssembler() ;
+    }
+
+    @Override
+    protected void processModulesAndArgs()
+    {
+        super.processModulesAndArgs() ;
+        if ( super.cmdStrictMode )
+            updateSyntax = Syntax.syntaxSPARQL_11 ;
+    }
+    
+    @Override
+    protected final void exec() {
+        DatasetGraph dataset = modDataset.getDatasetGraph() ;
+        if ( dataset == null )
+            dataset = dealWithNoDataset() ;
+        
+        if ( dataset.getDefaultGraph() == null )
+            dataset.setDefaultGraph(ModelFactory.createDefaultModel().getGraph()) ;
+        execUpdate(dataset) ;
+    }
+
+    protected abstract DatasetGraph dealWithNoDataset() ;
+
+    protected abstract void execUpdate(DatasetGraph graphStore) ;
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModAlgebra.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModAlgebra.java b/jena-cmds/src/main/java/arq/cmdline/ModAlgebra.java
new file mode 100644
index 0000000..cb269b5
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModAlgebra.java
@@ -0,0 +1,82 @@
+/*
+ * 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 arq.cmdline;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.sparql.algebra.Op ;
+import org.apache.jena.sparql.sse.SSE ;
+import org.apache.jena.util.FileManager ;
+
+public class ModAlgebra extends ModBase
+{
+    protected final ArgDecl queryFileDecl = new ArgDecl(ArgDecl.HasValue, "query", "file") ;
+
+    private String queryFilename   = null ;
+    private String queryString = null ;
+    private Op op = null ;
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Query") ;
+        cmdLine.add(queryFileDecl,
+                    "--query, --file",
+                    "File containing an algebra query") ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        if ( cmdLine.contains(queryFileDecl) )
+        {
+            queryFilename = cmdLine.getValue(queryFileDecl) ;
+            queryString = FileManager.get().readWholeFileAsUTF8(queryFilename) ;
+        }
+    
+        if ( cmdLine.getNumPositional() == 0 && queryFilename == null )
+            cmdLine.cmdError("No query string or query file") ;
+
+        if ( cmdLine.getNumPositional() > 1 )
+            cmdLine.cmdError("Only one query string allowed") ;
+    
+        if ( cmdLine.getNumPositional() == 1 && queryFilename != null )
+            cmdLine.cmdError("Either query string or query file - not both") ;
+
+        
+        if ( queryFilename == null )
+        {
+            String qs = cmdLine.getPositionalArg(0) ;
+            queryString = cmdLine.indirect(qs) ;
+        }
+    }
+    
+    public Op getOp()
+    {
+        if ( op != null )
+            return op ;
+        op = SSE.parseOp(queryString) ;
+        if ( op == null )
+            System.err.println("Failed to parse : "+queryString) ;
+        return op ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModAssembler.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModAssembler.java b/jena-cmds/src/main/java/arq/cmdline/ModAssembler.java
new file mode 100644
index 0000000..30e4573
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModAssembler.java
@@ -0,0 +1,84 @@
+/*
+ * 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 arq.cmdline;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.rdf.model.Resource ;
+import org.apache.jena.shared.JenaException ;
+import org.apache.jena.shared.NotFoundException ;
+import org.apache.jena.sparql.ARQException ;
+import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
+
+
+public class ModAssembler extends ModBase
+{
+    public static final ArgDecl assemblerDescDecl = new ArgDecl(ArgDecl.HasValue, "desc", "dataset") ;
+    private String assemblerFile = null ;
+    Object thingDescribed = null ;
+    
+    public ModAssembler()
+    { 
+        // Wire in assembler implementations
+        AssemblerUtils.init() ;
+    }
+    
+    // Dataset : default graph and named graphs
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        if ( cmdLine.contains(assemblerDescDecl) )
+            assemblerFile = cmdLine.getValue(assemblerDescDecl) ;
+    }
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        //cmdLine.getUsage().startCategory("Dataset") ;
+        cmdLine.add(assemblerDescDecl,
+                    "--desc=",
+                    "Assembler description file") ;
+    }
+    
+    public String getAssemblerFile() { return assemblerFile ; }
+    
+    // Should subclass and apply typing.
+    
+    public Object create(Resource type)
+    {
+        Object thing = null ;
+        try {
+            thing = AssemblerUtils.build(assemblerFile, type) ;
+        }
+        catch (ARQException ex) { throw ex; }
+        catch (NotFoundException ex)
+        { throw new CmdException("Not found: "+ex.getMessage()) ; }
+        catch (JenaException ex)
+        { throw ex ; }
+        catch (Exception ex)
+        { throw new CmdException("Error creating", ex) ; }
+        
+        return thing ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModContext.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModContext.java b/jena-cmds/src/main/java/arq/cmdline/ModContext.java
new file mode 100644
index 0000000..2d20f87
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModContext.java
@@ -0,0 +1,91 @@
+/*
+ * 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 arq.cmdline;
+
+import java.io.PrintStream ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.query.ARQ ;
+import org.apache.jena.sparql.util.Context ;
+import org.apache.jena.sparql.util.MappingRegistry ;
+import org.apache.jena.sparql.util.Symbol ;
+import org.apache.jena.system.JenaSystem ;
+
+/** Set Context items */
+public class ModContext extends ModBase
+{
+    static { JenaSystem.init(); }
+
+    protected final ArgDecl setDecl = new ArgDecl(ArgDecl.HasValue, "set", "define", "defn", "def") ;
+
+    private Context context = new Context() ;
+
+    @Override
+    public void registerWith(CmdGeneral cmdLine) {
+        cmdLine.getUsage().startCategory("Symbol definition");
+        cmdLine.add(setDecl, "--set", "Set a configuration symbol to a value");
+    }
+
+    public void checkCommandLine(CmdArgModule cmdLine) {}
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine) {
+        if ( cmdLine.getValues(setDecl) == null || cmdLine.getValues(setDecl).size() == 0 )
+            return;
+
+        for ( String arg : cmdLine.getValues(setDecl) ) {
+            String[] frags = arg.split("=", 2);
+            if ( frags.length != 2 ) {
+                throw new RuntimeException("Can't split '" + arg + "' -- looking for '=' to separate name and value");
+            }
+
+            String symbolName = frags[0];
+            String value = frags[1];
+
+            // Make it a long name.
+            symbolName = MappingRegistry.mapPrefixName(symbolName);
+            Symbol symbol = Symbol.create(symbolName);
+            context.set(symbol, value);
+        }
+
+        ARQ.getContext().putAll(context);
+    }
+
+    public void verbose() {
+        verbose(System.out);
+    }
+
+    public void verbose(PrintStream stream) {
+        IndentedWriter out = new IndentedWriter(stream);
+        verbose(out);
+        out.flush();
+    }
+
+    public void verbose(IndentedWriter out) {
+        for ( Symbol symbol : context.keys() ) {
+            String value = context.getAsString(symbol);
+            out.println(symbol + " -> " + value);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModDataset.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModDataset.java b/jena-cmds/src/main/java/arq/cmdline/ModDataset.java
new file mode 100644
index 0000000..01a0bb8
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModDataset.java
@@ -0,0 +1,49 @@
+/*
+ * 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 arq.cmdline;
+
+import jena.cmd.ModBase;
+
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+
+public abstract class ModDataset extends ModBase
+{
+    protected boolean createAttempted = false ;
+    protected Dataset dataset = null ;
+    
+    public ModDataset() {}
+    
+    final
+    public Dataset getDataset() { 
+        if ( ! createAttempted )
+            dataset = createDataset() ;
+        createAttempted = true ;
+        return dataset ;
+    }
+    
+    public DatasetGraph getDatasetGraph() {
+        Dataset ds = getDataset() ;
+        if ( ds == null )
+            return null ;
+        return ds.asDatasetGraph() ;
+    }
+
+    public abstract Dataset createDataset() ; 
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModDatasetAssembler.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModDatasetAssembler.java b/jena-cmds/src/main/java/arq/cmdline/ModDatasetAssembler.java
new file mode 100644
index 0000000..840136c
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModDatasetAssembler.java
@@ -0,0 +1,70 @@
+/*
+ * 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 arq.cmdline;
+
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral;
+
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.shared.JenaException ;
+import org.apache.jena.shared.NotFoundException ;
+import org.apache.jena.sparql.ARQException ;
+import org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab ;
+
+/** Add assembler to a general dataset description */
+public class ModDatasetAssembler extends ModDataset
+{
+    private ModAssembler modAssembler = new ModAssembler() ;
+
+    @Override
+    public Dataset createDataset()
+    {
+        if ( modAssembler.getAssemblerFile() == null )
+            return null ;
+        
+        try {
+            dataset = (Dataset)modAssembler.create(DatasetAssemblerVocab.tDataset) ;
+            if ( dataset == null )
+                throw new CmdException("No dataset description found in: "+modAssembler.getAssemblerFile()) ;
+        }
+        catch (CmdException | ARQException ex) { throw ex ; }
+        catch (NotFoundException ex)
+        { throw new CmdException("Not found: "+ex.getMessage()) ; }
+        catch (JenaException ex)
+        { throw ex ; }
+        catch (Exception ex)
+        { throw new CmdException("Error creating dataset", ex) ; }
+        return dataset ;
+        
+    }
+
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        modAssembler.registerWith(cmdLine) ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        modAssembler.processArgs(cmdLine) ;
+    }
+
+}