Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Editing Dali Project/FeatureDocs/Indigo/JAXB/AttributeAnnotations

Functional Specification: JAXB Attribute Annotations

[enter bug location here]

Document History

Date Author Version Description & Notes
10-11-2010 Paul Fullbright Draft

Feature overview

This feature is about support for JAXB attribute annotations

Goals:

  • Support JAXB attribute level annotations and default values
    • @XmlElement/Elements
    • @XmlElementRef/Refs
    • @XmlElementWrapper
    • @XmlAnyElement
    • @XmlAttribute
    • @XmlAnyAttribute
    • @XmlTransient
    • @XmlValue
    • @XmlID
    • @XmlIDRef
    • @XmlList
    • @XmlMixed
    • @XmlMimeType
    • @XmlAttachmentRef
    • @XmlInlineBinaryData
    • @XmlJavaTypeAdapter

Concepts

Attribute annotations are supported on JAXB fields and Java bean style properties. Unless @XmlTransient is present, all fields/properties that fulfill the type's access type are considered mapped JAXB attributes.

Requirements / Functionality

@XmlElement/Elements

@XmlElement is used on an attribute to indicate that it is mapped to an XML element or element ref. If there is not another mapping annotation on a legitimate JAXB attribute, and:

- the attribute is single valued - @XmlElement is assumed

- the attribute has a collection type - @XmlElements({ @XmlElement(nillable=true) }) is assumed

- the attribute has a collection type and has the @XmlList annotation - @XmlElement is assumed

  • name - String; name of the XML element to which this attribute is mapped; default value is based on the name of the attribute
  • namespace - String; target namespace with which the element must be qualified; default value is based on the class's namespace and the package's elementFormDefault setting - a "" value indicates the element is not to be qualified
  • defaultValue - String; the default value of this attribute; no default
  • nillable - boolean; whether the element is nillable; default is false
  • required - boolean; whether the element is required; default is false
  • type - Class; specifies the type to be used for populating the element; default is determined by spec table 8-14

@XmlElements is used as a container for @XmlElement. It is used on attributes with a parameterized collection type.

@XmlElementRef/Refs

@XmlElementRef dynamically associates an XML element name with a JAXB attribute. When an attribute is annotated with @XmlElement, the XML element name is statically derived from the attribute name. However, when this annotation is used, the XML element name is derived from the instance of the type of the attribute at runtime.

  • name - String; the name of the root XML element to which this attribute is mapped; default value is determined by spec table 8-18
  • namespace - String; namespace of the root XML element to which this attribute is mapped; default value is determined by spec table 8-18
  • type - Class; specifies the type to be used for populating the element; default is determined from attribute type

@XmlElementRef is used as a container for @XmlElementRef. It is used on attributes with a parameterized collection type.

@XmlElementWrapper

@XmlElementWrapper is used to generate an XML element wrapper around values. It is used on attributes with collection types.

  • name - String; name of the XML element to use as a wrapper; default is based on the attribute name
  • namespace - String; namespace with which to qualify the XML element; default value is based on the class's namespace and the package's elementFormDefault setting - a "" value indicates the element is not to be qualified
  • nillable - boolean; specifies if the wrapper element is nillable; default is false
  • required - boolean; specifies if the wrapper element is required; default is false

@XmlAnyElement

@XmlAnyElement serves as a "catch-all" property while unmarshalling xml content into a instance of a JAXB annotated class. It typically annotates a multi-valued attribute, but it can occur on single value attribute. During unmarshalling, each xml element that does not match a static @XmlElement or @XmlElementRef annotation for the other attributes on the class, is added to this "catch-all" property.

  • lax -
  • value -


Code Completion

Code completion should be implemented where feasible to help users with values.

Back to the top