Java Doc for XmlAnyElement.java in  » 6.0-JDK-Modules » jaxb-api » javax » xml » bind » annotation » Java Source Code / Java DocumentationJava Source Code and Java Documentation

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 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


javax.xml.bind.annotation.XmlAnyElement

XmlAnyElement
public @interface XmlAnyElement(Code)
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. It typically annotates a multi-valued JavaBean property, but it can occur on single value JavaBean property. During unmarshalling, each xml element that does not match a static @XmlElement or @XmlElementRef annotation for the other JavaBean properties on the class, is added to this "catch-all" property.

Usages:

 @XmlAnyElement
 public 
Element [] others;
 // Collection of 
Element  or JAXB elements.
 @XmlAnyElement(lax="true")
 public 
Object [] others;
 @XmlAnyElement
 private List<
Element > nodes;
 @XmlAnyElement
 private 
Element  node;
 

Restriction usage constraints

This annotation is mutually exclusive with XmlElement , XmlAttribute , XmlValue , XmlElements , XmlID , and XmlIDREF .

There can be only one XmlAnyElement annotated JavaBean property in a class and its super classes.

Relationship to other annotations

This annotation can be used with XmlJavaTypeAdapter , so that users can map their own data structure to DOM, which in turn can be composed into XML.

This annotation can be used with XmlMixed like this:

 // List of java.lang.String or DOM nodes.
 @XmlAnyElement @XmlMixed
 List<Object> others;
 

Schema To Java example

The following schema would produce the following Java class:

 <xs:complexType name="foo">
 <xs:sequence>
 <xs:element name="a" type="xs:int" />
 <xs:element name="b" type="xs:int" />
 <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
 </xs:sequence>
 </xs:complexType>
 
 class Foo {
 int a;
 int b;
 @
XmlAnyElement List<Element> any;
 }
 
It can unmarshal instances like

 <foo xmlns:e="extra">
 <a>1</a>
 <e:other />  // this will be bound to DOM, because unmarshalling is orderless
 <b>3</b>
 <e:other />
 <c>5</c>     // this will be bound to DOM, because the annotation doesn't remember namespaces.
 </foo>
 
The following schema would produce the following Java class:

 <xs:complexType name="bar">
 <xs:complexContent>
 <xs:extension base="foo">
 <xs:sequence>
 <xs:element name="c" type="xs:int" />
 <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
 </xs:sequence>
 </xs:extension>
 </xs:complexType>
 

 class Bar extends Foo {
 int c;
 // Foo.getAny() also represents wildcard content for type definition bar.
 }
 
It can unmarshal instances like

 <bar xmlns:e="extra">
 <a>1</a>
 <e:other />  // this will be bound to DOM, because unmarshalling is orderless
 <b>3</b>
 <e:other />
 <c>5</c>     // this now goes to Bar.c
 <e:other />  // this will go to Foo.any
 </bar>
 

Using XmlAnyElement with XmlElementRef

The XmlAnyElement annotation can be used with XmlElementRef s to designate additional elements that can participate in the content tree.

The following schema would produce the following Java class:


 <xs:complexType name="foo">
 <xs:choice maxOccurs="unbounded" minOccurs="0">
 <xs:element name="a" type="xs:int" />
 <xs:element name="b" type="xs:int" />
 <xs:any namespace="##other" processContents="lax" />
 </xs:choice>
 </xs:complexType>
 
 class Foo {
 @
XmlAnyElement (lax="true")
 @
XmlElementRefs ({
 @
XmlElementRef (name="a", type="JAXBElement.class")
 @
XmlElementRef (name="b", type="JAXBElement.class")
 })
List <
Object > others;
 }
 @XmlRegistry
 class ObjectFactory {
 ...
 @XmlElementDecl(name = "a", namespace = "", scope = Foo.class)
JAXBElement <Integer> createFooA( Integer i ) { ... }
 @XmlElementDecl(name = "b", namespace = "", scope = Foo.class)
JAXBElement <Integer> createFooB( Integer i ) { ... }
 
It can unmarshal instances like

 <foo xmlns:e="extra">
 <a>1</a>     // this will unmarshal to a 
<a href="../JAXBElement.java.htm"><B>JAXBElement</B></a>  instance whose value is 1.
 <e:other />  // this will unmarshal to a DOM 
<a href="../../../../../../6.0-JDK-Core/w3c/org/w3c/dom/Element.java.htm"><B>Element</B></a> .
 <b>3</b>     // this will unmarshal to a 
<a href="../JAXBElement.java.htm"><B>JAXBElement</B></a>  instance whose value is 1.
 </foo>
 

W3C XML Schema "lax" wildcard emulation

The lax element of the annotation enables the emulation of the "lax" wildcard semantics. For example, when the Java source code is annotated like this:
 @
XmlRootElement class Foo {
 @XmlAnyElement(lax=true)
 public 
Object [] others;
 }
 
then the following document will unmarshal like this:

 <foo>
 <unknown />
 <foo />
 </foo>
 Foo foo = unmarshal();
 // 1 for 'unknown', another for 'foo'
 assert foo.others.length==2;
 // 'unknown' unmarshals to a DOM element
 assert foo.others[0] instanceof Element;
 // because of lax=true, the 'foo' element eagerly
 // unmarshals to a Foo object.
 assert foo.others[1] instanceof Foo;
 

author:
   Kohsuke Kawaguchi
since:
   JAXB2.0


Field Summary
 booleanlax
     Controls the unmarshaller behavior when it sees elements known to the current JAXBContext .

When false

If false, all the elements that match the property will be unmarshalled to DOM, and the property will only contain DOM elements.

When true

If true, when an element matches a property marked with XmlAnyElement is known to JAXBContext (for example, there's a class with XmlRootElement that has the same tag name, or there's XmlElementDecl that has the same tag name), the unmarshaller will eagerly unmarshal this element to the JAXB object, instead of unmarshalling it to DOM.

 Class<? extends DomHandler>value
     Specifies the DomHandler which is responsible for actually converting XML from/to a DOM-like data structure.



Field Detail
lax
boolean lax(Code)
Controls the unmarshaller behavior when it sees elements known to the current JAXBContext .

When false

If false, all the elements that match the property will be unmarshalled to DOM, and the property will only contain DOM elements.

When true

If true, when an element matches a property marked with XmlAnyElement is known to JAXBContext (for example, there's a class with XmlRootElement that has the same tag name, or there's XmlElementDecl that has the same tag name), the unmarshaller will eagerly unmarshal this element to the JAXB object, instead of unmarshalling it to DOM. Additionally, if the element is unknown but it has a known xsi:type, the unmarshaller eagerly unmarshals the element to a JAXBElement , with the unknown element name and the JAXBElement value is set to an instance of the JAXB mapping of the known xsi:type.

As a result, after the unmarshalling, the property can become heterogeneous; it can have both DOM nodes and some JAXB objects at the same time.

This can be used to emulate the "lax" wildcard semantics of the W3C XML Schema.




value
Class<? extends DomHandler> value(Code)
Specifies the DomHandler which is responsible for actually converting XML from/to a DOM-like data structure.





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