incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1163590 - /incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/
Date Wed, 31 Aug 2011 12:03:45 GMT
Author: kwright
Date: Wed Aug 31 12:03:44 2011
New Revision: 1163590

URL: http://svn.apache.org/viewvc?rev=1163590&view=rev
Log:
Various script language cleanups.  Also, lay the groundwork for introducing dictionary variables,
which should make the handling of json responses much easier.

Modified:
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/Variable.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableArray.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBase.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBoolean.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfiguration.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfigurationNode.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConnectionName.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableFloat.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableInt.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableResult.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableString.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/Variable.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/Variable.java?rev=1163590&r1=1163589&r2=1163590&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/Variable.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/Variable.java
Wed Aug 31 12:03:44 2011
@@ -44,6 +44,8 @@ public interface Variable
   public static String ATTRIBUTE_VALUE = "__value__";
   /** Size attribute */
   public static String ATTRIBUTE_SIZE = "__size__";
+  /** Dict attribute */
+  public static String ATTRIBUTE_DICT = "__dict__";
   /** OK status attribute */
   public static String ATTRIBUTE_OKSTATUS = "__OK__";
   /** NOTFOUND status attribute */
@@ -55,6 +57,10 @@ public interface Variable
   public String getStringValue()
     throws ScriptException;
 
+  /** Get the variable's script value */
+  public String getScriptValue()
+    throws ScriptException;
+
   /** Get the variable's value as a Configuration object */
   public Configuration getConfigurationValue()
     throws ScriptException;

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableArray.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableArray.java?rev=1163590&r1=1163589&r2=1163590&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableArray.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableArray.java
Wed Aug 31 12:03:44 2011
@@ -31,9 +31,41 @@ public class VariableArray extends Varia
   public VariableArray()
   {
   }
+  
+  public int hashCode()
+  {
+    int rval = 0;
+    int i = 0;
+    while (i < array.size())
+    {
+      Variable v = array.get(i++);
+      rval += v.hashCode();
+    }
+    return rval;
+  }
 
-  /** Get a displayable string from this */
-  public String toString()
+  public boolean equals(Object o)
+  {
+    if (!(o instanceof VariableArray))
+      return false;
+    VariableArray va = (VariableArray)o;
+    if (va.array.size() != array.size())
+      return false;
+    int i = 0;
+    while (i < array.size())
+    {
+      Variable v = array.get(i);
+      Variable v2 = va.array.get(i);
+      if (!v.equals(v2))
+        return false;
+      i++;
+    }
+    return true;
+  }
+  
+  /** Get the variable's script value */
+  public String getScriptValue()
+    throws ScriptException
   {
     StringBuilder sb = new StringBuilder("[ ");
     int i = 0;

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBase.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBase.java?rev=1163590&r1=1163589&r2=1163590&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBase.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBase.java
Wed Aug 31 12:03:44 2011
@@ -36,6 +36,13 @@ public class VariableBase implements Var
   {
     throw new ScriptException("Cannot convert variable to string");
   }
+
+  /** Get the variable's script value */
+  public String getScriptValue()
+    throws ScriptException
+  {
+    throw new ScriptException("Variable has no script value");
+  }
   
   /** Get the variable's value as a Configuration object */
   public Configuration getConfigurationValue()
@@ -185,7 +192,7 @@ public class VariableBase implements Var
     else if (attributeName.equals(ATTRIBUTE_BOOLEAN))
       return new VariableBoolean(getBooleanValue());
     else if (attributeName.equals(ATTRIBUTE_SCRIPT))
-      return new VariableString(toString());
+      return new VariableString(getScriptValue());
     else
       throw new ScriptException("Variable has no attribute called '"+attributeName+"'");
   }

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBoolean.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBoolean.java?rev=1163590&r1=1163589&r2=1163590&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBoolean.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableBoolean.java
Wed Aug 31 12:03:44 2011
@@ -30,8 +30,21 @@ public class VariableBoolean extends Var
     this.value = value;
   }
 
-  /** Get a displayable string for the value */
-  public String toString()
+  public int hashCode()
+  {
+    return new Boolean(value).hashCode();
+  }
+  
+  public boolean equals(Object o)
+  {
+    if (!(o instanceof VariableBoolean))
+      return false;
+    return ((VariableBoolean)o).value == value;
+  }
+
+  /** Get the variable's script value */
+  public String getScriptValue()
+    throws ScriptException
   {
     if (value)
       return "true";

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfiguration.java?rev=1163590&r1=1163589&r2=1163590&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfiguration.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfiguration.java
Wed Aug 31 12:03:44 2011
@@ -51,8 +51,9 @@ public class VariableConfiguration exten
     }
   }
   
