You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Barnabas Davoti <ba...@empolis.no> on 2004/03/14 17:00:44 UTC

[Digester] "dynamic" attributes

Hi,

I'd like to process a configuration file with Digester. The element structure is 
given (predefined), but the attributes are not. It means the user can introduce 
new attribute names.
I was not able to implement this feature with Digester. Since it stores the 
attribute values as bean propery values, I should know all the attribute names 
in advance to configure the bean (I use DynaBeans). It's not quite possible 
since these custom attribute names will be discovered only during the parsing 
time. The XML instance is well-formed, but obviously not validated.

Is this a limitation of Digester? Any possible workaround?

Thanks for your help!

Barna


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [Digester] "dynamic" attributes

Posted by "Craig R. McClanahan" <cr...@apache.org>.
Better late than never ...

Quoting Barnabas Davoti <ba...@empolis.no>:

> Hi,
> 
> I'd like to process a configuration file with Digester. The element structure
> is 
> given (predefined), but the attributes are not. It means the user can
> introduce 
> new attribute names.
> I was not able to implement this feature with Digester. Since it stores the 
> attribute values as bean propery values, I should know all the attribute
> names 
> in advance to configure the bean (I use DynaBeans). It's not quite possible 
> since these custom attribute names will be discovered only during the parsing
> 
> time. The XML instance is well-formed, but obviously not validated.
> 
> Is this a limitation of Digester? Any possible workaround?
> 
> Thanks for your help!
> 
> Barna
> 

In addition to the FactoryCreateRule suggestion (which is a good one), you
should also note that the standard SetPropertiesRule will match up attributes
to properties without knowing any of that ahead of time ... the only constraint
is that the name of the attribute has to correspond to the name of the
property.  The ways that Struts and Tomcat use [digester] to parse
configuration files, for example, benefits tremendously from this feature,
because you don't have to add any new digester rules for custom subclasses that
have additional properties.

Craig McClanahan


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


Re: [Digester] "dynamic" attributes

Posted by Barnabas Davoti <ba...@empolis.no>.
Thanks very much! It works well using your solution. I see Digester is very 
flexible.

Barna


Tatu Vanhanen wrote:
> One option could be to use a FactoryCreateRule, where you can access all the
> attributes of the tag.
> In the method "public Object createObject(Attributes attributes)" of the
> factory class you can resolve the attributes and look if the created object
> has corresponding properties.
> - Tatu V.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


RE: [Digester] "dynamic" attributes

Posted by Tatu Vanhanen <ta...@graftor.fi>.
Hi
One option could be to use a FactoryCreateRule, where you can access all the
attributes of the tag.
In the method "public Object createObject(Attributes attributes)" of the
factory class you can resolve the attributes and look if the created object
has corresponding properties.

- Tatu V.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org