users@jaxb.java.net

Re: Using Custom bindings to generate small classes for big schem as

From: Katz Guy <Guy_Katz_at_icomverse.com>
Date: Thu, 27 Feb 2003 11:14:16 +0200

Hi;
I was pointed to the non goals of the spec to a specific item:
"NON GOALS:
Provide partial binding of an XML content root to a Java
representation, skipping descendants of the XML content root that
are not relevant to the task at hand.
If there is only a partial binding of all non-optional XML elements
reachable from an XML element, it would no longer be possible to
roundtrip the data back to its original XML content form. Partial
mapping results in a one-way trip from the XML to a Java
representation. There would be no marshal method from a Java
representation back to XML since in general it would not be possible to
produce a valid XML content from a partial Java representation of the
XML content root and its descendants."

I guess in my case I need only one way mapping (Object to XML only) so this
is quite a limitation for me.
I also found this:
"Formally describing support for binding an existing JavaBean class
to schema.
The feature will be considered for a future release but it was considered
out of scope for this release."

Can someone elaborate on this matter. What exactly was it supposed to do? It
seems that I could have used this also because Value Objects are simple java
beans.
Thanks.


Katz Guy wrote:
>
> Hi;
>
> Reading the jaxb user guide I couldn't understand if I can acheve the
> following. I would appreciate any help.
>
> basically , In my project i have huge huge xml schemas and would like to
> generate a small class(or a number of small classes) per schema which
> represent a fragment of that schema.
>
> For example; We would like the schema:
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified">
> <xs:element name="a">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="b" type="xs:string"/>
> <xs:element name="c" type="xs:string"/>
> <xs:element name="d" type="xs:string"/>
> <xs:element name="e">
> <xs:complexType>
> <xs:sequence>
> <xs:element
> name="f" type="xs:string"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:schema>
>
>
> To be generated into:
> Interface <someIfc>{
> public string getB();
> public void setB(String b);
> }
> and
> Class <someName> implements <someIfc>{
> String b;
> public string getB(){return b;}
> public void setB(String b){this.b=b;}
> }
>
> Discurding most of the schema content in the generated classes. Yet when
> transforming an instance of that class into XML we would like it to
> transfrom according to the full scema.
>
> For example:
> An instance of class <someName> with string value of b set to "b" will
> be transformed into:
> <a>
> <b>b</b>
> <c/>
> <d/>
> <e>
> <f/>
> </e>
> </a>
>
> Or something like that.
>
> I figured this would be done by custom bindings but could not find the
> way to do this in the user guide.(maybe I didn't understand the guide
> very well)
>

Guy,

The binding customizations allow you change the default bindings generated
by the compiler, but there is no way to limit the generated interfaces to
specific fragments of the schema as you described. There may be some
extremely limited use cases where you might be able to force JAXB to behave
this way, but in general this is not possible. I'll think about it some
more,
but in the mean-time, I'd be interested to know if anyone else on the list
has any thoughts...

--Ryan

> Is JAXB an apprepriate technology for this? I could not get this from
> the manual.
> I would really appreciate any respose
> Thanks.
>
>
>
> _______________________
> Guy Katz
> Comverse
> guy.katz_at_comverse.com
> +972 3 7663686
>
>