You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by ge...@locus.apache.org on 2000/12/30 15:42:01 UTC

cvs commit: jakarta-velocity/whiteboard/geir_context_20001228 InternalContext.java InternalContextBase.java AbstractContext.java Context.java README.txt velocity-0.71.jar

geirm       00/12/30 06:42:01

  Modified:    whiteboard/geir_context_20001228 AbstractContext.java
                        Context.java README.txt velocity-0.71.jar
  Added:       whiteboard/geir_context_20001228 InternalContext.java
                        InternalContextBase.java
  Log:
  Changes to implement jason's suggestion of getting rid of the public exposure
  of the InternalContext stuff.
  
  That's done here, preserving the user context info and the internal context
  info as a bundle so it will be preserved from use to use (so if you store it
  in your session...)
  
  Revision  Changes    Path
  1.3       +3 -13     jakarta-velocity/whiteboard/geir_context_20001228/AbstractContext.java
  
  Index: AbstractContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/whiteboard/geir_context_20001228/AbstractContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractContext.java	2000/12/29 22:19:05	1.2
  +++ AbstractContext.java	2000/12/30 14:42:00	1.3
  @@ -70,22 +70,16 @@
    * abstract routines that access your preferred storage method.
    *
    * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
  - * @version $Id: AbstractContext.java,v 1.2 2000/12/29 22:19:05 geirm Exp $
  + * @version $Id: AbstractContext.java,v 1.3 2000/12/30 14:42:00 geirm Exp $
    */
   
  -public abstract class AbstractContext implements Context, Serializable
  +public abstract class AbstractContext extends InternalContextBase  implements Context, InternalContext,  Serializable
   {
       /**
        *  we handle the context wrapping
        */
       private   Context  innerContext = null;
  -    
  -    /**
  -     *  for Velocity internal use : for introspection caching et al
  -     */
  -    private   InternalContextBase icb = new InternalContextBase();
  -
  - 
  +  
       /** implement to return a value from the context storage */
       public abstract Object internalGet( String key );
   
  @@ -192,7 +186,7 @@
   
       /**
        * Adds a name/value pair to the context.
  -     *
  +     * 
        * @param key   The name to key the provided value with.
        * @param value The corresponding value.
        */
  @@ -279,8 +273,4 @@
           return internalRemove(key);
       }        
   
  -    public InternalContext getInternalContext()
  -    {
  -        return icb;
  -    }
   }
  
  
  
  1.2       +1 -7      jakarta-velocity/whiteboard/geir_context_20001228/Context.java
  
  Index: Context.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/whiteboard/geir_context_20001228/Context.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Context.java	2000/12/29 19:21:28	1.1
  +++ Context.java	2000/12/30 14:42:00	1.2
  @@ -69,7 +69,7 @@
    * are stored in a Hashtable. 
    * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
    * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
  - * @version $Id: Context.java,v 1.1 2000/12/29 19:21:28 geirm Exp $
  + * @version $Id: Context.java,v 1.2 2000/12/30 14:42:00 geirm Exp $
    */
   public interface Context
   {
  @@ -97,7 +97,7 @@
        */
       public boolean containsKey(Object key);
   
  -    /*
  +    /**
        * Get all the keys for the values in the context
        */
       public Object[] getKeys();
  @@ -110,11 +110,5 @@
        *            if unmapped.
        */
       public Object remove(Object key);
  -
  -    /*
  -     * for internal use
  -     */
  -
  -    public InternalContext getInternalContext();
   }
   
  
  
  
  1.2       +12 -5     jakarta-velocity/whiteboard/geir_context_20001228/README.txt
  
  Index: README.txt
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/whiteboard/geir_context_20001228/README.txt,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- README.txt	2000/12/29 19:21:28	1.1
  +++ README.txt	2000/12/30 14:42:00	1.2
  @@ -34,9 +34,7 @@
   ---------
   Context.java : basic interface defintion.  It looks exactly like 
   the current Context, for the most part, except that put optionally
  -returns the Object it replaces, and the InternalContext crap is 
  -gotten as an object by the nodes rather than have the methods 
  -implemented by the Context.
  +returns the Object it replaces.
   
   AbstractContext.java : abstract class for a usable app-level Context.
   Handles the wrapping/chaining support as well as interfacing with the
  @@ -53,8 +51,8 @@
   TreeMapContext.java : another example of creating a new kind of Context, it uses
   a TreeMap for storage.
   
  -[yes, the two above aren't that interesting.  But show how one goes about
  -doing it. I'll try for a DBContext later when I have more time]
  +DBContext.jata : another [silly] example of a Context implementation that
  +serializes objects to and from a database (MySQL in my case...) Flaky, but works.
   
   MultiContextTest.java : the Test program but now uses the three above contexts
   together, wrapped/chained in a chain to demonstrate that it indeed works.
  @@ -65,6 +63,15 @@
   You can also use this against the testbed - chaining is used within the 
   TemplateTestCase.
   
  +Notes
  +-----
  +12/30/00
  +--------
  +1) It's snowing!
  +2) Jason had a great point - that the internalContext stuff should
  +be completely hidden from app level if possible - needed to remove 
  +the getInternalContext() accessor method from the Context interface and
  +the AbstractContext abstract base class.  So that's done.
   
   geir
   
  
  
  
  1.3       +381 -400  jakarta-velocity/whiteboard/geir_context_20001228/velocity-0.71.jar
  
  	<<Binary file>>
  
  
  1.1                  jakarta-velocity/whiteboard/geir_context_20001228/InternalContext.java
  
  Index: InternalContext.java
  ===================================================================
  package org.apache.velocity;
  
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.util.Hashtable;
  import java.io.Serializable;
  
  import org.apache.velocity.util.introspection.IntrospectionCacheData;
  
  /**
   *  class to encapsulate the 'stuff' for internal operation of velocity.  
   *  We use the context as a thread-safe storage : we take advantage of the
   *  fact that it's a visitor  of sorts  to all nodes (that matter) of the 
   *  AST during init() and render().
   *  Currently, it carries the template name for namespace
   *  support, as well as node-local context data introspection caching.
   *
   * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
   * @version $Id: InternalContext.java,v 1.1 2000/12/30 14:42:00 geirm Exp $
   */
  public interface InternalContext
  {
      /**
       *  set the current template name
       *
       *  @param s current template name to set
       */
      public void setCurrentTemplateName( String s );
      
      /**
       *  get the current template name
       *
       *  @return String current template name
       */
      public String getCurrentTemplateName();
  
      /**
       *  returns an IntrospectionCache Data (@see IntrospectionCacheData)
       *  object if exists for the key
       *
       *  @param key  key to find in cache
       *  @return cache object
       */
      public IntrospectionCacheData icacheGet( Object key );
      
      /**
       *  places an IntrospectionCache Data (@see IntrospectionCacheData)
       *  element in the cache for specified key
       *
       *  @param key  key 
       *  @param o  IntrospectionCacheData object to place in cache
       */
      public void icachePut( Object key, IntrospectionCacheData o );
  }
  
  
  
  1.1                  jakarta-velocity/whiteboard/geir_context_20001228/InternalContextBase.java
  
  Index: InternalContextBase.java
  ===================================================================
  package org.apache.velocity;
  
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.util.Hashtable;
  import java.io.Serializable;
  
  import org.apache.velocity.util.introspection.IntrospectionCacheData;
  
  /**
   *  class to encapsulate the 'stuff' for internal operation of velocity.  
   *  We use the context as a thread-safe storage : we take advantage of the
   *  fact that it's a visitor  of sorts  to all nodes (that matter) of the 
   *  AST during init() and render().
   *  Currently, it carries the template name for namespace
   *  support, as well as node-local context data introspection caching.
   *
   * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
   * @version $Id: InternalContextBase.java,v 1.1 2000/12/30 14:42:00 geirm Exp $
   */
  public class InternalContextBase implements InternalContext, Serializable
  {
      /**
       *  cache for node/context specific introspection information
       */
      private Hashtable introspectionCache = new Hashtable();
      
      /**
       *  Current template name.
       */
      private String strCurrentTemplate = "<undef>";
  
      /**
       *  set the current template name
       *
       *  @param s current template name to set
       */
      public void setCurrentTemplateName( String s )
      {
          strCurrentTemplate = s;
          return;
      }
      
      /**
       *  get the current template name
       *
       *  @return String current template name
       */
      public String getCurrentTemplateName()
      {
          return strCurrentTemplate;
      }
  
      /**
       *  returns an IntrospectionCache Data (@see IntrospectionCacheData)
       *  object if exists for the key
       *
       *  @param key  key to find in cache
       *  @return cache object
       */
      public IntrospectionCacheData icacheGet( Object key )
      {
          return ( IntrospectionCacheData ) introspectionCache.get( key );
      }
       
      /**
       *  places an IntrospectionCache Data (@see IntrospectionCacheData)
       *  element in the cache for specified key
       *
       *  @param key  key 
       *  @param o  IntrospectionCacheData object to place in cache
       */
      public void icachePut( Object key, IntrospectionCacheData o )
      {
          introspectionCache.put( key, o );
      }
  }