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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
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

santos kumar
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


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to avoid code duplication and reference code generated in another schema while code generation