commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james_strac...@yahoo.co.uk>
Subject Re: [jelly] Subclassing JellyContext
Date Fri, 06 Dec 2002 18:32:20 GMT
Variables should automatically be available to their child contexts so I
don't think you need to create your own JellyContext for that.

Also the push/pop features can be used by just creating and using child
context - its rather like using a local block in Java. There's also the
<j:scope> tag which creates a child variable scope, essentially making any
variables set inside the <j:scope> tag

One question; where will you be using these typesafe getters and setters you
want? Will it be inside a Jelly Tag implementation? If so, you could put
these typesafe methods in an AbstractTag...

public abstract class MyAbstractTag extends TagSupport {

    public Number getFoo() {
        return (Number) context.getVariable("foo");
    }

    ... etc.


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 2:40 PM
Subject: RE: [jelly] Subclassing JellyContext


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>

__________________________________________________
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>


Mime
View raw message