incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1160708 - /incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/
Date Tue, 23 Aug 2011 14:22:47 GMT
Author: kwright
Date: Tue Aug 23 14:22:47 2011
New Revision: 1160708

URL: http://svn.apache.org/viewvc?rev=1160708&view=rev
Log:
Tie up error handling for null cases

Modified:
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/DELETECommand.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/GETCommand.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/IfCommand.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PrintCommand.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/WhileCommand.java

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/DELETECommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/DELETECommand.java?rev=1160708&r1=1160707&r2=1160708&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/DELETECommand.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/DELETECommand.java
Tue Aug 23 14:22:47 2011
@@ -46,7 +46,7 @@ public class DELETECommand implements Co
       sp.syntaxError(currentStream,"Missing URL expression");
     
     // Perform the actual GET.
-    String urlString = url.resolve().getStringValue();
+    String urlString = sp.resolveMustExist(currentStream,url).getStringValue();
     
     try
     {

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/GETCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/GETCommand.java?rev=1160708&r1=1160707&r2=1160708&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/GETCommand.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/GETCommand.java
Tue Aug 23 14:22:47 2011
@@ -46,7 +46,7 @@ public class GETCommand implements Comma
       sp.syntaxError(currentStream,"Missing URL expression");
     
     // Perform the actual GET.
-    String urlString = url.resolve().getStringValue();
+    String urlString = sp.resolveMustExist(currentStream,url).getStringValue();
     
     try
     {

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/IfCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/IfCommand.java?rev=1160708&r1=1160707&r2=1160708&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/IfCommand.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/IfCommand.java
Tue Aug 23 14:22:47 2011
@@ -37,7 +37,7 @@ public class IfCommand implements Comman
     if (t == null || t.getToken() == null || !t.getToken().equals("then"))
       sp.syntaxError(currentStream,"Missing 'then' in if statement");
     currentStream.skip();
-    if (ifCondition.resolve().getBooleanValue())
+    if (sp.resolveMustExist(currentStream,ifCondition).getBooleanValue())
     {
       rval = sp.parseStatements(currentStream);
       t = currentStream.peek();

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java?rev=1160708&r1=1160707&r2=1160708&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java
Tue Aug 23 14:22:47 2011
@@ -53,8 +53,8 @@ public class POSTCommand implements Comm
       sp.syntaxError(currentStream,"Missing URL expression");
     
     // Perform the actual PUT.
-    String urlString = url.resolve().getStringValue();
-    String json = send.resolve().getJSONValue();
+    String urlString = sp.resolveMustExist(currentStream,url).getStringValue();
+    String json = sp.resolveMustExist(currentStream,send).getJSONValue();
     
     try
     {

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.java?rev=1160708&r1=1160707&r2=1160708&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.java
Tue Aug 23 14:22:47 2011
@@ -53,8 +53,8 @@ public class PUTCommand implements Comma
       sp.syntaxError(currentStream,"Missing URL expression");
     
     // Perform the actual PUT.
-    String urlString = url.resolve().getStringValue();
-    String json = send.resolve().getJSONValue();
+    String urlString = sp.resolveMustExist(currentStream,url).getStringValue();
+    String json = sp.resolveMustExist(currentStream,send).getJSONValue();
     
     try
     {

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PrintCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PrintCommand.java?rev=1160708&r1=1160707&r2=1160708&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PrintCommand.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PrintCommand.java
Tue Aug 23 14:22:47 2011
@@ -32,7 +32,7 @@ public class PrintCommand implements Com
     VariableReference expr = sp.evaluateExpression(currentStream);
     if (expr == null)
       sp.syntaxError(currentStream,"Missing print expression");
-    System.out.println(expr.resolve().getStringValue());
+    System.out.println(sp.resolveMustExist(currentStream,expr).getStringValue());
     return false;
   }
   

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java?rev=1160708&r1=1160707&r2=1160708&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java
Tue Aug 23 14:22:47 2011
@@ -193,7 +193,7 @@ public class ScriptParser
         VariableReference v = evaluateExpression_1(currentStream);
         if (v == null)
           syntaxError(currentStream,"Missing expression after '||'");
-        vr = resolveMustExist(vr).doublePipe(v.resolve());
+        vr = resolveMustExist(currentStream,vr).doublePipe(v.resolve());
       }
       else if (t != null && t.getPunctuation() != null && t.getPunctuation().equals("|"))
       {
@@ -201,7 +201,7 @@ public class ScriptParser
         VariableReference v = evaluateExpression_1(currentStream);
         if (v == null)
           syntaxError(currentStream,"Missing expression after '|'");
-        vr = resolveMustExist(vr).pipe(v.resolve());
+        vr = resolveMustExist(currentStream,vr).pipe(v.resolve());
       }
       else
         break;
@@ -256,7 +256,7 @@ public class ScriptParser
         VariableReference v = evaluateExpression_2(currentStream);
         if (v == null)
           syntaxError(currentStream,"Missing expression after '&&'");
-        vr = resolveMustExist(vr).doubleAmpersand(v.resolve());
+        vr = resolveMustExist(currentStream,vr).doubleAmpersand(v.resolve());
       }
       else if (t != null && t.getPunctuation() != null && t.getPunctuation().equals("&"))
       {
@@ -264,7 +264,7 @@ public class ScriptParser
         VariableReference v = evaluateExpression_2(currentStream);
         if (v == null)
           syntaxError(currentStream,"Missing expression after '&'");
-        vr = resolveMustExist(vr).ampersand(v.resolve());
+        vr = resolveMustExist(currentStream,vr).ampersand(v.resolve());
       }
       else
         break;
@@ -310,7 +310,7 @@ public class ScriptParser
       VariableReference v = evaluateExpression_2(currentStream);
       if (v == null)
         syntaxError(currentStream,"Missing expression after '!'");
-      return resolveMustExist(v).unaryExclamation();
+      return resolveMustExist(currentStream,v).unaryExclamation();
     }
     return evaluateExpression_3(currentStream);
   }
