From: Marc P. <ma...@an...> - 2003-07-23 23:34:02
|
On Wed, 23 Jul 2003 19:08:08 -0400 (GMT), Keats <ke...@su...> wrote: > It seems to me that a LazyVariableFactory is just another name for a > ContextTool. That's not what I proposed it for. > Yes there are more improvements that can be made to the ContextTool > mechanism. Decoupling it from the config is a good idea. That's what I mean for LazyVariableFactory. It is the impl in WM that knows that it has to look up tools and create them. i.e. we remove all the CT config stuff from WM "core" code, and stuff it into a LazyVariableFactory impl. Then in WebMacro.properties (for example): LazyVariableFactory: org.webmacro.legacy.ContextToolFactory This would reproduce the current behaviour of WM - reading the settings from Broker to find all the ContextToolXXXX properties and caching the info, and then when (if) asked it can create any of them on demand to be put into a context. Thus the code in Context becomes (pseudo): if (context.get(varname) == null) { if (broker.getLazyVariableFactory() != null) return broker.getLazyVariableFactory().getVariable( varname, this); } ...and there is no other CT logic in WM core code (Context or Broker). That's it. We just abstract the whole mechanism, and Eric and I will have no "LazyVariableFactory:" entry in WebMacro.properties :) See what I'm getting at? > Making it work with generic classes is also a step forward. In fact I've > implemented something like this, but noone seemed interested at the time. > Basically I built some adapters that take various kinds of classes > (static, singleton, factory, normal) and load them as context tools on > demand. I can probably dredge up this old code if anyone is interested. This is only necessary if the context-aware initialization thing is retained as is. Here's what I now propose, hopefully somewhat clearer: 1. Remove all CT logic from Context/Broker etc 2. Deprecate CT interface 3. Make the CT interface empty, instead extending a new core interface ContextAware with the same init(context) method currently in CT. This retains compatibility with current CTs while deprecating the interface itself, and gains us further abstraction in ContextAware. 4. We add an interface equivalent to LazyVariableFactory, with one method getVariable( name, context). 5. We add simple logic (as shown earlier) to make Context/Broker do the work of looking for the single instance of this factory if available, thus replacing the current CT instantiation logic 6. We put most of the excised CT login into an impl of LazyVariableFactory called ContextToolFactory and put this in some package like o.w.legacy or o.w.util. 7. We add code to the new Context/Broker logic so that after asking the LazyVariableFactory for a variable instance and getting one succesfully we do: if (newvar instanceof ContextAware) ((ContextAware)newvar).init( this); 8. We remove all context tool settings from WebMacro.defaults and put it in the shipped WebMacro.properties 9. We put "LazyVariableFactory: org.webmacro.legacy.ContextToolFactory" into WebMacro.properties. 10. Add get/setLazyVariableFactory(Class) to Broker/wherever so apps can supply custom handling. What this gets us: a) Removes CT from core WM concepts = cleaner WM focussing on template rendering not "data management" b) Retains CT compatibility for you old-fashioned types c) Brings us new context-aware vars - which context.put() could also check for, even though Brian says this is a waste of CPU - despite also pointing out that instanceof is pretty damn cheap these days, and we are typically talking maybe 5-10 puts per template. d) Gives applications the ability to completely control template variables. i.e. I may want to ship WM without modification but not allow templates access to $Request or $Response and instead have my own special vars for doing something similar. I expect this to be greeted with the usual disagreement :) -- Marc Palmer Contract Java Consultant/Developer w a n g j a m m e r s java and web software design experts with an ethical outlook http://www.wangjammers.org |