commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mattias J <mattias.jiderh...@expertsystem.se>
Subject Re: [Digester] Initializing statics
Date Fri, 20 May 2005 12:22:44 GMT
At 2005-05-20 14:04, you wrote:
>I have a static method that needs to load a rather large file once (this
>method is in a third party library, so refactoring is not an option):
>
>public class Foo
>{
>    /**
>    * Call once before using Foo to load
>    **/
>    public static void init(String filename);
>
>    ...
>}
>My config xmlrules file looks like:
>
><pattern value="example/foo">
>         <!-- static initializer, somewhat-->
>         <object-create-rule classname="Foo"/>
>         <call-method-rule methodname="init"
>                         paramcount="1" />
>         <call-param-rule paramnumber='0' attrname='file'/>
>     </pattern>
>
>And my configuration file looks like:
><example>
>      <foo file="path.to.foo.initialization.file"/>
></example>
>
>
>The object-create-rule is superflous to some extent, b/c the init call
>is on a static.  However, from my limited understanding of Digester, I
>need to have an object
>on the stack of type Foo in order to call a method on it (even if it is
>static).
>
>The above works, it's just that the object created is just thrown away,
>as it is not needed, since the other method that I use on Foo is also
>static.  I was just wondering if there was another way to do this, I can
>envision something like:
>
><call-static-method-rule methodname="init" paramcount="1"
>classname="Foo"/>
><call-param-rule paramnumber='0' attrname='file'/>
>
>Thanks,
>Grant

It was a while since I worked with Digester, so there might be a more 
straightforward way to call static methods which I have forgotten, but 
otherwise couldn't you use a factory-create-rule which could then access 
the file name through it's parameter
   public Object createObject(Attributes attributes)
?



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


Mime
View raw message