users@jaxb.java.net

Re: [feature request] Using defaults from code in a XSD default.

From: Gary Gregory <ggregory_at_seagullsw.com>
Date: Fri, 27 Jun 2003 14:46:34 -0400

It all a matter of point of view ;-)

I want to configure a third party component with a JAXB XML file. So, yes, I
am using JAXB to generate "bridge" code. I cannot mod the third party lib
but I *am* authoring the XML and XSD. So what I am looking for is to start
with the library and cherry pick constants from the library for use in the
XSD's default values.

Since JAXB is Java and XSD is language neutral, it feels like one should be
able to connect the Java dots in an XJB (binding) file. OTOH, this info
really should be in the XSD.

So this becomes an XSD/Ant processing issue for me and not so much a JAXB
issue.

So, ideally, I could add some Ant task just before I XJC my XSDs to say:
"Here at this point in the XSD binding use this value".

Well, that was helpful, sorry for thinking out loud.

Gary

-----Original Message-----
From: Kohsuke Kawaguchi [mailto:kohsuke.kawaguchi_at_sun.com]
Sent: Friday, June 27, 2003 07:39
To: JAXB-INTEREST_at_JAVA.SUN.COM
Subject: Re: [feature request] Using defaults from code in a XSD default.

Even if you tell JAXB the secondary source of the default value
information, that doesn't change the contract exposed by the schema.
Or are you using your schema just to generate code?

So it seems to me that another approach is to have JAXB generate default
values as constants, and modify your application to use those constants.

Yet another approach would be to pre-process your schema with XSLT or
whatever and add default values, then run it through XJC afterward.


Gary Gregory <ggregory_at_seagullsw.com> wrote:
> Hello,
>
> Some of our code uses a third party library (Apache Jakarta Commons
> HttpClient if you must know) and we configure one of our component which
> uses it with an XML file for which we have an XSD which we generate code
> with JAXB. So far so good and we like it.
>
> Right now, the XSD must be kept in sync with various default values in the
> library. For example, the lib has a setting called "maxConnectionsPerHost"
> with a default value of 2. So, in our XSD we have:
>
> <xs:attribute name="maxConnectionsPerHost" type="cics:positiveShort"
> use="optional" default="2">
>
> and
>
> <xs:simpleType name="positiveShort">
> <xs:restriction base="xs:unsignedShort">
> <xs:minInclusive value="1"/>
> </xs:restriction>
> </xs:simpleType>
>
> It would be nice if somehow, I could tell JAXB to pick up the default
value
> from "com.foo.ThatClass.THE_CONSTANT", which would minimize maintenance on
> keeping the XSD in sync with the code.
>
> Thanks,
> Gary
>


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