javax.xml.bind.annotation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » xml » javax.xml.bind.annotation 
javax.xml.bind.annotation

Defines annotations for customizing Java program elements to XML Schema mapping.

Package Specification

The following table shows the JAXB mapping annotations that can be associated with each program element.

Program Element JAXB annotation
Package
XmlAccessorOrder
XmlAccessorType
XmlSchema
XmlSchemaType
XmlSchemaTypes
XmlJavaTypeAdapter
XmlJavaTypeAdapters
Class
XmlAccessorOrder
XmlAccessorType
XmlInlineBinaryData
XmlRootElement
XmlType
XmlJavaTypeAdapter
Enum type
XmlEnum
XmlEnumValue (enum constant only)
XmlRootElement
XmlType
XmlJavaTypeAdapter
JavaBean Property/field
XmlElement
XmlElements
XmlElementRef
XmlElementRefs
XmlElementWrapper
XmlAnyElement
XmlAttribute
XmlAnyAttribute
XmlTransient
XmlValue
XmlID
XmlIDREF
XmlList
XmlMixed
XmlMimeType
XmlAttachmentRef
XmlInlineBinaryData
XmlElementDecl (only on method)
XmlJavaTypeAdapter
Parameter
XmlList
XmlAttachmentRef
XmlMimeType
XmlJavaTypeAdapter

Terminology

JavaBean property and field: For the purposes of mapping, there is no semantic difference between a field and a JavaBean property. Thus, an annotation that can be applied to a JavaBean property can always be applied to a field. Hence in the Javadoc documentation, for brevity, the term JavaBean property or property is used to mean either JavaBean property or a field. Where required, both are explicitly mentioned.

top level class: For the purpose of mapping, there is no semantic difference between a top level class and a static nested class. Thus, an annotation that can be applied to a top level class, can always be applied to a nested static class. Hence in the Javadoc documentation, for brevity, the term "top level class" or just class is used to mean either a top level class or a nested static class.

mapping annotation:A JAXB 2.0 defined program annotation based on the JSR 175 programming annotation facility.

Common Usage Constraints

The following usage constraints are defined here since they apply to more than annotation:

  • For a property, a given annotation can be applied to either read or write property but not both.
  • A property name must be different from any other property name in any of the super classes of the class being mapped.
  • A mapped field name or the decapitalized name of a mapped property must be unique within a class.

Notations

Namespace prefixes

The following namespace prefixes are used in the XML Schema fragments in this package.

Prefix Namespace Notes
xs http://www.w3.org/2001/XMLSchema Namespace of XML Schema namespace
ref http://ws-i.org/profiles/basic/1.1/xsd Namespace for swaref schema component
xsi http://www.w3.org/2001/XMLSchema-instance XML Schema namespace for instances
@since JAXB 2.0

Java Source File NameTypeComment
DomHandler.javaInterface Converts an element (and its descendants) from/to DOM (or similar) representation.

Implementations of this interface will be used in conjunction with XmlAnyElement annotation to map an element of XML into a representation of infoset such as W3C DOM.

Implementations hide how a portion of XML is converted into/from such DOM-like representation, allowing JAXB providers to work with arbitrary such library.

This interface is intended to be implemented by library writers and consumed by JAXB providers.

W3CDomHandler.javaClass
XmlAccessOrder.javaenum Used by XmlAccessorOrder to control the ordering of properties and fields in a JAXB bound class.
XmlAccessorOrder.javaAnnotation

Controls the ordering of fields and properties in a class.

XmlAccessorType.javaAnnotation

Controls whether fields or Javabean properties are serialized by default.

XmlAccessType.javaenum Used by XmlAccessorType to control serialization of fields or properties.
XmlAnyAttribute.javaAnnotation

Maps a JavaBean property to a map of wildcard attributes.

Usage

The @XmlAnyAttribute annotation can be used with the following program elements:

  • JavaBean property
  • non static, non transient field

See "Package Specification" in javax.xml.bind.package javadoc for additional common information.

The usage is subject to the following constraints:
  • At most one field or property in a class can be annotated with @XmlAnyAttribute.
XmlAnyElement.javaAnnotation Maps a JavaBean property to XML infoset representation and/or JAXB element.

This annotation serves as a "catch-all" property while unmarshalling xml content into a instance of a JAXB annotated class.

XmlAttachmentRef.javaAnnotation Marks a field/property that its XML form is a uri reference to mime content.
XmlAttribute.javaAnnotation

Maps a JavaBean property to a XML attribute.

XmlElement.javaAnnotation Maps a JavaBean property to a XML element derived from property name.

Usage

@XmlElement annotation can be used with the following program elements:

  • a JavaBean property
  • non static, non transient field
  • within XmlElements

The usage is subject to the following constraints:
XmlElementDecl.javaAnnotation Maps a factory method to a XML element.

Usage

The annotation creates a mapping between an XML schema element declaration and a element factory method that returns a JAXBElement instance representing the element declaration.
XmlElementRef.javaAnnotation

Maps a JavaBean property to a XML element derived from property's type.

Usage

@XmlElementRef annotation can be used with a JavaBean property or from within XmlElementRefs

This annotation dynamically associates an XML element name with the JavaBean property.

XmlElementRefs.javaAnnotation Marks a property that refers to classes with XmlElement or JAXBElement.
XmlElements.javaAnnotation

