commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [6/9] incubator-commonsrdf git commit: Added Jena* interfaces and GeneralizedTripleImpl
Date Fri, 08 Jul 2016 11:53:50 GMT
Added Jena* interfaces and GeneralizedTripleImpl

e.g. JenaIRI, JenaBlankNode


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

Branch: refs/heads/jena
Commit: 35c326166ef587adb460cfe36c23ea863b7cffba
Parents: 8a7b3ad
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Fri Jul 8 12:06:08 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Fri Jul 8 12:06:08 2016 +0100

----------------------------------------------------------------------
 .../apache/commons/rdf/jena/JenaBlankNode.java  |   7 +
 .../org/apache/commons/rdf/jena/JenaIRI.java    |   7 +
 .../apache/commons/rdf/jena/JenaLiteral.java    |   7 +
 .../org/apache/commons/rdf/jena/JenaNode.java   |  27 ---
 .../apache/commons/rdf/jena/JenaRDFTerm.java    |  27 +++
 .../org/apache/commons/rdf/jena/JenaTriple.java |   7 +-
 .../apache/commons/rdf/jena/JenaTripleLike.java |  34 +++
 .../commons/rdf/jena/RDFTermFactoryJena.java    | 241 ++++++++++++-------
 .../commons/rdf/jena/impl/AbstractRDFTerm.java  |   4 +-
 .../commons/rdf/jena/impl/BlankNodeImpl.java    |   4 +-
 .../rdf/jena/impl/GeneralizedTripleImpl.java    |  74 ++++++
 .../apache/commons/rdf/jena/impl/IRIImpl.java   |   4 +-
 .../commons/rdf/jena/impl/JenaFactory.java      |  44 ++--
 .../commons/rdf/jena/impl/LiteralImpl.java      |   3 +-
 .../apache/commons/rdf/jena/impl/QuadImpl.java  |   2 +-
 .../commons/rdf/jena/impl/TripleImpl.java       |  11 +-
 16 files changed, 358 insertions(+), 145 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/35c32616/jena/src/main/java/org/apache/commons/rdf/jena/JenaBlankNode.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaBlankNode.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaBlankNode.java
