commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [1/2] incubator-commonsrdf git commit: RDFTermFactoryJena -> JenaRDFTermFactory
Date Fri, 08 Jul 2016 14:18:28 GMT
Repository: incubator-commonsrdf
Updated Branches:
  refs/heads/jena 0f349723d -> a3cb3b13a


RDFTermFactoryJena -> JenaRDFTermFactory

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

Branch: refs/heads/jena
Commit: 76dbe500114bba89a9eef542c432dddb83c4c16b
Parents: 0f34972
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Fri Jul 8 14:07:55 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Fri Jul 8 14:07:55 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/jena/JenaRDFParserBuilder.java  |   6 +-
 .../commons/rdf/jena/JenaRDFTermFactory.java    | 543 +++++++++++++++++++
 .../commons/rdf/jena/RDFTermFactoryJena.java    | 543 -------------------
 .../rdf/jena/impl/GeneralizedTripleImpl.java    |   6 +-
 .../apache/commons/rdf/jena/impl/GraphImpl.java |  32 +-
 .../apache/commons/rdf/jena/impl/QuadImpl.java  |  10 +-
 .../commons/rdf/jena/impl/TripleImpl.java       |   6 +-
 .../commons/rdf/jena/TestBlankNodeJena.java     |   8 +-
 .../apache/commons/rdf/jena/TestGraphJena.java  |   2 +-
 .../jena/TestJenaGraphToCommonsRDFGraph.java    |   4 +-
 .../commons/rdf/jena/TestRDFParserBuilder.java  |   2 +-
 .../rdf/jena/TestRDFTermFactoryJena.java        |   2 +-
 12 files changed, 584 insertions(+), 580 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/76dbe500/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParserBuilder.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParserBuilder.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParserBuilder.java
index e0eb19d..9b5ac29 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParserBuilder.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParserBuilder.java
@@ -35,7 +35,7 @@ import org.apache.jena.riot.system.StreamRDFLib;
 public class JenaRDFParserBuilder extends AbstractRDFParserBuilder<JenaRDFParserBuilder> implements RDFParserBuilder {
 
 	protected RDFTermFactory createRDFTermFactory() {
-		return new RDFTermFactoryJena();
+		return new JenaRDFTermFactory();
 	}
 
 	@Override
@@ -45,10 +45,10 @@ public class JenaRDFParserBuilder extends AbstractRDFParserBuilder<JenaRDFParser
 			Graph jenaGraph = ((JenaGraph) getTargetGraph().get()).asJenaGraph();
 			dest = StreamRDFLib.graph(jenaGraph);
 		} else {
-			dest = RDFTermFactoryJena.streamJenaToCommonsRDF(getRdfTermFactory().get(), getTarget());
+			dest = JenaRDFTermFactory.streamJenaToCommonsRDF(getRdfTermFactory().get(), getTarget());
 		}
 
