On Sun, Jan 10, 2010 at 9:59 PM, bluejoe2008 <[email protected]> wrote:
> hello, everyone.
>
> i wrote some application-scoped or request-scoped tools in version 1.x, in 
> which all classes were added a method named 'init(Object)'. however, in 
> version 2.0, I noticed that 'init()' method is depracated, and methods such 
> as 'setRequest()', 'setServletContext()' and 'setSession()' should be 
> provided if necessary.

Or you can provide a configure(Map) method and that map will contain
what you need.

> so my first question is: how to write a application-scoped or request-scoped 
> tool? the web page "Creating 
> Tools"[http://velocity.apache.org/tools/devel/creatingtools.html] tells 
> something about it, but i can not find any suggestion on defining a scoped 
> class. which methods are required? should one non-argument constructor be 
> provided? should the constructor be public? i do not know.

yes, a public no-arg constructor is essential.   what scope you want
it to be in is dependent on the purpose of the tool.  setting the
scope of the tool is done via your tool configuration.  there are
annotations available to limit what scope configurations are allowed.

> second, i want to know how the velocity engine load tools, especially scoped 
> tools. maybe firstly the engine calls Class.newInstance() to create a 
> instance, then it call setRequest() to initialize context? this is just my 
> guess. i want to know the truth.

yes, newInstance(), then the property setters are called, then the
configure(Map) method, if it exists.

>
> sorry to bother you! waiting for your reply! many thanks!
>
> best regards,
> bluejoe
> 2010-1-11
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to