commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marc DeXeT (JIRA)" <>
Subject [jira] Commented: (JELLY-167) add 'public JellyContext newEmptyJellyContext()' to JellyContext
Date Sun, 23 Jan 2005 11:25:19 GMT
     [ ]
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 )
They're looking like :
public void doTag(XMLOutput output) throws ... {
   (...) //- check var, attributes and so on...
   JellyContext innerContext = context.newEmptyJellyContext();
   for (int i = 0; i < innerVarNames.length;i++) {
   context.setVariable(result, this.result);

public void addReturn(Object value){
   this.return = value;

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 :
JellyContext innerContext = new JellyContext();
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 :
    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 );
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();
  anwser.setVariable("systemScope", this.getVariable("systemScope");
  return answer;

It pretty easy to put in unit test :

public final void testEmptyChildContext() {
 JellyContext context = new JellyContext();
 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") ) ;


 // 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:
>      Project: jelly
>         Type: Wish
>   Components: core / taglib.core
>     Versions: 1.0-beta-5
>     Reporter: Marc DeXeT

> method 'public JellyContext newJellyContext()' uses 'public JellyContext(JellyContext
> This constructor copies parent properties AND parent variables.
> To create variables quenched context, you have to clear variables or to set inherit to
> 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:
If you want more information on JIRA, or have a bug to report see:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message