Following is a simple schema that is representative of the problem I'm
seeing:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="
http://www.w3.org/2001/XMLSchema">
<xs:complexType name="Employee">
<xs:sequence>
<xs:element ref="EmployeeInfo"/>
</xs:sequence>
</xs:complexType>
<!-- These would probably be in an external schema, perhaps as part
of a shared library -->
<xs:element name="EmployeeInfo" type="EmployeeInfo_Type"/>
<xs:complexType name="EmployeeInfo_Type">
<xs:sequence>
<xs:element name="first-name" type="xs:string"/>
<xs:element name="last-name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
I ran XJC against the schema three different times:
1) Using JAXB 1.0.5
2) Using JAXB 2.0.3
3) Using JAXB 2.0.3 (Adding generateValueClass="false" to the global
bindings)
I also specified the global binding 'underscoreBinding="asCharInWord"'
for all three cases. Anyway, here are the files that were generated for
all three cases (I've omitted the ObjectFactory classes and such for
brevity):
1)
- Employee.java
- EmployeeInfo.java
- EmployeeInfo_Type.java
2)
- Employee.java
- EmployeeInfo_Type.java
3)
- Employee.java
- EmployeeInfo_Type.java
It's that "EmployeeInfo.java" interface that's generated by JAXB 1.x
that I'm trying to generate w/my plug-in (looks like it might come from
my "ref" element in the "Employee" type). The relationship between the
files in JAXB 1.x is that "EmployeeInfo" is an interface that extends
"EmployeeInfo_Type". In addition there are corresponding factory
methods that return instances that implement these interfaces.
With JAXB 2.x, EmployeeInfo.java isn't even generated. If I specify
'generateValueClass="false"' the class is generated, but it's a concrete
class, not an interface. Since our code assumes things like casting
between "EmployeeInfo_Type" and "EmployeeInfo" we have a lot of problems
with JAXB 2 based on the assumptions we made in JAXB 1.x.
Is there a switch, setting or known work-around that will generate
interfaces similar to JAXB 1.x for all the generated classes? I've
tried most of the binding switches, and I've attempted to write a
plug-in that recreates these interfaces. While I was marginally
successful in re-creating the interfaces, I am still missing the
corresponding factory methods. Thoughts? Migrating the code by hand is
not really a feasible option at this time due to its size (hundreds of
files and thousands of references). Thanks.
Dan