Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.36.2. Substitution Groups in Java
Overview Copy linkLink copied to clipboard!
JAXBElement
class' support for wildcard definitions. Because the members of a substitution group must all share a common base type, the classes generated to support the elements' types also share a common base type. In addition, Apache CXF maps instances of the head element to JAXBElement<? extends T>
properties.
Generated object factory methods Copy linkLink copied to clipboard!
@XmlElementDecl
annotation decorating the object factory method includes two additional properties, as described in Table 36.1, “Properties for Declaring a JAXB Element is a Member of a Substitution Group”.
Property | Description |
---|---|
substitutionHeadNamespace | Specifies the namespace where the head element is defined. |
substitutionHeadName | Specifies the value of the head element's name attribute. |
@XmlElementDecl
contains only the default namespace property and the default name property.
Example 36.5. Object Factory Method for a Substitution Group
Substitution groups in interfaces Copy linkLink copied to clipboard!
JAXBElement<? extends T>
class. The runtime relies on Java's native type hierarchy to support the type substitution, and Java will catch any attempts to use unsupported types.
@XmlSeeAlso
annotation. This annotation specifies a list of classes required by the runtime for marshalling. Fore more information on using the @XmlSeeAlso
annotation see Section 31.4, “Adding Classes to the Runtime Marshaller”.
Example 36.6. WSDL Interface Using a Substitution Group
Example 36.7. Generated Interface Using a Substitution Group
@XmlSeeAlso
annotation. Listing the object factory for a namespace provides access to all of the generated classes for that namespace.
Substitution groups in complex types Copy linkLink copied to clipboard!
JAXBElement<? extends T>
property. It does not map it to a property containing an instance of the generated class generated to support the substitution group.
Example 36.8. Complex Type Using a Substitution Group
Example 36.9. Java Class for a Complex Type Using a Substitution Group
Setting a substitution group property Copy linkLink copied to clipboard!
JAXBElement<? extends T>
class. When the element is simply mapped to an object of the generated value class, you work with the object the same way you work with other Java objects that are part of a type hierarchy. You can substitute any of the subclasses for the parent class. You can inspect the object to determine its exact class, and cast it appropriately.
JAXBElement<? extends T>
object to hold instances of a substitution group, you must wrap the element's value in a JAXBElement<? extends T>
object. The best method to do this is to use the element creation methods provided by the object factory. They provide an easy means for creating an element based on its value.
Example 36.10. Setting a Member of a Substitution Group
- 1
- Instantiates an object factory.
- 2
- Instantiates a
PlasticWidgetType
object. - 3
- Instantiates a
JAXBElement<PlasticWidgetType>
object to hold a plastic widget element. - 4
- Instantiates a
WidgetOrderInfo
object. - 5
- Sets the
WidgetOrderInfo
object's widget to theJAXBElement
object holding the plastic widget element.
Getting the value of a substitution group property Copy linkLink copied to clipboard!
JAXBElement<? extends T>
object. You must to use the JAXBElement<? extends T>
object's getValue()
method. The following options determine the type of object returned by the getValue()
method:
- Use the
isInstance()
method of all the possible classes to determine the class of the element's value object. - Use the
JAXBElement<? extends T>
object'sgetName()
method to determine the element's name.ThegetName()
method returns a QName. Using the local name of the element, you can determine the proper class for the value object. - Use the
JAXBElement<? extends T>
object'sgetDeclaredType()
method to determine the class of the value object.ThegetDeclaredType()
method returns theClass
object of the element's value object.WarningThere is a possibility that thegetDeclaredType()
method will return the base class for the head element regardless of the actual class of the value object.
getName()
method.
Example 36.11. Getting the Value of a Member of the Substitution Group