You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Christian Sell <ch...@netcologne.de> on 2003/01/16 23:33:59 UTC
[jelly] taglib implementation questions
Hello,
I am trying to port an ANT-based tag library over to Jelly and have the
following questions:
- is there a way to create tags such that nested elements will be
created via reflction like in ANT, or do I have to implement & register
tag classes even for all tags that occur only on nested levels in my script?
- is there some way to automatically enforce a specific syntax (like a
DTD), or do my tags have to perform syntax validation of their own
(presumably in method doTag())?
thanks,
Christian
Re: [jelly] taglib implementation questions
Posted by James Strachan <ja...@yahoo.co.uk>.
From: "Christian Sell" <ch...@netcologne.de>
> I did not want to derive my taglib from BeanTagLibrary, because:
>
> 1) I dont like to be closely coupled to an external library, which only
> supplies optional features that are not at the core of my lib.
>
> 2) the above can also be rephrased as a OO design aspect. My library "is
> not a BeanTagLibrary". It has a completely different purpose. For
> example, by inheriting from BeanTagLibrary, it would suddenly support
> the "beandef" tag, which is completely alien to its function.
It'd be trivial to refactor the BeanTagLibrary class to make this optional
or refactor the common code into an abstract base class or something. i.e.
have a well defined extension point from which you can derive.
> after all, inheritance is only available once, and therefore should be
> used with caution..
OK I understand. So I'd say your choices are
* write your own tag library handling the mapping of tags -> beans and
properties however you wish with whatever code you wish.
* we could refactor BeanTagLibrary to make the things you don't want
optional (or move the reusable stuff to a base class etc). In particular
it'd be good if you could reuse UseBeanTag (from core) or BeanTag together
with BeanProperty tag.
* take a look at the betwixt tag library and see if thats more suitable to
your needs.
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
Re: [jelly] taglib implementation questions
Posted by Christian Sell <ch...@netcologne.de>.
I did not want to derive my taglib from BeanTagLibrary, because:
1) I dont like to be closely coupled to an external library, which only
supplies optional features that are not at the core of my lib.
2) the above can also be rephrased as a OO design aspect. My library "is
not a BeanTagLibrary". It has a completely different purpose. For
example, by inheriting from BeanTagLibrary, it would suddenly support
the "beandef" tag, which is completely alien to its function.
after all, inheritance is only available once, and therefore should be
used with caution..
James Strachan wrote:
> From: "Christian Sell" <ch...@netcologne.de>
>
>>Hi,
>>
>>is there a way to do this:
>>
>><mytag class="myClass">
>> <someTag someAtt="dada>
>> <anotherNestedElement att="dada"/>
>> </someTag>
>></mytag>
>>
>>where <mytag> comes from a library which is not derived from
>>BeanTagLibrary or any other Library, and the other tags are not defined
>>in any library.
>>
>>The result should be that from the nested tags an object hierarchy is
>>created, and the root object supplied to the mytag object through the
>>setSomeTag() method.
>
>
> Right now if you created your own library, deriving from BeanTagLibrary and
> registered "mytag" as a possible root tag, it'd all just work. However you
> did say...
>
>
>>where <mytag> comes from a library which is not derived from
>>BeanTagLibrary or any other Library
>
>
> why do you have this restriction? Is it namespaces that you don't want to
> expose to the end user? You can always register that the empty namespace
> binds to your tag library and it'd just work.
>
> e.g.
>
> public class MyTagLibrary extends BeanTagLibrary {
> public MyTagLibrary() {
> registerBean( "mytag", MyDefaultBean.class );
> }
> }
> ...
>
> JellyContext context = new JellyContext();
> context.registerTagLibrary( "", new MyTagLibrary() );
> context.runScript( "my.jelly" );
>
> then the script that you supplied would just work.
>
> 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: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
Re: [jelly] taglib implementation questions
Posted by James Strachan <ja...@yahoo.co.uk>.
From: "Christian Sell" <ch...@netcologne.de>
> BTW, the BeanTagLibrary seems to also require that objects implement
> createXX methods for nested elements. Why cant the object type simply be
> inferred from the argument of the setXX method, and the object be
> created by the default constructor? I think that is what Ant does.
AFAIK Ant uses similar kinds of createXX() methods.
Re: [jelly] taglib implementation questions
Posted by Christian Sell <ch...@netcologne.de>.
BTW, the BeanTagLibrary seems to also require that objects implement
createXX methods for nested elements. Why cant the object type simply be
inferred from the argument of the setXX method, and the object be
created by the default constructor? I think that is what Ant does.
thanks,
Christian
James Strachan wrote:
> From: "Christian Sell" <ch...@netcologne.de>
>
>>Hi,
>>
>>is there a way to do this:
>>
>><mytag class="myClass">
>> <someTag someAtt="dada>
>> <anotherNestedElement att="dada"/>
>> </someTag>
>></mytag>
>>
>>where <mytag> comes from a library which is not derived from
>>BeanTagLibrary or any other Library, and the other tags are not defined
>>in any library.
>>
>>The result should be that from the nested tags an object hierarchy is
>>created, and the root object supplied to the mytag object through the
>>setSomeTag() method.
>
>
> Right now if you created your own library, deriving from BeanTagLibrary and
> registered "mytag" as a possible root tag, it'd all just work. However you
> did say...
>
>
>>where <mytag> comes from a library which is not derived from
>>BeanTagLibrary or any other Library
>
>
> why do you have this restriction? Is it namespaces that you don't want to
> expose to the end user? You can always register that the empty namespace
> binds to your tag library and it'd just work.
>
> e.g.
>
> public class MyTagLibrary extends BeanTagLibrary {
> public MyTagLibrary() {
> registerBean( "mytag", MyDefaultBean.class );
> }
> }
> ...
>
> JellyContext context = new JellyContext();
> context.registerTagLibrary( "", new MyTagLibrary() );
> context.runScript( "my.jelly" );
>
> then the script that you supplied would just work.
>
> 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: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
Re: [jelly] taglib implementation questions
Posted by James Strachan <ja...@yahoo.co.uk>.
From: "Christian Sell" <ch...@netcologne.de>
> Hi,
>
> is there a way to do this:
>
> <mytag class="myClass">
> <someTag someAtt="dada>
> <anotherNestedElement att="dada"/>
> </someTag>
> </mytag>
>
> where <mytag> comes from a library which is not derived from
> BeanTagLibrary or any other Library, and the other tags are not defined
> in any library.
>
> The result should be that from the nested tags an object hierarchy is
> created, and the root object supplied to the mytag object through the
> setSomeTag() method.
Right now if you created your own library, deriving from BeanTagLibrary and
registered "mytag" as a possible root tag, it'd all just work. However you
did say...
> where <mytag> comes from a library which is not derived from
> BeanTagLibrary or any other Library
why do you have this restriction? Is it namespaces that you don't want to
expose to the end user? You can always register that the empty namespace
binds to your tag library and it'd just work.
e.g.
public class MyTagLibrary extends BeanTagLibrary {
public MyTagLibrary() {
registerBean( "mytag", MyDefaultBean.class );
}
}
...
JellyContext context = new JellyContext();
context.registerTagLibrary( "", new MyTagLibrary() );
context.runScript( "my.jelly" );
then the script that you supplied would just work.
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
Re: [jelly] taglib implementation questions
Posted by Christian Sell <ch...@netcologne.de>.
Hi,
is there a way to do this:
<mytag class="myClass">
<someTag someAtt="dada>
<anotherNestedElement att="dada"/>
</someTag>
</mytag>
where <mytag> comes from a library which is not derived from
BeanTagLibrary or any other Library, and the other tags are not defined
in any library.
The result should be that from the nested tags an object hierarchy is
created, and the root object supplied to the mytag object through the
setSomeTag() method.
thanks,
Christian Sell
Re: [jelly] taglib implementation questions
Posted by James Strachan <ja...@yahoo.co.uk>.
From: "Christian Sell" <ch...@netcologne.de>
> Hello,
>
> I am trying to port an ANT-based tag library over to Jelly and have the
> following questions:
Firstly, if you have some existing Ant tasks, they will just work inside the
Ant library for Jelly. (You may need to perform a <taskdef> first).
> - is there a way to create tags such that nested elements will be
> created via reflction like in ANT, or do I have to implement & register
> tag classes even for all tags that occur only on nested levels in my
script?
Sure its possible. This is what the Ant library does right now.
Also there's a bean library which uses a simplified (but similar) bean-like
way to create beans and connect them together For example here's the
JellyUnit test case showing it in action..
http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/jelly/jelly-tags/bean/
src/test/org/apache/commons/jelly/tags/bean/suite.jelly?rev=HEAD
To create this library, only the root bean (Customer) was registered, the
orders and product beans are set on a customer via introspection and a
couple of other methods (createFoo() and either addFoo() or setFoo());
http://cvs.apache.org/viewcvs.cgi/jakarta-commons-sandbox/jelly/jelly-tags/b
ean/src/test/org/apache/commons/jelly/tags/bean/MyTagLibrary.java?rev=HEAD
> - is there some way to automatically enforce a specific syntax (like a
> DTD),
Jelly is just XML so use any kind of XML validation technology you wish to
validate the XML (DTD, XML Schema, RelaxNG, Schematron etc)
> or do my tags have to perform syntax validation of their own
> (presumably in method doTag())?
Jelly usually does some validation for you - i.e. if you add an attribute to
a Tag that doesn't exist or is the wrong type (e.g. can't convert to a
number) it'll generate an error. Right now if Jelly doesn't find a Tag
implementation to use for an XML element, it just leaves it as some static
XML. I'm sure that could be disabled so that if an element is mispelled an
error could be generated.
When it comes to more complex validation, like that <j:case> should be
inside <j.switch> then normally thats quite easy to do a quick check inside
the Tag implementation. In these kinds of situations, where a child tag must
be inside some parent tag, the code will already be calling
findAncestorWithClass() and so its just a matter of adding an if() into the
code.
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