users@jaxb.java.net

Re: JAXB metainformation

From: Joan Antoni Farre <joan.antoni.farre_at_barcelona.eds.es>
Date: Fri, 11 Jul 2003 10:23:03 +0200

Thanks a lot, Gary and Kohsuke :)
Kohsuke, one more question, please. About "...I think you shouldn't be
using JAXB.", could you suggest a more suitable product?

Thank you again,

Juan





Gary Gregory <ggregory_at_seagullsw.com>@JAVA.SUN.COM> con fecha 10/07/2003
21:24:55

Por favor, responda a Discussion list for the Java Architecture for XML
       Binding <JAXB-INTEREST_at_JAVA.SUN.COM>

(Enviado por: Discussion list for the Java Architecture for XML Binding
         <JAXB-INTEREST_at_JAVA.SUN.COM>)


MENSAJE PERSONAL

Destinatarios: JAXB-INTEREST_at_JAVA.SUN.COM
Copia a (cc):

Referencia: Re: JAXB metainformation
Contenido:



" Or there's a library in Apache Commons that uses reflection to let you
build a reasonable toString method instantly."

FYI,

import org.apache.commons.lang.builder.ToStringBuilder;

public String toString() {
?? return ToStringBuilder.reflectionToString(this);
}

-----Original Message-----
From: Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi_at_Sun.COM]
Sent: Thursday, July 10, 2003 08:57
To: JAXB-INTEREST_at_JAVA.SUN.COM
Subject: Re: JAXB metainformation

Joan Antoni Farre <joan.antoni.farre_at_barcelona.eds.es> wrote:
> - Can JAXB generate toString() methods? If so, do they perform more or
less
> the value concatenation I've talked about? If no toString() methods can
be
> generated, it could be interesting for future JAXB versions.

It doesn't do what you describe out-of-the-box.

But you could use the <xjc:superClass/> customization and write the
toString method by yourself.

> - Does anyone know about some tool which can perform it?

Or there's a library in Apache Commons that uses reflection to let you
build a reasonable toString method instantly.

> - Is it possible to retrieve such information about the restrictions
which
> apply to every bean attribute (such as length for strings, for example)?.
I
> know the possibility of using XSOM to retrieve this information directly
> from the schema, but looks complicated and, probably, low performing. On
> the other hand, it's obvious that such information must be included in
the
> generated beans in order to be able to perform runtime validation. If
this
> possibility doesn't exist, I suggest to consider it for future versions.

If you need to work with JAXB-generated beans in a meta-level (that is,
if your code needs to be able to deal with arbitrary schema), I think
you shouldn't be using JAXB.

You should be able to work more easily at the level of the infoset.
You can just do the so-called "type-assignment" (I believe you could do
that by using some internal mechanism of Xerces, or you can use MSV).

With the type-assignment, you can find out what element/attribute
declaration applies to what element/attribute in a document.

Then you can dive into the corresponding schema definition.

I think the use case of JAXB is for programmers to be willingly bound
*statically* to schemas. In that scenario, I don't think being able to
read metadata is that important (but I'm happy to be corrected.)

> - If not, are there other (may be better) ways than XSOM to do it?

There are many other schema object models available out there. Search
the jaxb-interest archive.

regards,
--
Kohsuke Kawaguchi????????????????? 408-276-7063 (x17063)
Sun Microsystems?????????????????? kohsuke.kawaguchi_at_sun.com