Customizing Names and Identifiers
HydraExpress provides the ability to customize the names that the code generator creates.
If you wish to customize names and identifiers for all code generation, use the ‑datamap command line option when generating code to provide the name of an XML-based file that defines the new names.
If you wish to customize names and identifiers for specific instances, create a project file containing a mappings element and provide this to the code generator. This is the procedure described in this section.
A HydraExpress project file is XML. The root element of all HydraExpress project files is named rwsf-codegen-project. (See “The Project File,” in the HydraExpress Web Service Development Guide for more information.) In this case, it will contain a single mappings element. The mappings element may contain any number of name elements. Each name element declares a rule for HydraExpress to use when creating identifiers.
Each name element contains three required and one optional attribute:
xsdname — the name that appears in the schema
xsdtype — the type of definition the mapping applies to. This attribute may have a value of
element,
attribute,
complexType or
all.
name — the name HydraExpress uses in the generated code
namespace — the namespace in which the
element,
attribute, or
complexType is defined. This attribute is optional.
The HydraExpress project file below defines three name mappings:
<rwsf-codegen-project project-name="CustomMappings">
<mappings>
<name xsdname="recipientAddress"
xsdtype="element" name="ToAddress"/>
<name xsdname="address"
namespace="http://www.standardletters.com/address2"
xsdtype="complexType" name="AltAddress"/>
<name xsdname="body" xsdtype="all" name="LetterBody"/>
</mappings>
</rwsf-codegen-project>
The first name mapping specifies that HydraExpress will use the name ToAddress in code generated for an element named recipientAddress. Note that the mapping applies only to elements. Attributes or complex types with the name recipientAddress are not affected by this rule.
The second name mapping specifies that HydraExpress will use the name AltAddress in code generated for a complex type named address within the http://www.standardletters.com/address2 namespace.
The third name mapping specifies that HydraExpress will use the name LetterBody for any element, attribute, or complex type with a name of body.
Note that for complexType and element definitions that contain anonymous type definitions, the name mapping specifies the name of the accessor and mutator as well as the class name. Mapping rules that match element and attribute names in declarations within a complexType definition only affect the names of the get and set methods, since HydraExpress does not create classes for these declarations.
The mapping can also specify a full C++ class name under the
xsdname attribute, and any classes that end up with the given name (based on the naming rules in
Names and Identifiers ) will have their class names (and any associated accessors) remapped.