View Javadoc

    1   /*
    2    * joey-gen and its relative products are published under the terms
    3    * of the Apache Software License.
    4    *
    5    * Created on 2004/11/25 17:58:58
    6    */
    7   package org.asyrinx.joey.gen.task;
    8
    9   import java.util.Collection;
    10  import java.util.HashSet;
    11  import java.util.Iterator;
    12  import java.util.Set;
    13
    14  import org.apache.velocity.context.Context;
    15
    16  /***
    17   * @author takeshi
    18   */
    19  public class VelocityHelper {
    20
    21      /***
    22       *
    23       */
    24      public VelocityHelper(Context context) {
    25          super();
    26          this.context = context;
    27      }
    28
    29      private final Context context;
    30
    31      public Object newInstance(String className) {
    32          try {
    33              return Class.forName(className).newInstance();
    34          } catch (Exception e) {
    35              return null;
    36          }
    37      }
    38
    39      public Set toSet(Collection collection) {
    40          final Set result = new HashSet();
    41          for (Iterator i = collection.iterator(); i.hasNext();)
    42              result.add(i.next());
    43          return result;
    44      }
    45
    46      public Object put(String key, Object value) {
    47          return context.put(key, value);
    48      }
    49
    50  }