commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [17/19] incubator-commonsrdf git commit: Add asJenaModel() and fromJena(Model)
Date Thu, 08 Sep 2016 14:29:44 GMT
Add asJenaModel() and fromJena(Model)


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

Branch: refs/heads/jena
Commit: 361aaba1c2ec3791d9dd88f18ccb4142b562fb09
Parents: c752d8c
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Thu Sep 8 15:18:07 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Thu Sep 8 15:18:07 2016 +0100

----------------------------------------------------------------------
 jena/pom.xml                                    |  3 ++-
 .../org/apache/commons/rdf/jena/JenaGraph.java  | 19 +++++++++++++++
 .../commons/rdf/jena/JenaRDFTermFactory.java    | 18 +++++++++++++-
 .../apache/commons/rdf/jena/impl/GraphImpl.java | 25 +++++++++++++++++++-
 .../commons/rdf/jena/impl/JenaFactory.java      |  7 +++++-
 5 files changed, 68 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/361aaba1/jena/pom.xml
----------------------------------------------------------------------
diff --git a/jena/pom.xml b/jena/pom.xml
index 6bf0aeb..c06c5bf 100644
--- a/jena/pom.xml
+++ b/jena/pom.xml
@@ -48,6 +48,8 @@
 		<!-- Uncomment below and disable jena-osgi to access the regular non-osgi 
 			 Jena dependencies (e.g. for debugging) -->
 		<!-- 
+				--> 
+	
 		<dependency>
 			<groupId>org.apache.jena</groupId>
 			<artifactId>apache-jena-libs</artifactId>
@@ -55,7 +57,6 @@
 			<type>pom</type>
 			<scope>optional</scope>
 		</dependency>
-		--> 
 
 		<!-- As commons-rdf-jena is an OSGi bundle, we'll use the Jena OSGi bundle -->
 		<dependency>

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/361aaba1/jena/src/main/java/org/apache/commons/rdf/jena/JenaGraph.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaGraph.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaGraph.java
index 7596021..fa8954e 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaGraph.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaGraph.java
@@ -19,8 +19,27 @@
 package org.apache.commons.rdf.jena;
 
 import org.apache.jena.graph.Graph;
+import org.apache.jena.rdf.model.Model;
 
 /** Access the Jena graph backing this object */
 public interface JenaGraph extends org.apache.commons.rdf.api.Graph {
+	
+	/**
+	 * Return the underlying Jena {@link Graph}.
+	 * <p>
+	 * Changes to the Jena graph are reflected in the Commons RDF graph and vice versa.
+	 * 
+	 * @return A Jena {@link Graph}
+	 */
 	public Graph asJenaGraph();
+
+	/**
+	 * Return the underlying Jena {@link Model}.
+	 * <p>
+	 * Changes to the Jena model are reflected in the Commons RDF graph and vice
+	 * versa.
+	 * 
+	 * @return A Jena {@link Model}
+	 */	
+	public Model asJenaModel();
 }

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/361aaba1/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
index 52fde28..a75b61e 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTermFactory.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTermFactory.java
@@ -78,7 +78,7 @@ public final class JenaRDFTermFactory implements RDFTermFactory {
 	}
 	
 	@Override
-	public Dataset createDataset() throws UnsupportedOperationException {
+	public Dataset createDataset() {
 		return JenaFactory.createDataset(salt);
 	}
 
@@ -467,6 +467,22 @@ public final class JenaRDFTermFactory implements RDFTermFactory {
 		return JenaFactory.fromJena(graph, salt);
 	}
 
+	/**
+	 * Adapt an existing Jena {@link org.apache.jena.rdf.model.Model} to CommonsRDF {@link Graph}.

+	 * <p>
+	 * This does not ake a copy, changes to the CommonsRDF Graph are reflected in the jena
+	 * graph, which is accessible from {@link JenaGraph#asJenaGraph()}.
+	 * <p>
+	 * If the graph 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()}.
+
+	 */
+	public JenaGraph fromJena(org.apache.jena.rdf.model.Model model) {
+		return JenaFactory.fromJena(model, salt);
+	}	
 
 	/**
 	 * Adapt an existing Jena {@link org.apache.jena.graph.Graph} to CommonsRDF {@link Graph}.


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/361aaba1/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 02c4a25..3b74ee0 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
@@ -30,6 +30,8 @@ import org.apache.commons.rdf.jena.JenaGraph;
 import org.apache.commons.rdf.jena.JenaRDFTermFactory;
 import org.apache.jena.atlas.iterator.Iter;
 import org.apache.jena.graph.Node;
+import org.apache.jena.rdf.model.Model;
+import org.apache.jena.rdf.model.ModelFactory;
 import org.apache.jena.riot.Lang;
 import org.apache.jena.riot.RDFDataMgr;
 
@@ -37,12 +39,19 @@ public class GraphImpl implements JenaGraph {
 
 	private org.apache.jena.graph.Graph graph;
 	private UUID salt;
+	private Model model;
 
-	/* package */ GraphImpl(org.apache.jena.graph.Graph graph, UUID salt) {
+	GraphImpl(org.apache.jena.graph.Graph graph, UUID salt) {
 		this.graph = graph;
 		this.salt = salt;
 	}
 
+	GraphImpl(Model model, UUID salt) {
+		this.model = model;
+		this.graph = model.getGraph();
+		this.salt = salt;
+	}
+
 	@Override
 	public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
 		graph.add(org.apache.jena.graph.Triple.create(
@@ -128,4 +137,18 @@ public class GraphImpl implements JenaGraph {
 		return sw.toString();
 	}
 
+	@Override
+	public Model asJenaModel() {
+		if (model == null) {
+			synchronized(this) {
+				// As Model can be used for locks, we should make sure we don't make
+				// more than one model
+				if (model == null) {
+					model = ModelFactory.createModelForGraph(graph);
+				}
+			}
+		}
+		return model;
+	}
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/361aaba1/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 1832232..bc0ae0f 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
@@ -42,6 +42,7 @@ import org.apache.commons.rdf.jena.JenaTripleLike;
 import org.apache.commons.rdf.jena.JenaVariable;
 import org.apache.jena.graph.Node;
 import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.rdf.model.Model;
 import org.apache.jena.sparql.core.DatasetGraph;
 import org.apache.jena.sparql.core.DatasetGraphFactory;
 import org.apache.jena.sparql.graph.GraphFactory;
@@ -142,7 +143,7 @@ public class JenaFactory {
 		}
 		throw new IllegalArgumentException("Unrecognized node type: " + node);
 	}
-	
+
 	public static JenaGraph fromJena(org.apache.jena.graph.Graph graph) {
 		return new GraphImpl(graph, UUID.randomUUID());
 	}
@@ -151,6 +152,10 @@ public class JenaFactory {
 		return new GraphImpl(graph, salt);
 	}
 
+	public static JenaGraph fromJena(Model model, UUID salt) {
+		return new GraphImpl(model, salt);
+	}
+
 	public static JenaDataset fromJena(DatasetGraph datasetGraph) {
 		return new DatasetImpl(datasetGraph, UUID.randomUUID());
 	}


Mime
View raw message