commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [13/33] incubator-commonsrdf git commit: Improve javadoc.
Date Mon, 28 Mar 2016 04:55:09 GMT
Improve javadoc.

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

Branch: refs/heads/jena
Commit: f0a791758a8b6717146e0398158a89830cd26f5a
Parents: d804f74
Author: Andy Seaborne <andy@seaborne.org>
Authored: Sat Aug 29 19:27:10 2015 +0100
Committer: Andy Seaborne <andy@seaborne.org>
Committed: Sat Aug 29 19:27:10 2015 +0100

----------------------------------------------------------------------
 .../jena/commonsrdf/ConversionException.java    |  8 ++++
 .../apache/jena/commonsrdf/JenaCommonsRDF.java  | 50 ++++++++++----------
 .../jena/commonsrdf/RDFTermFactoryJena.java     |  2 +
 3 files changed, 35 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f0a79175/src/main/java/org/apache/jena/commonsrdf/ConversionException.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/jena/commonsrdf/ConversionException.java b/src/main/java/org/apache/jena/commonsrdf/ConversionException.java
index 8cee6b0..65cc04a 100644
--- a/src/main/java/org/apache/jena/commonsrdf/ConversionException.java
+++ b/src/main/java/org/apache/jena/commonsrdf/ConversionException.java
@@ -20,6 +20,14 @@ package org.apache.jena.commonsrdf;
 
 import org.apache.jena.shared.JenaException ;
 
