You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commonsrdf.apache.org by st...@apache.org on 2016/07/02 16:14:39 UTC
[22/50] [abbrv] incubator-commonsrdf git commit: package
org.apache.commons.rdf.jena
package org.apache.commons.rdf.jena
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/7a2650a1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/7a2650a1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/7a2650a1
Branch: refs/heads/jena
Commit: 7a2650a1b3e980af941c50ec1b6be200bfce9e33
Parents: 86eb7d2
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Mar 28 02:24:43 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Mar 28 02:28:51 2016 +0100
----------------------------------------------------------------------
jena/README.md | 2 +-
.../commons/rdf/jena/ConversionException.java | 37 +++++
.../apache/commons/rdf/jena/JenaCommonsRDF.java | 154 +++++++++++++++++++
.../commons/rdf/jena/RDFTermFactoryJena.java | 85 ++++++++++
.../examples/Ex_JenaGraphToCommonsRDFGraph.java | 54 +++++++
.../examples/Ex_ParseIntoCommonsRDFGraph.java | 52 +++++++
.../commons/rdf/jena/impl/JCR_BlankNode.java | 47 ++++++
.../commons/rdf/jena/impl/JCR_Factory.java | 86 +++++++++++
.../apache/commons/rdf/jena/impl/JCR_Graph.java | 115 ++++++++++++++
.../apache/commons/rdf/jena/impl/JCR_IRI.java | 55 +++++++
.../commons/rdf/jena/impl/JCR_Literal.java | 68 ++++++++
.../apache/commons/rdf/jena/impl/JCR_Term.java | 48 ++++++
.../commons/rdf/jena/impl/JCR_Triple.java | 88 +++++++++++
.../apache/commons/rdf/jena/impl/JenaGraph.java | 26 ++++
.../apache/commons/rdf/jena/impl/JenaNode.java | 26 ++++
.../commons/rdf/jena/impl/JenaTriple.java | 26 ++++
.../apache/commons/rdf/jena/impl/ToGraph.java | 68 ++++++++
.../jena/commonsrdf/ConversionException.java | 37 -----
.../apache/jena/commonsrdf/JenaCommonsRDF.java | 154 -------------------
.../jena/commonsrdf/RDFTermFactoryJena.java | 85 ----------
.../examples/Ex_JenaGraphToCommonsRDFGraph.java | 54 -------
.../examples/Ex_ParseIntoCommonsRDFGraph.java | 52 -------
.../jena/commonsrdf/impl/JCR_BlankNode.java | 47 ------
.../jena/commonsrdf/impl/JCR_Factory.java | 86 -----------
.../apache/jena/commonsrdf/impl/JCR_Graph.java | 115 --------------
.../apache/jena/commonsrdf/impl/JCR_IRI.java | 55 -------
.../jena/commonsrdf/impl/JCR_Literal.java | 68 --------
.../apache/jena/commonsrdf/impl/JCR_Term.java | 48 ------
.../apache/jena/commonsrdf/impl/JCR_Triple.java | 88 -----------
.../apache/jena/commonsrdf/impl/JenaGraph.java | 26 ----
.../apache/jena/commonsrdf/impl/JenaNode.java | 26 ----
.../apache/jena/commonsrdf/impl/JenaTriple.java | 26 ----
.../apache/jena/commonsrdf/impl/ToGraph.java | 68 --------
.../commons/rdf/jena/TS_JenaCommonsRDF.java | 41 +++++
.../commons/rdf/jena/TestBlankNodeJena.java | 36 +++++
.../apache/commons/rdf/jena/TestGraphJena.java | 33 ++++
.../rdf/jena/TestRDFTermFactoryJena.java | 33 ++++
.../jena/commonsrdf/TS_JenaCommonsRDF.java | 41 -----
.../jena/commonsrdf/TestBlankNodeJena.java | 36 -----
.../apache/jena/commonsrdf/TestGraphJena.java | 33 ----
.../jena/commonsrdf/TestRDFTermFactoryJena.java | 33 ----
jena/target/classes/META-INF/MANIFEST.MF | 4 +-
.../commons-rdf-jena/pom.properties | 2 +-
43 files changed, 1182 insertions(+), 1182 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/README.md
----------------------------------------------------------------------
diff --git a/jena/README.md b/jena/README.md
index f5d6277..c7f5135 100644
--- a/jena/README.md
+++ b/jena/README.md
@@ -3,7 +3,7 @@
Code showing using [Apache CommonsRDF](http://commonsrdf.incubator.apache.org/)
with [Apache Jena](http://jena.apache.org/).
-`package org.apache.jena.commonsrdf.examples`
+`package org.apache.commons.rdf.jena.examples`
* `Ex_ParseIntoCommonsRDFGraph`
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/src/main/java/org/apache/commons/rdf/jena/ConversionException.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/ConversionException.java b/jena/src/main/java/org/apache/commons/rdf/jena/ConversionException.java
new file mode 100644
index 0000000..44953cd
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/ConversionException.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 org.apache.commons.rdf.jena;
+
+import org.apache.jena.shared.JenaException ;
+
+/**
+ * Exception thrown when a problem arises across the Jena-CommonRDF boundary.
+ * This should not happen in well-formed RDF data but, for example, Jena triples
+ * allow
+ * <a href="http://www.w3.org/TR/rdf11-concepts/#section-generalized-rdf"
+ * >generalized RDF</a>.
+ */
+
+public class ConversionException extends JenaException {
+ public ConversionException() { super(); }
+ public ConversionException(String message) { super(message); }
+ public ConversionException(Throwable cause) { super(cause) ; }
+ public ConversionException(String message, Throwable cause) { super(message, cause) ; }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/src/main/java/org/apache/commons/rdf/jena/JenaCommonsRDF.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaCommonsRDF.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaCommonsRDF.java
new file mode 100644
index 0000000..a0fb178
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaCommonsRDF.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 org.apache.commons.rdf.jena;
+
+import org.apache.commons.rdf.api.* ;
+import org.apache.commons.rdf.jena.impl.*;
+import org.apache.jena.datatypes.RDFDatatype ;
+import org.apache.jena.datatypes.xsd.XSDDatatype ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.riot.system.StreamRDF ;
+import org.apache.jena.sparql.graph.GraphFactory ;
+
+/** A set of utilities for moving between CommonsRDF and Jena
+ * The {@link RDFTermFactory} for is {@link RDFTermFactoryJena} which
+ * creates CommonsRDF objects backed by Jena.
+ * <p>
+ * This class encapsulates moving between existing object (RDFTerms, Triples, Graphs)
+ * which is usually necessary when working with existing data.
+ *
+ * @see RDFTermFactoryJena
+ */
+public class JenaCommonsRDF {
+
+ /** Convert a CommonsRDF RDFTerm to a Jena Node.
+ * If the RDFTerm was from Jena originally, return that original object else
+ * create a copy using Jena objects.
+ */
+ public static Node toJena(RDFTerm term) {
+ if ( term instanceof JenaNode )
+ return ((JenaNode)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() ;
+ return NodeFactory.createBlankNode(id) ;
+ }
+ conversionError("Not a concrete RDF Term: "+term) ;
+ return null ;
+ }
+
+ /** Convert a CommonsRDF Triple to a Jena Triple.
+ * If the Triple was from Jena originally, return that original object else
+ * create a copy using Jena objects.
+ */
+ public static org.apache.jena.graph.Triple toJena(Triple triple) {
+ if ( triple instanceof JenaTriple )
+ return ((JenaTriple)triple).getTriple() ;
+ return new org.apache.jena.graph.Triple(toJena(triple.getSubject()), toJena(triple.getPredicate()), toJena(triple.getObject()) ) ;
+ }
+
+ /** Convert a CommonsRDF Graph to a Jena Graph.
+ * If the Graph was from Jena originally, return that original object else
+ * create a copy using Jena objects.
+ */
+ public static org.apache.jena.graph.Graph toJena(Graph graph) {
+ if ( graph instanceof JenaGraph )
+ return ((JenaGraph)graph).getGraph() ;
+ org.apache.jena.graph.Graph g = GraphFactory.createGraphMem() ;
+ graph.getTriples().forEach(t->g.add(toJena(t))) ;
+ return g ;
+ }
+
+ /** Adapt an existing Jena Node to CommonsRDF {@link RDFTerm}. */
+ public static RDFTerm fromJena( Node node) {
+ return JCR_Factory.fromJena(node) ;
+ }
+
+ /** Adapt an existing Jena Triple to CommonsRDF {@link Triple}. */
+ public static Triple fromJena(org.apache.jena.graph.Triple triple) {
+ return JCR_Factory.fromJena(triple) ;
+ }
+
+ /** Adapt an existring Jena Graph to CommonsRDF {@link Graph}.
+ * This does not take a copy.
+ * Changes to the CommonsRDF Graph are reflected in the jena graph.
+ */
+ public static Graph fromJena(org.apache.jena.graph.Graph graph) {
+ return JCR_Factory.fromJena(graph) ;
+ }
+
+ /** Convert from Jena {@link Node} to any RDFCommons implementation */
+ public static RDFTerm fromJena(RDFTermFactory factory, Node node) {
+ if ( node.isURI() )
+ return factory.createIRI(node.getURI()) ;
+ if ( node.isLiteral() ) {
+ String lang = node.getLiteralLanguage() ;
+ if ( lang != null && ! lang.isEmpty() )
+ return factory.createLiteral(node.getLiteralLexicalForm(), lang) ;
+ if ( node.getLiteralDatatype().equals(XSDDatatype.XSDstring) )
+ return factory.createLiteral(node.getLiteralLexicalForm()) ;
+ IRI dt = factory.createIRI(node.getLiteralDatatype().getURI()) ;
+ return factory.createLiteral(node.getLiteralLexicalForm(), dt);
+ }
+ if ( node.isBlank() )
+ return factory.createBlankNode(node.getBlankNodeLabel()) ;
+ throw new ConversionException("Node is not a concrete RDF Term: "+node) ;
+ }
+
+ /** Convert from Jena {@link org.apache.jena.graph.Triple} to any RDFCommons implementation */
+ public static Triple fromJena(RDFTermFactory factory, org.apache.jena.graph.Triple triple) {
+ BlankNodeOrIRI subject = (BlankNodeOrIRI)(fromJena(factory, triple.getSubject())) ;
+ IRI predicate = (IRI)(fromJena(factory, triple.getPredicate())) ;
+ RDFTerm object = fromJena(factory, triple.getObject()) ;
+ return factory.createTriple(subject, predicate, object) ;
+ }
+
+ /** Convert from Jena to any RDFCommons implementation.
+ * This is a copy, even if the factory is a RDFTermFactoryJena.
+ * Use {@link #fromJena(org.apache.jena.graph.Graph)} for a wrapper.
+ */
+ public static Graph fromJena(RDFTermFactory factory, org.apache.jena.graph.Graph graph) {
+ Graph g = factory.createGraph() ;
+ graph.find(Node.ANY, Node.ANY, Node.ANY).forEachRemaining( t-> {
+ g.add(fromJena(factory, t) );
+ }) ;
+ return g ;
+ }
+
+ /** Create a {@link StreamRDF} that inserts into any RDFCommons implementation of Graph */
+ public static StreamRDF streamJenaToCommonsRDF(RDFTermFactory factory, Graph graph) {
+ return new ToGraph(factory, graph) ;
+ }
+
+ public static void conversionError(String msg) {
+ throw new ConversionException(msg) ;
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/src/main/java/org/apache/commons/rdf/jena/RDFTermFactoryJena.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/RDFTermFactoryJena.java b/jena/src/main/java/org/apache/commons/rdf/jena/RDFTermFactoryJena.java
new file mode 100644
index 0000000..08572c1
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/RDFTermFactoryJena.java
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES 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.commons.rdf.jena;
+
+import org.apache.commons.rdf.api.* ;
+import org.apache.commons.rdf.jena.impl.JCR_Factory;
+
+/** RDFTermFactory with Jena-backed objects.
+ * See {@link JenaCommonsRDF} for other conversions of existing objects.
+ *
+ * @see RDFTermFactory
+ */
+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/7a2650a1/jena/src/main/java/org/apache/commons/rdf/jena/examples/Ex_JenaGraphToCommonsRDFGraph.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/examples/Ex_JenaGraphToCommonsRDFGraph.java b/jena/src/main/java/org/apache/commons/rdf/jena/examples/Ex_JenaGraphToCommonsRDFGraph.java
new file mode 100644
index 0000000..1ef4806
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/examples/Ex_JenaGraphToCommonsRDFGraph.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 org.apache.commons.rdf.jena.examples;
+
+import org.apache.commons.rdf.api.Graph ;
+import org.apache.commons.rdf.api.RDFTermFactory ;
+import org.apache.commons.rdf.jena.JenaCommonsRDF;
+import org.apache.commons.rdf.jena.RDFTermFactoryJena;
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFDataMgr ;
+import org.apache.jena.sparql.graph.GraphFactory ;
+
+/** Adapt a Jena Graph after parsing data into it */
+public class Ex_JenaGraphToCommonsRDFGraph {
+ static { LogCtl.setCmdLogging(); }
+
+ public static void main(String ...a) {
+ org.apache.jena.graph.Graph jGraph = GraphFactory.createGraphMem() ;
+ RDFDataMgr.read(jGraph, "D.ttl") ;
+
+ // "graph" is a CommonsRDF graph
+ Graph graph = JenaCommonsRDF.fromJena(jGraph) ;
+
+ // Add to CommonsRDF Graph
+ RDFTermFactory rft = new RDFTermFactoryJena() ;
+ graph.add(rft.createIRI("http://example/s2"),
+ rft.createIRI("http://example/p2"),
+ rft.createLiteral("foo")) ;
+ System.out.println("==== Write CommonsRDF graph\n") ;
+ graph.getTriples().forEach(System.out::println) ;
+
+ System.out.println("\n==== Write Jena graph directly\n") ;
+ // And its in the Jena graph
+ RDFDataMgr.write(System.out, jGraph, Lang.TTL) ;
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/src/main/java/org/apache/commons/rdf/jena/examples/Ex_ParseIntoCommonsRDFGraph.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/examples/Ex_ParseIntoCommonsRDFGraph.java b/jena/src/main/java/org/apache/commons/rdf/jena/examples/Ex_ParseIntoCommonsRDFGraph.java
new file mode 100644
index 0000000..1984c80
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/examples/Ex_ParseIntoCommonsRDFGraph.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 org.apache.commons.rdf.jena.examples;
+
+import org.apache.commons.rdf.api.Graph ;
+import org.apache.commons.rdf.api.RDFTermFactory ;
+import org.apache.commons.rdf.jena.JenaCommonsRDF;
+import org.apache.commons.rdf.jena.RDFTermFactoryJena;
+import org.apache.commons.rdf.simple.SimpleRDFTermFactory ;
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.riot.RDFDataMgr ;
+import org.apache.jena.riot.system.StreamRDF ;
+
+/** Use jena to parse data into an CommonsRDF graph */
+public class Ex_ParseIntoCommonsRDFGraph {
+ static { LogCtl.setCmdLogging(); }
+
+ public static void main(String ...a) {
+ System.out.println("== RDFTermFactoryJena") ;
+ RDFTermFactory rft1 = new RDFTermFactoryJena() ; // This can be a non-Jena backed factory
+ parse(rft1) ;
+ System.out.println() ;
+ System.out.println("== SimpleRDFTermFactory") ;
+ RDFTermFactory rft2 = new SimpleRDFTermFactory() ;
+ parse(rft2) ;
+ }
+
+ public static void parse(RDFTermFactory rft) {
+ Graph graph = rft.createGraph() ;
+ StreamRDF dest = JenaCommonsRDF.streamJenaToCommonsRDF(rft, graph) ;
+ RDFDataMgr.parse(dest, "D.ttl") ;
+ graph.getTriples().forEach(System.out::println) ;
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_BlankNode.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_BlankNode.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_BlankNode.java
new file mode 100644
index 0000000..8885bb4
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/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.commons.rdf.jena.impl;
+
+import org.apache.commons.rdf.api.BlankNode ;
+import org.apache.jena.graph.Node ;
+
+public class JCR_BlankNode extends JCR_Term implements BlankNode, JenaNode {
+
+ /*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/7a2650a1/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Factory.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Factory.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Factory.java
new file mode 100644
index 0000000..e934f70
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Factory.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 org.apache.commons.rdf.jena.impl;
+import static org.apache.commons.rdf.jena.JenaCommonsRDF.conversionError;
+
+import org.apache.commons.rdf.api.* ;
+import org.apache.commons.rdf.jena.JenaCommonsRDF;
+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)JenaCommonsRDF.fromJena(NodeFactory.createURI(iriStr));
+ }
+
+ public static Literal createLiteral(String lexStr) {
+ return new JCR_Literal(NodeFactory.createLiteral(lexStr));
+ }
+
+ public static Literal createLiteralDT(String lexStr, String datatypeIRI) {
+ return new JCR_Literal(NodeFactory.createLiteral(lexStr, NodeFactory.getType(datatypeIRI))) ;
+ }
+
+ public static Literal createLiteralLang(String lexStr, String langTag) {
+ return new JCR_Literal(NodeFactory.createLiteral(lexStr, langTag));
+ }
+
+ public static BlankNode createBlankNode() {
+ return new JCR_BlankNode(NodeFactory.createBlankNode());
+ }
+
+ public static BlankNode createBlankNode(String id) {
+ return new JCR_BlankNode(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) ;
+ }
+
+ public static Triple fromJena(org.apache.jena.graph.Triple triple) {
+ return new JCR_Triple(triple) ;
+ }
+
+ public static Graph fromJena(org.apache.jena.graph.Graph graph) {
+ return new JCR_Graph(graph) ;
+ }
+
+ public static RDFTerm fromJena(Node node) {
+ if ( node.isURI() )
+ return new JCR_IRI(node) ;
+ if ( node.isLiteral() ) {
+ return new JCR_Literal(node) ;
+// String lang = node.getLiteralLanguage() ;
+// if ( lang != null && lang.isEmpty() )
+// return createLiteralLang(node.getLiteralLexicalForm(), lang) ;
+// if ( node.getLiteralDatatype().equals(XSDDatatype.XSDstring) )
+// return createLiteral(node.getLiteralLexicalForm()) ;
+// return createLiteralDT(node.getLiteralLexicalForm(), node.getLiteralDatatype().getURI());
+ }
+ if ( node.isBlank() )
+ return new JCR_BlankNode(node) ;
+ conversionError("Node is not a concrete RDF Term: "+node) ;
+ return null ;
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Graph.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Graph.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Graph.java
new file mode 100644
index 0000000..f76ea4a
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Graph.java
@@ -0,0 +1,115 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES 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.commons.rdf.jena.impl;
+
+import java.io.StringWriter ;
+import java.util.Iterator ;
+import java.util.stream.Stream ;
+
+import org.apache.commons.rdf.api.* ;
+import org.apache.commons.rdf.jena.JenaCommonsRDF;
+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, JenaGraph {
+
+ private org.apache.jena.graph.Graph graph;
+
+ /*package*/ JCR_Graph(org.apache.jena.graph.Graph graph) {
+ this.graph = graph ;
+ }
+
+ @Override
+ public org.apache.jena.graph.Graph getGraph() {
+ return graph ;
+ }
+
+ @Override
+ public void add(Triple triple) { graph.add(JenaCommonsRDF.toJena(triple)); }
+
+ @Override
+ public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ graph.add(org.apache.jena.graph.Triple.create(JenaCommonsRDF.toJena(subject),
+ JenaCommonsRDF.toJena(predicate),
+ JenaCommonsRDF.toJena(object)));
+ }
+
+ @Override
+ public boolean contains(Triple triple) {
+ return graph.contains(JenaCommonsRDF.toJena(triple)) ;
+ }
+
+ @Override
+ public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return graph.contains(JenaCommonsRDF.toJena(subject),
+ JenaCommonsRDF.toJena(predicate),
+ JenaCommonsRDF.toJena(object) );
+ }
+
+ @Override
+ public void remove(Triple triple) { graph.delete(JenaCommonsRDF.toJena(triple)); }
+
+ @Override
+ public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ graph.delete(org.apache.jena.graph.Triple.create(JenaCommonsRDF.toJena(subject),
+ JenaCommonsRDF.toJena(predicate),
+ JenaCommonsRDF.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-> JenaCommonsRDF.fromJena(t)) ;
+ return Iter.asStream(iter2) ;
+
+ }
+
+ private Node toJenaAny(RDFTerm term) {
+ if ( term == null )
+ return Node.ANY ;
+ return JenaCommonsRDF.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/7a2650a1/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_IRI.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_IRI.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_IRI.java
new file mode 100644
index 0000000..fc8e366
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/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.commons.rdf.jena.impl;
+
+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, JenaNode {
+
+ /*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/7a2650a1/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Literal.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Literal.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Literal.java
new file mode 100644
index 0000000..08153cd
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/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.commons.rdf.jena.impl;
+
+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/7a2650a1/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Term.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Term.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Term.java
new file mode 100644
index 0000000..f676001
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/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.commons.rdf.jena.impl;
+
+import org.apache.jena.graph.Node ;
+import org.apache.jena.riot.out.NodeFmtLib ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.shared.impl.PrefixMappingImpl ;
+
+class JCR_Term implements JenaNode {
+ 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 NodeFmtLib.str(node) ;
+ }
+
+ @Override
+ public String toString() {
+ return ntriplesString() ;
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Triple.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Triple.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Triple.java
new file mode 100644
index 0000000..30b035c
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Triple.java
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES 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.commons.rdf.jena.impl;
+
+import java.util.Objects ;
+
+import org.apache.commons.rdf.api.* ;
+import org.apache.commons.rdf.jena.JenaCommonsRDF;
+
+public class JCR_Triple implements Triple, JenaTriple {
+ private final BlankNodeOrIRI subject ;
+ private final IRI predicate ;
+ private final RDFTerm object ;
+ private org.apache.jena.graph.Triple triple = null ;
+
+ /* package */ JCR_Triple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ this.subject = subject ;
+ this.predicate = predicate ;
+ this.object = object ;
+ }
+
+ /* package */ JCR_Triple(org.apache.jena.graph.Triple triple) {
+ this.subject = (BlankNodeOrIRI)JCR_Factory.fromJena(triple.getSubject()) ;
+ this.predicate = (IRI)JCR_Factory.fromJena(triple.getPredicate()) ;
+ this.object = JCR_Factory.fromJena(triple.getObject()) ;
+ this.triple = triple ;
+ }
+
+ @Override
+ public org.apache.jena.graph.Triple getTriple() {
+ if ( triple == null )
+ triple = org.apache.jena.graph.Triple.create(JenaCommonsRDF.toJena(subject), JenaCommonsRDF.toJena(predicate), JenaCommonsRDF.toJena(object)) ;
+ return triple ;
+ }
+
+ @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()) ;
+ }
+
+ @Override
+ public String toString() {
+ return getSubject()+" "+getPredicate()+" "+getObject()+" ." ;
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraph.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraph.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraph.java
new file mode 100644
index 0000000..9f0b588
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraph.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.commons.rdf.jena.impl;
+
+import org.apache.jena.graph.Graph ;
+
+/** Access the Jena graph backing this object */
+public interface JenaGraph {
+ public Graph getGraph() ;
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaNode.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaNode.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaNode.java
new file mode 100644
index 0000000..6e4075d
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaNode.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.commons.rdf.jena.impl;
+
+import org.apache.jena.graph.Node ;
+
+/** Access the Jena node backing this object */
+public interface JenaNode {
+ public Node getNode() ;
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaTriple.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaTriple.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaTriple.java
new file mode 100644
index 0000000..0374cf9
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaTriple.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.commons.rdf.jena.impl;
+
+import org.apache.jena.graph.Triple ;
+
+/** Access the Jena triple backing this object */
+public interface JenaTriple {
+ public Triple getTriple() ;
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/src/main/java/org/apache/commons/rdf/jena/impl/ToGraph.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/ToGraph.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/ToGraph.java
new file mode 100644
index 0000000..45e817c
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/ToGraph.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.commons.rdf.jena.impl;
+
+import org.apache.commons.rdf.api.Graph ;
+import org.apache.commons.rdf.api.RDFTermFactory ;
+import org.apache.commons.rdf.jena.JenaCommonsRDF;
+import org.apache.jena.riot.system.StreamRDF ;
+
+/** Adapter to go from Jena StreamRDF (e.g. a parser output stream) to a CommonsRDF Graph */
+public class ToGraph implements StreamRDF {
+
+ private Graph graph;
+ private RDFTermFactory factory;
+
+ public ToGraph(RDFTermFactory factory) {
+ this(factory, factory.createGraph()) ;
+ }
+
+ public ToGraph(RDFTermFactory factory, Graph graph) {
+ this.factory = factory ;
+ this.graph = graph ;
+ }
+
+ @Override
+ public void start() {}
+
+ @Override
+ public void triple(org.apache.jena.graph.Triple triple) {
+ graph.add(JenaCommonsRDF.fromJena(factory, triple)) ;
+ }
+
+ @Override
+ public void quad(org.apache.jena.sparql.core.Quad quad) {
+ throw new UnsupportedOperationException() ;
+ }
+
+ @Override
+ public void base(String base) {}
+
+ @Override
+ public void prefix(String prefix, String iri) {}
+
+ @Override
+ public void finish() {}
+
+ public Graph getGraph() {
+ return graph;
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/src/main/java/org/apache/jena/commonsrdf/ConversionException.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/jena/commonsrdf/ConversionException.java b/jena/src/main/java/org/apache/jena/commonsrdf/ConversionException.java
deleted file mode 100644
index 65cc04a..0000000
--- a/jena/src/main/java/org/apache/jena/commonsrdf/ConversionException.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 org.apache.jena.commonsrdf;
-
-import org.apache.jena.shared.JenaException ;
-
-/**
- * Exception thrown when a problem arises across the Jena-CommonRDF boundary.
- * This should not happen in well-formed RDF data but, for example, Jena triples
- * allow
- * <a href="http://www.w3.org/TR/rdf11-concepts/#section-generalized-rdf"
- * >generalized RDF</a>.
- */
-
-public class ConversionException extends JenaException {
- public ConversionException() { super(); }
- public ConversionException(String message) { super(message); }
- public ConversionException(Throwable cause) { super(cause) ; }
- public ConversionException(String message, Throwable cause) { super(message, cause) ; }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/src/main/java/org/apache/jena/commonsrdf/JenaCommonsRDF.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/jena/commonsrdf/JenaCommonsRDF.java b/jena/src/main/java/org/apache/jena/commonsrdf/JenaCommonsRDF.java
deleted file mode 100644
index 1b24560..0000000
--- a/jena/src/main/java/org/apache/jena/commonsrdf/JenaCommonsRDF.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 org.apache.jena.commonsrdf;
-
-import org.apache.commons.rdf.api.* ;
-import org.apache.jena.commonsrdf.impl.* ;
-import org.apache.jena.datatypes.RDFDatatype ;
-import org.apache.jena.datatypes.xsd.XSDDatatype ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.riot.system.StreamRDF ;
-import org.apache.jena.sparql.graph.GraphFactory ;
-
-/** A set of utilities for moving between CommonsRDF and Jena
- * The {@link RDFTermFactory} for is {@link RDFTermFactoryJena} which
- * creates CommonsRDF objects backed by Jena.
- * <p>
- * This class encapsulates moving between existing object (RDFTerms, Triples, Graphs)
- * which is usually necessary when working with existing data.
- *
- * @see RDFTermFactoryJena
- */
-public class JenaCommonsRDF {
-
- /** Convert a CommonsRDF RDFTerm to a Jena Node.
- * If the RDFTerm was from Jena originally, return that original object else
- * create a copy using Jena objects.
- */
- public static Node toJena(RDFTerm term) {
- if ( term instanceof JenaNode )
- return ((JenaNode)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() ;
- return NodeFactory.createBlankNode(id) ;
- }
- conversionError("Not a concrete RDF Term: "+term) ;
- return null ;
- }
-
- /** Convert a CommonsRDF Triple to a Jena Triple.
- * If the Triple was from Jena originally, return that original object else
- * create a copy using Jena objects.
- */
- public static org.apache.jena.graph.Triple toJena(Triple triple) {
- if ( triple instanceof JenaTriple )
- return ((JenaTriple)triple).getTriple() ;
- return new org.apache.jena.graph.Triple(toJena(triple.getSubject()), toJena(triple.getPredicate()), toJena(triple.getObject()) ) ;
- }
-
- /** Convert a CommonsRDF Graph to a Jena Graph.
- * If the Graph was from Jena originally, return that original object else
- * create a copy using Jena objects.
- */
- public static org.apache.jena.graph.Graph toJena(Graph graph) {
- if ( graph instanceof JenaGraph )
- return ((JenaGraph)graph).getGraph() ;
- org.apache.jena.graph.Graph g = GraphFactory.createGraphMem() ;
- graph.getTriples().forEach(t->g.add(toJena(t))) ;
- return g ;
- }
-
- /** Adapt an existing Jena Node to CommonsRDF {@link RDFTerm}. */
- public static RDFTerm fromJena( Node node) {
- return JCR_Factory.fromJena(node) ;
- }
-
- /** Adapt an existing Jena Triple to CommonsRDF {@link Triple}. */
- public static Triple fromJena(org.apache.jena.graph.Triple triple) {
- return JCR_Factory.fromJena(triple) ;
- }
-
- /** Adapt an existring Jena Graph to CommonsRDF {@link Graph}.
- * This does not take a copy.
- * Changes to the CommonsRDF Graph are reflected in the jena graph.
- */
- public static Graph fromJena(org.apache.jena.graph.Graph graph) {
- return JCR_Factory.fromJena(graph) ;
- }
-
- /** Convert from Jena {@link Node} to any RDFCommons implementation */
- public static RDFTerm fromJena(RDFTermFactory factory, Node node) {
- if ( node.isURI() )
- return factory.createIRI(node.getURI()) ;
- if ( node.isLiteral() ) {
- String lang = node.getLiteralLanguage() ;
- if ( lang != null && ! lang.isEmpty() )
- return factory.createLiteral(node.getLiteralLexicalForm(), lang) ;
- if ( node.getLiteralDatatype().equals(XSDDatatype.XSDstring) )
- return factory.createLiteral(node.getLiteralLexicalForm()) ;
- IRI dt = factory.createIRI(node.getLiteralDatatype().getURI()) ;
- return factory.createLiteral(node.getLiteralLexicalForm(), dt);
- }
- if ( node.isBlank() )
- return factory.createBlankNode(node.getBlankNodeLabel()) ;
- throw new ConversionException("Node is not a concrete RDF Term: "+node) ;
- }
-
- /** Convert from Jena {@link org.apache.jena.graph.Triple} to any RDFCommons implementation */
- public static Triple fromJena(RDFTermFactory factory, org.apache.jena.graph.Triple triple) {
- BlankNodeOrIRI subject = (BlankNodeOrIRI)(fromJena(factory, triple.getSubject())) ;
- IRI predicate = (IRI)(fromJena(factory, triple.getPredicate())) ;
- RDFTerm object = fromJena(factory, triple.getObject()) ;
- return factory.createTriple(subject, predicate, object) ;
- }
-
- /** Convert from Jena to any RDFCommons implementation.
- * This is a copy, even if the factory is a RDFTermFactoryJena.
- * Use {@link #fromJena(org.apache.jena.graph.Graph)} for a wrapper.
- */
- public static Graph fromJena(RDFTermFactory factory, org.apache.jena.graph.Graph graph) {
- Graph g = factory.createGraph() ;
- graph.find(Node.ANY, Node.ANY, Node.ANY).forEachRemaining( t-> {
- g.add(fromJena(factory, t) );
- }) ;
- return g ;
- }
-
- /** Create a {@link StreamRDF} that inserts into any RDFCommons implementation of Graph */
- public static StreamRDF streamJenaToCommonsRDF(RDFTermFactory factory, Graph graph) {
- return new ToGraph(factory, graph) ;
- }
-
- public static void conversionError(String msg) {
- throw new ConversionException(msg) ;
- }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/src/main/java/org/apache/jena/commonsrdf/RDFTermFactoryJena.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/jena/commonsrdf/RDFTermFactoryJena.java b/jena/src/main/java/org/apache/jena/commonsrdf/RDFTermFactoryJena.java
deleted file mode 100644
index d9d577a..0000000
--- a/jena/src/main/java/org/apache/jena/commonsrdf/RDFTermFactoryJena.java
+++ /dev/null
@@ -1,85 +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.commonsrdf;
-
-import org.apache.commons.rdf.api.* ;
-import org.apache.jena.commonsrdf.impl.JCR_Factory ;
-
-/** RDFTermFactory with Jena-backed objects.
- * See {@link JenaCommonsRDF} for other conversions of existing objects.
- *
- * @see RDFTermFactory
- */
-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/7a2650a1/jena/src/main/java/org/apache/jena/commonsrdf/examples/Ex_JenaGraphToCommonsRDFGraph.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/jena/commonsrdf/examples/Ex_JenaGraphToCommonsRDFGraph.java b/jena/src/main/java/org/apache/jena/commonsrdf/examples/Ex_JenaGraphToCommonsRDFGraph.java
deleted file mode 100644
index ceeeb53..0000000
--- a/jena/src/main/java/org/apache/jena/commonsrdf/examples/Ex_JenaGraphToCommonsRDFGraph.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 org.apache.jena.commonsrdf.examples;
-
-import org.apache.commons.rdf.api.Graph ;
-import org.apache.commons.rdf.api.RDFTermFactory ;
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.apache.jena.commonsrdf.JenaCommonsRDF ;
-import org.apache.jena.commonsrdf.RDFTermFactoryJena ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFDataMgr ;
-import org.apache.jena.sparql.graph.GraphFactory ;
-
-/** Adapt a Jena Graph after parsing data into it */
-public class Ex_JenaGraphToCommonsRDFGraph {
- static { LogCtl.setCmdLogging(); }
-
- public static void main(String ...a) {
- org.apache.jena.graph.Graph jGraph = GraphFactory.createGraphMem() ;
- RDFDataMgr.read(jGraph, "D.ttl") ;
-
- // "graph" is a CommonsRDF graph
- Graph graph = JenaCommonsRDF.fromJena(jGraph) ;
-
- // Add to CommonsRDF Graph
- RDFTermFactory rft = new RDFTermFactoryJena() ;
- graph.add(rft.createIRI("http://example/s2"),
- rft.createIRI("http://example/p2"),
- rft.createLiteral("foo")) ;
- System.out.println("==== Write CommonsRDF graph\n") ;
- graph.getTriples().forEach(System.out::println) ;
-
- System.out.println("\n==== Write Jena graph directly\n") ;
- // And its in the Jena graph
- RDFDataMgr.write(System.out, jGraph, Lang.TTL) ;
- }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/src/main/java/org/apache/jena/commonsrdf/examples/Ex_ParseIntoCommonsRDFGraph.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/jena/commonsrdf/examples/Ex_ParseIntoCommonsRDFGraph.java b/jena/src/main/java/org/apache/jena/commonsrdf/examples/Ex_ParseIntoCommonsRDFGraph.java
deleted file mode 100644
index cb77289..0000000
--- a/jena/src/main/java/org/apache/jena/commonsrdf/examples/Ex_ParseIntoCommonsRDFGraph.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 org.apache.jena.commonsrdf.examples;
-
-import org.apache.commons.rdf.api.Graph ;
-import org.apache.commons.rdf.api.RDFTermFactory ;
-import org.apache.commons.rdf.simple.SimpleRDFTermFactory ;
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.apache.jena.commonsrdf.JenaCommonsRDF ;
-import org.apache.jena.commonsrdf.RDFTermFactoryJena ;
-import org.apache.jena.riot.RDFDataMgr ;
-import org.apache.jena.riot.system.StreamRDF ;
-
-/** Use jena to parse data into an CommonsRDF graph */
-public class Ex_ParseIntoCommonsRDFGraph {
- static { LogCtl.setCmdLogging(); }
-
- public static void main(String ...a) {
- System.out.println("== RDFTermFactoryJena") ;
- RDFTermFactory rft1 = new RDFTermFactoryJena() ; // This can be a non-Jena backed factory
- parse(rft1) ;
- System.out.println() ;
- System.out.println("== SimpleRDFTermFactory") ;
- RDFTermFactory rft2 = new SimpleRDFTermFactory() ;
- parse(rft2) ;
- }
-
- public static void parse(RDFTermFactory rft) {
- Graph graph = rft.createGraph() ;
- StreamRDF dest = JenaCommonsRDF.streamJenaToCommonsRDF(rft, graph) ;
- RDFDataMgr.parse(dest, "D.ttl") ;
- graph.getTriples().forEach(System.out::println) ;
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_BlankNode.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_BlankNode.java b/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_BlankNode.java
deleted file mode 100644
index ef11a0e..0000000
--- a/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_BlankNode.java
+++ /dev/null
@@ -1,47 +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.commonsrdf.impl;
-
-import org.apache.commons.rdf.api.BlankNode ;
-import org.apache.jena.graph.Node ;
-
-public class JCR_BlankNode extends JCR_Term implements BlankNode, JenaNode {
-
- /*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/7a2650a1/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_Factory.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_Factory.java b/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_Factory.java
deleted file mode 100644
index e1c2b52..0000000
--- a/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_Factory.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 org.apache.jena.commonsrdf.impl;
-import static org.apache.jena.commonsrdf.JenaCommonsRDF.conversionError;
-
-import org.apache.commons.rdf.api.* ;
-import org.apache.jena.commonsrdf.JenaCommonsRDF ;
-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)JenaCommonsRDF.fromJena(NodeFactory.createURI(iriStr));
- }
-
- public static Literal createLiteral(String lexStr) {
- return new JCR_Literal(NodeFactory.createLiteral(lexStr));
- }
-
- public static Literal createLiteralDT(String lexStr, String datatypeIRI) {
- return new JCR_Literal(NodeFactory.createLiteral(lexStr, NodeFactory.getType(datatypeIRI))) ;
- }
-
- public static Literal createLiteralLang(String lexStr, String langTag) {
- return new JCR_Literal(NodeFactory.createLiteral(lexStr, langTag));
- }
-
- public static BlankNode createBlankNode() {
- return new JCR_BlankNode(NodeFactory.createBlankNode());
- }
-
- public static BlankNode createBlankNode(String id) {
- return new JCR_BlankNode(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) ;
- }
-
- public static Triple fromJena(org.apache.jena.graph.Triple triple) {
- return new JCR_Triple(triple) ;
- }
-
- public static Graph fromJena(org.apache.jena.graph.Graph graph) {
- return new JCR_Graph(graph) ;
- }
-
- public static RDFTerm fromJena(Node node) {
- if ( node.isURI() )
- return new JCR_IRI(node) ;
- if ( node.isLiteral() ) {
- return new JCR_Literal(node) ;
-// String lang = node.getLiteralLanguage() ;
-// if ( lang != null && lang.isEmpty() )
-// return createLiteralLang(node.getLiteralLexicalForm(), lang) ;
-// if ( node.getLiteralDatatype().equals(XSDDatatype.XSDstring) )
-// return createLiteral(node.getLiteralLexicalForm()) ;
-// return createLiteralDT(node.getLiteralLexicalForm(), node.getLiteralDatatype().getURI());
- }
- if ( node.isBlank() )
- return new JCR_BlankNode(node) ;
- conversionError("Node is not a concrete RDF Term: "+node) ;
- return null ;
- }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7a2650a1/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_Graph.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_Graph.java b/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_Graph.java
deleted file mode 100644
index ef043e4..0000000
--- a/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_Graph.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.commonsrdf.impl;
-
-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.commonsrdf.JenaCommonsRDF ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFDataMgr ;
-
-public class JCR_Graph implements Graph, JenaGraph {
-
- private org.apache.jena.graph.Graph graph;
-
- /*package*/ JCR_Graph(org.apache.jena.graph.Graph graph) {
- this.graph = graph ;
- }
-
- @Override
- public org.apache.jena.graph.Graph getGraph() {
- return graph ;
- }
-
- @Override
- public void add(Triple triple) { graph.add(JenaCommonsRDF.toJena(triple)); }
-
- @Override
- public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- graph.add(org.apache.jena.graph.Triple.create(JenaCommonsRDF.toJena(subject),
- JenaCommonsRDF.toJena(predicate),
- JenaCommonsRDF.toJena(object)));
- }
-
- @Override
- public boolean contains(Triple triple) {
- return graph.contains(JenaCommonsRDF.toJena(triple)) ;
- }
-
- @Override
- public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return graph.contains(JenaCommonsRDF.toJena(subject),
- JenaCommonsRDF.toJena(predicate),
- JenaCommonsRDF.toJena(object) );
- }
-
- @Override
- public void remove(Triple triple) { graph.delete(JenaCommonsRDF.toJena(triple)); }
-
- @Override
- public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- graph.delete(org.apache.jena.graph.Triple.create(JenaCommonsRDF.toJena(subject),
- JenaCommonsRDF.toJena(predicate),
- JenaCommonsRDF.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-> JenaCommonsRDF.fromJena(t)) ;
- return Iter.asStream(iter2) ;
-
- }
-
- private Node toJenaAny(RDFTerm term) {
- if ( term == null )
- return Node.ANY ;
- return JenaCommonsRDF.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/7a2650a1/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_IRI.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_IRI.java b/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_IRI.java
deleted file mode 100644
index 888169e..0000000
--- a/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_IRI.java
+++ /dev/null
@@ -1,55 +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.commonsrdf.impl;
-
-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, JenaNode {
-
- /*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/7a2650a1/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_Literal.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_Literal.java b/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_Literal.java
deleted file mode 100644
index 97284c9..0000000
--- a/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_Literal.java
+++ /dev/null
@@ -1,68 +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.commonsrdf.impl;
-
-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/7a2650a1/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_Term.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_Term.java b/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_Term.java
deleted file mode 100644
index f2f27ec..0000000
--- a/jena/src/main/java/org/apache/jena/commonsrdf/impl/JCR_Term.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 org.apache.jena.commonsrdf.impl;
-
-import org.apache.jena.graph.Node ;
-import org.apache.jena.riot.out.NodeFmtLib ;
-import org.apache.jena.shared.PrefixMapping ;
-import org.apache.jena.shared.impl.PrefixMappingImpl ;
-
-class JCR_Term implements JenaNode {
- 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 NodeFmtLib.str(node) ;
- }
-
- @Override
- public String toString() {
- return ntriplesString() ;
- }
-}
-