You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by di...@apache.org on 2012/07/03 16:27:14 UTC

svn commit: r1356751 - in /velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script: VelocityBindings.java VelocityScriptContext.java

Author: dishara
Date: Tue Jul  3 14:27:13 2012
New Revision: 1356751

URL: http://svn.apache.org/viewvc?rev=1356751&view=rev
Log:
Adding comments to VelocityScript

Modified:
    velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityBindings.java
    velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptContext.java

Modified: velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityBindings.java
URL: http://svn.apache.org/viewvc/velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityBindings.java?rev=1356751&r1=1356750&r2=1356751&view=diff
==============================================================================
--- velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityBindings.java (original)
+++ velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityBindings.java Tue Jul  3 14:27:13 2012
@@ -29,6 +29,9 @@ import java.util.Set;
 
 public class VelocityBindings implements Bindings,Context {
 
+  /**
+     * Map which keeps the binding of names and associated values
+     */
     private Map<String,Object> map;
 
   /**

Modified: velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptContext.java
URL: http://svn.apache.org/viewvc/velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptContext.java?rev=1356751&r1=1356750&r2=1356751&view=diff
==============================================================================
--- velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptContext.java (original)
+++ velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptContext.java Tue Jul  3 14:27:13 2012
@@ -33,18 +33,53 @@ import java.util.List;
 
 public class VelocityScriptContext implements ScriptContext {
 
+    /**
+     *    A binding reference dedicated to  cover engine scope
+     */
     private Bindings engineScope;
+
+
+    /**
+     *   A binding reference dedicated to  cover global scope
+     */
     private Bindings globalScope;
+
+
+    /**
+     *   Script context reader  for system in put. In other words Reader to be used by the script to read input.
+     */
     private Reader reader;
+
+
+    /**
+     *   The Writer for scripts to use when displaying output.
+     */
     private Writer writer;
+
+
+    /**
+     *  A dedicated Writer used to display error output.
+     */
     private Writer errorWriter;
+
+
+    /**
+     *    List which stores the scopes supported by the scripting engine
+     */
     private static List<Integer> scopes;
 
 
+    /**
+     *    Default constructor which init the scopes and readers and writers
+     */
     public VelocityScriptContext() {
          init();
     }
 
+
+    /**
+     *   Instantiates the scopes(global and engine), readers and writers for the context
+     */
     private void init() {
         engineScope = new VelocityBindings();
         globalScope = null;
@@ -54,6 +89,14 @@ public class VelocityScriptContext imple
     }
 
 
+  /**
+     *  Associates a Bindings instance with a particular scope in this ScriptContext
+     * @param bindings  The Bindings to associate with the given scope
+     * @param i  scope
+     *  Throws:
+     * java.lang.IllegalArgumentException - If no Bindings is defined for the specified scope value in ScriptContexts of this type.
+     * java.lang.NullPointerException - if value of scope is ENGINE_SCOPE and the specified Bindings is null.
+     */
     public void setBindings(Bindings bindings, int i)  {
         switch (i){
          case ENGINE_SCOPE:
@@ -70,9 +113,14 @@ public class VelocityScriptContext imple
          default:
              throw new IllegalArgumentException("Invalid scope value");
         }
-
     }
 
+
+  /**
+     * @param i  scope
+     * @return   The associated Bindings. Returns null if it has not been set.
+     * throws java.lang.IllegalArgumentException - If no Bindings is defined for the specified scope value in ScriptContext of this type.
+     */
     public Bindings getBindings(int i) {
        switch (i) {
          case ENGINE_SCOPE:
@@ -84,7 +132,23 @@ public class VelocityScriptContext imple
         }
     }
 
+
+
+  /**
+     *  Sets the value of an attribute in a given scope.
+     * @param s  attribute name
+     * @param o  attribute value
+     * @param i  scope
+     * Throws
+     * java.lang.IllegalArgumentException - if the name is empty or if the scope is invalid.
+     * java.lang.NullPointerException - if the name is null.
+     */
     public void setAttribute(String s, Object o, int i) {
+
+         if(s == null) {
+             throw new NullPointerException("Name cannot be null .");
+         }
+
          switch (i) {
          case ENGINE_SCOPE:
               engineScope.put(s,o);
@@ -97,10 +161,25 @@ public class VelocityScriptContext imple
          default:
              throw new IllegalArgumentException("Invalid scope value");
         }
-
     }
 
+
+
+  /**
+     *  Gets the value of an attribute in a given scope.
+     * @param s  name of the attribute
+     * @param i  scope
+     * @return  The value of the attribute. Returns null is the name does not exist in the given scope.
+     * Throws :
+     *  java.lang.IllegalArgumentException - if the name is empty or if the value of scope is invalid.
+     * java.lang.NullPointerException - if the name is null.
+     */
     public Object getAttribute(String s, int i) {
+
+         if(s == null) {
+             throw new NullPointerException("Name cannot be null .");
+         }
+
         switch (i) {
         case ENGINE_SCOPE:
              return engineScope.get(s);
@@ -113,8 +192,25 @@ public class VelocityScriptContext imple
             throw new IllegalArgumentException("Invalid scope value");
        }
 
-}
+    }
+
+
+
+  /**
+     *   Remove an attribute in a given scope.
+     * @param s   The name of the attribute to remove
+     * @param i  The scope in which to remove the attribute
+     * @return   The removed value
+     * Throws:
+     * java.lang.IllegalArgumentException - if the name is empty or if the scope is invalid.
+     * java.lang.NullPointerException - if the name is null.
+     */
     public Object removeAttribute(String s, int i) {
+
+         if(s == null) {
+             throw new NullPointerException("Name cannot be null .");
+         }
+
         switch (i) {
         case ENGINE_SCOPE:
              return engineScope.remove(s);
@@ -129,7 +225,22 @@ public class VelocityScriptContext imple
 
     }
 
+
+  /**
+     * Retrieves the value of the attribute with the given name in the scope occurring earliest in the search order.
+     * The order is determined by the numeric value of the scope parameter (lowest scope values first.
+     * @param s   name of the attribute to return
+     * @return   The value of the attribute in the lowest scope for which an attribute with the given name is defined. Returns null
+     * if no attribute with the name exists in any scope.
+     * Throws:
+     * java.lang.NullPointerException - if the name is null.
+     * java.lang.IllegalArgumentException - if the name is empty.
+     */
     public Object getAttribute(String s) {
+         if(s == null) {
+             throw new NullPointerException("Name cannot be null .");
+         }
+
         if(engineScope.containsKey(s)) {
          return getAttribute(s,ENGINE_SCOPE);
         } else if (globalScope != null && (globalScope.containsKey(s))) {
@@ -138,7 +249,20 @@ public class VelocityScriptContext imple
         return null;
     }
 
+
+  /**
+     *  Get the lowest scope in which an attribute is defined.
+     * @param s name of the attribute
+     * @return  The lowest scope. Returns -1 if no attribute with the given name is defined in any scope.
+     * Throws:
+     * java.lang.NullPointerException - if name is null.
+     * java.lang.IllegalArgumentException - if name is empty.
+     */
     public int getAttributesScope(String s) {
+
+        if(s == null) {
+             throw new NullPointerException("Name cannot be null .");
+        }
         if(engineScope.containsKey(s)) {
            return ENGINE_SCOPE;
         } else if(globalScope != null && globalScope.containsKey(s)) {
@@ -148,30 +272,65 @@ public class VelocityScriptContext imple
         }
     }
 
+
+  /**
+     *  Returns the Writer for scripts to use when displaying output.
+     * @return
+     */
     public Writer getWriter() {
         return writer;
     }
 
+
+  /**
+     *  Returns the Writer used to display error output.
+     * @return
+     */
     public Writer getErrorWriter() {
         return errorWriter;
     }
 
+
+  /**
+     *   Sets the Writer for scripts to use when displaying output.
+     * @param writer
+     */
     public void setWriter(Writer writer) {
         this.writer = writer;
     }
 
+
+  /**
+     *  Sets the Writer used to display error output.
+     * @param writer
+     */
     public void setErrorWriter(Writer writer) {
         this.errorWriter = writer;
     }
 
+
+  /**
+     *  Returns a Reader to be used by the script to read input.
+     * @return
+     */
     public Reader getReader() {
         return reader;
     }
 
+
+  /**
+     *  Sets the Reader for scripts to read input .
+     * @param reader
+     */
     public void setReader(Reader reader) {
         this.reader = reader;
     }
 
+
+  /**
+     *  Returns immutable List of all the valid values for scope in the ScriptContext.
+     * @return
+     */
     public List<Integer> getScopes() {
         return scopes;
     }