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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to