javax.xml.bind.annotation

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 geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » jaxb api » 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.

XmlSeeAlso.javaAnnotation Instructs JAXB to also bind other classes when binding this class.

Java makes it impractical/impossible to list all sub-classes of a given class.

XmlTransient.javaAnnotation

Prevents the mapping of a JavaBean property/type 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.