Skip to main content

customizing od IDREF / IDREFS

4 replies [Last post]
Joined: 2005-06-08

Can I customize the Java-Binding of IDREF / IDREFS?

If I have a Schema type like that:

Can I customize the Java binding so that the following interface is generated?

interface Person {
Person getFather();
void setFather(Person value);
Person getMother();
void setMother(Person value);
List getChildren();

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-09

Ah, good point. We used to have a customization to do this, but it's not ported to 2.0.

You are welcome to file this as an issue to to track the progress and so that we won't forget.

Joined: 2005-06-08

I don't know how to file an issue.
But I have an extension of the problem.

If the complexType 'Person' would be split into two independent complexTypes 'Male' and 'Female',
there should be a customizing so that the generated java types 'Male' and 'Female' implement (or extend) an existing (not generated) java interface 'Person'
and this mix-in java interface 'Person' should be usable for the customizing of IDREF and IDREFS.

Joined: 2003-06-25

We are assuming that this problem is for JAXB 2.0.
While JAXB 1.0 bound schema constructs to only interfaces,
JAXB 2.0 binds schema constructs to either interfaces or value
classes, the latter being the default.

For JAXB 2.0 an alternative to using is to use
baseType customization. is not portable since it
is not supported by the spec. However, currently there are some bugs
which need to be fixed before this case will work.

1. JAXB 2.0 defines the following customization to allow customize the
type to which a schema component is bound:

The customization is useful for:
a. specializing the type of the generated property (e.g. Person in
your example ) instead of java.lang.Object. This is useful for
binding of xs:IDREF.

b. conversely, generalizing the type of the generated property (
e.g. java.lang.Object instead of int). This is useful for
supporting type substitution of simple types.

Note the above solution will not work JAXB 1.0 since JAXB 1.0 did
not support the "name" attribute on customization.

2. Here is your schema along with the customization.
(po.Person is used in teh customization - assumption is that the
schema is generated into a package po).


3. Note:

a. is needed to
generate interfaces.

b. I changed the schema type for element "Name" from "xs:string" to
"xs:ID". This is necessary because at runtime an instance of the
type that is referenced from a property to which xs:IDREF is
bound is required to have a property bound to xs:ID by the time
the object tree is marshalled. In your example,

would be bound (after the baseType customization shown above)
would bind to:

Person getMother();
void setMother(Person );

Thus an instance of Person set via call setMother() must have a
property/field annotated with @XmlID attribute when the object
tree is marshalled.

c. The class name specified by "name" attribute in name=".."/> must be a fully qualified class name. However,
if a fully qualified class name is used, then the following
error is obtained:

----------- error -------------- -d bld -p po src/po.xsd
parsing a schema...
compiling a schema...
[ERROR] A class/interface with the same name "po.Person" is
already in use. Use a class customization to resolve this

unknown location

[ERROR] (Relevant to above error) another "Person" is generated
from here.
line 9 of file:/D:/jaxb/samples/users/s2j/test2/src/po.xsd

Failed to produce code.
------------ error --------------

I will file an issue against this in Issue Tracker so we
can track and fix this bug in a future rev of the RI.

You can get around by using a name relative to the package and
fixing the generated PersonImpl class to get it to compile i.e.

instead of

d. When an object tree is marshalled, you will get the following XML:





Child1 Child2


The marshalled value for schema construct with type xs:IDREF is
incorrect. It needs be marshalled as:




We will fix this as well.

Joined: 2003-06-25