@@ -346,7 +346,7 @@ public class ScriptParser
         VariableReference v = evaluateExpression_4(currentStream);
         if (v == null)
           syntaxError(currentStream,"Missing expression after '=='");
-        vr = resolveMustExist(vr).doubleEquals(v.resolve());
+        vr = resolveMustExist(currentStream,vr).doubleEquals(v.resolve());
       }
       else if (t != null && t.getPunctuation() != null && t.getPunctuation().equals("!="))
       {
@@ -354,7 +354,7 @@ public class ScriptParser
         VariableReference v = evaluateExpression_4(currentStream);
         if (v == null)
           syntaxError(currentStream,"Missing expression after '!='");
-        vr = resolveMustExist(vr).exclamationEquals(v.resolve());
+        vr = resolveMustExist(currentStream,vr).exclamationEquals(v.resolve());
       }
       else if (t != null && t.getPunctuation() != null && t.getPunctuation().equals("<"))
       {
@@ -362,7 +362,7 @@ public class ScriptParser
         VariableReference v = evaluateExpression_4(currentStream);
         if (v == null)
           syntaxError(currentStream,"Missing expression after '<'");
-        vr = resolveMustExist(vr).lesserAngle(v.resolve());
+        vr = resolveMustExist(currentStream,vr).lesserAngle(v.resolve());
       }
       else if (t != null && t.getPunctuation() != null && t.getPunctuation().equals(">"))
       {
@@ -370,7 +370,7 @@ public class ScriptParser
         VariableReference v = evaluateExpression_4(currentStream);
         if (v == null)
           syntaxError(currentStream,"Missing expression after '>'");
-        vr = resolveMustExist(vr).greaterAngle(v.resolve());
+        vr = resolveMustExist(currentStream,vr).greaterAngle(v.resolve());
       }
       else if (t != null && t.getPunctuation() != null && t.getPunctuation().equals("<="))
       {
@@ -378,7 +378,7 @@ public class ScriptParser
         VariableReference v = evaluateExpression_4(currentStream);
         if (v == null)
           syntaxError(currentStream,"Missing expression after '<='");
-        vr = resolveMustExist(vr).lesserAngleEquals(v.resolve());
+        vr = resolveMustExist(currentStream,vr).lesserAngleEquals(v.resolve());
       }
       else if (t != null && t.getPunctuation() != null && t.getPunctuation().equals(">="))
       {
@@ -386,7 +386,7 @@ public class ScriptParser
         VariableReference v = evaluateExpression_4(currentStream);
         if (v == null)
           syntaxError(currentStream,"Missing expression after '>='");
-        vr = resolveMustExist(vr).greaterAngleEquals(v.resolve());
+        vr = resolveMustExist(currentStream,vr).greaterAngleEquals(v.resolve());
       }
       else
         break;
@@ -461,7 +461,7 @@ public class ScriptParser
         VariableReference v = evaluateExpression_5(currentStream);
         if (v == null)
           syntaxError(currentStream,"Missing expression after '+'");
