The good thing about Velocity Context is that you can put a lot of objects into the Context and give all them to HTML-XML-writer, then HTML-writer can do whatever he wants with those objects, or do nothing at all, whilst CPU time is spent only when he actually do something. Those objects in the Context can be thought of as a problem-oriented-language targeted at HTML-writer.
This path, however, is not as convenient and efficient as it could be: A lot of objects in the Context might need to use some context-specific information, such as session, specific request parameters, or something else put into the Context by someone. And there is only a few ways for the object to receive this information. One is to synchronize access to all objects in the Context as a whole, that is, only one Velocity Context might be merged into template at the time, so that we can just give the Context to all the objects before merging it. Other is for every new Context to create all the objects from scratch and give the Context to each object thru object's constructor. (I'll be glad to hear of another ways to accoplish this). Described methods are surely inconvenient. The first kills concurency and may produce user-visible hangs. The second forces us to recreat all the objects in the Context, which is not at all efficient, becouse memory allocation is never cheap and objects might have some heavy initializers in constructors or do some internal caching, which is humped when we recreate them, and it is neither convenient nor efficient when we have to create proxies to objects whoes number of instances should be limited, instead of just placing those objects into the Context. I came to simple solution for this problem by giving the Context thru the hidden parameter of a method: If method exists without hidden Context parameter, then it is executed as usual, but if no such method exists, then I check for a method with the same parameters plus the hidden Context parameter, and if it is present, it is executed receiving the current Context. Thus shared objects can be put into Velocity Context and remain there, and a big part of a context can be shared thru the context chaining, with only dynamically changed values, such as session, placed into the each-time-allocated Context. Attached (as a demo) are my patches for "velocity-1.3.1". If someone is interested and want to reimplement it for the mainline, great. If someone is still interested, but have no time to implement, there is a chance that I will try to write a better patch for velocity-1.4.1-rc1, which, perhaps, should be more integrated, becouse of Uberspect. Although I don't know, yet, how the ASTMethod is generated.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