A container for multiple @ XmlElement annotations. Multiple annotations of the same type are not allowed on a program element.

XmlElementWrapper.javaAnnotation Generates a wrapper element around XML representation. This is primarily intended to be used to produce a wrapper XML element around collections.
XmlEnum.javaAnnotation

Maps an enum type Enum to XML representation.

This annotation, together with XmlEnumValue provides a mapping of enum type to XML representation.

Usage

The @XmlEnum annotation can be used with the following program elements:

  • enum type

The usage is subject to the following constraints:

See "Package Specification" in javax.xml.bind.package javadoc for additional common information

An enum type is mapped to a schema simple type with enumeration facets.

XmlEnumValue.javaAnnotation Maps an enum constant in Enum type to XML representation.
XmlID.javaAnnotation

Maps a JavaBean property to XML ID.

To preserve referential integrity of an object graph across XML serialization followed by a XML deserialization, requires an object reference to be marshalled by reference or containment appropriately.

XmlIDREF.javaAnnotation

Maps a JavaBean property to XML IDREF.

To preserve referential integrity of an object graph across XML serialization followed by a XML deserialization, requires an object reference to be marshalled by reference or containment appropriately.

XmlInlineBinaryData.javaAnnotation Disable consideration of XOP encoding for datatypes that are bound to base64-encoded binary data in XML.

When XOP encoding is enabled as described in AttachmentMarshaller.isXOPPackage , this annotation disables datatypes such as Image or Source or byte[] that are bound to base64-encoded binary from being considered for XOP encoding.

XmlList.javaAnnotation Used to map a property to a list simple type.

Usage

The @XmlList annotation can be used with the following program elements:

  • JavaBean property
  • field

When a collection property is annotated just with @XmlElement, each item in the collection will be wrapped by an element. For example,

 @XmlRootElement
 class Foo {
 @XmlElement
 List<String> data;
 }
 
would produce XML like this:

 <foo>
 <data>abc</data>
 <data>def</data>
 </foo>
 
@XmlList annotation, on the other hand, allows multiple values to be represented as whitespace-separated tokens in a single element.
XmlMimeType.javaAnnotation Associates the MIME type that controls the XML representation of the property.

This annotation is used in conjunction with datatypes such as Image or Source that are bound to base64-encoded binary in XML.

If a property that has this annotation has a sibling property bound to the xmime:contentType attribute, and if in the instance the property has a value, the value of the attribute takes precedence and that will control the marshalling.

XmlMixed.javaAnnotation

Annotate a JavaBean multi-valued property to support mixed content.

The usage is subject to the following constraints:

  • can be used with @XmlElementRef, @XmlElementRefs or @XmlAnyElement

The following can be inserted into @XmlMixed annotated multi-valued property

  • XML text information items are added as values of java.lang.String.
  • Children element information items are added as instances of JAXBElement or instances with a class that is annotated with @XmlRootElement.
  • Unknown content that is not be bound to a JAXB mapped class is inserted as Element .
XmlNs.javaAnnotation

Associates a namespace prefix with a XML namespace URI.

XmlNsForm.javaenum Enumeration of XML Schema namespace qualifications.
XmlRegistry.javaAnnotation Marks a class that has XmlElementDecl s.
XmlRootElement.javaAnnotation Maps a class or an enum type to an XML element.

Usage

The @XmlRootElement annotation can be used with the following program elements:

  • a top level class
  • an enum type

See "Package Specification" in javax.xml.bind.package javadoc for additional common information.

When a top level class or an enum type is annotated with the @XmlRootElement annotation, then its value is represented as XML element in an XML document.

This annotation can be used with the following annotations: XmlType , XmlEnum , XmlAccessorType , XmlAccessorOrder .

Example 1: Associate an element with XML Schema type

 // Example: Code fragment
 @XmlRootElement
 class Point {
 int x;
 int y;
 Point(int _x,int _y) {x=_x;y=_y;}
 }
 
 //Example: Code fragment corresponding to XML output
 marshal( new Point(3,5), System.out);
 

 <!-- Example: XML output -->
 <point>
 <x> 3 </x>
 <y> 5 </y>
 </point>
 
The annotation causes an global element declaration to be produced in the schema.
XmlSchema.javaAnnotation

Maps a package name to a XML namespace.

XmlSchemaType.javaAnnotation Maps a Java type to a simple schema built-in type.

Usage

@XmlSchemaType annotation can be used with the following program elements:

  • a JavaBean property
  • field
  • package

@XmlSchemaType annotation defined for Java type applies to all references to the Java type from a property/field.

XmlSchemaTypes.javaAnnotation

A container for multiple @ XmlSchemaType annotations.

Multiple annotations of the same type are not allowed on a program element.

XmlTransient.javaAnnotation

Prevents the mapping of a JavaBean property to XML representation.

The @XmlTransient annotation is useful for resolving name collisions between a JavaBean property name and a field name or preventing the mapping of a field/property.

XmlType.javaAnnotation

Maps a class or an enum type to a XML Schema type.

Usage

The @XmlType annnotation can be used with the following program elements:

  • a top level class
  • an enum type

See "Package Specification" in javax.xml.bind.package javadoc for additional common information.

Mapping a Class

A class maps to a XML Schema type.

XmlValue.javaAnnotation

Enables mapping a class to a XML Schema complex type with a simpleContent or a XML Schema simple type.

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.