+/**
+ * Exception thrown when a problem arises across the Jena-CommonRDF boundary.
+ * This should not happen in well-formed RDF data but, for example, Jena triples
+ * allow 
+ * <a href="http://www.w3.org/TR/rdf11-concepts/#section-generalized-rdf"
+ * >generalized RDF</a>.
+ */
+
 public class ConversionException extends JenaException {
     public ConversionException()                                  { super(); }
     public ConversionException(String message)                    { super(message); }

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f0a79175/src/main/java/org/apache/jena/commonsrdf/JenaCommonsRDF.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/jena/commonsrdf/JenaCommonsRDF.java b/src/main/java/org/apache/jena/commonsrdf/JenaCommonsRDF.java
index c7e10db..1b24560 100644
--- a/src/main/java/org/apache/jena/commonsrdf/JenaCommonsRDF.java
+++ b/src/main/java/org/apache/jena/commonsrdf/JenaCommonsRDF.java
@@ -19,7 +19,6 @@
 package org.apache.jena.commonsrdf;
 
 import org.apache.commons.rdf.api.* ;
-import org.apache.jena.atlas.lib.NotImplemented ;
 import org.apache.jena.commonsrdf.impl.* ;
 import org.apache.jena.datatypes.RDFDatatype ;
 import org.apache.jena.datatypes.xsd.XSDDatatype ;
@@ -29,13 +28,13 @@ import org.apache.jena.riot.system.StreamRDF ;
 import org.apache.jena.sparql.graph.GraphFactory ;
 
 /** A set of utilities for moving between CommonsRDF and Jena
- * The {@code RDFTermFactory} is {@link RDFTermFactoryJena} for
- * creating CommonsRDF objects backed by Jena.   
-
+ * The {@link RDFTermFactory} for is {@link RDFTermFactoryJena} which
+ * creates CommonsRDF objects backed by Jena.   
+ * <p>
  * This class encapsulates moving between existing object (RDFTerms, Triples, Graphs)
- * if necessary.   
+ * which is usually necessary when working with existing data.   
  * 
- *  @see RDFTermFactoryJena
+ * @see RDFTermFactoryJena
  */
 public class JenaCommonsRDF {
 
@@ -87,22 +86,25 @@ public class JenaCommonsRDF {
         return g ;   
     }
 
-    /** Adapt an existing Jena Node to CommonsRDF. */
+    /** Adapt an existing Jena Node to CommonsRDF {@link RDFTerm}. */
     public static RDFTerm fromJena( Node node) {
         return JCR_Factory.fromJena(node) ;
     }
 
-    /** Adapt an existing Jena Triple to CommonsRDF. */
+    /** Adapt an existing Jena Triple to CommonsRDF {@link Triple}. */
     public static Triple fromJena(org.apache.jena.graph.Triple triple) {
         return JCR_Factory.fromJena(triple) ;
     }
 
-    /** Adapt an existring Jena Graph to CommonsRDF.  This does not take a copy. */  
+    /** Adapt an existring Jena Graph to CommonsRDF {@link Graph}.
+     * This does not take a copy.
+     * Changes to the CommonsRDF Graph are reflected in the jena graph.
+     */    
     public static Graph fromJena(org.apache.jena.graph.Graph graph) {
         return JCR_Factory.fromJena(graph) ;
     }
 
-    /** Convert from Jena to any RDFCommons implementation */
+    /** Convert from Jena {@link Node} to any RDFCommons implementation */
     public static RDFTerm fromJena(RDFTermFactory factory, Node node) {
         if ( node.isURI() )
             return factory.createIRI(node.getURI()) ;
@@ -117,11 +119,10 @@ public class JenaCommonsRDF {
         }
         if ( node.isBlank() )
             return factory.createBlankNode(node.getBlankNodeLabel()) ;
-        //error("Node is not a concrete RDF Term: "+node) ;
-        return null ;
+        throw new ConversionException("Node is not a concrete RDF Term: "+node) ;
     }
 
-    /** Convert from Jena to any RDFCommons implementation */
+    /** Convert from Jena {@link org.apache.jena.graph.Triple} to any RDFCommons implementation
*/
    public static Triple fromJena(RDFTermFactory factory, org.apache.jena.graph.Triple triple)
{
         BlankNodeOrIRI subject = (BlankNodeOrIRI)(fromJena(factory, triple.getSubject()))
;
         IRI predicate = (IRI)(fromJena(factory, triple.getPredicate())) ;
@@ -129,24 +130,23 @@ public class JenaCommonsRDF {
         return factory.createTriple(subject, predicate, object) ;
     }
 
-   /** Convert from Jena to any RDFCommons implementation */
+   /** 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 ) 
-           return JCR_Factory.fromJena(graph) ;
-       throw new NotImplemented() ;
-    //        /return JCR_Factory.fromJena(factory, graph) ;
+       Graph g = factory.createGraph() ;
+       graph.find(Node.ANY, Node.ANY, Node.ANY).forEachRemaining( t-> {
+           g.add(fromJena(factory, t) );
+       }) ;
+       return g ;
    }
-
-   /** Convert from Jena to any RDFCommons implementation */
+   
+   /** Create a {@link StreamRDF} that inserts into any RDFCommons implementation of Graph
*/
    public static StreamRDF streamJenaToCommonsRDF(RDFTermFactory factory, Graph graph) {
        return new ToGraph(factory, graph) ;
    }
 
-   /** Convert from Jena to any RDFCommons implementation */
-   public static StreamRDF steramJenaToCommonsRDF(Graph graph) {
-       return streamJenaToCommonsRDF(new RDFTermFactoryJena(), graph) ;
-   }
-
    public static void conversionError(String msg) {
         throw new ConversionException(msg) ;
     }

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f0a79175/src/main/java/org/apache/jena/commonsrdf/RDFTermFactoryJena.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/jena/commonsrdf/RDFTermFactoryJena.java b/src/main/java/org/apache/jena/commonsrdf/RDFTermFactoryJena.java
index d5afca6..d9d577a 100644
--- a/src/main/java/org/apache/jena/commonsrdf/RDFTermFactoryJena.java
+++ b/src/main/java/org/apache/jena/commonsrdf/RDFTermFactoryJena.java
@@ -23,6 +23,8 @@ import org.apache.jena.commonsrdf.impl.JCR_Factory ;
 
 /** RDFTermFactory with Jena-backed objects.
  *  See {@link JenaCommonsRDF} for other conversions of existing objects. 
+ *  
+ *  @see RDFTermFactory
  */
 public class RDFTermFactoryJena implements RDFTermFactory {
     


Mime
View raw message