-        vr = resolveMustExist(vr).plus(v.resolve());
+        vr = resolveMustExist(currentStream,vr).plus(v.resolve());
       }
       else if (t != null && t.getPunctuation() != null && t.getPunctuation().equals("-"))
       {
@@ -469,7 +469,7 @@ public class ScriptParser
         VariableReference v = evaluateExpression_5(currentStream);
         if (v == null)
           syntaxError(currentStream,"Missing expression after '-'");
-        vr = resolveMustExist(vr).minus(v.resolve());
+        vr = resolveMustExist(currentStream,vr).minus(v.resolve());
       }
       else
         break;
@@ -520,7 +520,7 @@ public class ScriptParser
         VariableReference v = evaluateExpression_6(currentStream);
         if (v == null)
           syntaxError(currentStream,"Missing expression after '*'");
-        vr = resolveMustExist(vr).asterisk(v.resolve());
+        vr = resolveMustExist(currentStream,vr).asterisk(v.resolve());
       }
       else if (t != null && t.getPunctuation() != null && t.getPunctuation().equals("/"))
       {
@@ -528,7 +528,7 @@ public class ScriptParser
         VariableReference v = evaluateExpression_6(currentStream);
         if (v == null)
           syntaxError(currentStream,"Missing expression after '/'");
-        vr = resolveMustExist(vr).slash(v.resolve());
+        vr = resolveMustExist(currentStream,vr).slash(v.resolve());
       }
       else
         break;
@@ -574,7 +574,7 @@ public class ScriptParser
       VariableReference v = evaluateExpression_6(currentStream);
       if (v == null)
         syntaxError(currentStream,"Missing expression after '-'");
-      return resolveMustExist(v).unaryMinus();
+      return resolveMustExist(currentStream,v).unaryMinus();
     }
     return parseVariableReference(currentStream);
   }
@@ -648,8 +648,8 @@ public class ScriptParser
 	VariableReference expression = evaluateExpression(currentStream);
 	if (expression == null)
 	  syntaxError(currentStream,"Missing expression after '['");
-	int indexValue = resolveMustExist(expression).getIntValue();
-	vr = resolveMustExist(vr).getIndexed(indexValue);
+	int indexValue = resolveMustExist(currentStream,expression).getIntValue();
+	vr = resolveMustExist(currentStream,vr).getIndexed(indexValue);
 	t = currentStream.peek();
 	if (t == null || t.getPunctuation() == null || !t.getPunctuation().equals("]"))
 	  syntaxError(currentStream,"Missing ']'");
@@ -661,7 +661,7 @@ public class ScriptParser
 	t = currentStream.peek();
 	if (t == null || t.getToken() == null)
 	  syntaxError(currentStream,"Need attribute name");
-	vr = resolveMustExist(vr).getAttribute(t.getToken());
+	vr = resolveMustExist(currentStream,vr).getAttribute(t.getToken());
 	currentStream.skip();
       }
       else
@@ -817,22 +817,29 @@ public class ScriptParser
   public static void syntaxError(TokenStream currentStream, String message)
     throws ScriptException
   {
-    Token t = currentStream.peek();
-    if (t == null)
-      throw new ScriptException("Syntax error: "+message+", at end of file");
-    else
-      t.throwException("Syntax error: "+message+": "+t);
+    localError(currentStream,"Syntax error: "+message);
   }
   
-  public static Variable resolveMustExist(VariableReference vr)
+  public static Variable resolveMustExist(TokenStream currentStream, VariableReference vr)
     throws ScriptException
   {
     Variable v = vr.resolve();
     if (v == null)
-      throw new ScriptException("Expression cannot be null");
+      localError(currentStream,"Expression cannot be null");
     return v;
   }
   
+  public static void localError(TokenStream currentStream, String message)
+    throws ScriptException
+  {
+    Token t = currentStream.peek();
+    if (t == null)
+      throw new ScriptException(message+", at end of file");
+    else
+      t.throwException(message+": "+t);
+  }
+  
+  
   public static void main(String[] argv)
   {
     if (argv.length > 1)

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/WhileCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/WhileCommand.java?rev=1160708&r1=1160707&r2=1160708&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/WhileCommand.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/WhileCommand.java
Tue Aug 23 14:22:47 2011
@@ -46,7 +46,7 @@ public class WhileCommand implements Com
       if (t == null || t.getToken() == null || !t.getToken().equals("do"))
         sp.syntaxError(rts,"Missing 'do' in while statement");
       rts.skip();
-      if (whileCondition.resolve().getBooleanValue())
+      if (sp.resolveMustExist(rts,whileCondition).getBooleanValue())
       {
         breakFromLoop = sp.parseStatements(rts);
       }



Mime
View raw message