blob: 3acd95025f15ed6e175ad11f179284b850630302 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<title>XmlAnyElement</title>
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="XmlAnyElement";
}
}
catch(err) {
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../jakarta/xml/bind/annotation/XmlAnyAttribute.html" title="annotation in jakarta.xml.bind.annotation"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../jakarta/xml/bind/annotation/XmlAttachmentRef.html" title="annotation in jakarta.xml.bind.annotation"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../index.html?jakarta/xml/bind/annotation/XmlAnyElement.html" target="_top">Frames</a></li>
<li><a href="XmlAnyElement.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Required&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.optional.element.summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.element.detail">Element</a></li>
</ul>
</div>
<a name="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">jakarta.xml.bind.annotation</div>
<h2 title="Annotation Type XmlAnyElement" class="title">Annotation Type XmlAnyElement</h2>
</div>
<div class="contentContainer">
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre>@Retention(value=RUNTIME)
@Target(value={FIELD,METHOD})
public @interface <span class="memberNameLabel">XmlAnyElement</span></pre>
<div class="block">Maps a JavaBean property to XML infoset representation and/or JAXB element.
<p>
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 &#64;XmlElement or &#64;XmlElementRef
annotation for the other JavaBean properties on the class, is added to this
"catch-all" property.
<h2>Usages:</h2>
<pre>
&#64;XmlAnyElement
public <code>Element</code>[] others;
// Collection of <code>Element</code> or JAXB elements.
&#64;XmlAnyElement(lax="true")
public <code>Object</code>[] others;
&#64;XmlAnyElement
private List&lt;<code>Element</code>&gt; nodes;
&#64;XmlAnyElement
private <code>Element</code> node;
</pre>
<h2>Restriction usage constraints</h2>
<p>
This annotation is mutually exclusive with
<a href="../../../../jakarta/xml/bind/annotation/XmlElement.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlElement</code></a>, <a href="../../../../jakarta/xml/bind/annotation/XmlAttribute.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlAttribute</code></a>, <a href="../../../../jakarta/xml/bind/annotation/XmlValue.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlValue</code></a>,
<a href="../../../../jakarta/xml/bind/annotation/XmlElements.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlElements</code></a>, <a href="../../../../jakarta/xml/bind/annotation/XmlID.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlID</code></a>, and <a href="../../../../jakarta/xml/bind/annotation/XmlIDREF.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlIDREF</code></a>.
<p>
There can be only one <a href="../../../../jakarta/xml/bind/annotation/XmlAnyElement.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlAnyElement</code></a> annotated JavaBean property
in a class and its super classes.
<h2>Relationship to other annotations</h2>
<p>
This annotation can be used with <a href="../../../../jakarta/xml/bind/annotation/adapters/XmlJavaTypeAdapter.html" title="annotation in jakarta.xml.bind.annotation.adapters"><code>XmlJavaTypeAdapter</code></a>, so that users
can map their own data structure to DOM, which in turn can be composed
into XML.
<p>
This annotation can be used with <a href="../../../../jakarta/xml/bind/annotation/XmlMixed.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlMixed</code></a> like this:
<pre>
// List of java.lang.String or DOM nodes.
&#64;XmlAnyElement &#64;XmlMixed
List&lt;Object&gt; others;
</pre>
<h2>Schema To Java example</h2>
The following schema would produce the following Java class:
<pre><code>
&lt;xs:complexType name="foo"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="a" type="xs:int" /&gt;
&lt;xs:element name="b" type="xs:int" /&gt;
&lt;xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
</code></pre>
<pre>
class Foo {
int a;
int b;
&#64;<a href="../../../../jakarta/xml/bind/annotation/XmlAnyElement.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlAnyElement</code></a>
List&lt;Element&gt; any;
}
</pre>
It can unmarshal instances like
<pre><code>
&lt;foo xmlns:e="extra"&gt;
&lt;a&gt;1&lt;/a&gt;
&lt;e:other /&gt; // this will be bound to DOM, because unmarshalling is orderless
&lt;b&gt;3&lt;/b&gt;
&lt;e:other /&gt;
&lt;c&gt;5&lt;/c&gt; // this will be bound to DOM, because the annotation doesn't remember namespaces.
&lt;/foo&gt;
</code></pre>
The following schema would produce the following Java class:
<pre><code>
&lt;xs:complexType name="bar"&gt;
&lt;xs:complexContent&gt;
&lt;xs:extension base="foo"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="c" type="xs:int" /&gt;
&lt;xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /&gt;
&lt;/xs:sequence&gt;
&lt;/xs:extension&gt;
&lt;/xs:complexType&gt;
</code></pre>
<pre>
class Bar extends Foo {
int c;
// Foo.getAny() also represents wildcard content for type definition bar.
}
</pre>
It can unmarshal instances like
<pre><code>
&lt;bar xmlns:e="extra"&gt;
&lt;a&gt;1&lt;/a&gt;
&lt;e:other /&gt; // this will be bound to DOM, because unmarshalling is orderless
&lt;b&gt;3&lt;/b&gt;
&lt;e:other /&gt;
&lt;c&gt;5&lt;/c&gt; // this now goes to Bar.c
&lt;e:other /&gt; // this will go to Foo.any
&lt;/bar&gt;
</code></pre>
<h2>Using <a href="../../../../jakarta/xml/bind/annotation/XmlAnyElement.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlAnyElement</code></a> with <a href="../../../../jakarta/xml/bind/annotation/XmlElementRef.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlElementRef</code></a></h2>
<p>
The <a href="../../../../jakarta/xml/bind/annotation/XmlAnyElement.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlAnyElement</code></a> annotation can be used with <a href="../../../../jakarta/xml/bind/annotation/XmlElementRef.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlElementRef</code></a>s to
designate additional elements that can participate in the content tree.
<p>
The following schema would produce the following Java class:
<pre><code>
&lt;xs:complexType name="foo"&gt;
&lt;xs:choice maxOccurs="unbounded" minOccurs="0"&gt;
&lt;xs:element name="a" type="xs:int" /&gt;
&lt;xs:element name="b" type="xs:int" /&gt;
&lt;xs:any namespace="##other" processContents="lax" /&gt;
&lt;/xs:choice&gt;
&lt;/xs:complexType&gt;
</code></pre>
<pre>
class Foo {
&#64;<a href="../../../../jakarta/xml/bind/annotation/XmlAnyElement.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlAnyElement</code></a>(lax="true")
&#64;<a href="../../../../jakarta/xml/bind/annotation/XmlElementRefs.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlElementRefs</code></a>({
&#64;<a href="../../../../jakarta/xml/bind/annotation/XmlElementRef.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlElementRef</code></a>(name="a", type="JAXBElement.class")
&#64;<a href="../../../../jakarta/xml/bind/annotation/XmlElementRef.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlElementRef</code></a>(name="b", type="JAXBElement.class")
})
<code>List</code>&lt;<code>Object</code>&gt; others;
}
&#64;XmlRegistry
class ObjectFactory {
...
&#64;XmlElementDecl(name = "a", namespace = "", scope = Foo.class)
<a href="../../../../jakarta/xml/bind/JAXBElement.html" title="class in jakarta.xml.bind"><code>JAXBElement</code></a>&lt;Integer&gt; createFooA( Integer i ) { ... }
&#64;XmlElementDecl(name = "b", namespace = "", scope = Foo.class)
<a href="../../../../jakarta/xml/bind/JAXBElement.html" title="class in jakarta.xml.bind"><code>JAXBElement</code></a>&lt;Integer&gt; createFooB( Integer i ) { ... }
</pre>
It can unmarshal instances like
<pre>
<code> &lt;foo xmlns:e="extra"&gt;</code>
<code> &lt;a&gt;1&lt;/a&gt;</code> // this will unmarshal to a <a href="../../../../jakarta/xml/bind/JAXBElement.html" title="class in jakarta.xml.bind"><code>JAXBElement</code></a> instance whose value is 1.
<code> &lt;e:other /&gt;</code> // this will unmarshal to a DOM <code>Element</code>.
<code> &lt;b&gt;3&lt;/b&gt;</code> // this will unmarshal to a <a href="../../../../jakarta/xml/bind/JAXBElement.html" title="class in jakarta.xml.bind"><code>JAXBElement</code></a> instance whose value is 1.
<code> &lt;/foo&gt;</code>
</pre>
<h2>W3C XML Schema "lax" wildcard emulation</h2>
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:
<pre>
&#64;<a href="../../../../jakarta/xml/bind/annotation/XmlRootElement.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlRootElement</code></a>
class Foo {
&#64;XmlAnyElement(lax=true)
public <code>Object</code>[] others;
}
</pre>
then the following document will unmarshal like this:
<pre><code>
&lt;foo&gt;
&lt;unknown /&gt;
&lt;foo /&gt;
&lt;/foo&gt;
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;
</code></pre></div>
<dl>
<dt><span class="simpleTagLabel">Since:</span></dt>
<dd>1.6, JAXB 2.0</dd>
</dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- =========== ANNOTATION TYPE OPTIONAL MEMBER SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="annotation.type.optional.element.summary">
<!-- -->
</a>
<h3>Optional Element Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Optional Element Summary table, listing optional elements, and an explanation">
<caption><span>Optional Elements</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Optional Element and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>boolean</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../jakarta/xml/bind/annotation/XmlAnyElement.html#lax--">lax</a></span></code>
<div class="block">Controls the unmarshaller behavior when it sees elements
known to the current <a href="../../../../jakarta/xml/bind/JAXBContext.html" title="class in jakarta.xml.bind"><code>JAXBContext</code></a>.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>java.lang.Class&lt;? extends <a href="../../../../jakarta/xml/bind/annotation/DomHandler.html" title="interface in jakarta.xml.bind.annotation">DomHandler</a>&gt;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../jakarta/xml/bind/annotation/XmlAnyElement.html#value--">value</a></span></code>
<div class="block">Specifies the <a href="../../../../jakarta/xml/bind/annotation/DomHandler.html" title="interface in jakarta.xml.bind.annotation"><code>DomHandler</code></a> which is responsible for actually
converting XML from/to a DOM-like data structure.</div>
</td>
</tr>
</table>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ ANNOTATION TYPE MEMBER DETAIL =========== -->
<ul class="blockList">
<li class="blockList"><a name="annotation.type.element.detail">
<!-- -->
</a>
<h3>Element Detail</h3>
<a name="lax--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>lax</h4>
<pre>public abstract&nbsp;boolean&nbsp;lax</pre>
<div class="block">Controls the unmarshaller behavior when it sees elements
known to the current <a href="../../../../jakarta/xml/bind/JAXBContext.html" title="class in jakarta.xml.bind"><code>JAXBContext</code></a>.
<dl>
<dt>When false</dt>
<dd>
If false, all the elements that match the property will be unmarshalled
to DOM, and the property will only contain DOM elements.
</dd>
<dt>When true</dt>
<dd>
If true, when an element matches a property marked with <a href="../../../../jakarta/xml/bind/annotation/XmlAnyElement.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlAnyElement</code></a>
is known to <a href="../../../../jakarta/xml/bind/JAXBContext.html" title="class in jakarta.xml.bind"><code>JAXBContext</code></a> (for example, there's a class with
<a href="../../../../jakarta/xml/bind/annotation/XmlRootElement.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlRootElement</code></a> that has the same tag name, or there's
<a href="../../../../jakarta/xml/bind/annotation/XmlElementDecl.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlElementDecl</code></a> 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 <a href="../../../../jakarta/xml/bind/JAXBElement.html" title="class in jakarta.xml.bind"><code>JAXBElement</code></a>, with the unknown element name and
the JAXBElement value is set to an instance of the JAXB mapping of the
known xsi:type.
</dd>
</dl>
<p>
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.
<p>
This can be used to emulate the "lax" wildcard semantics of the W3C XML Schema.</div>
<dl>
<dt>Default:</dt>
<dd>false</dd>
</dl>
</li>
</ul>
</li>
</ul>
<ul class="blockList">
<li class="blockList"><a name="value--">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>value</h4>
<pre>public abstract&nbsp;java.lang.Class&lt;? extends <a href="../../../../jakarta/xml/bind/annotation/DomHandler.html" title="interface in jakarta.xml.bind.annotation">DomHandler</a>&gt;&nbsp;value</pre>
<div class="block">Specifies the <a href="../../../../jakarta/xml/bind/annotation/DomHandler.html" title="interface in jakarta.xml.bind.annotation"><code>DomHandler</code></a> which is responsible for actually
converting XML from/to a DOM-like data structure.</div>
<dl>
<dt>Default:</dt>
<dd>jakarta.xml.bind.annotation.W3CDomHandler.class</dd>
</dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../jakarta/xml/bind/annotation/XmlAnyAttribute.html" title="annotation in jakarta.xml.bind.annotation"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../jakarta/xml/bind/annotation/XmlAttachmentRef.html" title="annotation in jakarta.xml.bind.annotation"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../index.html?jakarta/xml/bind/annotation/XmlAnyElement.html" target="_top">Frames</a></li>
<li><a href="XmlAnyElement.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Required&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.optional.element.summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.element.detail">Element</a></li>
</ul>
</div>
<a name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</body>
</html>