commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Ext-Mike.Ho...@nokia.com>
Subject RE: [jelly] Subclassing JellyContext
Date Thu, 05 Dec 2002 14:40:30 GMT
James, thanks for the pointer re createChildContext().

I am not clear what the scoping refactoring you refer to means exactly, even after reading
the link you sent ;-)  But never mind.  My scoping requirements are to be able to have a variable
value visible only to its children.  Maybe this is supported already, but I have gone ahead
and written this:

    protected void pushVariable(String variableName, Object value) {
        if ( context.getVariable(variableName) != null ) {
            oldVariableValues.put(variableName,context.getVariable(variableName));
        } else {
            newVariableNames.add(variableName);
        }
        log.debug("Setting variable " + variableName + " to value " + value);
        context.setVariable(variableName,value);
    }

followed by 

    protected void popVariables() {
        log.debug("Starting to pop variables");
        for(Iterator i=newVariableNames.iterator();i.hasNext();) {
            final String variableName = (String)i.next();
            log.debug("Removing variable named " + variableName);
            context.removeVariable(variableName);
        }
        for(Iterator i=oldVariableValues.keySet().iterator();i.hasNext();) {
            final String variableName = (String) i.next();
            log.debug("Resetting value for variable named " + variableName);
            context.setVariable(variableName,oldVariableValues.get(variableName));
        }
    }

And these two methods are on an AbstractTag.  I _would_ prefer to have the methods on a context
though.

But the real reason I want to subclass is to allow myself write typesafe and intuitive variable
setters and getters for variables that have meaning to my application.  

So instead of 

context.setVariable(VariableNames.APPLICATION_MODE,"fast") 

I can do 

((MyContext)context).setApplicationMode("fast") 

and then 

String applicationMode = ((MyContext)context).getApplicationMode()

Better than having to remember a bunch of names of variables and what type they are.

> -----Original Message-----
> From: ext James Strachan [mailto:james_strachan@yahoo.co.uk]
> Sent: 05. December 2002 16:22
> To: Jakarta Commons Developers List
> Subject: Re: [jelly] Subclassing JellyContext
> 
> 
> There's a factory method, createChildContext() which you can 
> override to
> create your own context...
> 
> public class MyContext extends JellyContext {
> 
>     public MyContext(JellyContext parent) {
>         super(parent);
>     }
> 
>     protected JellyContext createChildContext() {
>         return new MyContext(this);
>     }
> }
> 
> Note that soon we'll be refactoring the variable scope logic 
> out of the
> JellyContext so that you could just provide your own variable Scope
> implementation to change how variables behave. Thats 
> typically the usual
> reason folks need their own JellyContext implementation
> 
> There's more details of this here...
> 
> http://jira.werken.com/secure/ViewIssue.jspa?key=JELLY-1
> 
> James
> -------
> http://radio.weblogs.com/0112098/
> ----- Original Message -----
> From: <Ext-Mike.Hogan@nokia.com>
> To: <commons-dev@jakarta.apache.org>
> Sent: Thursday, December 05, 2002 1:13 PM
> Subject: [jelly] Subclassing JellyContext
> 
> 
> Hi,
> 
> Is there any way I can override the creation of JellyContext 
> instances so I
> can put in my own subclass?
> 
> Thanks,
> Mike.
> 
> --
> To unsubscribe, e-mail:
> <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:commons-dev-help@jakarta.apache.org>
> 
> __________________________________________________
> 
> Do You Yahoo!?
> 
> Everything you'll ever need on one web page
> 
> from News and Sport to Email and Music Charts
> 
> http://uk.my.yahoo.com
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: 
> <mailto:commons-dev-help@jakarta.apache.org>
> 
> 

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message