Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to avoid code duplication and reference code generated in another schema while code generation  RSS feed

santos kumar
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have the following requirement

<!-- for brevity. Its in namepace with prefix xsda -->

<xs:complexType name="AddressType">
<xs:element name="Address">
<xs:restriction base="xs:string"/>

<!-- for brevity. Its in namepace with prefix xsdb -->
<complexType name="person">
<xs:element name="HomeAddress" type='xsda:AddressType'/>


When i generate code this happens
class person
@XmlElement(name = "homeAddress", required = true)
protected xsdb.AddressType homeAddress;
but we want

class person
@XmlElement(name = "HomeAddress", required = true)
protected xsda.AddressType HomeAddress;

Just reference the class generated in common xsd and if possible even the object factory should reference xsd a object factory so it create AddressType class again.


public xsda.AddressType createAddressType() {
return new AddressType();

instead of

public xsdb.AddressType createAddressType() {
return new AddressType();

We just need reference and we arent essentially inheriting(extending the base.).I tried with inheritance plugin and could'nt achieve it. [please correct the mistakes if any]

<jaxb:bindings schemaLocation="file:/F:/xsdb.xsd" node="/xsd:schema">
<jaxb:package name="inheritedpackage" /> <!- is it correct-->
<inheritancebjectFactory packageName="commonpackage" />
<jaxb:bindings node="//xsd:element[@name='homeAddress']">
<!-- --- why is there empty class??saw it in examples -->

i also worked on inheritance with child class adding nothing to base something like

in child xsd:

<complextype name='homeaddress'>
<xsd:extension base="xsda:Addresstype" />
<!-- inheriting and not adding to base class -->

That too didnt work.Got compilation errors

Please let me know how it can be done.Thanks for the patience and effort.Much appreciated.


With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!