new file mode 100644
index 0000000..3c7a912
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaBlankNode.java
@@ -0,0 +1,7 @@
+package org.apache.commons.rdf.jena;
+
+import org.apache.commons.rdf.api.BlankNode;
+
+public interface JenaBlankNode extends JenaRDFTerm, BlankNode {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/35c32616/jena/src/main/java/org/apache/commons/rdf/jena/JenaIRI.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaIRI.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaIRI.java
new file mode 100644
index 0000000..c001d74
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaIRI.java
@@ -0,0 +1,7 @@
+package org.apache.commons.rdf.jena;
+
+import org.apache.commons.rdf.api.IRI;
+
+public interface JenaIRI extends JenaRDFTerm, IRI {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/35c32616/jena/src/main/java/org/apache/commons/rdf/jena/JenaLiteral.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaLiteral.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaLiteral.java
new file mode 100644
index 0000000..a2906ff
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaLiteral.java
@@ -0,0 +1,7 @@
+package org.apache.commons.rdf.jena;
+
+import org.apache.commons.rdf.api.Literal;
+
+public interface JenaLiteral extends JenaRDFTerm, Literal {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/35c32616/jena/src/main/java/org/apache/commons/rdf/jena/JenaNode.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaNode.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaNode.java
deleted file mode 100644
index 4be7940..0000000
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaNode.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.rdf.jena;
-
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.jena.graph.Node;
-
-/** Access the Jena node backing this object */
-public interface JenaNode extends RDFTerm {
-	public Node asJenaNode();
-}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/35c32616/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTerm.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTerm.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTerm.java
new file mode 100644
index 0000000..623f8b4
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTerm.java
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.rdf.jena;
+
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.jena.graph.Node;
+
+/** Access the Jena node backing this object */
+public interface JenaRDFTerm extends RDFTerm {
+	public Node asJenaNode();
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/35c32616/jena/src/main/java/org/apache/commons/rdf/jena/JenaTriple.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaTriple.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaTriple.java
index 3735bdd..b94cc08 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaTriple.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaTriple.java
@@ -18,9 +18,10 @@
 
 package org.apache.commons.rdf.jena;
 
-import org.apache.jena.graph.Triple;
+import org.apache.commons.rdf.api.BlankNodeOrIRI;
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.RDFTerm;
 
 /** Access the Jena triple backing this object */
-public interface JenaTriple extends org.apache.commons.rdf.api.Triple {
-	public Triple asJenaTriple();
+public interface JenaTriple extends org.apache.commons.rdf.api.Triple, JenaTripleLike<BlankNodeOrIRI,
IRI, RDFTerm> {
 }

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/35c32616/jena/src/main/java/org/apache/commons/rdf/jena/JenaTripleLike.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaTripleLike.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaTripleLike.java
new file mode 100644
index 0000000..4f0deb8
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaTripleLike.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.rdf.jena;
+
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.jena.graph.Triple;
+
+/** Access the Jena triple backing this object */
+public interface JenaTripleLike<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm>

+	extends org.apache.commons.rdf.api.TripleLike<S,P,O> {
+
+	/**
+	 * Return the adapted Jena triple
+	 * 
+	 * @return Adapted Jena {@link Triple}.
+	 */
+	Triple asJenaTriple();
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/35c32616/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
index 1515a78..2ffabfb 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/RDFTermFactoryJena.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/RDFTermFactoryJena.java
@@ -64,96 +64,158 @@ public final class RDFTermFactoryJena implements RDFTermFactory {
 	}
 
 	@Override
-	public BlankNode createBlankNode() {
+	public JenaBlankNode createBlankNode() {
 		return JenaFactory.createBlankNode(salt);
 	}
 
 	@Override
-	public BlankNode createBlankNode(String name) {
+	public JenaBlankNode createBlankNode(String name) {
 		return JenaFactory.createBlankNode(name, salt);
 	}
 
 	@Override
-	public Graph createGraph() {
+	public JenaGraph createGraph() {
 		return JenaFactory.createGraph(salt);
 	}
 
 	@Override
-	public IRI createIRI(String iri) {
+	public JenaIRI createIRI(String iri) {
 		validateIRI(iri);
 		return JenaFactory.createIRI(iri);
 	}
 
 	@Override
-	public Literal createLiteral(String lexicalForm) {
+	public JenaLiteral createLiteral(String lexicalForm) {
 		return JenaFactory.createLiteral(lexicalForm);
 	}
 
 	@Override
-	public Literal createLiteral(String lexicalForm, IRI dataType) {
+	public JenaLiteral createLiteral(String lexicalForm, IRI dataType) {
 		return JenaFactory.createLiteralDT(lexicalForm, dataType.getIRIString());
 	}
 
 	@Override
-	public Literal createLiteral(String lexicalForm, String languageTag) {
+	public JenaLiteral createLiteral(String lexicalForm, String languageTag) {
 		validateLang(languageTag);
 		return JenaFactory.createLiteralLang(lexicalForm, languageTag);
 	}
 
 	@Override
-	public Triple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+	public JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
 		return JenaFactory.createTriple(subject, predicate, object);
 	}
 
 	/**
 	 * Adapt an existing Jena Node to CommonsRDF {@link RDFTerm}.
 	 * <p>
-	 * If {@link Node#isLiteral()}, then the returned value is a 
-	 * {@link Literal}. If {@link Node#isURI(), the returned value is a 
-	 * IRI. If Node#isBlank(), the returned value is a {@link BlankNode}, 
-	 * which will use a {@link UUID} salt from this {@link RDFTermFactoryJena} instance
-	 * in combination with {@link Node#getBlankNodeId()} 
-	 * for the purpose of its {@link BlankNode#uniqueReference()}.
+	 * If {@link Node#isLiteral()}, then the returned value is a {@link Literal}.
+	 * If {@link Node#isURI(), the returned value is a IRI. If Node#isBlank(),
+	 * the returned value is a {@link BlankNode}, which will use a {@link UUID}
+	 * salt from this {@link RDFTermFactoryJena} instance in combination with
+	 * {@link Node#getBlankNodeId()} for the purpose of its
+	 * {@link BlankNode#uniqueReference()}.
 	 * 
-	 * @param node The Jena Node to adapt. It's {@link Node#isConcrete()} must be <code>true</code>.
-	 * @throws ConversionException if the node is not concrete.
+	 * @see #fromJena(Node, UUID)
+	 * @see #fromJena(RDFTermFactory, Node)
+	 * 
+	 * @param node
+	 *            The Jena Node to adapt. It's {@link Node#isConcrete()} must be
+	 *            <code>true</code>.
+	 * @throws ConversionException
+	 *             if the node is not concrete.
 	 */
-	public RDFTerm fromJena(Node node) throws ConversionException {
+	public JenaRDFTerm fromJena(Node node) throws ConversionException {
 		return JenaFactory.fromJena(node, salt);
 	}
 
 	/**
 	 * Adapt an existing Jena Node to CommonsRDF {@link RDFTerm}.
 	 * <p>
-	 * If {@link Node#isLiteral()}, then the returned value is a 
-	 * {@link Literal}. If {@link Node#isURI(), the returned value is a 
-	 * IRI. If Node#isBlank(), the returned value is a {@link BlankNode}, 
-	 * which will use the provided {@link UUID} salt 
-	 * in combination with {@link Node#getBlankNodeId()} 
-	 * for the purpose of its {@link BlankNode#uniqueReference()}.
+	 * If {@link Node#isLiteral()}, then the returned value is a {@link Literal}
+	 * . If {@link Node#isURI(), the returned value is a IRI. If Node#isBlank(),
+	 * the returned value is a {@link BlankNode}, which will use the provided
+	 * {@link UUID} salt in combination with {@link Node#getBlankNodeId()} for
+	 * the purpose of its {@link BlankNode#uniqueReference()}.
+	 * 
+	 * @see #fromJena(Node)
+	 * @see #fromJena(RDFTermFactory, Node)
 	 * 
-	 * @param node The Jena Node to adapt. It's {@link Node#isConcrete()} must be <code>true</code>.
-	 * @param salt UUID salt for the purpose of {@link BlankNode#uniqueReference()}
-	 * @throws ConversionException if the node is not concrete.
+	 * @param node
+	 *            The Jena Node to adapt. It's {@link Node#isConcrete()} must be
+	 *            <code>true</code>.
+	 * @param salt
+	 *            UUID salt for the purpose of
+	 *            {@link BlankNode#uniqueReference()}
+	 * @throws ConversionException
+	 *             if the node is not concrete.
 	 */
-	public static RDFTerm fromJena(Node node, UUID salt) {
+	public static JenaRDFTerm fromJena(Node node, UUID salt) {
 		return JenaFactory.fromJena(node, salt);
 	}
 	
 	/**
+	 * Convert from Jena {@link Node} to any RDFCommons implementation.
+	 * <p>
+	 * Note that if the {@link Node#isBlank()}, then the factory's 
+	 * {@link RDFTermFactory#createBlankNode(String)} will be used, meaning
+	 * that care should be taken if reusing an {@link RDFTermFactory} instance
+	 * for multiple conversion sessions.
+	 * 
+	 * @see #fromJena(Node)
+	 * @see #fromJena(Node, UUID)
+	 * 
+	 * @param factory {@link RDFTermFactory} to use for creating {@link RDFTerm}.
+	 * @param node
+	 *            The Jena Node to adapt. It's {@link Node#isConcrete()} must be
+	 *            <code>true</code>.
+	 * @throws ConversionException
+	 *             if the node is not concrete.
+	 */
+	public static RDFTerm fromJena(RDFTermFactory factory, Node node) {
+		if (node == null) {
+			return null;
+		}
+		if (factory instanceof RDFTermFactoryJena) {
+			// No need to convert, just wrap
+			return ((RDFTermFactoryJena) factory).fromJena(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())
+			// The factory
+			return factory.createBlankNode(node.getBlankNodeLabel());
+		throw new ConversionException("Node is not a concrete RDF Term: " + node);
+	}	
+	
+	/**
 	 * Adapt an existing Jena Triple to CommonsRDF {@link Triple}.
 	 * <p>
 	 * If the triple contains any {@link Node#isBlank()}, then any corresponding
-	 * {@link BlankNode} will use a {@link UUID} salt from this 
-	 * {@link RDFTermFactoryJena} instance
-	 * in combination with {@link Node#getBlankNodeId()} 
-	 * for the purpose of its {@link BlankNode#uniqueReference()}.
+	 * {@link BlankNode} will use a {@link UUID} salt from this
+	 * {@link RDFTermFactoryJena} instance in combination with
+	 * {@link Node#getBlankNodeId()} for the purpose of its
+	 * {@link BlankNode#uniqueReference()}.
+	 *
+	 * @see #fromJena(org.apache.jena.graph.Triple, UUID)
+	 * @see #fromJena(RDFTermFactory, org.apache.jena.graph.Triple)
 	 * 
 	 * @param triple
 	 *            Jena triple
-	 * @return Adapted triple          
+	 * @return Adapted triple
+	 * @throws ConversionException
+	 *             if any of the triple's nodes are not concrete or the triple
+	 *             is a generalized triple
 	 */
-	public Triple fromJena(org.apache.jena.graph.Triple triple) {
+	public JenaTriple fromJena(org.apache.jena.graph.Triple triple) throws ConversionException
{
 		return JenaFactory.fromJena(triple, salt);
 	}
 
@@ -161,31 +223,62 @@ public final class RDFTermFactoryJena implements RDFTermFactory {
 	 * Adapt an existing Jena Triple to CommonsRDF {@link Triple}.
 	 * <p>
 	 * If the triple contains any {@link Node#isBlank()}, then any corresponding
-	 * {@link BlankNode} will use the provided a {@link UUID} salt
-	 * in combination with {@link Node#getBlankNodeId()} 
-	 * for the purpose of its {@link BlankNode#uniqueReference()}.
+	 * {@link BlankNode} will use the provided a {@link UUID} salt in
+	 * combination with {@link Node#getBlankNodeId()} for the purpose of its
+	 * {@link BlankNode#uniqueReference()}.
 	 * 
 	 * @param triple
 	 *            Jena triple
 	 * @param salt
 	 *            A {@link UUID} salt for adapting any {@link BlankNode}s
-	 * @return Adapted triple          
+	 * @return Adapted triple
+	 * @throws ConversionException
+	 *             if any of the triple's nodes are not concrete or the triple
+	 *             is a generalized triple
 	 */
-	public static Triple fromJena(org.apache.jena.graph.Triple triple, UUID salt) {
+	public static JenaTriple fromJena(org.apache.jena.graph.Triple triple, UUID salt) throws
ConversionException {
 		return JenaFactory.fromJena(triple, salt);
 	}
-	
 
 	/**
-	 * 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.
+	 * Convert from Jena {@link org.apache.jena.graph.Triple} to any RDFCommons
+	 * implementation.
+	 * <p>
+	 * Note that if any of the triple's nodes {@link Node#isBlank()}, then the factory's 
+	 * {@link RDFTermFactory#createBlankNode(String)} will be used, meaning
+	 * that care should be taken if reusing an {@link RDFTermFactory} instance
+	 * for multiple conversion sessions.
+	 * 
+	 * @see #fromJena(org.apache.jena.graph.Triple)
+	 * @see #fromJena(org.apache.jena.graph.Triple, UUID)
+	 *
+	 * @param factory {@link RDFTermFactory} to use for creating the {@link Triple} and its
+	 * {@link RDFTerm}s.
+	 * @param triple
+	 *            Jena triple
+	 * @return Converted triple
+	 * @throws ConversionException
+	 *             if any of the triple's nodes are not concrete or the triple
+	 *             is a generalized triple
 	 */
-	public static Graph fromJena(org.apache.jena.graph.Graph graph) {
-		// NOTE: This generates a new UUID salt per graph
-		return JenaFactory.fromJena(graph);
+	public static Triple fromJena(RDFTermFactory factory, org.apache.jena.graph.Triple triple)

+			throws ConversionException{
+		if (factory instanceof RDFTermFactoryJena) {
+			// No need to convert, just wrap
+			return ((RDFTermFactoryJena) factory).fromJena(triple);
+		}
+		BlankNodeOrIRI subject;
+		IRI predicate;
+		try {
+			subject = (BlankNodeOrIRI) (fromJena(factory, triple.getSubject()));
+			predicate = (IRI) (fromJena(factory, triple.getPredicate()));
+		} (catch ClassCastException ex) {
+			throw new ConversionException("Can't convert generalized triple: " + triple, ex);
+		}
+		RDFTerm object = fromJena(factory, triple.getObject());
+		return factory.createTriple(subject, predicate, object);
 	}
-	
+
 	/**
 	 * Adapt an existing Jena Quad to CommonsRDF {@link Quad}.
 	 * <p>
@@ -207,13 +300,14 @@ public final class RDFTermFactoryJena implements RDFTermFactory {
 	 * Adapt an existing Jena Quad to CommonsRDF {@link Quad}.
 	 * <p>
 	 * If the quad contains any {@link Node#isBlank()}, then any corresponding
-	 * {@link BlankNode} will use a {@link UUID} salt from this 
-	 * {@link RDFTermFactoryJena} instance
+	 * {@link BlankNode} will use the provided {@link UUID} salt
 	 * in combination with {@link Node#getBlankNodeId()} 
 	 * for the purpose of its {@link BlankNode#uniqueReference()}.
 	 * 
 	 * @param quad
 	 *            Jena quad
+	 * @param salt
+	 *            A {@link UUID} salt for adapting any {@link BlankNode}s
 	 * @return Adapted quad
 	 */		
 	public static Quad fromJena(org.apache.jena.sparql.core.Quad quad, UUID salt) {
@@ -221,33 +315,16 @@ public final class RDFTermFactoryJena implements RDFTermFactory {
 	}
 
 	/**
-	 * Convert from Jena {@link Node} to any RDFCommons implementation
-	 * 
-	 * @param salt
+	 * Adapt an existing 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 RDFTerm fromJena(RDFTermFactory factory, Node node) {
-		if (node == null) {
-			return null;
-		}
-		if (factory instanceof RDFTermFactoryJena) {
-			// No need to convert, just wrap
-			return ((RDFTermFactoryJena) factory).fromJena(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);
+	public static Graph fromJena(org.apache.jena.graph.Graph graph) {
+		// NOTE: This generates a new UUID salt per graph
+		return JenaFactory.fromJena(graph);
 	}
+	
+
 
 	/**
 	 * Convert from Jena to any RDFCommons implementation. This is a copy, even
@@ -267,20 +344,6 @@ public final class RDFTermFactoryJena implements RDFTermFactory {
 		return g;
 	}
 
-	/**
-	 * 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)
{
-		if (factory instanceof RDFTermFactoryJena) {
-			// No need to convert, just wrap
-			return ((RDFTermFactoryJena) factory).fromJena(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);
-	}
 
 	public static Quad fromJena(RDFTermFactory factory, org.apache.jena.sparql.core.Quad quad)
{
 		if (factory instanceof RDFTermFactoryJena) {
@@ -368,7 +431,9 @@ public final class RDFTermFactoryJena implements RDFTermFactory {
 	public static org.apache.jena.graph.Triple toJena(Triple triple) {
 		if (triple instanceof JenaTriple)
 			return ((JenaTriple) triple).asJenaTriple();
-		return new org.apache.jena.graph.Triple(toJena(triple.getSubject()), toJena(triple.getPredicate()),
+		return new org.apache.jena.graph.Triple(
+				toJena(triple.getSubject()), 
+				toJena(triple.getPredicate()),
 				toJena(triple.getObject()));
 	}
 

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/35c32616/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractRDFTerm.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractRDFTerm.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractRDFTerm.java
index e7bc125..5c828ef 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractRDFTerm.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractRDFTerm.java
@@ -19,11 +19,11 @@
 package org.apache.commons.rdf.jena.impl;
 
 import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.jena.JenaNode;
+import org.apache.commons.rdf.jena.JenaRDFTerm;
 import org.apache.jena.graph.Node;
 import org.apache.jena.riot.out.NodeFmtLib;
 
-class AbstractRDFTerm implements JenaNode, RDFTerm {
+class AbstractRDFTerm implements JenaRDFTerm, RDFTerm {
 	private Node node;
 	// static private PrefixMapping empty = new PrefixMappingImpl() ;
 

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/35c32616/jena/src/main/java/org/apache/commons/rdf/jena/impl/BlankNodeImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/BlankNodeImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/BlankNodeImpl.java
index fc7d1c3..928da61 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/BlankNodeImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/BlankNodeImpl.java
@@ -21,10 +21,10 @@ package org.apache.commons.rdf.jena.impl;
 import java.util.UUID;
 
 import org.apache.commons.rdf.api.BlankNode;
-import org.apache.commons.rdf.jena.JenaNode;
+import org.apache.commons.rdf.jena.JenaBlankNode;
 import org.apache.jena.graph.Node;
 
-public class BlankNodeImpl extends AbstractRDFTerm implements BlankNode, JenaNode {
+public class BlankNodeImpl extends AbstractRDFTerm implements JenaBlankNode {
 
 	private UUID salt;
 

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/35c32616/jena/src/main/java/org/apache/commons/rdf/jena/impl/GeneralizedTripleImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/GeneralizedTripleImpl.java
b/jena/src/main/java/org/apache/commons/rdf/jena/impl/GeneralizedTripleImpl.java
new file mode 100644
index 0000000..c36c615
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/GeneralizedTripleImpl.java
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES 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.UUID;
+
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.jena.ConversionException;
+import org.apache.commons.rdf.jena.JenaTripleLike;
+import org.apache.commons.rdf.jena.RDFTermFactoryJena;
+
+public class GeneralizedTripleImpl implements JenaTripleLike<RDFTerm, RDFTerm, RDFTerm>
{
+	private final RDFTerm object;
+	private final RDFTerm predicate;
+	private final RDFTerm subject;
+	private org.apache.jena.graph.Triple triple = null;
+
+	/* package */ GeneralizedTripleImpl(RDFTerm subject, RDFTerm predicate, RDFTerm object)
{
+		this.subject = subject;
+		this.predicate = predicate;
+		this.object = object;
+	}
+
+	/* package */ GeneralizedTripleImpl(org.apache.jena.graph.Triple triple, UUID salt) throws
ConversionException {
+		this.subject = JenaFactory.fromJena(triple.getSubject(), salt);
+		this.predicate = JenaFactory.fromJena(triple.getPredicate(), salt);
+		this.object = JenaFactory.fromJena(triple.getObject(), salt);
+		this.triple = triple;
+	}
+
+	@Override
+	public org.apache.jena.graph.Triple asJenaTriple() {
+		if (triple == null)
+			triple = org.apache.jena.graph.Triple.create(RDFTermFactoryJena.toJena(subject),
+					RDFTermFactoryJena.toJena(predicate), RDFTermFactoryJena.toJena(object));
+		return triple;
+	}
+	@Override
+	public RDFTerm getObject() {
+		return object;
+	}
+
+	@Override
+	public RDFTerm getPredicate() {
+		return predicate;
+	}
+
+	@Override
+	public RDFTerm getSubject() {
+		return subject;
+	}
+
+	@Override
+	public String toString() {
+		return getSubject() + " " + getPredicate() + " " + getObject() + " .";
+	}
+	
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/35c32616/jena/src/main/java/org/apache/commons/rdf/jena/impl/IRIImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/IRIImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/IRIImpl.java
index d5373b7..9ad20d0 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/IRIImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/IRIImpl.java
@@ -19,11 +19,11 @@
 package org.apache.commons.rdf.jena.impl;
 
 import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.jena.JenaNode;
+import org.apache.commons.rdf.jena.JenaIRI;
 import org.apache.jena.graph.Node;
 import org.apache.jena.graph.NodeFactory;
 
-public class IRIImpl extends AbstractRDFTerm implements IRI, JenaNode {
+public class IRIImpl extends AbstractRDFTerm implements JenaIRI {
 
 	/* package */ IRIImpl(Node node) {
 		super(node);

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/35c32616/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java
index 2b4eab9..797557c 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java
@@ -22,13 +22,17 @@ import java.util.UUID;
 
 import org.apache.commons.rdf.api.BlankNode;
 import org.apache.commons.rdf.api.BlankNodeOrIRI;
-import org.apache.commons.rdf.api.Graph;
 import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.Literal;
 import org.apache.commons.rdf.api.Quad;
 import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.Triple;
 import org.apache.commons.rdf.jena.ConversionException;
+import org.apache.commons.rdf.jena.JenaBlankNode;
+import org.apache.commons.rdf.jena.JenaGraph;
+import org.apache.commons.rdf.jena.JenaIRI;
+import org.apache.commons.rdf.jena.JenaLiteral;
+import org.apache.commons.rdf.jena.JenaRDFTerm;
+import org.apache.commons.rdf.jena.JenaTriple;
+import org.apache.commons.rdf.jena.JenaTripleLike;
 import org.apache.jena.graph.Node;
 import org.apache.jena.graph.NodeFactory;
 import org.apache.jena.sparql.graph.GraphFactory;
@@ -38,44 +42,48 @@ public class JenaFactory {
 		return new BlankNodeImpl(NodeFactory.createBlankNode(), UUID.randomUUID());
 	}
 
-	public static BlankNode createBlankNode(String id, UUID salt) {
+	public static JenaBlankNode createBlankNode(String id, UUID salt) {
 		return new BlankNodeImpl(NodeFactory.createBlankNode(id), salt);
 	}
 
-	public static BlankNode createBlankNode(UUID salt) {
+	public static JenaBlankNode createBlankNode(UUID salt) {
 		return new BlankNodeImpl(NodeFactory.createBlankNode(), salt);
 	}
 
-	public static Graph createGraph() {
+	public static JenaGraph createGraph() {
 		return createGraph(UUID.randomUUID());
 	}
 
-	public static Graph createGraph(UUID salt) {
+	public static JenaGraph createGraph(UUID salt) {
 		return new GraphImpl(GraphFactory.createDefaultGraph(), salt);
 	}
 
 	// basic components to commonsrdf backed by Jena.
-	public static IRI createIRI(String iriStr) {
+	public static JenaIRI createIRI(String iriStr) {
 		return new IRIImpl(iriStr);
 	}
 
-	public static Literal createLiteral(String lexStr) {
+	public static JenaLiteral createLiteral(String lexStr) {
 		return new LiteralImpl(NodeFactory.createLiteral(lexStr));
 	}
 
-	public static Literal createLiteralDT(String lexStr, String datatypeIRI) {
+	public static JenaLiteral createLiteralDT(String lexStr, String datatypeIRI) {
 		return new LiteralImpl(NodeFactory.createLiteral(lexStr, NodeFactory.getType(datatypeIRI)));
 	}
 
-	public static Literal createLiteralLang(String lexStr, String langTag) {
+	public static JenaLiteral createLiteralLang(String lexStr, String langTag) {
 		return new LiteralImpl(NodeFactory.createLiteral(lexStr, langTag));
 	}
 
-	public static Triple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
{
+	public static JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
{
 		return new TripleImpl(subject, predicate, object);
 	}
 
-	public static RDFTerm fromJena(Node node, UUID salt) throws ConversionException {
+	public static JenaTripleLike<RDFTerm, RDFTerm, RDFTerm> createGeneralizedTriple(RDFTerm
subject, RDFTerm predicate, RDFTerm object) {
+		return new GeneralizedTripleImpl(subject, predicate, object);
+	}
+	
+	public static JenaRDFTerm fromJena(Node node, UUID salt) throws ConversionException {
 		if (node.isURI())
 			return new IRIImpl(node);
 		if (node.isLiteral()) {
@@ -92,18 +100,22 @@ public class JenaFactory {
 		throw new ConversionException("Node is not a concrete RDF Term: " + node);
 	}
 
-	public static Graph fromJena(org.apache.jena.graph.Graph graph) {
+	public static JenaGraph fromJena(org.apache.jena.graph.Graph graph) {
 		return new GraphImpl(graph, UUID.randomUUID());
 	}
 
-	public static Graph fromJena(org.apache.jena.graph.Graph graph, UUID salt) {
+	public static JenaGraph fromJena(org.apache.jena.graph.Graph graph, UUID salt) {
 		return new GraphImpl(graph, salt);
 	}
 
-	public static Triple fromJena(org.apache.jena.graph.Triple triple, UUID salt) {
+	public static JenaTriple fromJena(org.apache.jena.graph.Triple triple, UUID salt) {
 		return new TripleImpl(triple, salt);
 	}
 
+	public static JenaTripleLike<RDFTerm, RDFTerm, RDFTerm> fromJenaGeneralized(org.apache.jena.graph.Triple
triple, UUID salt) {
+		return new GeneralizedTripleImpl(triple, salt);
+	}
+	
 	public static Quad fromJena(org.apache.jena.sparql.core.Quad quad, UUID salt) {
 		return new QuadImpl(quad, salt);
 	}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/35c32616/jena/src/main/java/org/apache/commons/rdf/jena/impl/LiteralImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/LiteralImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/LiteralImpl.java
index efcf099..0530d08 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/LiteralImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/LiteralImpl.java
@@ -23,9 +23,10 @@ import java.util.Optional;
 
 import org.apache.commons.rdf.api.IRI;
 import org.apache.commons.rdf.api.Literal;
+import org.apache.commons.rdf.jena.JenaLiteral;
 import org.apache.jena.graph.Node;
 
-public class LiteralImpl extends AbstractRDFTerm implements Literal {
+public class LiteralImpl extends AbstractRDFTerm implements JenaLiteral {
 
 	/* package */ LiteralImpl(Node node) {
 		super(node);

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/35c32616/jena/src/main/java/org/apache/commons/rdf/jena/impl/QuadImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/QuadImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/QuadImpl.java
index 31c96b2..16deb02 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/QuadImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/QuadImpl.java
@@ -30,7 +30,7 @@ import org.apache.commons.rdf.api.Triple;
 import org.apache.commons.rdf.jena.JenaQuad;
 import org.apache.commons.rdf.jena.RDFTermFactoryJena;
 
-public class QuadImpl implements Quad, JenaQuad {
+public class QuadImpl implements JenaQuad {
 
 	private final Optional<BlankNodeOrIRI> graphName;
 	private final RDFTerm object;

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/35c32616/jena/src/main/java/org/apache/commons/rdf/jena/impl/TripleImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/TripleImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/TripleImpl.java
index 3a0f15b..f65fd6d 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/TripleImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/TripleImpl.java
@@ -25,6 +25,7 @@ import org.apache.commons.rdf.api.BlankNodeOrIRI;
 import org.apache.commons.rdf.api.IRI;
 import org.apache.commons.rdf.api.RDFTerm;
 import org.apache.commons.rdf.api.Triple;
+import org.apache.commons.rdf.jena.ConversionException;
 import org.apache.commons.rdf.jena.JenaTriple;
 import org.apache.commons.rdf.jena.RDFTermFactoryJena;
 
@@ -40,9 +41,13 @@ public class TripleImpl implements Triple, JenaTriple {
 		this.object = object;
 	}
 
-	/* package */ TripleImpl(org.apache.jena.graph.Triple triple, UUID salt) {
-		this.subject = (BlankNodeOrIRI) JenaFactory.fromJena(triple.getSubject(), salt);
-		this.predicate = (IRI) JenaFactory.fromJena(triple.getPredicate(), salt);
+	/* package */ TripleImpl(org.apache.jena.graph.Triple triple, UUID salt) throws ConversionException
{
+		try {
+			this.subject = (BlankNodeOrIRI) JenaFactory.fromJena(triple.getSubject(), salt);
+			this.predicate = (IRI) JenaFactory.fromJena(triple.getPredicate(), salt);
+		} catch (ClassCastException ex) {
+			throw new ConversionException("Can't adapt generalized triple: " + triple, ex);
+		}
 		this.object = JenaFactory.fromJena(triple.getObject(), salt);
 		this.triple = triple;
 	}



Mime
View raw message