commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simone Tripodi <simonetrip...@apache.org>
Subject Re: [digester] Multiple paths mapped to one object
Date Thu, 06 Mar 2014 11:04:32 GMT
Hi Jan,

there's no kind of magic, just annotate the class fields as:

@ObjectCreate.List(value = {
        @ObjectCreate(pattern = "*/HTABLE"),
        @ObjectCreate(pattern = "*/VTABLE"),
        @ObjectCreate(pattern = "*/XTABLE")
})
public class Table {

    @SetProperty // you can omit the 'attributeName' since it is the same
as in the attribute
    private String name;

    @SetProperty(attributeName = "x")
    private Long posX;

    @SetProperty(attributeName = "y")
    private Long posY;

    @BeanPropertySetter(pattern = "*/rows")
    private Long rows;

}

please let us know if it works! :)
Alles Gute!
-Simo

http://people.apache.org/~simonetripodi/
http://twitter.com/simonetripodi


On Wed, Mar 5, 2014 at 11:55 AM, Jan Fröhlich
<Jan.Froehlich@infomotion.de>wrote:

> Hi all,
>
> given an XML with something like
> <REPORT>
>     <XTABLE name="Table1" x="1200" y="2250">
>         <rows>10</rows>
>     </XTABLE>
>     <VTABLE name="Table2" x="1400" y="2250">
>         <rows>14</rows>
>     </VTABLE>
>     <HTABLE name="Table3" x="1600" y="2250">
>         <rows>17</rows>
>     </HTABLE>
> </REPORT>
>
> I would like to map all nodes (XTABLE, VTABLE and HTABLE) to one class
> Table and set the properties.
> While learning digester I created a class for each tag, but now I want to
> improve that.
>
> For the class itself the following should work
> @ObjectCreate.List(value = {
>         @ObjectCreate(pattern = "*/HTABLE"),
>         @ObjectCreate(pattern = "*/VTABLE"),
>         @ObjectCreate(pattern = "*/XTABLE")
> })
> public class Table {
>     private String name;
>     private Long posX;
>     private Long posY;
>     private Long rows;
>
> }
>
> But how should I annotate the properties as I have to set the pattern
> attribute to all @SetProperty annotations and the pattern is different for
> all of them.
>
> Any help appreciated.
>
> Jan
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message