The SOAP example uses the HydraExpress project file example-project.xml to specify the way HydraExpress maps names in the schema to class names. The mappings element in the project file allows you to customize the names of the classes that the code generator generates. The name of this file is passed to HydraExpress when the code generator is invoked.
The SOAP schema defines datatypes and elements that have identical names, as shown in the schema fragment below:
<xs:element name="Envelope" type="tns:Envelope" /> <xs:complexType name="Envelope" > ... </xs:complexType> <xs:element name="Header" type="tns:Header" /> <xs:complexType name="Header" > ... </xs:complexType> <xs:element name="Body" type="tns:Body" /> <xs:complexType name="Body" > ... </xs:complexType>
In general, the code generator creates the name of a class from the name attribute of the element that defines the schema feature represented by the class. In this case, following that strategy would result in two classes with the same name. To avoid the name conflict, the compiler adds the word Type to the name of the class that represents the datatype. For example, the compiler generates class EnvelopeType to represent the datatype Envelope and generates class Envelope to represent the top-level element Envelope.
The mappings element of the HydraExpress project file offers added flexibility. The SOAP example uses the customized mappings included the HydraExpress project file below:
<rwsf-codegen-project> <options> <option name='project-name' value='soapExample'/> <option name='stl' value='true'/> <option name='whitespace' value='true'/> </options> <mappings> <name xsdname="Body" xsdtype="element" name="BodyElement"/> <name xsdname="Envelope" xsdtype="element" name="EnvelopeElement"/> <name xsdname="Header" xsdtype="element" name="HeaderElement"/> <namespace uri="http://schemas.xmlsoap.org/soap/envelope/" name="tns"/> </mappings> <files> <inputSchema file='soap.xsd'/> <inputSchema file='trade.xsd'/> </files> </rwsf-codegen-project>
The contents of the mappings element tells the compiler to create class HeaderElement to represent the element Header, to create class BodyElement to represent the element Body, and to create class EnvelopeElement to represent the element Envelope.
Note that this customized mapping does not affect the names that the compiler uses for the datatype classes. As Table 3 shows, the code generator adds the Type suffix in response to name conflicts in the schema document, regardless of whether an actual class name conflict exists:
Name in Schema | Default Class Name | Class Name With Configuration File |
Envelope element | Envelope | EnvelopeElement |
Envelope complexType | EnvelopeType | EnvelopeType |
Header element | Header | HeaderElement |
Header complexType | HeaderType | HeaderType |
Body element | Body | BodyElement |
Body complexType | BodyType | BodyType |
By including the customized mapping, we remove any ambiguity as to whether a class represents a datatype or an element.
©2004-2007 Copyright Quovadx, Inc. All Rights Reserved.
Quovadx and Rogue Wave are registered trademarks of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.