users@jaxb.java.net

RE: JAXB 2.0 default values

From: Scott Allan <sallan1000_at_aol.com>
Date: Wed, 7 Sep 2005 21:31:53 -0500

I'm trying to build a plugin to add the default values from the schema
to my bean. I can't seem to find an easy way to obtain the field that
corresponds to the property without checking all of them. There is no
getField() method that I can find. The field() methods all seem to be
for creating new fields.



        for( CPropertyInfo p : co.target.getProperties() ) {

                String fieldName = p.getName(true);

                String fieldName2 = p.getName(false);

                // would like to use something like
co.implClass.getField(...) here.

                // instead need to check all fields

                for (JFieldVar field : co.implClass.fields())

                {

                  if (field.name().equals(fieldName2))

                  System.out.println("Set field.init value here for
"+field.name());

                }

        }



> -----Original Message-----

> From: Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi_at_Sun.COM]

> Sent: Wednesday, September 07, 2005 5:56 PM

> To: users_at_jaxb.dev.java.net

> Subject: Re: JAXB 2.0 default values

>

>

> Dmitri Colebatch wrote:

> > I don't understand the logic behind this. Are you saying that if I

> > have:

> >

> > <foo>

> > <bar />

> > </foo>

> >

> > where in the schema bar has a default value of "x" then

> > foo.getBar().equals("x")? Yet if I have

> >

> > <foo />

> >

> > foo.getBar() is null?

>

> Yup. Just one more reason to hate W3C XML Schema, if you ask me...

>

>

> --

> Kohsuke Kawaguchi

> Sun Microsystems kohsuke.kawaguchi_at_sun.com

>




  _____

<< ella for Spam Control >> has removed 26807 Spam messages and set
aside 2 Newsletters for me
You can use it too - and it's FREE! www.ellaforspam.com