Coverage Report - org.apache.fulcrum.template.DefaultTemplateContext
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultTemplateContext
0%
0/14
0%
0/2
1.143
 
 1  
 package org.apache.fulcrum.template;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 
 23  
 import java.util.HashMap;
 24  
 
 25  
 /**
 26  
  *  General purpose implemention of the application Context
 27  
  *  interface for general application use.  This class should
 28  
  *  be used in place of the original Context class.
 29  
  *
 30  
  *  This implementation uses a HashMap  (@see java.util.HashMap )
 31  
  *  for data storage.
 32  
  *
 33  
  *  This context implementation cannot be shared between threads
 34  
  *  without those threads synchronizing access between them, as
 35  
  *  the HashMap is not synchronized, nor are some of the fundamentals
 36  
  *  of AbstractContext.  If you need to share a Context between
 37  
  *  threads with simultaneous access for some reason, please create
 38  
  *  your own and extend the interface Context
 39  
  *
 40  
  *  @see org.apache.velocity.context.Context
 41  
  *
 42  
  *  @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
 43  
  *  @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
 44  
  *  @author <a href="mailto:fedor.karpelevitch@home.com">Fedor Karpelevitch</a>
 45  
  *  @version $Id: DefaultTemplateContext.java 535465 2007-05-05 06:58:06Z tv $
 46  
  */
 47  
 public class DefaultTemplateContext
 48  
     implements TemplateContext
 49  
 {
 50  
     /**
 51  
      *  storage for key/value pairs
 52  
      */
 53  0
     private HashMap context = new HashMap();
 54  
 
 55  
     /**
 56  
      * default contructor, does nothing
 57  
      * interesting
 58  
      */
 59  
     public DefaultTemplateContext()
 60  0
     {
 61  0
     }
 62  
 
 63  
     /**
 64  
      * Allow chained contexts.
 65  
      */
 66  
     public DefaultTemplateContext(TemplateContext context)
 67  
     {
 68  0
         super();
 69  
 
 70  
         //!! I realize this is not the most efficient
 71  
         // way to do this, but I'm not sure if chained
 72  
         // contexts can work with templating solutions
 73  
         // other than velocity. I don't see why not right
 74  
         // of the bat, but this will work for now.
 75  
 
 76  0
         Object[] keys = context.getKeys();
 77  
 
 78  0
         for (int i = 0; i < keys.length; i++)
 79  
         {
 80  0
             put((String) keys[i], context.get((String)keys[i]));
 81  
         }
 82  0
     }
 83  
 
 84  
     public void put(String key, Object value)
 85  
     {
 86  0
         context.put(key, value);
 87  0
     }
 88  
 
 89  
     public Object get(String key)
 90  
     {
 91  0
         return context.get(key);
 92  
     }
 93  
 
 94  
     public Object remove(Object key)
 95  
     {
 96  0
         return context.remove(key);
 97  
     }
 98  
 
 99  
     public boolean containsKey(Object key)
 100  
     {
 101  0
         return context.containsKey(key);
 102  
     }
 103  
 
 104  
     public Object[] getKeys()
 105  
     {
 106  0
         return context.keySet().toArray();
 107  
     }
 108  
 }
 109