-  /** Get a string from this */
-  public String toString()
+  /** Get the variable's script value */
+  public String getScriptValue()
+    throws ScriptException
   {
     StringBuilder sb = new StringBuilder();
     sb.append("{ ");

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfigurationNode.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfigurationNode.java?rev=1163590&r1=1163589&r2=1163590&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfigurationNode.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConfigurationNode.java
Wed Aug 31 12:03:44 2011
@@ -38,8 +38,9 @@ public class VariableConfigurationNode e
     configurationNode = node;
   }
   
-  /** Get the variable's value as a string */
-  public String toString()
+  /** Get the variable's script value */
+  public String getScriptValue()
+    throws ScriptException
   {
     StringBuilder sb = new StringBuilder();
     sb.append("<< ");

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConnectionName.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConnectionName.java?rev=1163590&r1=1163589&r2=1163590&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConnectionName.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableConnectionName.java
Wed Aug 31 12:03:44 2011
@@ -34,8 +34,22 @@ public class VariableConnectionName exte
     this.connectionName = connectionName;
     this.encodedConnectionName = encode(connectionName);
   }
+
+  public int hashCode()
+  {
+    return connectionName.hashCode();
+  }
   
-  public String toString()
+  public boolean equals(Object o)
+  {
+    if (!(o instanceof VariableConnectionName))
+      return false;
+    return ((VariableConnectionName)o).connectionName.equals(connectionName);
+  }
+
+  /** Get the variable's script value */
+  public String getScriptValue()
+    throws ScriptException
   {
     StringBuilder sb = new StringBuilder();
     sb.append("(new connectionname \"");

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableFloat.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableFloat.java?rev=1163590&r1=1163589&r2=1163590&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableFloat.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableFloat.java
Wed Aug 31 12:03:44 2011
@@ -30,8 +30,21 @@ public class VariableFloat extends Varia
     this.value = value;
   }
   
-  /** Get a displayable string for the value */
-  public String toString()
+  public int hashCode()
+  {
+    return new Double(value).hashCode();
+  }
+  
+  public boolean equals(Object o)
+  {
+    if (!(o instanceof VariableFloat))
+      return false;
+    return ((VariableFloat)o).value == value;
+  }
+
+  /** Get the variable's script value */
+  public String getScriptValue()
+    throws ScriptException
   {
     return new Double(value).toString();
   }

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableInt.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableInt.java?rev=1163590&r1=1163589&r2=1163590&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableInt.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableInt.java
Wed Aug 31 12:03:44 2011
@@ -30,8 +30,21 @@ public class VariableInt extends Variabl
     this.value = value;
   }
 
-  /** Get a displayable string for the value */
-  public String toString()
+  public int hashCode()
+  {
+    return new Integer(value).hashCode();
+  }
+  
+  public boolean equals(Object o)
+  {
+    if (!(o instanceof VariableInt))
+      return false;
+    return ((VariableInt)o).value == value;
+  }
+  
+  /** Get the variable's script value */
+  public String getScriptValue()
+    throws ScriptException
   {
     return Integer.toString(value);
   }

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableResult.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableResult.java?rev=1163590&r1=1163589&r2=1163590&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableResult.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableResult.java
Wed Aug 31 12:03:44 2011
@@ -34,8 +34,9 @@ public class VariableResult extends Vari
     this.result = new VariableConfiguration(json);
   }
   
-  /** Get the variable's value as a string */
-  public String toString()
+  /** Get the variable's script value */
+  public String getScriptValue()
+    throws ScriptException
   {
     return "("+Integer.toString(resultCode)+") "+result.toString();
   }

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableString.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableString.java?rev=1163590&r1=1163589&r2=1163590&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableString.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableString.java
Wed Aug 31 12:03:44 2011
@@ -30,8 +30,21 @@ public class VariableString extends Vari
     this.value = value;
   }
 
-  /** Get a displayable string for the value */
-  public String toString()
+  public int hashCode()
+  {
+    return value.hashCode();
+  }
+  
+  public boolean equals(Object o)
+  {
+    if (!(o instanceof VariableString))
+      return false;
+    return ((VariableString)o).value.equals(value);
+  }
+
+  /** Get the variable's script value */
+  public String getScriptValue()
+    throws ScriptException
   {
     StringBuilder sb = new StringBuilder();
     sb.append("\"");

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java?rev=1163590&r1=1163589&r2=1163590&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/VariableURL.java
Wed Aug 31 12:03:44 2011
@@ -36,7 +36,21 @@ public class VariableURL extends Variabl
       this.encodedURL = this.encodedURL.substring(0,this.encodedURL.length()-1);
   }
   
-  public String toString()
+  public int hashCode()
+  {
+    return encodedURL.hashCode();
+  }
+  
+  public boolean equals(Object o)
+  {
+    if (!(o instanceof VariableURL))
+      return false;
+    return ((VariableURL)o).encodedURL.equals(encodedURL);
+  }
+
+  /** Get the variable's script value */
+  public String getScriptValue()
+    throws ScriptException
   {
     StringBuilder sb = new StringBuilder();
     sb.append("\"");



Mime
View raw message