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.此内容没有您所选择的语言版本。
35.3. Deriving Complex Types from Simple Types
Overview 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Apache CXF supports derivation of a complex type from a simple type. A simple type has, by definition, neither sub-elements nor attributes. Hence, one of the main reasons for deriving a complex type from a simple type is to add attributes to the simple type.
There are two ways of deriving a complex type from a simple type:
Derivation by extension 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Example 35.12, “Deriving a Complex Type from a Simple Type by Extension” shows an example of a complex type, internationalPrice, derived by extension from the xsd:decimal primitive type to include a currency attribute.
Example 35.12. Deriving a Complex Type from a Simple Type by Extension
The
simpleContent
element indicates that the new type does not contain any sub-elements. The extension
element specifies that the new type extends xsd:decimal.
Derivation by restriction 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Example 35.13, “Deriving a Complex Type from a Simple Type by Restriction” shows an example of a complex type, idType, that is derived by restriction from xsd:string. The defined type restricts the possible values of xsd:stringto values that are ten characters in length. It also adds an attribute to the type.
Example 35.13. Deriving a Complex Type from a Simple Type by Restriction
As in Example 35.12, “Deriving a Complex Type from a Simple Type by Extension” the
simpleContent
element signals that the new type does not contain any children. This example uses a restriction
element to constrain the possible values used in the new type. The attribute
element adds the element to the new type.
Mapping to Java 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
A complex type derived from a simple type is mapped to a Java class that is decorated with the
@XmlType
annotation. The generated class contains a member variable, value
, of the simple type from which the complex type is derived. The member variable is decorated with the @XmlValue
annotation. The class also has a getValue()
method and a setValue()
method. In addition, the generated class has a member variable, and the associated getter and setter methods, for each attribute that extends the simple type.
Example 35.14, “idType Java Class” shows the Java class generated for the idType type defined in Example 35.13, “Deriving a Complex Type from a Simple Type by Restriction”.
Example 35.14. idType Java Class