-		Lang lang = getContentTypeSyntax().flatMap(RDFTermFactoryJena::rdfSyntaxToLang).orElse(null);
+		Lang lang = getContentTypeSyntax().flatMap(JenaRDFTermFactory::rdfSyntaxToLang).orElse(null);
 		String baseStr = getBase().map(IRI::getIRIString).orElse(null);
 
 		if (getSourceIri().isPresent()) {

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/76dbe500/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTermFactory.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTermFactory.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTermFactory.java
new file mode 100644
index 0000000..f31173b
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTermFactory.java
@@ -0,0 +1,543 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES 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 java.util.Optional;
+import java.util.UUID;
+import java.util.function.Consumer;
+
+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.RDFSyntax;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.api.RDFTermFactory;
+import org.apache.commons.rdf.api.Triple;
+import org.apache.commons.rdf.api.TripleLike;
+import org.apache.commons.rdf.jena.impl.JenaFactory;
+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.Lang;
+import org.apache.jena.riot.RDFLanguages;
+import org.apache.jena.riot.system.StreamRDF;
+import org.apache.jena.riot.system.StreamRDFBase;
+import org.apache.jena.sparql.graph.GraphFactory;
+
+/**
+ * RDFTermFactory with Jena-backed objects.
+ * <p>
+ * This factory can also convert existing objects from/to Jena with methods like
+ * {@link #fromJena(org.apache.jena.graph.Graph)} and {@link #toJena(Graph)}.
+ * 
+ * @see RDFTermFactory
+ */
+public final class JenaRDFTermFactory implements RDFTermFactory {
+
+	private UUID salt;
+
+	public JenaRDFTermFactory() {
+		this.salt = UUID.randomUUID();
+	}
+
+	public JenaRDFTermFactory(UUID salt) {
+		this.salt = salt;
+	}
+
+	@Override
+	public JenaBlankNode createBlankNode() {
+		return JenaFactory.createBlankNode(salt);
+	}
+
+	@Override
+	public JenaBlankNode createBlankNode(String name) {
+		return JenaFactory.createBlankNode(name, salt);
+	}
+
+	@Override
+	public JenaGraph createGraph() {
+		return JenaFactory.createGraph(salt);
+	}
+
+	@Override
+	public JenaIRI createIRI(String iri) {
+		validateIRI(iri);
+		return JenaFactory.createIRI(iri);
+	}
+
+	@Override
+	public JenaLiteral createLiteral(String lexicalForm) {
+		return JenaFactory.createLiteral(lexicalForm);
+	}
+
+	@Override
+	public JenaLiteral createLiteral(String lexicalForm, IRI dataType) {
+		return JenaFactory.createLiteralDT(lexicalForm, dataType.getIRIString());
+	}
+
+	@Override
+	public JenaLiteral createLiteral(String lexicalForm, String languageTag) {
+		validateLang(languageTag);
+		return JenaFactory.createLiteralLang(lexicalForm, languageTag);
+	}
+
+	@Override
+	public JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+		return JenaFactory.createTriple(subject, predicate, object);
+	}
+	
+	/**
+	 * Adapt a generalized Jena Triple to a CommonsRDF {@link TripleLike} statement.
+	 * <p>
+	 * The generalized triple supports any {@link RDFTerm} as its {@link TripleLike#getSubject()}
+	 * {@link TripleLike#getPredicate()} or {@link TripleLike#getObject()}. 
+	 * <p>
+	 * If the Jena triple contains any {@link Node#isBlank()}, then any corresponding
+	 * {@link BlankNode} will use a {@link UUID} salt from this
+	 * {@link JenaRDFTermFactory} 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 subject The subject of the statement
+	 *            
+	 * @return Adapted {@link TripleLike}. Note that the generalized triple does
+	 *         <strong>not</strong> implement {@link Triple#equals(Object)} or
+	 *         {@link Triple#hashCode()}.
+	 * @throws ConversionException
+	 *             if any of the triple's nodes are not concrete
+	 */
+	public JenaTripleLike<RDFTerm, RDFTerm, RDFTerm> createGeneralizedTriple(
+			RDFTerm subject, RDFTerm predicate, RDFTerm object) {
+		return JenaFactory.createGeneralizedTriple(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 JenaRDFTermFactory} instance in combination with
+	 * {@link Node#getBlankNodeId()} for the purpose of its
+	 * {@link BlankNode#uniqueReference()}.
+	 * 
+	 * @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 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()}.
+	 * 
+	 * @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.
+	 */
+	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 JenaRDFTermFactory) {
+			// No need to convert, just wrap
+			return ((JenaRDFTermFactory) 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 JenaRDFTermFactory} 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
+	 * @throws ConversionException
+	 *             if any of the triple's nodes are not concrete or the triple
+	 *             is a generalized triple
+	 */
+	public JenaTriple fromJena(org.apache.jena.graph.Triple triple) throws ConversionException {
+		return JenaFactory.fromJena(triple, salt);
+	}
+
+
+	/**
+	 * Adapt a generalized Jena Triple to a CommonsRDF {@link TripleLike}.
+	 * <p>
+	 * The generalized triple supports any {@link RDFTerm} as its {@link TripleLike#getSubject()}
+	 * {@link TripleLike#getPredicate()} or {@link TripleLike#getObject()}. 
+	 * <p>
+	 * If the Jena triple contains any {@link Node#isBlank()}, then any corresponding
+	 * {@link BlankNode} will use the provided {@link UUID} salt 
+	 * 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
+	 * @param salt
+	 *            UUID salt for the purpose of
+	 *            {@link BlankNode#uniqueReference()}
+	 * @return Adapted {@link TripleLike}. Note that the generalized triple does
+	 *         <strong>not</strong> implement {@link Triple#equals(Object)} or
+	 *         {@link Triple#hashCode()}.
+	 * @throws ConversionException
+	 *             if any of the triple's nodes are not concrete
+	 */
+	public JenaTripleLike<RDFTerm, RDFTerm, RDFTerm> fromJenaGeneralized(org.apache.jena.graph.Triple triple, UUID salt) throws ConversionException {
+		return JenaFactory.fromJenaGeneralized(triple, salt);
+	}
+	
+	/**
+	 * Adapt a generalized Jena Triple to a CommonsRDF {@link TripleLike}.
+	 * <p>
+	 * The generalized triple supports any {@link RDFTerm} as its {@link TripleLike#getSubject()}
+	 * {@link TripleLike#getPredicate()} or {@link TripleLike#getObject()}. 
+	 * <p>
+	 * If the Jena triple contains any {@link Node#isBlank()}, then any corresponding
+	 * {@link BlankNode} will use a {@link UUID} salt from this
+	 * {@link JenaRDFTermFactory} 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 {@link TripleLike}. Note that the generalized triple does
+	 *         <strong>not</strong> implement {@link Triple#equals(Object)} or
+	 *         {@link Triple#hashCode()}.
+	 * @throws ConversionException
+	 *             if any of the triple's nodes are not concrete
+	 */
+	public JenaTripleLike<RDFTerm, RDFTerm, RDFTerm> fromJenaGeneralized(org.apache.jena.graph.Triple triple) throws ConversionException {
+		return JenaFactory.fromJenaGeneralized(triple, salt);
+	}
+	
+	
+	/**
+	 * 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()}.
+	 * 
+	 * @param triple
+	 *            Jena triple
+	 * @param salt
+	 *            A {@link UUID} salt for adapting any {@link BlankNode}s
+	 * @return Adapted triple
+	 * @throws ConversionException
+	 *             if any of the triple's nodes are not concrete or the triple
+	 *             is a generalized triple
+	 */
+	public static JenaTriple fromJena(org.apache.jena.graph.Triple triple, UUID salt) throws ConversionException {
+		return JenaFactory.fromJena(triple, salt);
+	}
+
+	/**
+	 * 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 Triple fromJena(RDFTermFactory factory, org.apache.jena.graph.Triple triple) 
+			throws ConversionException{
+		if (factory instanceof JenaRDFTermFactory) {
+			// No need to convert, just wrap
+			return ((JenaRDFTermFactory) 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>
+	 * If the quad contains any {@link Node#isBlank()}, then any corresponding
+	 * {@link BlankNode} will use a {@link UUID} salt from this 
+	 * {@link JenaRDFTermFactory} instance
+	 * in combination with {@link Node#getBlankNodeId()} 
+	 * for the purpose of its {@link BlankNode#uniqueReference()}.
+	 * 
+	 * @param quad
+	 *            Jena quad
+	 * @return Adapted quad
+	 */	
+	public Quad fromJena(org.apache.jena.sparql.core.Quad quad) {
+		return JenaFactory.fromJena(quad, salt);
+	}
+	
+	/**
+	 * 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 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) {
+		return JenaFactory.fromJena(quad, 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 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
+	 * 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) {
+		if (factory instanceof JenaRDFTermFactory) {
+			// No need to convert, just wrap
+			return fromJena(graph);
+		}
+
+		Graph g = factory.createGraph();
+		graph.find(Node.ANY, Node.ANY, Node.ANY).forEachRemaining(t -> {
+			g.add(fromJena(factory, t));
+		});
+		return g;
+	}
+
+
+	public static Quad fromJena(RDFTermFactory factory, org.apache.jena.sparql.core.Quad quad) {
+		if (factory instanceof JenaRDFTermFactory) {
+			// No need to convert, just wrap
+			return ((JenaRDFTermFactory) factory).fromJena(quad);
+		}
+		BlankNodeOrIRI graphName = (BlankNodeOrIRI) (fromJena(factory, quad.getGraph()));
+		BlankNodeOrIRI subject = (BlankNodeOrIRI) (fromJena(factory, quad.getSubject()));
+		IRI predicate = (IRI) (fromJena(factory, quad.getPredicate()));
+		RDFTerm object = fromJena(factory, quad.getObject());
+		return factory.createQuad(graphName, subject, predicate, object);
+	}
+
+	public static Optional<RDFSyntax> langToRdfSyntax(Lang lang) {
+		return RDFSyntax.byMediaType(lang.getContentType().getContentType());
+	}
+
+	public static Optional<Lang> rdfSyntaxToLang(RDFSyntax rdfSyntax) {
+		return Optional.ofNullable(RDFLanguages.contentTypeToLang(rdfSyntax.mediaType));
+	}
+
+	/**
+	 * Create a {@link StreamRDF} that inserts into any RDFCommons
+	 * implementation of Graph
+	 */
+	public static StreamRDF streamJenaToCommonsRDF(RDFTermFactory factory, Consumer<Quad> consumer) {
+		return new StreamRDFBase() {
+			@Override
+			public void quad(org.apache.jena.sparql.core.Quad quad) {
+				consumer.accept(fromJena(factory, quad));
+			}
+		};
+	}
+
+	/**
+	 * 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).asJenaGraph();
+		org.apache.jena.graph.Graph g = GraphFactory.createGraphMem();
+		graph.stream().forEach(t -> g.add(toJena(t)));
+		return g;
+	}
+
+	/**
+	 * 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 == null) {
+			return null;
+		}
+		if (term instanceof JenaRDFTerm)
+			// TODO: What if it's a BlankNodeImpl with
+			// a different salt? Do we need to rewrite the
+			// jena blanknode identifier?
+			return ((JenaRDFTerm) term).asJenaNode();
+
+		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);
+		}
+		throw new ConversionException("Not a concrete RDF Term: " + term);
+	}
+
+	/**
+	 * 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).asJenaTriple();
+		return new org.apache.jena.graph.Triple(
+				toJena(triple.getSubject()), 
+				toJena(triple.getPredicate()),
+				toJena(triple.getObject()));
+	}
+
+	// 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();
+	}
+
+	private static void validateLang(String languageTag) {
+		if (languageTag.contains(" "))
+			throw new IllegalArgumentException("Invalid language tag: " + languageTag);
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/76dbe500/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
deleted file mode 100644
index 760d911..0000000
--- a/jena/src/main/java/org/apache/commons/rdf/jena/RDFTermFactoryJena.java
+++ /dev/null
@@ -1,543 +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 java.util.Optional;
-import java.util.UUID;
-import java.util.function.Consumer;
-
-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.RDFSyntax;
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.RDFTermFactory;
-import org.apache.commons.rdf.api.Triple;
-import org.apache.commons.rdf.api.TripleLike;
-import org.apache.commons.rdf.jena.impl.JenaFactory;
-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.Lang;
-import org.apache.jena.riot.RDFLanguages;
-import org.apache.jena.riot.system.StreamRDF;
-import org.apache.jena.riot.system.StreamRDFBase;
-import org.apache.jena.sparql.graph.GraphFactory;
-
-/**
- * RDFTermFactory with Jena-backed objects.
- * <p>
- * This factory can also convert existing objects from/to Jena with methods like
- * {@link #fromJena(org.apache.jena.graph.Graph)} and {@link #toJena(Graph)}.
- * 
- * @see RDFTermFactory
- */
-public final class RDFTermFactoryJena implements RDFTermFactory {
-
-	private UUID salt;
-
-	public RDFTermFactoryJena() {
-		this.salt = UUID.randomUUID();
-	}
-
-	public RDFTermFactoryJena(UUID salt) {
-		this.salt = salt;
-	}
-
-	@Override
-	public JenaBlankNode createBlankNode() {
-		return JenaFactory.createBlankNode(salt);
-	}
-
-	@Override
-	public JenaBlankNode createBlankNode(String name) {
-		return JenaFactory.createBlankNode(name, salt);
-	}
-
-	@Override
-	public JenaGraph createGraph() {
-		return JenaFactory.createGraph(salt);
-	}
-
-	@Override
-	public JenaIRI createIRI(String iri) {
-		validateIRI(iri);
-		return JenaFactory.createIRI(iri);
-	}
-
-	@Override
-	public JenaLiteral createLiteral(String lexicalForm) {
-		return JenaFactory.createLiteral(lexicalForm);
-	}
-
-	@Override
-	public JenaLiteral createLiteral(String lexicalForm, IRI dataType) {
-		return JenaFactory.createLiteralDT(lexicalForm, dataType.getIRIString());
-	}
-
-	@Override
-	public JenaLiteral createLiteral(String lexicalForm, String languageTag) {
-		validateLang(languageTag);
-		return JenaFactory.createLiteralLang(lexicalForm, languageTag);
-	}
-
-	@Override
-	public JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
-		return JenaFactory.createTriple(subject, predicate, object);
-	}
-	
-	/**
-	 * Adapt a generalized Jena Triple to a CommonsRDF {@link TripleLike} statement.
-	 * <p>
-	 * The generalized triple supports any {@link RDFTerm} as its {@link TripleLike#getSubject()}
-	 * {@link TripleLike#getPredicate()} or {@link TripleLike#getObject()}. 
-	 * <p>
-	 * If the Jena 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()}.
-	 *
-	 * @see #fromJena(org.apache.jena.graph.Triple, UUID)
-	 * @see #fromJena(RDFTermFactory, org.apache.jena.graph.Triple)
-	 * 
-	 * @param subject The subject of the statement
-	 *            
-	 * @return Adapted {@link TripleLike}. Note that the generalized triple does
-	 *         <strong>not</strong> implement {@link Triple#equals(Object)} or
-	 *         {@link Triple#hashCode()}.
-	 * @throws ConversionException
-	 *             if any of the triple's nodes are not concrete
-	 */
-	public JenaTripleLike<RDFTerm, RDFTerm, RDFTerm> createGeneralizedTriple(
-			RDFTerm subject, RDFTerm predicate, RDFTerm object) {
-		return JenaFactory.createGeneralizedTriple(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()}.
-	 * 
-	 * @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 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()}.
-	 * 
-	 * @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.
-	 */
-	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()}.
-	 *
-	 * @see #fromJena(org.apache.jena.graph.Triple, UUID)
-	 * @see #fromJena(RDFTermFactory, org.apache.jena.graph.Triple)
-	 * 
-	 * @param triple
-	 *            Jena triple
-	 * @return Adapted triple
-	 * @throws ConversionException
-	 *             if any of the triple's nodes are not concrete or the triple
-	 *             is a generalized triple
-	 */
-	public JenaTriple fromJena(org.apache.jena.graph.Triple triple) throws ConversionException {
-		return JenaFactory.fromJena(triple, salt);
-	}
-
-
-	/**
-	 * Adapt a generalized Jena Triple to a CommonsRDF {@link TripleLike}.
-	 * <p>
-	 * The generalized triple supports any {@link RDFTerm} as its {@link TripleLike#getSubject()}
-	 * {@link TripleLike#getPredicate()} or {@link TripleLike#getObject()}. 
-	 * <p>
-	 * If the Jena triple contains any {@link Node#isBlank()}, then any corresponding
-	 * {@link BlankNode} will use the provided {@link UUID} salt 
-	 * 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
-	 * @param salt
-	 *            UUID salt for the purpose of
-	 *            {@link BlankNode#uniqueReference()}
-	 * @return Adapted {@link TripleLike}. Note that the generalized triple does
-	 *         <strong>not</strong> implement {@link Triple#equals(Object)} or
-	 *         {@link Triple#hashCode()}.
-	 * @throws ConversionException
-	 *             if any of the triple's nodes are not concrete
-	 */
-	public JenaTripleLike<RDFTerm, RDFTerm, RDFTerm> fromJenaGeneralized(org.apache.jena.graph.Triple triple, UUID salt) throws ConversionException {
-		return JenaFactory.fromJenaGeneralized(triple, salt);
-	}
-	
-	/**
-	 * Adapt a generalized Jena Triple to a CommonsRDF {@link TripleLike}.
-	 * <p>
-	 * The generalized triple supports any {@link RDFTerm} as its {@link TripleLike#getSubject()}
-	 * {@link TripleLike#getPredicate()} or {@link TripleLike#getObject()}. 
-	 * <p>
-	 * If the Jena 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()}.
-	 *
-	 * @see #fromJena(org.apache.jena.graph.Triple, UUID)
-	 * @see #fromJena(RDFTermFactory, org.apache.jena.graph.Triple)
-	 * 
-	 * @param triple
-	 *            Jena triple
-	 * @return Adapted {@link TripleLike}. Note that the generalized triple does
-	 *         <strong>not</strong> implement {@link Triple#equals(Object)} or
-	 *         {@link Triple#hashCode()}.
-	 * @throws ConversionException
-	 *             if any of the triple's nodes are not concrete
-	 */
-	public JenaTripleLike<RDFTerm, RDFTerm, RDFTerm> fromJenaGeneralized(org.apache.jena.graph.Triple triple) throws ConversionException {
-		return JenaFactory.fromJenaGeneralized(triple, salt);
-	}
-	
-	
-	/**
-	 * 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()}.
-	 * 
-	 * @param triple
-	 *            Jena triple
-	 * @param salt
-	 *            A {@link UUID} salt for adapting any {@link BlankNode}s
-	 * @return Adapted triple
-	 * @throws ConversionException
-	 *             if any of the triple's nodes are not concrete or the triple
-	 *             is a generalized triple
-	 */
-	public static JenaTriple fromJena(org.apache.jena.graph.Triple triple, UUID salt) throws ConversionException {
-		return JenaFactory.fromJena(triple, salt);
-	}
-
-	/**
-	 * 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 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>
-	 * If the quad 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()}.
-	 * 
-	 * @param quad
-	 *            Jena quad
-	 * @return Adapted quad
-	 */	
-	public Quad fromJena(org.apache.jena.sparql.core.Quad quad) {
-		return JenaFactory.fromJena(quad, salt);
-	}
-	
-	/**
-	 * 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 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) {
-		return JenaFactory.fromJena(quad, 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 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
-	 * 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) {
-		if (factory instanceof RDFTermFactoryJena) {
-			// No need to convert, just wrap
-			return fromJena(graph);
-		}
-
-		Graph g = factory.createGraph();
-		graph.find(Node.ANY, Node.ANY, Node.ANY).forEachRemaining(t -> {
-			g.add(fromJena(factory, t));
-		});
-		return g;
-	}
-
-
-	public static Quad fromJena(RDFTermFactory factory, org.apache.jena.sparql.core.Quad quad) {
-		if (factory instanceof RDFTermFactoryJena) {
-			// No need to convert, just wrap
-			return ((RDFTermFactoryJena) factory).fromJena(quad);
-		}
-		BlankNodeOrIRI graphName = (BlankNodeOrIRI) (fromJena(factory, quad.getGraph()));
-		BlankNodeOrIRI subject = (BlankNodeOrIRI) (fromJena(factory, quad.getSubject()));
-		IRI predicate = (IRI) (fromJena(factory, quad.getPredicate()));
-		RDFTerm object = fromJena(factory, quad.getObject());
-		return factory.createQuad(graphName, subject, predicate, object);
-	}
-
-	public static Optional<RDFSyntax> langToRdfSyntax(Lang lang) {
-		return RDFSyntax.byMediaType(lang.getContentType().getContentType());
-	}
-
-	public static Optional<Lang> rdfSyntaxToLang(RDFSyntax rdfSyntax) {
-		return Optional.ofNullable(RDFLanguages.contentTypeToLang(rdfSyntax.mediaType));
-	}
-
-	/**
-	 * Create a {@link StreamRDF} that inserts into any RDFCommons
-	 * implementation of Graph
-	 */
-	public static StreamRDF streamJenaToCommonsRDF(RDFTermFactory factory, Consumer<Quad> consumer) {
-		return new StreamRDFBase() {
-			@Override
-			public void quad(org.apache.jena.sparql.core.Quad quad) {
-				consumer.accept(fromJena(factory, quad));
-			}
-		};
-	}
-
-	/**
-	 * 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).asJenaGraph();
-		org.apache.jena.graph.Graph g = GraphFactory.createGraphMem();
-		graph.stream().forEach(t -> g.add(toJena(t)));
-		return g;
-	}
-
-	/**
-	 * 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 == null) {
-			return null;
-		}
-		if (term instanceof JenaRDFTerm)
-			// TODO: What if it's a BlankNodeImpl with
-			// a different salt? Do we need to rewrite the
-			// jena blanknode identifier?
-			return ((JenaRDFTerm) term).asJenaNode();
-
-		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);
-		}
-		throw new ConversionException("Not a concrete RDF Term: " + term);
-	}
-
-	/**
-	 * 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).asJenaTriple();
-		return new org.apache.jena.graph.Triple(
-				toJena(triple.getSubject()), 
-				toJena(triple.getPredicate()),
-				toJena(triple.getObject()));
-	}
-
-	// 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();
-	}
-
-	private static void validateLang(String languageTag) {
-		if (languageTag.contains(" "))
-			throw new IllegalArgumentException("Invalid language tag: " + languageTag);
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/76dbe500/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
index c36c615..97ff7c5 100644
--- 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
@@ -23,7 +23,7 @@ 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;
+import org.apache.commons.rdf.jena.JenaRDFTermFactory;
 
 public class GeneralizedTripleImpl implements JenaTripleLike<RDFTerm, RDFTerm, RDFTerm> {
 	private final RDFTerm object;
@@ -47,8 +47,8 @@ public class GeneralizedTripleImpl implements JenaTripleLike<RDFTerm, RDFTerm, R
 	@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));
+			triple = org.apache.jena.graph.Triple.create(JenaRDFTermFactory.toJena(subject),
+					JenaRDFTermFactory.toJena(predicate), JenaRDFTermFactory.toJena(object));
 		return triple;
 	}
 	@Override

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/76dbe500/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java
index 1e03b2c..02c4a25 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java
@@ -27,7 +27,7 @@ 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.JenaGraph;
-import org.apache.commons.rdf.jena.RDFTermFactoryJena;
+import org.apache.commons.rdf.jena.JenaRDFTermFactory;
 import org.apache.jena.atlas.iterator.Iter;
 import org.apache.jena.graph.Node;
 import org.apache.jena.riot.Lang;
@@ -46,14 +46,14 @@ public class GraphImpl implements JenaGraph {
 	@Override
 	public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
 		graph.add(org.apache.jena.graph.Triple.create(
-				RDFTermFactoryJena.toJena(subject),
-				RDFTermFactoryJena.toJena(predicate), 
-				RDFTermFactoryJena.toJena(object)));
+				JenaRDFTermFactory.toJena(subject),
+				JenaRDFTermFactory.toJena(predicate), 
+				JenaRDFTermFactory.toJena(object)));
 	}
 
 	@Override
 	public void add(Triple triple) {
-		graph.add(RDFTermFactoryJena.toJena(triple));
+		graph.add(JenaRDFTermFactory.toJena(triple));
 	}
 
 	@Override
@@ -74,27 +74,27 @@ public class GraphImpl implements JenaGraph {
 	@Override
 	public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
 		return graph.contains(
-				RDFTermFactoryJena.toJena(subject), 
-				RDFTermFactoryJena.toJena(predicate),
-				RDFTermFactoryJena.toJena(object));
+				JenaRDFTermFactory.toJena(subject), 
+				JenaRDFTermFactory.toJena(predicate),
+				JenaRDFTermFactory.toJena(object));
 	}
 
 	@Override
 	public boolean contains(Triple triple) {
-		return graph.contains(RDFTermFactoryJena.toJena(triple));
+		return graph.contains(JenaRDFTermFactory.toJena(triple));
 	}
 
 	@Override
 	public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
 		graph.delete(org.apache.jena.graph.Triple.create(
-				RDFTermFactoryJena.toJena(subject),
-				RDFTermFactoryJena.toJena(predicate), 
-				RDFTermFactoryJena.toJena(object)));
+				JenaRDFTermFactory.toJena(subject),
+				JenaRDFTermFactory.toJena(predicate), 
+				JenaRDFTermFactory.toJena(object)));
 	}
 
 	@Override
 	public void remove(Triple triple) {
-		graph.delete(RDFTermFactoryJena.toJena(triple));
+		graph.delete(JenaRDFTermFactory.toJena(triple));
 	}
 
 	@Override
@@ -104,13 +104,13 @@ public class GraphImpl implements JenaGraph {
 
 	@Override
 	public Stream<? extends Triple> stream() {
-		RDFTermFactoryJena factory = new RDFTermFactoryJena(salt);
+		JenaRDFTermFactory factory = new JenaRDFTermFactory(salt);
 		return Iter.asStream(graph.find(null, null, null), true).map(factory::fromJena);
 	}
 
 	@Override
 	public Stream<? extends Triple> stream(BlankNodeOrIRI s, IRI p, RDFTerm o) {
-		RDFTermFactoryJena factory = new RDFTermFactoryJena(salt);
+		JenaRDFTermFactory factory = new JenaRDFTermFactory(salt);
 		return Iter.asStream(graph.find(toJenaAny(s), toJenaAny(p), toJenaAny(o)), true)
 				.map(factory::fromJena);
 	}
@@ -118,7 +118,7 @@ public class GraphImpl implements JenaGraph {
 	private Node toJenaAny(RDFTerm term) {
 		if (term == null)
 			return Node.ANY;
-		return RDFTermFactoryJena.toJena(term);
+		return JenaRDFTermFactory.toJena(term);
 	}
 
 	@Override

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/76dbe500/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 16deb02..19f154c 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
@@ -28,7 +28,7 @@ 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.JenaQuad;
-import org.apache.commons.rdf.jena.RDFTermFactoryJena;
+import org.apache.commons.rdf.jena.JenaRDFTermFactory;
 
 public class QuadImpl implements JenaQuad {
 
@@ -57,10 +57,10 @@ public class QuadImpl implements JenaQuad {
 	public org.apache.jena.sparql.core.Quad asJenaQuad() {
 		if (quad == null) {
 			quad = org.apache.jena.sparql.core.Quad.create(
-					RDFTermFactoryJena.toJena(graphName.orElse(null)),
-					RDFTermFactoryJena.toJena(subject), 
-					RDFTermFactoryJena.toJena(predicate),
-					RDFTermFactoryJena.toJena(object));
+					JenaRDFTermFactory.toJena(graphName.orElse(null)),
+					JenaRDFTermFactory.toJena(subject), 
+					JenaRDFTermFactory.toJena(predicate),
+					JenaRDFTermFactory.toJena(object));
 		}
 		return quad;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/76dbe500/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 f65fd6d..cadbdf5 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
@@ -27,7 +27,7 @@ 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;
+import org.apache.commons.rdf.jena.JenaRDFTermFactory;
 
 public class TripleImpl implements Triple, JenaTriple {
 	private final RDFTerm object;
@@ -55,8 +55,8 @@ public class TripleImpl implements Triple, JenaTriple {
 	@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));
+			triple = org.apache.jena.graph.Triple.create(JenaRDFTermFactory.toJena(subject),
+					JenaRDFTermFactory.toJena(predicate), JenaRDFTermFactory.toJena(object));
 		return triple;
 	}
 

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/76dbe500/jena/src/test/java/org/apache/commons/rdf/jena/TestBlankNodeJena.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestBlankNodeJena.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestBlankNodeJena.java
index 764ee70..10edd09 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestBlankNodeJena.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestBlankNodeJena.java
@@ -18,6 +18,8 @@
 
 package org.apache.commons.rdf.jena;
 
+import java.util.UUID;
+
 import org.apache.commons.rdf.api.AbstractBlankNodeTest ;
 import org.apache.commons.rdf.api.BlankNode ;
 import org.apache.commons.rdf.jena.impl.JenaFactory;
@@ -25,14 +27,16 @@ import org.apache.commons.rdf.jena.impl.JenaFactory;
 public class TestBlankNodeJena extends AbstractBlankNodeTest {
 
 	
-    @Override
+    private static final UUID SALT = UUID.fromString("ccfde817-55b8-4a5f-bc2d-6bfd8eaa41ce");
+
+	@Override
     protected BlankNode getBlankNode() {
         return JenaFactory.createBlankNode() ;
     }
     
     @Override
     protected BlankNode getBlankNode(String identifier) {
-        return JenaFactory.createBlankNode(identifier) ;
+        return JenaFactory.createBlankNode(identifier, SALT) ;
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/76dbe500/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
index 973b7b1..e2749bb 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
@@ -25,7 +25,7 @@ public class TestGraphJena extends AbstractGraphTest {
 
     @Override
     public RDFTermFactory createFactory() {
-        return new RDFTermFactoryJena() ;
+        return new JenaRDFTermFactory() ;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/76dbe500/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
index cfe5642..c81a8b1 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
@@ -56,10 +56,10 @@ public class TestJenaGraphToCommonsRDFGraph {
         RDFDataMgr.read(jGraph, turtleFile.toUri().toString()) ;
         
         // "graph" is a CommonsRDF graph 
-        Graph graph = JenaCommonsRDF.fromJena(jGraph) ;
+        Graph graph = JenaRDFTermFactory.fromJena(jGraph) ;
         
         // Add to CommonsRDF Graph
-        RDFTermFactory rft = new RDFTermFactoryJena() ;
+        RDFTermFactory rft = new JenaRDFTermFactory() ;
         graph.add(rft.createIRI("http://example/s2"),
                   rft.createIRI("http://example/p2"),
                   rft.createLiteral("foo")) ;

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/76dbe500/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
index f230bdd..c689d0e 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
@@ -53,7 +53,7 @@ public class TestRDFParserBuilder {
 
 	@Test
 	public void parseTurtle() throws Exception {
-		Graph g = new RDFTermFactoryJena().createGraph();
+		Graph g = new JenaRDFTermFactory().createGraph();
 		Future<ParseResult> gFuture = new JenaRDFParserBuilder().contentType(RDFSyntax.TURTLE).source(turtleFile)
 				.target(g).parse();
 		gFuture.get(5, TimeUnit.SECONDS);

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/76dbe500/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
index 6aa153f..4baec9c 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
@@ -25,7 +25,7 @@ public class TestRDFTermFactoryJena extends AbstractRDFTermFactoryTest {
 	
     @Override
     public RDFTermFactory createFactory() {
-        return new RDFTermFactoryJena() ;
+        return new JenaRDFTermFactory() ;
     }
 
 }


Mime
View raw message