[ http://issues.apache.org/jira/browse/JELLY-167?page=comments#action_57961 ] Marc DeXeT commented on JELLY-167: ----------------------------------
Hans Gilde said : > Could you give an example of an existing piece of code that would be improved? I have done a lot a thing based upon isolated context concept, as tags which execute their body according to external parameters, it's a tricky thing to modularize script, act as local variables in function (or method to stay object) : (see http://issues.apache.org/jira/browse/JELLY-193 ) They're looking like : <code> public void doTag(XMLOutput output) throws ... { (...) //- check var, attributes and so on... JellyContext innerContext = context.newEmptyJellyContext(); for (int i = 0; i < innerVarNames.length;i++) { innerContext.setVariable(innerVarNames[i],context.getVariable(externVarNames[i]); } getBody().run(innerContext,output); context.setVariable(result, this.result); } public void addReturn(Object value){ this.return = value; } </code> This way, you can resolve variable names collision, and for very big script as I have, collision it's a real problem ! Yesterday, tag caching asside, just doing : <code> JellyContext innerContext = new JellyContext(); </code> was enough. But with Paul new Tag caching feature, you have to set innerContext current context child to be sure to get the real ancestor and not a created one. If you put in the first tag body a child tag like this : <code> public void doAction(XMLOutput output) throws ... { tag = (CallableTag) findAncestorWithClass(CallableTag.class); if ( tag == null ) { throw new JellyTagException("Must be nested in CallableTag"); } tag.addReturn( value ); } <code> You have to be sure It's his real ancestor. This is an example, but I have also a lot modular features to use external script without name collision, as you can call a method without local and member variable collision. > Are you suggesting getting rid of inherit and export? No no, no thing so radical, may be ths method name would be "newEmptyChildContext()". I'am thinking about is : public JellyContext newEmptyChildContext() { JellyContext answer = this.newJellyCotext(); answer.clearVariable(); answer.setInherit(false); anwser.setVariable("systemScope", this.getVariable("systemScope"); return answer; } It pretty easy to put in unit test : public final void testEmptyChildContext() { JellyContext context = new JellyContext(); context.setVariable("externalVar","external"); JellyContext emptyChild = context.newEmptyChildContext(); // Child and parent are really child and parent. assertSame(context, emptyChild.getParent()); // Child doesn't see parent var. assertNull( emptyChild.getVariable( "externalVar") ) ; emptyChild.setVariable("internVar","intern"); // Parent doesn't see child var. assertNull( context .getVariable( "externalVar") ) ; } Remember that isolated context can be a response to var name collision, it's not a fantasy, it could be usefull and I think to define over several projects same jelly subclass to get the same feature it's not clever (and tiring for me :) ). It could be a little improvement for now, but it could be very used (in my opinion) if this feature is part of core API. Well, it's just my point of view, but I believe in it :) > add 'public JellyContext newEmptyJellyContext()' to JellyContext > ---------------------------------------------------------------- > > Key: JELLY-167 > URL: http://issues.apache.org/jira/browse/JELLY-167 > Project: jelly > Type: Wish > Components: core / taglib.core > Versions: 1.0-beta-5 > Reporter: Marc DeXeT > > method 'public JellyContext newJellyContext()' uses 'public > JellyContext(JellyContext parent)'. > This constructor copies parent properties AND parent variables. > To create variables quenched context, you have to clear variables or to set > inherit to false. > I wish to have a new method 'public JellyContext newEmptyJellyContext()' > which copies all root context properties (as tag caching) but DOESN'T copy > variables map. > Even if you could do the same with inherit or variable map clearing or other > methods, it would be more meaningful to use a assigned method -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
