You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2016/07/12 09:07:24 UTC

[2/2] jena git commit: Update comments. Reformat. Simplify.

Update comments. Reformat. Simplify.

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

Branch: refs/heads/master
Commit: 3bbe2d8d7b6f6b47740b68df244e25cbb8473779
Parents: 4507109
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Jul 12 10:06:52 2016 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Jul 12 10:06:52 2016 +0100

----------------------------------------------------------------------
 .../org/apache/jena/sparql/expr/E_Function.java | 58 +++++++-------------
 .../jena/sparql/function/FunctionBase.java      | 37 ++-----------
 .../jena/sparql/function/library/SystemVar.java | 28 ++++++----
 3 files changed, 41 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/3bbe2d8d/jena-arq/src/main/java/org/apache/jena/sparql/expr/E_Function.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/expr/E_Function.java b/jena-arq/src/main/java/org/apache/jena/sparql/expr/E_Function.java
index 63ddc67..7b1501e 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/expr/E_Function.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/expr/E_Function.java
@@ -39,99 +39,81 @@ public class E_Function extends ExprFunctionN
     public static boolean WarnOnUnknownFunction = true ;
     private String functionIRI ;
     
-    // Only set after a copySubstitute has been done by PlanFilter.
-    // at which point this instance if not part of the query abstract syntax.  
     private Function function = null ;
     private boolean functionBound = false ;
 
