From: <kea...@na...> - 2003-01-22 20:37:25
|
I've been out of town so I haven't had a chance to really follow this thread, but I definitely like the general idea. On the issue of helpers vs. ContextTools, I've been playing around with generic ContextTool loaders which I think can go a long way to addressing the issue. For example, I've created a FactoryToolLoader class which lets you configure any factory method to put objects into the context. This is basically a "Flyweight" factory class for loading singletons into the context. You configure it as follows: ================================================================ # Load a class using SampleFatoryTool.getInstance() into the context as $Sample ContextTools.Sample: org.webmacro.datatable.FactoryToolLoader Sample.ClassName: org.webmacro.datatable.SampleFactoryTool # Load a class using ListUtil.getInstance() into the context as $Lister ContextTools.Lister: org.webmacro.datatable.FactoryToolLoader Lister.ClassName: org.webmacro.servlet.ListUtil ================================================================ By default it uses "getInstance" as the method name, although you can specify a MethodName parameter if you want. We could do something similar for "scoped" classes (global/static, per app, per session, per request). Per request classes with an method matching "void setContext(Context)" could get access to the current context. Session and app classes could use setSession and setBroker or some such. I haven't worked out the destroy() semantics yet, but that should be straightforward. The beauty of this is that it requires no changes to any classes, just a couple new context tools, and then virtually any class can be used as a tool with minimal configuration and no WM specific code. Of course we could simplify things even further by having new configuration options, e.g., StaticContextTool.Thingy: o.w.u.SomeStaticThingy GlobalContextTool.Dodad: o.w.u.SomeGlobalDodad AppContextTool.Whatzama: o.w.u.SomeAppWhatzamajigger SessionContextTool.Dohick: o.w.u.SomeSessionDohicky RequestContextTool.Mabob: o.w.u.SomeRequestThingamabob Thoughts? Keats |