background image

Resolving the Conflicts

<< Using a Binding Declarations File | Bind Choice Example >>
<< Using a Binding Declarations File | Bind Choice Example >>
F
IX
C
OLLIDES
E
XAMPLE
63
Resolving the Conflicts in example.xsd
The first conflict in
example.xsd
, using the Java reserved name
Class
for an
element name, is resolved in
binding.xjb
with the
<class>
and
<property>
declarations on the schema element node
Class
:
<jxb:bindings node="//xs:element[@name='Class']">
<jxb:class name="Clazz"/>
<jxb:property name="Clazz"/>
</jxb:bindings>
The second conflict in
example.xsd
, the namespace collision between the
ele-
ment FooBar
and the
complexType FooBar
, is resolved in
binding.xjb
by
using a
<nameXmlTransform>
declaration at the
<schemaBindings>
level to
append the suffix
Element
to all
element
definitions.
This customization handles the case where there are many name conflicts due to
systemic collisions between two symbol spaces, usually named type definitions
and global element declarations. By appending a suffix or prefix to every Java
identifier representing a specific XML symbol space, this single customization
resolves all name collisions:
<jxb:schemaBindings>
<jxb:package name="example"/>
<jxb:nameXmlTransform>
<jxb:elementName suffix="Element"/>
</jxb:nameXmlTransform>
</jxb:schemaBindings>
The third conflict in
example.xsd
, the namespace collision between the
ele-
ment zip
and the
attribute zip
, is resolved in
binding.xjb
by mapping the
attribute zip
to property named
zipAttribute
:
<jxb:bindings node=".//xs:attribute[@name='zip']">
<jxb:property name="zipAttribute"/>
</jxb:bindings>
If you add the
binding
parameter you removed back to the
xjc
task in the
build.xml
file and then run
ant
in the
<INSTALL>/examples/jaxb/fix-col-
lides
directory, the customizations in
binding.xjb
will be passed to the
xjc
binding compiler, which will then resolve the conflicts in
example.xsd
in the
schema-derived Java classes.