commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Sell <christian.s...@netcologne.de>
Subject Re: [jelly] taglib implementation questions
Date Mon, 20 Jan 2003 23:04:34 GMT
Dominique Devienne wrote:
> -----Original Message-----
> From: Christian Sell [mailto:christian.sell@netcologne.de] 
> Sent: Monday, January 20, 2003 12:13 PM
> To: Jakarta Commons Users List
> Subject: Re: [jelly] taglib implementation questions
> 
> Dominique Devienne wrote:
> 
>>Ant does not use setMyAttr(SomeType) for nested elements, just for
>>attributes, and requires a SomeType(String) Ctor when an 'myattr'
> 
> attribute
> 
>>is found.
> 
> 
> ?? What would the String argument to the constructor be?
> [DD] How about the attribute value ;-)

I still dont see what constructor you are talking about. I think the ant 
docs are quite clear on this, I've included them for reference below. In 
summary, if you provide an addXxx(XClass x) method, Ant will instantiate 
the object using the no-arg constructor. Attributes will be set the 
usual way, using the setXX methods on the nested elements.


IMO, it would be nice if the bean tag was able to find the nearest 
parent element that implements BeanSource, and from there proceed 
according to the ant rules (see below) and instantiate nested elements 
directly. All that would be required of the outermost element is to 
implement BeanSource and an appropriate addXX method. No library 
inheritance or tag registration.


from ant user manual:
===============================================
Let's assume your task shall support nested elements with the name 
inner. First of all, you need a class that represents this nested 
element. Often you simply want to use one of Ant's classes like 
org.apache.tools.ant.types.FileSet to support nested fileset elements.

Attributes of the nested elements or nested child elements of them will 
be handled using the same mechanism used for tasks (i.e. setter methods 
for attributes, addText for nested text and create/add/addConfigured 
methods for child elements).

Now you have a class NestedElement that is supposed to be used for your 
nested <inner> elements, you have three options:

    1. public NestedElement createInner()
    2. public void addInner(NestedElement anInner)
    3. public void addConfiguredInner(NestedElement anInner)

What is the difference?

Option 1 makes the task create the instance of NestedElement, there are 
no restrictions on the type. For the options 2 and 3, Ant has to create 
an instance of NestedInner before it can pass it to the task, this 
means, NestedInner must have a public no-arg constructor. This is the 
only difference between options 1 and 2.



> 
> 
>>What you are referring to is addMyElem(MyElemClass) which does use the
>>default MyElemClass default Ctor when seeing a nested <myelem> element. Or
>>as James pointed out, use MyElemClass createMyElem(), to enable
>>polymorphism. --DD
> 
> 
> ok, so there we are - Ant does not require the createXXX() method, but 
> makes it optional. Thats what I was referring to.
> [DD] Not really optional... You either provide a addXXX() or a createXXX,
> but if you provide neither, you don't get nested elements.
> 
> - Christian
> 
> --
> To unsubscribe, e-mail:   <mailto:commons-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:commons-user-help@jakarta.apache.org>
> 
> 



Mime
View raw message