[Simple-support] Possible enhancements
Brought to you by:
niallg
|
From: Mike Q. <mik...@su...> - 2007-05-01 10:26:33
|
Hi all,
=20
First off, nice project! I've finally got fed up at navigating around
dom4j nodes so was looking around for xml binding stuff. Started
looking at JAXB but I'm not sure I've ever seen a more complicated way
of doing something that should be so simple. My next stop was google
search "xml binding simple" which brought me here.
=20
I really like the annotation approach to doing this as it's quick and
easy to understand. The tutorial was also excellent as I could actually
start coding in <5 minutes, bit of a novelty after spending an hour
poring over JAXB APIs.
=20
I have some suggestions to maybe enhance/simplify some areas regarding
the annotations. Please don't take this as any form of criticism, just
some ideas :)
=20
=20
1) Default the element/attribute name to the field/method it is on (not
sure if the annotations are supported on methods)
=20
e.g.
=20
@Attribute( name =3D "path" )
private String path;
The name =3D "path" seems pretty redundant to me in this case. Could =
just
be
=20
@Attribute
private String path;
=20
=20
2) Derive types from generics/array types where possible.
=20
=20
@ElementList( name =3D "schemas", type =3D Schema.class)
private List< Schema > schemas;
OR
=20
@ElementArray( name =3D "schemas", type =3D Schema.class)
private Schema[] schemas;
I believe the type/class can be derived from the generic type of the
array type.
=20
field.getType().getComponentType().
=20
Generics you can use
=20
((ParameterizedType)field.getGenericType()).getActualTypeArguments()[ 0
].
=20
=20
Combined with 1) above makes the above examples
=20
=20
@ElementList
private List< Schema > schemas;
OR
=20
@ElementArray
private Schema[] schemas;
=20
=20
3) Make the annotations limited on what they can be applied to. Minor
point, but at the moment I can use @Attribute on a class if I really
want to. I imagine nothing would go wrong, it would just be ignored,
but it adds another piece of implicit documentation.
=20
@Target( FIELD, METHOD )
@Retention(RetentionPolicy.RUNTIME)
public @interface Attribute {
=20
=20
=20
Cheers.
=20
Mike.
This e-mail is bound by the terms and conditions described at http://www=
=2Esubexazure.com/mail-disclaimer.html
=0D |