commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [02/33] incubator-commonsrdf git commit: First draft
Date Mon, 28 Mar 2016 04:54:58 GMT
First draft


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

Branch: refs/heads/jena
Commit: aab479a285f426055158ea23201e84e45ded010d
Parents: 820412d
Author: Andy Seaborne <andy@seaborne.org>
Authored: Wed Aug 26 15:44:24 2015 +0100
Committer: Andy Seaborne <andy@seaborne.org>
Committed: Wed Aug 26 15:44:24 2015 +0100

----------------------------------------------------------------------
 .gitignore                                      |  32 +++--
 CONTRIBUTING.md                                 |   7 ++
 LICENSE                                         |   5 +-
 pom.xml                                         |  75 ++++++++++++
 .../org/apache/jena/commons/JCR_BlankNode.java  |  47 ++++++++
 .../org/apache/jena/commons/JCR_Factory.java    | 117 +++++++++++++++++++
 .../java/org/apache/jena/commons/JCR_Graph.java | 112 ++++++++++++++++++
 .../java/org/apache/jena/commons/JCR_IRI.java   |  55 +++++++++
 .../org/apache/jena/commons/JCR_Literal.java    |  68 +++++++++++
 .../java/org/apache/jena/commons/JCR_Term.java  |  48 ++++++++
 .../org/apache/jena/commons/JCR_Triple.java     |  67 +++++++++++
 .../org/apache/jena/commons/JenaCommonsRDF.java |  26 +++++
 .../apache/jena/commons/RDFTermFactoryJena.java |  80 +++++++++++++
 src/main/java/org/apache/jena/commons/TODO.java |  26 +++++
 .../apache/jena/commons/TestBlankNodeJena.java  |  35 ++++++
 .../org/apache/jena/commons/TestGraphJena.java  |  32 +++++
 .../jena/commons/TestRDFTermFactoryJena.java    |  32 +++++
 17 files changed, 853 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/aab479a2/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 32858aa..fc05569 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,12 +1,28 @@
-*.class
+# Maven and build files
+target/
 
-# Mobile Tools for Java (J2ME)
-.mtj.tmp/
+# Eclipse
+.classpath
+.project
+.settings
+.recommenders
+.metadata
 
-# Package Files #
+# Idea IntelliJ
+*.ipr
+*.iws
+*.iml
+.idea/
+
+# Caches
+.scala_dependencies
+
+# Other
+.DS_Store
 *.jar
-*.war
-*.ear
 
-# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
-hs_err_pid*
+# Backups
+pom.xml.backup
+*~
+.#*
+\#*

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/aab479a2/CONTRIBUTING.md
----------------------------------------------------------------------
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..4e03fb2
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,7 @@
+Contributions to this project will be gratefully received.
+
+The work of this project may be contributed to the Apache Software Foundation.
+
+Contributors may be asked to sign a Apache Software Grant
+
+[http://www.apache.org/licenses/software-grant.txt](http://www.apache.org/licenses/software-grant.txt)

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/aab479a2/LICENSE
----------------------------------------------------------------------
diff --git a/LICENSE b/LICENSE
index 8f71f43..ad410e1 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-                                 Apache License
+Apache License
                            Version 2.0, January 2004
                         http://www.apache.org/licenses/
 
@@ -198,5 +198,4 @@
    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.
-
+   limitations under the License.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/aab479a2/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..46730bb
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,75 @@
+<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>
+
+  <groupId>org.seaborne</groupId>
+  <artifactId>commonsrdf-jena</artifactId>
+  <version>0.0.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <name>commonsrdf-jena</name>
+  <description>Commons Java library for RDF 1.1</description>
+
+  <inceptionYear>2014</inceptionYear>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+    <ver.commonsrdf>0.1.0-incubating</ver.commonsrdf>
+  </properties>
+
+  <licenses>
+    <license>
+      <name>The Apache Software License, Version 2.0</name>
+      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+      <distribution>repo</distribution>
+    </license>
+  </licenses>
+
+
+  <build>
+    <plugins>
+      <plugin>
+	<groupId>org.apache.maven.plugins</groupId>
+	<artifactId>maven-compiler-plugin</artifactId>
+	<version>3.1</version>
+	<configuration>
+	  <source>1.8</source>
+	  <target>1.8</target>
+	  <encoding>UTF-8</encoding>
+	</configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.jena</groupId>
+      <artifactId>apache-jena-libs</artifactId>
+      <version>3.0.0</version>
+      <type>pom</type>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-rdf-api</artifactId>
+      <version>${ver.commonsrdf}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-rdf-api</artifactId>
+      <version>${ver.commonsrdf}</version>
+      <classifier>tests</classifier>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.11</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/aab479a2/src/main/java/org/apache/jena/commons/JCR_BlankNode.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/jena/commons/JCR_BlankNode.java b/src/main/java/org/apache/jena/commons/JCR_BlankNode.java
new file mode 100644
index 0000000..f01049d
--- /dev/null
+++ b/src/main/java/org/apache/jena/commons/JCR_BlankNode.java
@@ -0,0 +1,47 @@
+/**
+ * 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.commons;
+
+import org.apache.commons.rdf.api.BlankNode ;
+import org.apache.jena.graph.Node ;
+
+public class JCR_BlankNode extends JCR_Term implements BlankNode, JenaCommonsRDF {
+
+    /*package*/ JCR_BlankNode(Node node) { super(node) ; }
+
+    @Override
+    public String uniqueReference() {
+        return getNode().getBlankNodeLabel() ;
+    }
+
+    @Override
+    public int hashCode() {
+        return uniqueReference().hashCode() ;
+    }
+    
+    @Override
+    public boolean equals(Object other) {
+        if ( other == this ) return true ;
+        if ( other == null ) return false ;
+        if ( ! ( other instanceof BlankNode ) ) return false ;
+        BlankNode bNode = (BlankNode)other ;
+        return  uniqueReference().equals(bNode.uniqueReference()) ;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/aab479a2/src/main/java/org/apache/jena/commons/JCR_Factory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/jena/commons/JCR_Factory.java b/src/main/java/org/apache/jena/commons/JCR_Factory.java
new file mode 100644
index 0000000..e914267
--- /dev/null
+++ b/src/main/java/org/apache/jena/commons/JCR_Factory.java
@@ -0,0 +1,117 @@
+/**
+ * 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.commons;
+
+import org.apache.commons.rdf.api.* ;
+import org.apache.jena.datatypes.RDFDatatype ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.sparql.graph.GraphFactory ;
+
+public class JCR_Factory {
+    // basic components to commonsrdf backed by Jena. 
+    public static IRI createIRI(String iriStr) {
+        return (IRI)fromJena(NodeFactory.createURI(iriStr));
+    }
+
+    public static Literal createLiteral(String lexStr) {
+        return (Literal)fromJena(NodeFactory.createLiteral(lexStr));
+    }
+
+    public static Literal createLiteralDT(String lexStr, String datatypeIRI) {
+        return (Literal)fromJena(NodeFactory.createLiteral(lexStr, NodeFactory.getType(datatypeIRI)))
;
+    }
+
+    public static Literal createLiteralLang(String lexStr, String langTag) {
+        return (Literal)fromJena(NodeFactory.createLiteral(lexStr, langTag));
+    }
+
+    public static BlankNode createBlankNode() {
+        return (BlankNode)fromJena(NodeFactory.createBlankNode());
+    }
+
+    public static BlankNode createBlankNode(String id) {
+        return (BlankNode)fromJena(NodeFactory.createBlankNode(id));
+    }
+    
+    public static Graph createGraph() { return new JCR_Graph(GraphFactory.createDefaultGraph())
; }
+    
+    public static Triple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
{ 
+        return new JCR_Triple(subject, predicate, object) ;
+    }
+    
+//    // Nodes to commonsrdf. 
+//    public static IRI createIRI(Node iri) { return ()
+//    public static Literal createLiteral(Node lexStr) { return null ; }
+//    public static BlankNode createBlankNode(Node bNode) { return null ; }
+
+    
+    // commonsrdf to jena
+    public static org.apache.jena.graph.Triple toJena(Triple triple) {
+        return new org.apache.jena.graph.Triple(toJena(triple.getSubject()), toJena(triple.getPredicate()),
toJena(triple.getObject()) ) ;   
+    }
+    
+    public static Node toJena(RDFTerm term) {
+        if ( term instanceof JenaCommonsRDF )
+            return ((JenaCommonsRDF)term).getNode() ;
+        
+        if ( term instanceof IRI ) 
+            return NodeFactory.createURI(((IRI)term).getIRIString()) ;
+        
+        if ( term instanceof Literal ) {
+            Literal lit = (Literal)term ; 
+            RDFDatatype dt = NodeFactory.getType(lit.getDatatype().getIRIString()) ;
+            String lang = lit.getLanguageTag().orElse("") ;
+            return NodeFactory.createLiteral(lit.getLexicalForm(), lang, dt) ; 
+        }
+        
+        if ( term instanceof BlankNode ) {
+            String id = ((BlankNode)term).uniqueReference() ;
+            // XXX ???
+            // preserve skolemization vs gen new id?
+            return NodeFactory.createBlankNode(id) ;
+        }
+        
+        error("Not a concrete RDF Term: "+term) ;
+        return null ;
+    }
+    // jena to commonsrdf
+    public static RDFTerm fromJena(Node node) {
+        if ( node.isURI() )
+            return new JCR_IRI(node) ; 
+        if ( node.isLiteral() )
+            return new JCR_Literal(node) ;
+        if ( node.isBlank() ) {
+            return new JCR_BlankNode(node) ;
+        }
+        error("Node is not a concrete RDF Term: "+node) ;
+        return null ;
+    }
+ 
+    public static Triple fromJena(org.apache.jena.graph.Triple triple) {
+        return createTriple((BlankNodeOrIRI)fromJena(triple.getSubject()),
+                            (IRI)fromJena(triple.getPredicate()),
+                            fromJena(triple.getObject())) ;
+    }
+    private static void error(String msg) {
+        System.err.println("Error: "+msg) ;
+        throw new RuntimeException(msg) ;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/aab479a2/src/main/java/org/apache/jena/commons/JCR_Graph.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/jena/commons/JCR_Graph.java b/src/main/java/org/apache/jena/commons/JCR_Graph.java
new file mode 100644
index 0000000..788aae7
--- /dev/null
+++ b/src/main/java/org/apache/jena/commons/JCR_Graph.java
@@ -0,0 +1,112 @@
+/**
+ * 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.commons;
+
+import static org.apache.jena.commons.JCR_Factory.toJena ;
+import static org.apache.jena.commons.JCR_Factory.fromJena ;
+
+import java.io.StringWriter ;
+import java.util.Iterator ;
+import java.util.stream.Stream ;
+
+import org.apache.commons.rdf.api.* ;
+import org.apache.jena.atlas.iterator.Iter ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFDataMgr ;
+
+public class JCR_Graph implements Graph {
+
+    private org.apache.jena.graph.Graph graph;
+
+    /*package*/ JCR_Graph(org.apache.jena.graph.Graph graph) {
+        this.graph = graph ;
+    }
+    
+    @Override
+    public void add(Triple triple) { graph.add(JCR_Factory.toJena(triple)); }
+
+    @Override
+    public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) { 
+        graph.add(org.apache.jena.graph.Triple.create(toJena(subject),
+                                                      toJena(predicate),
+                                                      toJena(object)));
+    }
+
+    @Override
+    public boolean contains(Triple triple) {
+        return graph.contains(toJena(triple)) ; 
+    }
+
+    @Override
+    public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+        return graph.contains(toJena(subject),
+                              toJena(predicate),
+                              toJena(object) );
+    }
+
+    @Override
+    public void remove(Triple triple) { graph.delete(JCR_Factory.toJena(triple)); }
+
+    @Override
+    public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+        graph.delete(org.apache.jena.graph.Triple.create(toJena(subject),
+                                                         toJena(predicate),
+                                                         toJena(object)));
+    }
+
+    @Override
+    public void clear() { graph.clear(); }
+
+    @Override
+    public long size() {
+        return graph.size() ;
+    }
+
+    @Override
+    public Stream<? extends Triple> getTriples() {
+        return getTriples(null, null, null) ;
+    }
+
+    @Override
+    public Stream<? extends Triple> getTriples(BlankNodeOrIRI subject, IRI predicate,
RDFTerm object) {
+        Iterator<org.apache.jena.graph.Triple> iter = graph.find(toJenaAny(subject),toJenaAny(predicate),toJenaAny(object))
;
+        Iterator<Triple> iter2 = Iter.map(iter, t-> fromJena(t)) ;
+        return Iter.asStream(iter2) ;
+                        
+    }
+
+    private Node toJenaAny(RDFTerm term) {
+        if ( term == null )
+            return Node.ANY ;
+        return toJena(term) ;
+    }
+
+    @Override
+    public void close() { graph.close(); }
+    
+    @Override
+    public String toString() {
+        StringWriter sw = new StringWriter() ;
+        RDFDataMgr.write(sw, graph, Lang.NT) ;
+        return sw.toString() ;
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/aab479a2/src/main/java/org/apache/jena/commons/JCR_IRI.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/jena/commons/JCR_IRI.java b/src/main/java/org/apache/jena/commons/JCR_IRI.java
new file mode 100644
index 0000000..d8566a7
--- /dev/null
+++ b/src/main/java/org/apache/jena/commons/JCR_IRI.java
@@ -0,0 +1,55 @@
+/**
+ * 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.commons;
+
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.NodeFactory ;
+
+import org.apache.commons.rdf.api.* ;
+
+public class JCR_IRI extends JCR_Term implements IRI, JenaCommonsRDF {
+
+    /*package*/ JCR_IRI(String iriStr) {
+        super(NodeFactory.createURI(iriStr)) ;
+    }
+    
+    /*package*/ JCR_IRI(Node node) {
+        super(node) ;
+    }
+
+    @Override
+    public String getIRIString() {
+        return getNode().getURI() ;
+    }
+    
+    @Override
+    public int hashCode() {
+        return getIRIString().hashCode() ;
+    }
+    
+    @Override
+    public boolean equals(Object other) {
+        if ( other == this ) return true ;
+        if ( other == null ) return false ;
+        if ( ! ( other instanceof IRI ) ) return false ;
+        IRI iri = (IRI)other ;
+        return getIRIString().equals(iri.getIRIString()) ;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/aab479a2/src/main/java/org/apache/jena/commons/JCR_Literal.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/jena/commons/JCR_Literal.java b/src/main/java/org/apache/jena/commons/JCR_Literal.java
new file mode 100644
index 0000000..970ffe9
--- /dev/null
+++ b/src/main/java/org/apache/jena/commons/JCR_Literal.java
@@ -0,0 +1,68 @@
+/**
+ * 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.commons;
+
+import java.util.Objects ;
+import java.util.Optional ;
+
+import org.apache.commons.rdf.api.IRI ;
+import org.apache.commons.rdf.api.Literal ;
+import org.apache.jena.graph.Node ;
+
+public class JCR_Literal extends JCR_Term implements Literal {
+
+    /* package */ JCR_Literal(Node node) {
+        super(node) ;
+    }
+
+    @Override
+    public String getLexicalForm() {
+        return getNode().getLiteralLexicalForm() ;
+    }
+
+    @Override
+    public IRI getDatatype() {
+        return JCR_Factory.createIRI(getNode().getLiteralDatatype().getURI()) ;
+    }
+
+    @Override
+    public Optional<String> getLanguageTag() {
+        String x = getNode().getLiteralLanguage() ;
+        if ( x == null || x.isEmpty() )
+            return Optional.empty() ; 
+        return Optional.of(x) ;
+    }
+    
+    @Override
+    public int hashCode() {
+        return Objects.hash(getLexicalForm(), getDatatype(), getLanguageTag()) ;
+    }
+    
+    @Override
+    public boolean equals(Object other) {
+        if ( other == this ) return true ;
+        if ( other == null ) return false ;
+        if ( ! ( other instanceof Literal ) ) return false ;
+        Literal literal = (Literal)other ;
+        return  getLexicalForm().equals(literal.getLexicalForm()) &&
+                getLanguageTag().equals(literal.getLanguageTag()) &&
+                getDatatype().equals(literal.getDatatype()) ;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/aab479a2/src/main/java/org/apache/jena/commons/JCR_Term.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/jena/commons/JCR_Term.java b/src/main/java/org/apache/jena/commons/JCR_Term.java
new file mode 100644
index 0000000..a07d2d9
--- /dev/null
+++ b/src/main/java/org/apache/jena/commons/JCR_Term.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 org.apache.jena.commons;
+
+import org.apache.jena.graph.Node ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.shared.impl.PrefixMappingImpl ;
+import org.apache.jena.sparql.util.FmtUtils ;
+
+class JCR_Term implements JenaCommonsRDF {
+    private Node node;
+    static private PrefixMapping empty = new PrefixMappingImpl() ; 
+    
+    protected JCR_Term(Node node) {
+        this.node = node ;
+    }
+    
+    @Override
+    public Node getNode() {
+        return node ;
+    }
+
+    public String ntriplesString() {
+        return FmtUtils.stringForNode(node, empty) ;
+    }
+    
+    @Override
+    public String toString() {
+        return ntriplesString() ; 
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/aab479a2/src/main/java/org/apache/jena/commons/JCR_Triple.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/jena/commons/JCR_Triple.java b/src/main/java/org/apache/jena/commons/JCR_Triple.java
new file mode 100644
index 0000000..2f46653
--- /dev/null
+++ b/src/main/java/org/apache/jena/commons/JCR_Triple.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 org.apache.jena.commons;
+
+import java.util.Objects ;
+
+import org.apache.commons.rdf.api.* ;
+
+public class JCR_Triple implements Triple {
+    private final BlankNodeOrIRI subject ;
+    private final IRI predicate ;
+    private final RDFTerm object ;
+
+    /* package */ JCR_Triple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+        this.subject = subject ;
+        this.predicate = predicate ;
+        this.object = object ;
+    }
+    
+    @Override
+    public BlankNodeOrIRI getSubject() {
+        return subject ;
+    }
+
+    @Override
+    public IRI getPredicate() {
+        return predicate ;
+    }
+
+    @Override
+    public RDFTerm getObject() {
+        return object ;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(getSubject(), getPredicate(), getObject()) ;
+    }
+
+    @Override
+    public boolean equals(Object other) {
+        if ( other == this ) return true ;
+        if ( other == null ) return false ;
+        if ( ! ( other instanceof Triple ) ) return false ;
+        Triple triple = (Triple)other ;
+        return  getSubject().equals(triple.getSubject()) &&
+            getPredicate().equals(triple.getPredicate()) &&
+            getObject().equals(triple.getObject()) ;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/aab479a2/src/main/java/org/apache/jena/commons/JenaCommonsRDF.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/jena/commons/JenaCommonsRDF.java b/src/main/java/org/apache/jena/commons/JenaCommonsRDF.java
new file mode 100644
index 0000000..d8f22f4
--- /dev/null
+++ b/src/main/java/org/apache/jena/commons/JenaCommonsRDF.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 org.apache.jena.commons;
+
+import org.apache.jena.graph.Node ;
+
+public interface JenaCommonsRDF {
+    public Node getNode() ;
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/aab479a2/src/main/java/org/apache/jena/commons/RDFTermFactoryJena.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/jena/commons/RDFTermFactoryJena.java b/src/main/java/org/apache/jena/commons/RDFTermFactoryJena.java
new file mode 100644
index 0000000..e4f8ed3
--- /dev/null
+++ b/src/main/java/org/apache/jena/commons/RDFTermFactoryJena.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 org.apache.jena.commons;
+
+import org.apache.commons.rdf.api.* ;
+
+public class RDFTermFactoryJena implements RDFTermFactory {
+    
+    @Override
+    public BlankNode createBlankNode() {
+        return JCR_Factory.createBlankNode() ;
+    }
+
+    @Override
+    public BlankNode createBlankNode(String name) {
+        return JCR_Factory.createBlankNode(name) ;
+    }
+
+    @Override
+    public Graph createGraph() {
+        return JCR_Factory.createGraph() ;
+    }
+
+    @Override
+    public IRI createIRI(String iri) {
+        validateIRI(iri) ;
+        return JCR_Factory.createIRI(iri) ;
+    }
+
+    // Some simple validations - full IRI parsing is not cheap. 
+    private static void validateIRI(String iri) {
+        if ( iri.contains(" ") ) throw new IllegalArgumentException() ;
+        if ( iri.contains("<") ) throw new IllegalArgumentException() ;
+        if ( iri.contains(">") ) throw new IllegalArgumentException() ;
+    }
+
+    @Override
+    public Literal createLiteral(String lexicalForm) {
+        return JCR_Factory.createLiteral(lexicalForm) ;
+    }
+
+    @Override
+    public Literal createLiteral(String lexicalForm, IRI dataType) {
+        return JCR_Factory.createLiteralDT(lexicalForm, dataType.getIRIString()) ;
+    }
+
+    @Override
+    public Literal createLiteral(String lexicalForm, String languageTag) {
+        validateLang(languageTag) ;
+        return JCR_Factory.createLiteralLang(lexicalForm, languageTag) ;
+    }
+
+    private static void validateLang(String languageTag) {
+        if ( languageTag.contains(" ") ) throw new IllegalArgumentException() ;
+    }
+
+    @Override
+    public Triple createTriple(BlankNodeOrIRI subject, IRI predicate, 
+                                RDFTerm object) {
+        return JCR_Factory.createTriple(subject, predicate, object) ;
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/aab479a2/src/main/java/org/apache/jena/commons/TODO.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/jena/commons/TODO.java b/src/main/java/org/apache/jena/commons/TODO.java
new file mode 100644
index 0000000..4aa1fd3
--- /dev/null
+++ b/src/main/java/org/apache/jena/commons/TODO.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 org.apache.jena.commons;
+
+public class TODO {
+    // HashCode and equals
+    // Invalid language
+    // Invalid IRI string.
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/aab479a2/src/test/java/org/apache/jena/commons/TestBlankNodeJena.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/jena/commons/TestBlankNodeJena.java b/src/test/java/org/apache/jena/commons/TestBlankNodeJena.java
new file mode 100644
index 0000000..117a352
--- /dev/null
+++ b/src/test/java/org/apache/jena/commons/TestBlankNodeJena.java
@@ -0,0 +1,35 @@
+/**
+ * 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.commons;
+
+import org.apache.commons.rdf.api.AbstractBlankNodeTest ;
+import org.apache.commons.rdf.api.BlankNode ;
+
+public class TestBlankNodeJena extends AbstractBlankNodeTest {
+    @Override
+    protected BlankNode getBlankNode() {
+        return JCR_Factory.createBlankNode() ;
+    }
+    
+    @Override
+    protected BlankNode getBlankNode(String identifier) {
+        return JCR_Factory.createBlankNode(identifier) ;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/aab479a2/src/test/java/org/apache/jena/commons/TestGraphJena.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/jena/commons/TestGraphJena.java b/src/test/java/org/apache/jena/commons/TestGraphJena.java
new file mode 100644
index 0000000..66df1d0
--- /dev/null
+++ b/src/test/java/org/apache/jena/commons/TestGraphJena.java
@@ -0,0 +1,32 @@
+/**
+ * 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.commons;
+
+import org.apache.commons.rdf.api.AbstractGraphTest ;
+import org.apache.commons.rdf.api.RDFTermFactory ;
+
+public class TestGraphJena extends AbstractGraphTest {
+
+    @Override
+    public RDFTermFactory createFactory() {
+        return new RDFTermFactoryJena() ;
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/aab479a2/src/test/java/org/apache/jena/commons/TestRDFTermFactoryJena.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/jena/commons/TestRDFTermFactoryJena.java b/src/test/java/org/apache/jena/commons/TestRDFTermFactoryJena.java
new file mode 100644
index 0000000..c65bbc9
--- /dev/null
+++ b/src/test/java/org/apache/jena/commons/TestRDFTermFactoryJena.java
@@ -0,0 +1,32 @@
+/**
+ * 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.commons;
+
+import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest ;
+import org.apache.commons.rdf.api.RDFTermFactory ;
+
+public class TestRDFTermFactoryJena extends AbstractRDFTermFactoryTest {
+
+    @Override
+    public RDFTermFactory createFactory() {
+        return new RDFTermFactoryJena() ;
+    }
+
+}
+



Mime
View raw message