-    public E_Function(String functionIRI, ExprList args)
-    {
+    public E_Function(String functionIRI, ExprList args) {
         super(name, args) ;
-        this.functionIRI = functionIRI ; 
+        this.functionIRI = functionIRI ;
     }
 
     @Override
     public String getFunctionIRI() { return functionIRI ; }
     
     // The Function subsystem takes over evaluation via SpecialForms.
-    // This is merely to allow "function" to behave as special forms
-    // (this is discouraged).
-    // Doing the function call in evalSpecial maintains the old 
-    // interface to functions.
+    // This allows a "function" to behave as special forms (this is discouraged).
     
     @Override
-    public NodeValue evalSpecial(Binding binding, FunctionEnv env)
-    {
+    public NodeValue evalSpecial(Binding binding, FunctionEnv env) {
         // Only needed because some tests call straight in.
         // Otherwise, the buildFunction() calls should have done everything
-        if ( ! functionBound  )
+        if ( !functionBound )
             buildFunction(env.getContext()) ;
         if ( function == null )
-            throw new ExprEvalException("URI <"+getFunctionIRI()+"> not bound") ;
+            throw new ExprEvalException("URI <" + getFunctionIRI() + "> not bound") ;
         NodeValue r = function.exec(binding, args, getFunctionIRI(), env) ;
         return r ;
     }
     
     @Override
-    public NodeValue eval(List<NodeValue> args)
-    {
-        // For functions, we delay argument evaluation to the "Function" heierarchy
-        // so applications can add their own functional forms.
+    public NodeValue eval(List<NodeValue> args) {
+        // evalSpecial hands over function evaluation to the "Function" hierarchy
         throw new ARQInternalErrorException() ;
     }
 
-    public void buildFunction(Context cxt)
-    {
+    public void buildFunction(Context cxt) {
         try { bindFunction(cxt) ; }
-        catch (ExprException ex)
-        {
+        catch (ExprException ex) {
             if ( WarnOnUnknownFunction )
                 ARQ.getExecLogger().warn("URI <"+functionIRI+"> has no registered function factory") ;
         }
     }
     
-    private void bindFunction(Context cxt)
-    {
+    private void bindFunction(Context cxt) {
         if ( functionBound )
             return ;
-        
+
         FunctionRegistry registry = chooseRegistry(cxt) ;
         FunctionFactory ff = registry.get(functionIRI) ;
-        
-        if ( ff == null )
-        {
+
+        if ( ff == null ) {
             functionBound = true ;
-            throw new ExprEvalException("URI <"+functionIRI+"> not found as a function") ;
+            throw new ExprEvalException("URI <" + functionIRI + "> not found as a function") ;
         }
         function = ff.create(functionIRI) ;
         function.build(functionIRI, args) ;
         functionBound = true ;
     }
     
-    private FunctionRegistry chooseRegistry(Context context)
-    {
+    private FunctionRegistry chooseRegistry(Context context) {
         FunctionRegistry registry = FunctionRegistry.get(context) ;
         if ( registry == null )
             registry = FunctionRegistry.get() ;
         return registry ;
     }
-    
+
     @Override
-    public String getFunctionPrintName(SerializationContext cxt)
-    {
+    public String getFunctionPrintName(SerializationContext cxt) {
         return FmtUtils.stringForURI(functionIRI, cxt) ;
     }
 
     @Override
-    public String getFunctionName(SerializationContext cxt)
-    {
+    public String getFunctionName(SerializationContext cxt) {
         return FmtUtils.stringForURI(functionIRI, cxt) ;
     }
 
-
     @Override
-    public Expr copy(ExprList newArgs)
-    {
+    public Expr copy(ExprList newArgs) {
         return new E_Function(getFunctionIRI(), newArgs) ;
     }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/3bbe2d8d/jena-arq/src/main/java/org/apache/jena/sparql/function/FunctionBase.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/function/FunctionBase.java b/jena-arq/src/main/java/org/apache/jena/sparql/function/FunctionBase.java
index c2c54be..c55a988 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/function/FunctionBase.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/function/FunctionBase.java
@@ -26,32 +26,18 @@ import org.apache.jena.sparql.engine.binding.Binding ;
 import org.apache.jena.sparql.expr.Expr ;
 import org.apache.jena.sparql.expr.ExprList ;
 import org.apache.jena.sparql.expr.NodeValue ;
-import org.apache.jena.sparql.util.Context ;
 
-/** Interface to value-testing extensions to the expression evaluator. */
+/** Impleemntation root for custom function evaluation. */  
+public abstract class FunctionBase implements Function {
 
-public abstract class FunctionBase implements Function
-{
-    String uri = null ;
-    protected ExprList arguments = null ;
-    private FunctionEnv env ;
-    
     @Override
-    public final void build(String uri, ExprList args)
-    {
-        this.uri = uri ;
-        arguments = args ;
+    public final void build(String uri, ExprList args) {
+        // Rename for legacy reasons.
         checkBuild(uri, args) ;
     }
 
     @Override
-    public NodeValue exec(Binding binding, ExprList args, String uri, FunctionEnv env)
-    {
-        // This is merely to allow functions to be 
-        // It duplicates code in E_Function/ExprFunctionN.
-        
-        this.env = env ;
-        
+    public NodeValue exec(Binding binding, ExprList args, String uri, FunctionEnv env) {
         if ( args == null )
             // The contract on the function interface is that this should not happen.
             throw new ARQInternalErrorException("FunctionBase: Null args list") ;
@@ -64,24 +50,11 @@ public abstract class FunctionBase implements Function
         }
         
         NodeValue nv =  exec(evalArgs) ;
-        arguments = null ;
         return nv ;
     }
     
-    /** Return the Context object for this execution */
-    public Context getContext() { return env.getContext() ; }
-    
     /** Function call to a list of evaluated argument values */ 
     public abstract NodeValue exec(List<NodeValue> args) ;
 
     public abstract void checkBuild(String uri, ExprList args) ;
-    
-//    /** Get argument, indexing from 1 **/
-//    public NodeValue getArg(int i)
-//    {
-//        i = i-1 ;
-//        if ( i < 0 || i >= arguments.size()  )
-//            return null ;
-//        return (NodeValue)arguments.get(i) ;
-//    }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/3bbe2d8d/jena-arq/src/main/java/org/apache/jena/sparql/function/library/SystemVar.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/function/library/SystemVar.java b/jena-arq/src/main/java/org/apache/jena/sparql/function/library/SystemVar.java
index 7baf105..97c7431 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/function/library/SystemVar.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/function/library/SystemVar.java
@@ -18,21 +18,23 @@
 
 package org.apache.jena.sparql.function.library;
 
-//import org.apache.commons.logging.*;
-
 import org.apache.jena.atlas.lib.Lib ;
 import org.apache.jena.graph.Node ;
+import org.apache.jena.sparql.engine.binding.Binding ;
 import org.apache.jena.sparql.expr.ExprEvalException ;
 import org.apache.jena.sparql.expr.ExprException ;
+import org.apache.jena.sparql.expr.ExprList ;
 import org.apache.jena.sparql.expr.NodeValue ;
-import org.apache.jena.sparql.function.FunctionBase0 ;
+import org.apache.jena.sparql.function.Function ;
+import org.apache.jena.sparql.function.FunctionEnv ;
 import org.apache.jena.sparql.util.Symbol ;
 
-/** Function that returns the value of a system variable. */
-
-public class SystemVar extends FunctionBase0
+/**
+ * Function that returns the value of a system variable.
+ */
+public class SystemVar implements Function
 {
-    Symbol systemSymbol ;
+    private Symbol systemSymbol ;
     protected SystemVar(Symbol systemSymbol)
     {
         if ( systemSymbol == null )
@@ -40,12 +42,11 @@ public class SystemVar extends FunctionBase0
         this.systemSymbol = systemSymbol ;
     }
     
-    /** Processes evaluated args */
+    // Need to intercept exec so we can get to the FunctionEnv
     @Override
-    public NodeValue exec()
-    {
-        Object obj = getContext().get(systemSymbol) ;
-        
+    public NodeValue exec(Binding binding, ExprList args, String uri, FunctionEnv env) {
+        // Ignore arguments.
+        Object obj = env.getContext().get(systemSymbol) ;
         if ( obj == null )
             throw new ExprEvalException("null for system symbol: "+systemSymbol) ;
         if ( ! ( obj instanceof Node ) )
@@ -58,4 +59,7 @@ public class SystemVar extends FunctionBase0
         NodeValue nv = NodeValue.makeNode(n) ;
         return nv ;
     }
+
+    @Override
+    public void build(String uri, ExprList args) {}
 }