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