jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1375233 - in /jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra: Transformer.java op/OpExt.java
Date Mon, 20 Aug 2012 21:34:25 GMT
Author: andy
Date: Mon Aug 20 21:34:25 2012
New Revision: 1375233

URL: http://svn.apache.org/viewvc?rev=1375233&view=rev
Log:
Add one-level transform operation to Transformer.
Add apply(Transform) to OpExt (but usually it's a "ARQNotImplemented" exception)

Modified:
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/Transformer.java
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpExt.java

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/Transformer.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/Transformer.java?rev=1375233&r1=1375232&r2=1375233&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/Transformer.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/Transformer.java Mon
Aug 20 21:34:25 2012
@@ -61,7 +61,6 @@ public class Transformer
         return transformSkipService(transform, op, null, null) ; 
     }
 
-    
     /** Transform an algebra expression except skip (leave alone) any OpService nodes */
     public static Op transformSkipService(Transform transform, Op op, OpVisitor beforeVisitor,
OpVisitor afterVisitor)
     {
@@ -82,6 +81,14 @@ public class Transformer
         }
     }
     
+    /** Transform an Op - not recursively */ 
+    public static Op transformOne(Transform transform, Op op)
+    {
+        OpTransformApplyOne visitor = new OpTransformApplyOne(transform) ;
+        op.visit(visitor) ;
+        return visitor.result ;
+    }
+    
     // To allow subclassing this class, we use a singleton pattern 
     // and theses protected methods.
     protected Op transformation(Transform transform, Op op, OpVisitor beforeVisitor, OpVisitor
afterVisitor)
@@ -385,4 +392,35 @@ public class Transformer
         public Op transform(OpService opService, Op subOp)
         { return opService ; } 
     }
+    
+    static class OpTransformApplyOne extends OpVisitorByType
+    {
+        private final Transform transform ;
+        Op result ;
+
+        OpTransformApplyOne(Transform transform)
+        {
+            this.transform = transform ;
+        }
+
+        @Override
+        protected void visitN(OpN op)
+        { result = op.apply(transform, op.getElements()) ; }
+
+        @Override
+        protected void visit2(Op2 op)
+        { result = op.apply(transform, op.getLeft(), op.getRight()) ; }
+
+        @Override
+        protected void visit1(Op1 op)
+        { result = op.apply(transform, op.getSubOp()) ; }
+
+        @Override
+        protected void visit0(Op0 op)
+        { result = op.apply(transform) ; }
+
+        @Override
+        protected void visitExt(OpExt op)
+        { op.apply(transform) ; }
+    }
 }

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpExt.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpExt.java?rev=1375233&r1=1375232&r2=1375233&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpExt.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpExt.java Mon Aug
20 21:34:25 2012
@@ -20,8 +20,10 @@ package com.hp.hpl.jena.sparql.algebra.o
 
 import org.openjena.atlas.io.IndentedWriter ;
 
+import com.hp.hpl.jena.sparql.ARQNotImplemented ;
 import com.hp.hpl.jena.sparql.algebra.Op ;
 import com.hp.hpl.jena.sparql.algebra.OpVisitor ;
+import com.hp.hpl.jena.sparql.algebra.Transform ;
 import com.hp.hpl.jena.sparql.engine.ExecutionContext ;
 import com.hp.hpl.jena.sparql.engine.QueryIterator ;
 import com.hp.hpl.jena.sparql.serializer.SerializationContext ;
@@ -81,6 +83,8 @@ public abstract class OpExt extends OpBa
             out.ensureStartOfLine() ;
     }
     
+    public Op apply(Transform transform) { throw new ARQNotImplemented("OpExt.appy(Transform)")
; } 
+    
 //    /** Return the sub tag - must match the builder */ 
 //    public abstract String getSubTag() ;
 



Mime
View raw message