jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rve...@apache.org
Subject jena git commit: More flexible fix for JENA-939
Date Wed, 13 May 2015 09:36:03 GMT
Repository: jena
Updated Branches:
  refs/heads/master beeb6b524 -> 1e505a8a8


More flexible fix for JENA-939

Add a specific overload to QueryFactory that takes in an existing
serialization context


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/1e505a8a
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/1e505a8a
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/1e505a8a

Branch: refs/heads/master
Commit: 1e505a8a87d54ef2ac79e6ab5b26fd980a589c75
Parents: beeb6b5
Author: Rob Vesse <rvesse@apache.org>
Authored: Wed May 13 10:34:39 2015 +0100
Committer: Rob Vesse <rvesse@apache.org>
Committed: Wed May 13 10:34:39 2015 +0100

----------------------------------------------------------------------
 .../sparql/serializer/FormatterElement.java     | 15 ++++------
 .../serializer/QuerySerializerFactory.java      | 29 ++++++++++++++++++--
 .../sparql/serializer/SerializerRegistry.java   | 18 ++++++++----
 3 files changed, 43 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/1e505a8a/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java
b/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java
index 33033f7..62d58ac 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java
@@ -27,6 +27,8 @@ import org.apache.jena.atlas.io.IndentedWriter ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.graph.Triple ;
 import org.apache.jena.query.Query ;
+import org.apache.jena.query.QueryVisitor;
+import org.apache.jena.query.Syntax;
 import org.apache.jena.sparql.core.BasicPattern ;
 import org.apache.jena.sparql.core.PathBlock ;
 import org.apache.jena.sparql.core.TriplePath ;
@@ -453,16 +455,9 @@ public class FormatterElement extends FormatterBase
         // JENA-939 : factory.create calls "new NodeToLabelMapBNode("b", false)", i.e. a
new mapping
         // which looses the history and so reuses labels. 
         
-//        // Serialize with respect to the outer context prologue.
-//        QuerySerializerFactory factory = SerializerRegistry.get().getQuerySerializerFactory(Syntax.syntaxARQ);
-//        QueryVisitor serializer = factory.create(Syntax.syntaxARQ, context.getPrologue()
, out);
-//        q.visit(serializer);
-        
-        // For the query pattern, use the same context
-        QuerySerializer serializer = new QuerySerializer(out, 
-                                                         new FormatterElement(out, context),
-                                                         new FmtExprSPARQL(out, context),
-                                                         null);
+        // Serialize with respect to the existing context
+        QuerySerializerFactory factory = SerializerRegistry.get().getQuerySerializerFactory(Syntax.syntaxARQ);
+        QueryVisitor serializer = factory.create(Syntax.syntaxARQ, context, out);
         q.visit(serializer);
         
         out.decIndent(INDENT) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/1e505a8a/jena-arq/src/main/java/org/apache/jena/sparql/serializer/QuerySerializerFactory.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/serializer/QuerySerializerFactory.java
b/jena-arq/src/main/java/org/apache/jena/sparql/serializer/QuerySerializerFactory.java
index 3e65da5..a515f9d 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/serializer/QuerySerializerFactory.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/serializer/QuerySerializerFactory.java
@@ -19,9 +19,9 @@
 package org.apache.jena.sparql.serializer;
 
 import org.apache.jena.atlas.io.IndentedWriter;
-import org.apache.jena.query.QueryVisitor ;
-import org.apache.jena.query.Syntax ;
-import org.apache.jena.sparql.core.Prologue ;
+import org.apache.jena.query.QueryVisitor;
+import org.apache.jena.query.Syntax;
+import org.apache.jena.sparql.core.Prologue;
 
 /**
  * Interface for query serializer factories, these may be registered with the
@@ -38,6 +38,29 @@ public interface QuerySerializerFactory {
 
     /**
      * Return a serializer for the given syntax
+     * 
+     * @param syntax
+     *            Syntax
+     * @param prologue
+     *            Prologue
+     * @param writer
+     *            Writer
+     * @return Serializer
      */
     public QueryVisitor create(Syntax syntax, Prologue prologue, IndentedWriter writer);
+
+    /**
+     * Returns a serializer for the given syntax using an existing serialization
+     * context, this method should only be called for serializing sub-queries
+     * where the outer context must be honoured
+     * 
+     * @param syntax
+     *            Syntax
+     * @param context
+     *            Serialization Context
+     * @param writer
+     *            Writer
+     * @return Serializer
+     */
+    public QueryVisitor create(Syntax syntax, SerializationContext context, IndentedWriter
writer);
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/1e505a8a/jena-arq/src/main/java/org/apache/jena/sparql/serializer/SerializerRegistry.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/serializer/SerializerRegistry.java
b/jena-arq/src/main/java/org/apache/jena/sparql/serializer/SerializerRegistry.java
index 13342d5..bac3c54 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/serializer/SerializerRegistry.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/serializer/SerializerRegistry.java
@@ -22,13 +22,13 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.jena.atlas.io.IndentedWriter;
-import org.apache.jena.query.QueryVisitor ;
-import org.apache.jena.query.Syntax ;
+import org.apache.jena.query.QueryVisitor;
+import org.apache.jena.query.Syntax;
 import org.apache.jena.riot.system.IRIResolver;
-import org.apache.jena.sparql.core.Prologue ;
-import org.apache.jena.sparql.modify.request.UpdateSerializer ;
-import org.apache.jena.sparql.modify.request.UpdateWriter ;
-import org.apache.jena.sparql.util.NodeToLabelMapBNode ;
+import org.apache.jena.sparql.core.Prologue;
+import org.apache.jena.sparql.modify.request.UpdateSerializer;
+import org.apache.jena.sparql.modify.request.UpdateWriter;
+import org.apache.jena.sparql.util.NodeToLabelMapBNode;
 
 /**
  * Provides a registry of serializers for queries and updates
@@ -75,6 +75,12 @@ public class SerializerRegistry {
             }
 
             @Override
+            public QueryVisitor create(Syntax syntax, SerializationContext context, IndentedWriter
writer) {
+                return new QuerySerializer(writer, new FormatterElement(writer, context),
new FmtExprSPARQL(writer,
+                        context), new FmtTemplate(writer, context));
+            }
+
+            @Override
             public boolean accept(Syntax syntax) {
                 // Since ARQ syntax is a super set of SPARQL 1.1 both SPARQL 1.0
                 // and SPARQL 1.1 can be serialized by the same serializer


Mime
View raw message