On Tue, Jan 12, 2010 at 1:20 AM, bluejoe2008 <[email protected]> wrote: > thank you very much! > > if i provide 'public void configure(Map map)', > then what other entries will be contained in the map except those properties > what i defined in the tool.xml explicitly?
it depends on the scope of the tool and whether you are using just GenericTools or VelocityView. this map is generally created by a ToolContext class. the base implementation will add these when it makes sense to: context requestPath velocityEngine log catchExceptions (if a MethodExceptionEventHandler is configured for the engine) ViewToolContext can add those and these also: request locale (if the request is not null) response session servletContext > in other words, if i provide setter methods, > which implicit methods will be called before the tool be used? > setServletContext()? setRequest()? or others? > i need a list of such methods. it's the same list as above, just turned into setters (requestPath -> setRequestPath(string)) > many thanks! > > 2010-01-12 > > > > bluejoe2008 > > > > 发件人: Nathan Bubna > 发送时间: 2010-01-12 05:40:04 > 收件人: Velocity Users List > 抄送: > 主题: Re: how to create a custom tool in tool 2.0? > > 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] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
