36.5. Customizing Fixed Value Attribute Mapping
Overview
globalBindings customization element. You can also customize the mapping of fixed value attributes to Java constants at a more localized level using the property element.
Global customization
globalBinding element's fixedAttributeAsConstantProperty attribute. Setting this attribute to true instructs the code generator to map any attribute defined using fixed attribute to a Java constant.
Example 36.21. in-Line Customization to Force Generation of Constants
<schema targetNamespace="http://widget.com/types/widgetTypes"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="2.0">
<annotation>
<appinfo>
<jaxb:globalBindings fixedAttributeAsConstantProperty="true" />
</appinfo>
</annotation>
...
</schema>Example 36.22. Binding File to Force Generation of Constants
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.0">
<jaxb:bindings schemaLocation="types.xsd">
<jaxb:globalBindings fixedAttributeAsConstantProperty="true" />
<jaxb:bindings>
<jaxb:bindings>Local mapping
property element's fixedAttributeAsConstantProperty attribute. Setting this attribute to true instructs the code generator to map any attribute defined using fixed attribute to a Java constant.
Example 36.23. In-Line Customization to Force Generation of Constants
<schema targetNamespace="http://widget.com/types/widgetTypes"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="2.0">
<complexType name="widgetAttr">
<sequence>
...
</sequence>
<attribute name="fixer" type="xsd:int" fixed="7">
<annotation>
<appinfo>
<jaxb:property fixedAttributeAsConstantProperty="true" />
</appinfo>
</annotation>
</attribute>
</complexType>
...
</schema>Example 36.24. Binding File to Force Generation of Constants
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.0">
<jaxb:bindings schemaLocation="types.xsd">
<jaxb:bindings node="xsd:complexType[@name='widgetAttr']">
<jaxb:bindings node="xsd:attribute[@name='fixer']">
<jaxb:property fixedAttributeAsConstantProperty="true" />
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
<jaxb:bindings>Java mapping
fixed attribute, the attribute is mapped to a Java constant, as shown in Example 36.25, “Mapping of a Fixed Value Attribute to a Java Constant”.
Example 36.25. Mapping of a Fixed Value Attribute to a Java Constant
@XmlAttribute public final static type NAME = value;
attribute element's name attribute to all capital letters.
attribute element's fixed attribute.
Example 36.26. Fixed Value Attribute Mapped to a Java Constant
@XmlRootElement(name = "widgetAttr")
public class WidgetAttr {
...
@XmlAttribute
public final static int FIXER = 7;
...
}
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.