dlr 01/10/21 19:37:50 Modified: src/java/org/apache/velocity VelocityContext.java Log: Patch cooked up by Geir and myself to address <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4321>. Adds two new ctors to support easy interoperability with the JDK's Map classes: public VelocityContext(Map context) public VelocityContext(Map context, Context innerContext) Revision Changes Path 1.5 +39 -16 jakarta-velocity/src/java/org/apache/velocity/VelocityContext.java Index: VelocityContext.java =================================================================== RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/VelocityContext.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -u -r1.4 -r1.5 --- VelocityContext.java 2001/03/19 22:32:49 1.4 +++ VelocityContext.java 2001/10/22 02:37:49 1.5 @@ -55,6 +55,7 @@ */ import java.util.HashMap; +import java.util.Map; import org.apache.velocity.context.AbstractContext; import org.apache.velocity.context.Context; @@ -79,24 +80,33 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a> * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> * @author <a href="mailto:[EMAIL PROTECTED]">Fedor Karpelevitch</a> - * @version $Id: VelocityContext.java,v 1.4 2001/03/19 22:32:49 geirm Exp $ + * @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a> + * @version $Id: VelocityContext.java,v 1.5 2001/10/22 02:37:49 dlr Exp $ */ public class VelocityContext extends AbstractContext implements Cloneable { /** - * storage for key/value pairs + * Storage for key/value pairs. */ - private HashMap context = new HashMap(); + private Map context = null; /** - * default contructor, does nothing - * interesting + * Creates a new instance (with no inner context). */ public VelocityContext() { - super(); + this(null, null); } + /** + * Creates a new instance with the provided storage (and no inner + * context). + */ + public VelocityContext(Map context) + { + this(context, null); + } + /** * Chaining constructor, used when you want to * wrap a context in another. The inner context @@ -104,13 +114,28 @@ * wrapping context will only effect the outermost * context * - * @param innerContext context impl to wrap + * @param innerContext The <code>Context</code> implementation to + * wrap. */ public VelocityContext( Context innerContext ) + { + this(null, innerContext); + } + + /** + * Initializes internal storage (never to <code>null</code>), and + * inner context. + * + * @param context Internal storage, or <code>null</code> to + * create default storage. + * @param innerContext Inner context. + */ + public VelocityContext(Map context, Context innerContext) { - super( innerContext ); + super(innerContext); + this.context = (context == null ? new HashMap() : context); } - + /** * retrieves value for key from internal * storage @@ -171,23 +196,21 @@ } /** - * Clones this context object - * @return Object an instance of this Context + * Clones this context object. + * + * @return A deep copy of this <code>Context</code>. */ public Object clone() { VelocityContext clone = null; - try { clone = (VelocityContext) super.clone(); - clone.context = (HashMap) context.clone(); + clone.context = new HashMap(context); } - catch (CloneNotSupportedException cnse) + catch (CloneNotSupportedException ignored) { } return clone; } - } -
