manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1161364 - in /incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine: Variable.java VariableBase.java
Date Thu, 25 Aug 2011 02:29:53 GMT
Author: kwright
Date: Thu Aug 25 02:29:52 2011
New Revision: 1161364

URL: http://svn.apache.org/viewvc?rev=1161364&view=rev
Log:
Add castes to give control over the data type

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/VariableBase.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=1161364&r1=1161363&r2=1161364&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
Thu Aug 25 02:29:52 2011
@@ -28,6 +28,14 @@ public interface Variable
 {
   // Special attributes
   
+  /** Conversion to string */
+  public static String ATTRIBUTE_STRING = "__string__";
+  /** Conversion to int */
+  public static String ATTRIBUTE_INT = "__int__";
+  /** Conversion to float */
+  public static String ATTRIBUTE_FLOAT = "__float__";
+  /** Conversion to boolean */
+  public static String ATTRIBUTE_BOOLEAN = "__boolean__";
   /** Name attribute */
   public static String ATTRIBUTE_NAME = "__name__";
   /** Value attribute */

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=1161364&r1=1161363&r2=1161364&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
Thu Aug 25 02:29:52 2011
@@ -176,7 +176,16 @@ public class VariableBase implements Var
   public VariableReference getAttribute(String attributeName)
     throws ScriptException
   {
-    throw new ScriptException("Variable has no attribute called '"+attributeName+"'");
+    if (attributeName.equals(ATTRIBUTE_STRING))
+      return new VariableString(getStringValue());
+    else if (attributeName.equals(ATTRIBUTE_INT))
+      return new VariableInt(getIntValue());
+    else if (attributeName.equals(ATTRIBUTE_FLOAT))
+      return new VariableFloat(getDoubleValue());
+    else if (attributeName.equals(ATTRIBUTE_BOOLEAN))
+      return new VariableBoolean(getBooleanValue());
+    else
+      throw new ScriptException("Variable has no attribute called '"+attributeName+"'");
   }
   
   /** Insert an object into this variable at a position. */



Mime
View raw message