Nesting customizations
Jibx2Wsdl supports extensive customizations for modifying the default conversions between Java data structures and XML schema representations. The customizations use an XML representation with a nested organization that matches how your Java classes are organized into packages. Here's a simple example (taken from
example2):
<custom force-classes="true" strip-prefixes="m_">
<package name="com.sosnoski.ws.library.jibx2wsdl"
namespace="http://sosnoski.com/ws/library">
<class name="Book" requireds="type title isbn authors">
<field field="m_type" attribute="type"/>
<field field="m_isbn" attribute="isbn"/>
</class>
<class name="Type" requireds="description name"/>
</package>
</custom>This example defines four levels of customizations. The top level, those defined as attributes of the <custom> element, apply to
all classes which Jibx2Wsdl will process. In this case the first option,
force-classes="true", just sets an option on the binding definition itself, while the second one,
strip-prefixes="m_" tells Jibx2Wsdl to ignore the prefix "m_" when converting Java field names to value names.
The second level of customizations are defined by the <package> element in the example. On this element, the required
name attribute gives the name of the package, while the
namespace attribute defines a namespace to be used for classes within that package.
The third level of customizations are defined by the <class> elements nested within the <package> element. On these elements, the required
name attribute gives the name of the class, while the other attributes set options that apply to that class. In this example, the only options used at this level are telling Jibx2Wsdl that some of the values defined by the classes are required.
Finally, the fourth level of customizations are defined by the <field> elements within the first <class> element. The required
field attribute gives the field name, while the
attribute attribute tells Jibx2Wsdl to use attributes for the XML representation of these fields, and gives the corresponding attribute name. If it seems like a lot of effort to have these separate elements just to say that a value is to be an attribute rather than an element, you'll be relieved to know that there's actually a simpler approach to do the same thing, using flag characters on names in the
requireds list (or
optionals list, if appropriate) of the containing <class> element - but the <field> element or alternatives are still useful for other purposes, and this usage is a way to include them in this simple example.
<package> elements can be nested inside other <package> elements. When <package> and <class> elements are nested within the customizations, the names used are always relative to the containing <package> element. You can also use a <class> element directly as a child of the <custom> element, but in this case you need to specify the fully-qualified class name.
You might expect inner classes to be handled the same way, nesting the <class> element for the inner class within that for the containing class - but at least for now, that's not the case. Jibx2Wsdl instead requires a separate <class> element as a sibling of that for the containing class, using a '$' separator for the inner class name (with the inner class name given as "Outer$Inner", for instance).
Nesting elements and attributes
The basic nesting customization elements are used for controlling how Java data structures are translated into XML representations. These customizations are used by both
Jibx2Wsdl and
BindingGenerator.
Jibx2Wsdl also defines some extension elements which can be added to the customizations information for controlling how service classes are translated into WSDL definitions.
The basic nesting customization elements are the three you were introduced to in the last section: The <custom> element itself, the <package> element, and the <class> element. As mentioned in that section, the <custom> element is always the root element of a customization document, and can have <package> child elements, <class> child elements, or both. <package> elements can in turn contain other <package> and/or <class> child elements. The only restriction is that you need to nest these in a way that reflects the package structure - so if you have a <package> element present for a particular package, any <package> elements referring to subpackages and any <class> elements referring to classes in that package or in subpackages must be nested inside the original <package> element.
An example might help explain this part: If you have a <package> element referencing the "com.sosnoski.ws.library" package, and another <package> element referencing the "com.sosnoski.ws.library.data" package, and a <class> element referencing the "com.sosnoski.ws.library.data.Book" class, then these elements would need to be nested in that order. If you have another <class> element referencing the "com.sosnoski.ws.store.Item" class, that's outside the package hierarchy for the first three elements. So these would be structured as:
<package name="com.sosnoski.ws.library" ...>
<package name="data" ...>
<class name="Book" .../>
</package>
</package>
<class name="com.sosnoski.ws.store.Item" .../>Note again that the names used for these nested <package> and <class> elements are always relative to the containing <package>, if any.
The
Jibx2Wsdl extension elements are <wsdl> and <service>. The <wsdl> element, if present, must always be a direct child of the <custom> element at the root of the customization document. It can contain any number of child <service> elements, which can in turn contain <operation> elements, and the latter can contain other elements. The <operation> elements don't define any settings inherited by their child elements, though, so they're not considered as part of this set of nesting customization elements.
All the different nesting customization elements share a common basic set of attributes, and any values set for these attributes are inherited by child elements (unless overridden by a new setting at the child level). Here's the list:
| Attribute | Interpretation |
|---|
| namespace | Basic namespace URI used for definitions. Note that by default, this will just be a base value which will be extended for child packages (see namespace-style attribute, below). |
| namespace-style | Technique used to derive namespace URIs. Values are "none", "package", or "fixed". The default is "package", meaning namespaces are derived from package names. To set a fixed namespace for a package and all child packages, you need to both specify the namespace (see namespace attribute, above) and set this values "fixed". |
| name-style | Technique used to derive XML names from Java value names. This can be "camel-case", "upper-camel-case", "hyphenated", "dotted", or "underscored" (all hopefully somewhat self-explanatory). "camel-case" is the default. |
| require | Types to be treated as required values (unless otherwise specified). This can be "none", "primitives", "objects", or "all". The default is "primitives". |
Besides these attributes that apply to all the different nesting customization elements, there's another set that applies only to the ones used for basic bindings (<custom>, <package>, and <class>):
| Attribute | Interpretation |
|---|
| property-access | Determines whether the values to be included in the binding are found by looking at fields ("false") or get/set property access methods ("true"). The default is "false", meaning fields will be used. |
| strip-prefixes | Space-separated list of strings to be stripped from the start of field names in order to find the value name (e.g., strip-prefixes="m_ s_"). |
| strip-suffixes | Space-separated list of strings to be stripped from the end of field names in order to find the value name (e.g., strip-suffixes="Int Float"). |
| map-abstract | Determines whether the mapping definitions for classes included in the binding should be made abstract ("true"), equivalent to schema complexType definitions, or concrete ("false"), equivalent to schema element definitions. The default is "true", meaning abstract mappings will be used. |
| force-mapping | Determines whether every <class> element should have a corresponding mapping in the JiBX binding ("true"), or if mappings should only be used if needed ("false"). If this is "false" (the default), JiBX may instead use an embedded structure definition in the binding (corresponding to an embedded complexType in the schema definition). |
| wrap-collections | Determines whether the representation for collections should use wrapper elements around the items in the collection ("true") or just embed the items directly ("false"). The default is "false". |
The third group of nesting customization attributes apply only to the WSDL-specific nesting elements (<wsdl> and <service>):
| Attribute | Interpretation |
|---|
| set-actions | Determines whether the generated WSDL should specify soapAction values as part of the operation definitions. Some frameworks require these action values to be present. The default is "true", meaning the action values will be defined. |
| use-nillable | Determines whether nillable="true" will be specified in the schema definition for optional values used as method parameters. The default is "false", meaning minOccurs="0" will be used rather than nillable. |
| service-base | Sets the base address used for the service endpoint address specified in the WSDL. The default is "http://localhost:8080/axis2/services" at the <wsdl> level, which will be modified by appending the service name on the end. |
Nesting customization element details
<custom> element
This is the root of the customization document. The only child elements allowed are <wsdl> (if using Jibx2Wsdl, not if using BindingGenerator), <package>, and <class>. In addition to the first two groups of nesting attributes listed above, this supports the following attributes:
| Attribute | Interpretation |
|---|
| To be added |
<package> element
This element defines customizations that apply to a particular package, along with any subpackages, and classes both in the package and any subpackages. The only child elements allowed are <package> and <class>. In addition to the first two groups of nesting attributes listed above, this supports the following attributes:
| Attribute | Interpretation |
|---|
| To be added |
<class> element
This element defines customizations that apply to a particular class. The only child elements allowed are <field>, <collection-field>, <property>, and <collection-property>. In addition to the first two groups of nesting attributes listed above, this supports the following attributes:
| Attribute | Interpretation |
|---|
| element-name | Gives the schema element name corresponding to this class. If this is not supplied, the element name is derived from the class name. The element name is only used if needed. |
| type-name | Gives the schema complexType name corresponding to this class. If this is not supplied, the type name is derived from the class name. The type name is only used if needed. |
| create-type | Gives the type to be created when an instance of this class is needed (corresponding to the JiBX binding definition create-type attribute). |
| factory | Gives the factory method to be used to create an instance of this class (corresponding to the JiBX binding definition factory attribute). |
| form | |
| includes | Space-separated list of value names to be included in binding. The names can include an optional leading flag character to indicate the type of representation to be used for the value. See the paragraph below this table for details. |
| includes | Space-separated list of value names to be included in the XML representation. The names can use an optional leading flag character to indicate the type of representation to be used for the value. See the paragraph below this table for details. |
| excludes | Space-separated list of value names to be excluded from binding. |
| requireds | Space-separated list of value names to be included as required values in the XML representation. The names can use an optional leading flag character to indicate the type of representation to be used for the value. See the paragraph below this table for details. |
| optionals | Space-separated list of value names to be included as optional values in the XML representation. The names can use an optional leading flag character to indicate the type of representation to be used for the value. See the paragraph below this table for details. |
| use-super | Determines whether values from superclasses of this class should also be included in the XML representation. The default is "true". |
Value names used in the
include,
exclude,
requireds, and
optionals lists are either field names, with any prefixes or suffixes stripped, or property names (as found from get/set access methods), whichever is appropriate (see the
property-access attribute in the second table of common nesting definitions, above). In the case of the
include,
requireds, and
optionals lists the names can be prefixed with a flag character to indicate the type of representation to be used for the value: '@' for an attribute, '/' for an element, and '#' for a text value (NOTE: '#' is not yet supported). This approach provides an easy way to override the default choice of representation without needing to add a separate child element for each value.
Value specification elements
The value specification elements each provide customization details for a particular field or property of a class. They can only be used as the children of a <class> element, and cannot have any child elements. They share a common set of attribute values:
| Attribute | Interpretation |
|---|
| element | The element name to be used for this value (only if to be represented as an element). If not supplied, the element name is derived from the value name. |
| attribute | The attribute name to be used for this value (only if to be represented as an attribute). If not supplied, the attribute name is derived from the value name. |
| actual-type | The actual type to be assumed for this value. This actual type can be a specific variation of the stated type of a field or property, but must be assignable to a variable of the stated type. It corresponds to the JiBX binding definition actual-type attribute. |
| create-type | The type to be created when an instance of this value is needed (corresponding to the JiBX binding definition create-type attribute). |
| factory | Gives the factory method to be used to create an instance of this value (corresponding to the JiBX binding definition factory attribute). |
| required | Determines whether the value is treated as required ("true") or optional ("false"). The default is determined based on the value type and the nesting customization require value. |
<field> element
This element defines customizations that apply to a particular field. This defines one attribute in addition to the common set listed above:
| Attribute | Interpretation |
|---|
| field | The exact field name (no prefixes or suffixes are stripped). |
<collection-field> element
This element defines customizations that apply to a particular field defining a collection of values. This defines three attributes in addition to the common set listed above:
| Attribute | Interpretation |
|---|
| field | The exact field name (no prefixes or suffixes are stripped). |
| item-type | The type of items contained in the collection. |
| item-name | The element name to be used for the individual items present in the collection. |
<property> element
This element defines customizations that apply to a particular property. This defines two attributes in addition to the common set listed above:
| Attribute | Interpretation |
|---|
| get-name | The exact method name used for read access to the value. |
| set-name | The exact method name used for write access to the value. |
<collection-property> element
This element defines customizations that apply to a particular property defining a collection of values. This defines four attributes in addition to the common set listed above:
| Attribute | Interpretation |
|---|
| get-name | The exact method name used for read access to the value. |
| set-name | The exact method name used for write access to the value. |
| item-type | The type of items contained in the collection. |
| item-name | The element name to be used for the individual items present in the collection. |