Author: nbubna
Date: Mon Sep 19 11:55:28 2005
New Revision: 290238

URL: http://svn.apache.org/viewcvs?rev=290238&view=rev
Log:
be more robust in handling null inputs (part of Henning's patch for Issue 
VELOCITY-375

Modified:
    
jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/ViewToolInfo.java

Modified: 
jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/ViewToolInfo.java
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/ViewToolInfo.java?rev=290238&r1=290237&r2=290238&view=diff
==============================================================================
--- 
jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/ViewToolInfo.java
 (original)
+++ 
jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/ViewToolInfo.java
 Mon Sep 19 11:55:28 2005
@@ -30,8 +30,8 @@
  * given object before being returned.
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Nathan Bubna</a>
- *
- * @version $Id: ViewToolInfo.java,v 1.10 2004/11/11 06:26:27 nbubna Exp $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
+ * @version $Id$
  */
 public class ViewToolInfo implements ToolInfo
 {
@@ -76,7 +76,6 @@
         this.key = key;
     }
 
-
     /**
      * If an instance of the tool cannot be created from
      * the classname passed to this method, it will throw an exception.
@@ -85,16 +84,23 @@
      */
     public void setClassname(String classname) throws Exception
     {
-        this.clazz = getApplicationClass(classname);
-        /* create an instance and see if it is a ViewTool or Configurable */
-        Object instance = clazz.newInstance();
-        if (instance instanceof ViewTool)
+        if (classname != null && classname.length() != 0)
         {
-            this.initializable = true;
+            this.clazz = getApplicationClass(classname);
+            /* create an instance and see if it is a ViewTool or Configurable 
*/
+            Object instance = clazz.newInstance();
+            if (instance instanceof ViewTool)
+            {
+                this.initializable = true;
+            }
+            if (instance instanceof Configurable)
+            {
+                this.configurable = true;
+            }
         }
-        if (instance instanceof Configurable)
+        else
         {
-            this.configurable = true;
+            this.clazz = null;
         }
     }
 
@@ -133,10 +139,9 @@
 
     public String getClassname()
     {
-        return clazz.getName();
+        return clazz != null ? clazz.getName() : null;
     }
 
-
     /**
      * Get parameters for this tool.
      * @since VelocityTools 1.1
@@ -153,6 +158,12 @@
      */
     public Object getInstance(Object initData)
     {
+        if (clazz == null)
+        {
+            LOG.error("Tool "+this.key+" has no Class definition!");
+            return null;
+        }
+
         Object tool = null;
         try
         {
@@ -165,12 +176,12 @@
         catch (IllegalAccessException e)
         {
             LOG.error("Exception while instantiating instance of \"" +
-                      getClassname() + "\": " + e);
+                    getClassname() + "\": " + e);
         }
         catch (InstantiationException e)
         {
             LOG.error("Exception while instantiating instance of \"" +
-                      getClassname() + "\": " + e);
+                    getClassname() + "\": " + e);
         }
         if (configurable)
         {
@@ -182,5 +193,4 @@
         }
         return tool;
     }
-
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to