You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by nb...@apache.org on 2003/11/06 07:16:18 UTC

cvs commit: jakarta-velocity-tools/src/java/org/apache/velocity/tools/view ViewToolInfo.java

nbubna      2003/11/05 22:16:18

  Modified:    src/java/org/apache/velocity/tools/view ViewToolInfo.java
  Log:
  load classes using the webapp's classloader
  
  Revision  Changes    Path
  1.5       +25 -2     jakarta-velocity-tools/src/java/org/apache/velocity/tools/view/ViewToolInfo.java
  
  Index: ViewToolInfo.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity-tools/src/java/org/apache/velocity/tools/view/ViewToolInfo.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ViewToolInfo.java	22 Jul 2003 18:30:27 -0000	1.4
  +++ ViewToolInfo.java	6 Nov 2003 06:16:18 -0000	1.5
  @@ -80,6 +80,29 @@
       public ViewToolInfo() {}
   
   
  +    //TODO: if classloading becomes needed elsewhere, move this to a utils class
  +    /**
  +     * Return the <code>Class</code> object for the specified fully qualified
  +     * class name, from this web application's class loader.  If no 
  +     * class loader is set for the current thread, then the class loader
  +     * that loaded this class will be used.
  +     *
  +     * @param className Fully qualified class name to be loaded
  +     * @return Class object
  +     * @exception ClassNotFoundException if the class cannot be found
  +     * @since VelocityTools 1.1
  +     */
  +    protected Class getApplicationClass(String name) throws ClassNotFoundException
  +    {
  +        ClassLoader loader = Thread.currentThread().getContextClassLoader();
  +        if (loader == null)
  +        {
  +            loader = ViewToolInfo.class.getClassLoader();
  +        }
  +        return loader.loadClass(name);
  +    }
  +
  +
       /***********************  Mutators *************************/
   
       public void setKey(String key)
  @@ -96,7 +119,7 @@
        */
       public void setClassname(String classname) throws Exception
       {
  -        this.clazz = Class.forName(classname);
  +        this.clazz = getApplicationClass(classname);
           /* create an instance and see if it is initializable */
           if (clazz.newInstance() instanceof ViewTool)
           {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org