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 14:11:47 UTC
svn commit: r1356689 - in
/velocity/sandbox/jsr223/velocity-engine-scripting/src:
main/java/org/apache/velocity/script/
test/java/org/apache/velocity/script/test/
Author: dishara
Date: Tue Jul 3 12:11:46 2012
New Revision: 1356689
URL: http://svn.apache.org/viewvc?rev=1356689&view=rev
Log:
Adding comments to VelocityBinding
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/VelocityScriptEngine.java
velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/BasicTest.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=1356689&r1=1356688&r2=1356689&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 12:11:46 2012
@@ -31,6 +31,10 @@ public class VelocityBindings implements
private Map<String,Object> map;
+ /**
+ *
+ * @param map pre created binding map passed to initialize.
+ */
public VelocityBindings(Map<String,Object> map) {
if(map == null) {
throw new NullPointerException("Cannot pass a null map to initialize VelocityBindings");
@@ -38,20 +42,28 @@ public class VelocityBindings implements
this.map = map;
}
+ /**
+ * Default constructor which creates a new Map instance
+ */
public VelocityBindings(){
this.map = new HashMap<String, Object>();
}
-
+ /**
+ * Set a named value.
+ * @param s The name associated with the value.
+ * @param o The value associated with the name.
+ * @return The value previously associated with the given key/name. Returns null if no value was previously associated with the name.
+ */
public Object put(String s, Object o) {
validateKey(s);
return map.put(s,o);
}
/**
- * Inherits from Context
+ * Inherits from org.apache.velocity.Context
* @param key The name of the desired value.
- * @return
+ * @return Returns the value associate with the given key
*/
public Object get(String key) {
validateKey(key);
@@ -59,12 +71,17 @@ public class VelocityBindings implements
}
/**
- * inherits from Context
+ * Inherits from org.apache.velocity.Context
+ * @return All names added in the map
*/
public Object[] getKeys() {
return map.keySet().toArray();
}
+ /**
+ *
+ * @param map , All the values in this map will be add in to the binding
+ */
public void putAll(Map<? extends String, ? extends Object> map) {
for (Map.Entry<? extends String, ? extends Object> entry : map.entrySet()) {
String key = entry.getKey();
@@ -73,52 +90,99 @@ public class VelocityBindings implements
}
}
+ /**
+ * Clears the map
+ */
public void clear() {
map.clear();
}
+ /**
+ *
+ * @return returns the keys as a Set collection
+ */
public Set<String> keySet() {
return map.keySet();
}
+ /**
+ *
+ * @return Returns all values associated win the map
+ */
public Collection<Object> values() {
return map.values();
}
+ /**
+ * EntrySet in interface java.util.Map<java.lang.String,java.lang.Object>
+ * @return entrySet
+ */
public Set<Entry<String, Object>> entrySet() {
return map.entrySet();
}
+ /**
+ *
+ * @return the size of the map
+ */
public int size() {
return map.size();
}
+ /**
+ *
+ * @return whether the map is empty
+ */
public boolean isEmpty() {
return map.isEmpty();
}
+ /**
+ * Check whether the given name is already binded to a value
+ * @param o name
+ * @return true if the given name contains a binding else false
+ */
public boolean containsKey(Object o) {
validateKey(o);
return map.containsKey(o);
}
+ /**
+ * Check whether the given value is already binded to a name in the map
+ * @param o name
+ * @return true if the given value contains a binding else false
+ */
public boolean containsValue(Object o) {
return map.containsValue(o);
}
+ /**
+ * Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map
+ * contains a mapping for a key k such that (key==null ? k==null : key.equals(k)).
+ * @param o name
+ * @return the value binded to the given name
+ */
public Object get(Object o) {
validateKey(o);
return map.get(o);
}
+ /**
+ * Removes the mapping for this key from this map if it is present (optional operation).
+ * @param o name
+ * @return Remove the value binded to the given name and the name itself from the mapping
+ */
public Object remove(Object o) {
validateKey(o);
return map.remove(o);
}
/**
- * Validates key and throw corresponding exceptions for JSR 223 compliance
- * @param key
+ * Validates key and throw corresponding exceptions for JSR 223 compliance
+ * Throws: java.lang.NullPointerException - if key is null
+ * java.lang.ClassCastException - if key is not String
+ * java.lang.IllegalArgumentException - if key is empty String
+ * @param key which used to validate the binding
*/
private void validateKey(Object key) {
if (key == null) {
Modified: velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptEngine.java
URL: http://svn.apache.org/viewvc/velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptEngine.java?rev=1356689&r1=1356688&r2=1356689&view=diff
==============================================================================
--- velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptEngine.java (original)
+++ velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptEngine.java Tue Jul 3 12:11:46 2012
@@ -99,7 +99,7 @@ public class VelocityScriptEngine implem
}
private void initVelocityEngine(Properties props) {
- if (velocityEngine != null) {
+ if (velocityEngine == null) {
synchronized (this) {
velocityEngine = new VelocityEngine();
velocityEngine.init(props);
Modified: velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/BasicTest.java
URL: http://svn.apache.org/viewvc/velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/BasicTest.java?rev=1356689&r1=1356688&r2=1356689&view=diff
==============================================================================
--- velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/BasicTest.java (original)
+++ velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/BasicTest.java Tue Jul 3 12:11:46 2012
@@ -34,6 +34,7 @@ public class BasicTest {
@Test
public void simpleTestCase() throws ScriptException {
+ System.setProperty(VelocityScriptEngine.VELOCITY_PROPERTIES,"/home/dishara/tmp/jsr223/velocity-engine-examples/src/main/resources/velocity.properties") ;
ScriptEngineManager manager = new ScriptEngineManager();
manager.registerEngineName("velocity",new VelocityScriptEngineFactory());
@@ -41,6 +42,8 @@ public class BasicTest {
ScriptEngineFactory fac = engine.getFactory();
engine.put("first", "HELLO");
engine.put("second", "world");
+ System.out.println("#####"+ engine.eval("----this is a comment, set variable name with \"Edw\" value"));
+
//TODO this is a dummt test infact. Need to complete the rest as engine impl finishes.
}
}