commons-user 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] Control of expression execution for an attribute
Date Tue, 18 Mar 2003 15:42:41 GMT
 From: "Kevin Ross" <Kevin.Ross@iVerticalLeap.com>
> Thanks James,
>
> I've been looking specifically how to accomplish this, and I must say,
> nice work :)  Jelly seems to allow me to do this at different stages,
> notably:
>
> XMLParser.setExpressionFactory()

Yes - you can override the default ExpressionFactory on a per JellyContext
basis. So if (say) you wanted to use Jython expressions everywhere or JXPath
or JavaScript or BeanShell or whatever, you can overload that by customizing
the XMLParser used by a JellyContext.


> TagLib.createExpression()

This hook is useful if a certain attribute/element wish to have a certain
custom expression factory used based on context. e.g. the XML tag library
uses this mechanism to use the XPath ExpressionFactory for the 'select'
attribute.

So you could use this mechanism to provide some custom library-specific
Expression processing - choosing exactly which which ExpressionFactory to
use based on the context in which the expression occurs.


> Tag.setX(Expression)

This is mostly to allow the tag to evaluate the expression in a custom way.
e.g. if the tag really just wants to iterate over the values of an
expression it could do

    for (Iterator iter = expression.evaluateAsIterator(); iter.hasNext(); )
{
        ...

etc.

Certain custom Expression implementations could ahve special evaluation
mechanisms that you might wanna use in certain circumstances.


> This kind of forethought exemplifies a well built tool.

Thanks!

> I think I'll shoot for the Tag.set...(Expression) because it will be a
> fairly isolated incident.

Cool


> Thanks again,

No problem.

James
-------
http://radio.weblogs.com/0112098/


>
> Kevin Ross
>
> -----Original Message-----
> From: James Strachan [mailto:james_strachan@yahoo.co.uk]
> Sent: Tuesday, March 18, 2003 9:07 AM
> To: Jakarta Commons Users List
> Subject: Re: [jelly] Control of expression execution for an attribute
>
>  From: "Kevin Ross" <Kevin.Ross@iVerticalLeap.com>
> > I am looking to try and support multiple different expressions for a
> > single attribute.  I hope to inspect the expression at runtime,
> > determine what type it is with some sort of certainty, and execute the
> > appropriate expression type.
> >
> > Once the tag is called (setter or invoke), is there any way for me to
> > access the original expression for that attribute, so I can custom
> > process with jexl or xpath or . etc.?
>
> You could process multiple expressions first then pass the result into
> the
> tag.
>
> e.g.
>
> <j:set var="temp" value="..."/>
> <j:if test="${something == 'abc'}">
>     <j:set var="temp" value="bar"/>
> </j:if>
>
> <foo a=${temp}"/>
>
> If you want a Tag to process the Expression in some way you could
> specify
> your setter method as being of type Expression...
>
> public class FooTag {
>     private Expression exp;
>
>     public void setA(Expression exp) {
>         this.exp = exp;
>     }
>
>     public void doTag(XMLOutput  out) {
>         Object result = exp.evaluate(context);
>         ...
>     }
> }
>
> then you'd get access to the Expression object and it will not be
> evaluated
> by default - then its up to your tag to evaluate the expression however
> you
> like.
>
> Note that the intention is for the Expression object to be read only (so
> it
> can be cached) but that you can evaluate it, with whatever context you
> like,
> however many times you like.
>
> James
> -------
> http://radio.weblogs.com/0112098/
>
> __________________________________________________
> 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: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-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

Mime
View raw message