commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Grant Ingersoll" <GSIng...@syr.edu>
Subject Re: [Digester] Initializing statics
Date Fri, 20 May 2005 12:04:58 GMT
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


>>> skitching@apache.org 5/19/2005 7:35:24 PM >>>
On Thu, 2005-05-19 at 14:22 -0400, Grant Ingersoll wrote:
> Hi,
> 
> I have a class that has a static initializer the loads a rather
large
> file (this is in a library class) and I would like to initialize it
with
> the file via Digester.  Right now, I create a dummy object of that
class
> and then apply a CallMethodRule invoking the init method with the
> attribute containing the file name.  While this works, seems like a
> waste to construct the dummy object.  Is there a preferred way to
pass
> configurable arguments to a static method on a class?
> 

Sorry, Grant, but I don't understand. Perhaps you could provide some
code demonstrating what you're trying to achieve?

Regards,

Simon


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


---------------------------------------------------------------------
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