velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r551650 - in /velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools: OldToolInfo.java ToolInfo.java
Date Thu, 28 Jun 2007 18:23:34 GMT
Author: nbubna
Date: Thu Jun 28 11:23:33 2007
New Revision: 551650

URL: http://svn.apache.org/viewvc?view=rev&rev=551650
Log:
refactor actual configuration of the tool into a seperate method

Modified:
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/OldToolInfo.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/ToolInfo.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=551650&r1=551649&r2=551650
==============================================================================
--- 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 Thu
Jun 28 11:23:33 2007
@@ -69,22 +69,22 @@
 
 
     @Override
-    public Object create(Map<String,Object> dynamicProperties)
+    protected void configure(Object tool, Map<String,Object> configuration)
     {
-        Object tool = super.create(dynamicProperties);
+        // have specific setters and configure(Map) called first
+        super.configure(tool, configuration);
 
         if (this.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
             // to that class here, so as not to pollute the generic jar
-            Object ctx = dynamicProperties.get(ToolContext.CONTEXT_KEY);
+            Object ctx = configuration.get(ToolContext.CONTEXT_KEY);
             if (ctx != null)
             {
                 invoke(this.init, tool, ctx);
             }
         }
-        return tool;
     }
 
 }

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/ToolInfo.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/ToolInfo.java?view=diff&rev=551650&r1=551649&r2=551650
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/ToolInfo.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/ToolInfo.java Thu
Jun 28 11:23:33 2007
@@ -217,25 +217,40 @@
         /* Get the tool instance */
         Object tool = newInstance();
 
-        /* if the tool is configurable and we have properties... */
+        /* put configured props into the combo last, since
+           dynamic properties will almost always be conventions
+           and we need to let configuration win out */
         Map<String,Object> combinedProps =
-            combine(this.properties, dynamicProperties);
+            combine(dynamicProperties, this.properties);
+
+        // perform the actual configuration of the new tool
+        configure(tool, combinedProps);
+        return tool;
+    }
+
+
+    /***********************  protected methods *************************/
+
+    /**
+     * Actually performs configuration of the newly instantiated tool
+     * using the combined final set of configuration properties. First,
+     * specific setters matching the configuration keys are called, then
+     * the general configure(Map) method (if any) is called.
+     */
+    protected void configure(Object tool, Map<String,Object> configuration)
+    {
         //TODO: make this step optional?
         // look for specific setters
-        for (String name : combinedProps.keySet())
+        for (String name : configuration.keySet())
         {
-            setProperty(tool, name, combinedProps.get(name));
+            setProperty(tool, name, configuration.get(name));
         }
 
         if (hasConfigure())
         {
-            invoke(getConfigure(), tool, combinedProps);
+            invoke(getConfigure(), tool, configuration);
         }
-        return tool;
     }
-
-
-    /***********************  protected methods *************************/
 
     protected Method getConfigure()
     {



Mime
View raw message