Author: nbubna
Date: Fri Jul 20 13:03:12 2007
New Revision: 558113

URL: http://svn.apache.org/viewvc?view=rev&rev=558113
Log:
make init transient for proper serialization

Modified:
    
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/OldToolInfo.java

Modified: 
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/OldToolInfo.java
URL: 
http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/OldToolInfo.java?view=diff&rev=558113&r1=558112&r2=558113
==============================================================================
--- 
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/OldToolInfo.java
 (original)
+++ 
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/OldToolInfo.java
 Fri Jul 20 13:03:12 2007
@@ -35,7 +35,7 @@
     private static final long serialVersionUID = -4062162635847288761L;
     public static final String INIT_METHOD_NAME = "init";
 
-    private Method init;
+    private transient Method init;
 
     /**
      * Creates a new instance using the minimum required info
@@ -46,6 +46,23 @@
         super(key, clazz);
     }
 
+    protected Method getInit()
+    {
+        if (this.init == null)
+        {
+            try
+            {
+                // try to get an init(Object) method
+                this.init = clazz.getMethod("init", new Class[]{ Object.class 
});
+            }
+            catch (NoSuchMethodException nsme)
+            {
+                // ignore
+            }
+        }
+        return this.init;
+    }
+
     /**
      * 
      *
@@ -56,15 +73,8 @@
     {
         super.setClass(clazz);
 
-        try
-        {
-            // try to get an init(Object) method
-            this.init = clazz.getMethod("init", new Class[]{ Object.class });
-        }
-        catch (NoSuchMethodException nsme)
-        {
-            // ignore
-        }
+        // clear any existing init method
+        this.init = null;
     }
 
 
@@ -74,7 +84,8 @@
         // have specific setters and configure(Map) called first
         super.configure(tool, configuration);
 
-        if (this.init != null)
+        Method init = getInit();
+        if (init != null)
         {
             // ctx should, in all cases where a tool has such a method,
             // actually be a View(Tool)Context, but we don't want to link
@@ -82,7 +93,7 @@
             Object ctx = configuration.get(ToolContext.CONTEXT_KEY);
             if (ctx != null)
             {
-                invoke(this.init, tool, ctx);
+                invoke(init, tool, ctx);
             }
         }
     }


Reply via email to