aspose file tools
The moose likes XML and Related Technologies and the fly likes How to avoid code duplication and reference  code generated in another schema while code generation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Reply Bookmark "How to avoid code duplication and reference  code generated in another schema while code generation" Watch "How to avoid code duplication and reference  code generated in another schema while code generation" New topic
Author

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

santhosh kumar gnanasuriyan
Greenhorn

Joined: Jan 11, 2012
Posts: 2
We have the following requirement

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


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




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

}

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.

like

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:schemaBindings>
<jaxb:package name="inheritedpackage" /> <!- is it correct-->
</jaxb:schemaBindings>
<inheritancebjectFactory packageName="commonpackage" />
<jaxb:bindings node="//xsd:element[@name='homeAddress']">
</class>
<!-- --- why is there empty class??saw it in examples -->
<inheritance:implement>a.AddressType</inheritance:implement>
</jaxb:bindings>
</jaxb:bindings>


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

in child xsd:


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

That too didnt work.Got compilation errors


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


--Santhosh


 
 
subject: How to avoid code duplication and reference code generated in another schema while code generation
 
Threads others viewed
converting xsd to html
JAXB bindings
Problems with JAXB-generated javadoc code
Invalid type (xsi:type) is set when XML request is generated from web service client
Customizing JAXB
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture