blob: 14fad6e6a68dc00825fc59d42c8c16fe1ef3f343 [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>XmlAdapter</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="XmlAdapter";
}
}
catch(err) {
}
//-->
var methods = {"i0":6,"i1":6};
var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],4:["t3","Abstract Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
var tableTab = "tableTab";
var activeTableTab = "activeTableTab";
</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="../../../../../javax/xml/bind/annotation/adapters/NormalizedStringAdapter.html" title="class in javax.xml.bind.annotation.adapters"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../../javax/xml/bind/annotation/adapters/XmlJavaTypeAdapter.html" title="annotation in javax.xml.bind.annotation.adapters"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?javax/xml/bind/annotation/adapters/XmlAdapter.html" target="_top">Frames</a></li>
<li><a href="XmlAdapter.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>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</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">javax.xml.bind.annotation.adapters</div>
<h2 title="Class XmlAdapter" class="title">Class XmlAdapter&lt;ValueType,BoundType&gt;</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>javax.xml.bind.annotation.adapters.XmlAdapter&lt;ValueType,BoundType&gt;</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<dl>
<dt><span class="paramLabel">Type Parameters:</span></dt>
<dd><code>BoundType</code> - The type that JAXB doesn't know how to handle. An adapter is written
to allow this type to be used as an in-memory representation through
the <code>ValueType</code>.</dd>
<dd><code>ValueType</code> - The type that JAXB knows how to handle out of the box.</dd>
</dl>
<dl>
<dt>Direct Known Subclasses:</dt>
<dd><a href="../../../../../org/apache/openejb/jee/bval/Adapter1.html" title="class in org.apache.openejb.jee.bval">Adapter1</a>, <a href="../../../../../org/apache/openejb/jee/BooleanAdapter.html" title="class in org.apache.openejb.jee">BooleanAdapter</a>, <a href="../../../../../javax/xml/bind/annotation/adapters/CollapsedStringAdapter.html" title="class in javax.xml.bind.annotation.adapters">CollapsedStringAdapter</a>, <a href="../../../../../org/apache/openejb/config/typed/util/DurationAdapter.html" title="class in org.apache.openejb.config.typed.util">DurationAdapter</a>, <a href="../../../../../org/apache/openejb/jee/HandlerChainsStringQNameAdapter.html" title="class in org.apache.openejb.jee">HandlerChainsStringQNameAdapter</a>, <a href="../../../../../javax/xml/bind/annotation/adapters/HexBinaryAdapter.html" title="class in javax.xml.bind.annotation.adapters">HexBinaryAdapter</a>, <a href="../../../../../org/apache/openejb/config/sys/ListAdapter.html" title="class in org.apache.openejb.config.sys">ListAdapter</a>, <a href="../../../../../org/apache/openejb/jee/LoadOnStartupAdapter.html" title="class in org.apache.openejb.jee">LoadOnStartupAdapter</a>, <a href="../../../../../javax/xml/bind/annotation/adapters/NormalizedStringAdapter.html" title="class in javax.xml.bind.annotation.adapters">NormalizedStringAdapter</a>, <a href="../../../../../org/apache/openejb/config/sys/PropertiesAdapter.html" title="class in org.apache.openejb.config.sys">PropertiesAdapter</a>, <a href="../../../../../org/apache/openejb/jee/oejb3/PropertiesAdapter.html" title="class in org.apache.openejb.jee.oejb3">PropertiesAdapter</a>, <a href="../../../../../org/apache/openejb/jee/jpa/unit/PropertiesAdapter.html" title="class in org.apache.openejb.jee.jpa.unit">PropertiesAdapter</a>, <a href="../../../../../org/apache/openejb/jee/StringAdapter.html" title="class in org.apache.openejb.jee">StringAdapter</a>, <a href="../../../../../org/apache/openejb/jee/TimeUnitAdapter.html" title="class in org.apache.openejb.jee">TimeUnitAdapter</a>, <a href="../../../../../org/apache/openejb/jee/TrimStringAdapter.html" title="class in org.apache.openejb.jee">TrimStringAdapter</a>, <a href="../../../../../org/apache/openejb/jee/wls/TrueFalseAdapter.html" title="class in org.apache.openejb.jee.wls">TrueFalseAdapter</a></dd>
</dl>
<hr>
<br>
<pre>public abstract class <span class="typeNameLabel">XmlAdapter&lt;ValueType,BoundType&gt;</span>
extends java.lang.Object</pre>
<div class="block">Adapts a Java type for custom marshaling.
<p> <b> Usage: </b> </p>
<p>
Some Java types do not map naturally to an XML representation, for
example <code>HashMap</code> or other non JavaBean classes. Conversely,
an XML representation may map to a Java type but an application may
choose to access the XML representation using another Java
type. For example, the schema to Java binding rules bind
xs:DateTime by default to XmlGregorianCalendar. But an application
may desire to bind xs:DateTime to a custom type,
MyXmlGregorianCalendar, for example. In both cases, there is a
mismatch between <i> bound type </i>, used by an application to
access XML content and the <i> value type</i>, that is mapped to an
XML representation.
<p>
This abstract class defines methods for adapting a bound type to a value
type or vice versa. The methods are invoked by the JAXB binding
framework during marshaling and unmarshalling:
<ul>
<li> <b> XmlAdapter.marshal(...): </b> During marshalling, JAXB
binding framework invokes XmlAdapter.marshal(..) to adapt a
bound type to value type, which is then marshaled to XML
representation. </li>
<li> <b> XmlAdapter.unmarshal(...): </b> During unmarshalling,
JAXB binding framework first unmarshals XML representation
to a value type and then invokes XmlAdapter.unmarshal(..) to
adapt the value type to a bound type. </li>
</ul>
Writing an adapter therefore involves the following steps:
<ul>
<li> Write an adapter that implements this abstract class. </li>
<li> Install the adapter using the annotation <a href="../../../../../javax/xml/bind/annotation/adapters/XmlJavaTypeAdapter.html" title="annotation in javax.xml.bind.annotation.adapters"><code>XmlJavaTypeAdapter</code></a> </li>
</ul>
<p><b>Example:</b> Customized mapping of <code>HashMap</code></p>
<p> The following example illustrates the use of
<code>@XmlAdapter</code> and <code>@XmlJavaTypeAdapter</code> to
customize the mapping of a <code>HashMap</code>.
<p> <b> Step 1: </b> Determine the desired XML representation for HashMap.
<pre><code>
&lt;hashmap&gt;
&lt;entry key="id123"&gt;this is a value&lt;/entry&gt;
&lt;entry key="id312"&gt;this is another value&lt;/entry&gt;
...
&lt;/hashmap&gt;
</code></pre>
<p> <b> Step 2: </b> Determine the schema definition that the
desired XML representation shown above should follow.
<pre><code>
&lt;xs:complexType name="myHashMapType"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="entry" type="myHashMapEntryType"
minOccurs = "0" maxOccurs="unbounded"/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;xs:complexType name="myHashMapEntryType"&gt;
&lt;xs:simpleContent&gt;
&lt;xs:extension base="xs:string"&gt;
&lt;xs:attribute name="key" type="xs:int"/&gt;
&lt;/xs:extension&gt;
&lt;/xs:simpleContent&gt;
&lt;/xs:complexType&gt;
</code></pre>
<p> <b> Step 3: </b> Write value types that can generate the above
schema definition.
<pre>
public class MyHashMapType {
List&lt;MyHashMapEntryType&gt; entry;
}
public class MyHashMapEntryType {
&#64;XmlAttribute
public Integer key;
&#64;XmlValue
public String value;
}
</pre>
<p> <b> Step 4: </b> Write the adapter that adapts the value type,
MyHashMapType to a bound type, HashMap, used by the application.
<pre><code>
public final class MyHashMapAdapter extends
XmlAdapter&lt;MyHashMapType,HashMap&gt; { ... }
</code></pre>
<p> <b> Step 5: </b> Use the adapter.
<pre>
public class Foo {
&#64;XmlJavaTypeAdapter(MyHashMapAdapter.class)
HashMap hashmap;
...
}
</pre>
The above code fragment will map to the following schema:
<pre><code>
&lt;xs:complexType name="Foo"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="hashmap" type="myHashMapType"&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
</code></pre></div>
<dl>
<dt><span class="simpleTagLabel">Since:</span></dt>
<dd>1.6, JAXB 2.0</dd>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../../javax/xml/bind/annotation/adapters/XmlJavaTypeAdapter.html" title="annotation in javax.xml.bind.annotation.adapters"><code>XmlJavaTypeAdapter</code></a></dd>
</dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.summary">
<!-- -->
</a>
<h3>Constructor Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
<caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier</th>
<th class="colLast" scope="col">Constructor and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>protected </code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../javax/xml/bind/annotation/adapters/XmlAdapter.html#XmlAdapter--">XmlAdapter</a></span>()</code>
<div class="block">Do-nothing constructor for the derived classes.</div>
</td>
</tr>
</table>
</li>
</ul>
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method.summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t3" class="tableTab"><span><a href="javascript:show(4);">Abstract Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code>abstract <a href="../../../../../javax/xml/bind/annotation/adapters/XmlAdapter.html" title="type parameter in XmlAdapter">ValueType</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../javax/xml/bind/annotation/adapters/XmlAdapter.html#marshal-BoundType-">marshal</a></span>(<a href="../../../../../javax/xml/bind/annotation/adapters/XmlAdapter.html" title="type parameter in XmlAdapter">BoundType</a>&nbsp;v)</code>
<div class="block">Convert a bound type to a value type.</div>
</td>
</tr>
<tr id="i1" class="rowColor">
<td class="colFirst"><code>abstract <a href="../../../../../javax/xml/bind/annotation/adapters/XmlAdapter.html" title="type parameter in XmlAdapter">BoundType</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../javax/xml/bind/annotation/adapters/XmlAdapter.html#unmarshal-ValueType-">unmarshal</a></span>(<a href="../../../../../javax/xml/bind/annotation/adapters/XmlAdapter.html" title="type parameter in XmlAdapter">ValueType</a>&nbsp;v)</code>
<div class="block">Convert a value type to a bound type.</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.Object</h3>
<code>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.detail">
<!-- -->
</a>
<h3>Constructor Detail</h3>
<a name="XmlAdapter--">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>XmlAdapter</h4>
<pre>protected&nbsp;XmlAdapter()</pre>
<div class="block">Do-nothing constructor for the derived classes.</div>
</li>
</ul>
</li>
</ul>
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method.detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="unmarshal-java.lang.Object-">
<!-- -->
</a><a name="unmarshal-ValueType-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>unmarshal</h4>
<pre>public abstract&nbsp;<a href="../../../../../javax/xml/bind/annotation/adapters/XmlAdapter.html" title="type parameter in XmlAdapter">BoundType</a>&nbsp;unmarshal(<a href="../../../../../javax/xml/bind/annotation/adapters/XmlAdapter.html" title="type parameter in XmlAdapter">ValueType</a>&nbsp;v)
throws java.lang.Exception</pre>
<div class="block">Convert a value type to a bound type.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>v</code> - The value to be converted. Can be null.</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.lang.Exception</code> - if there's an error during the conversion. The caller is responsible for
reporting the error to the user through <a href="../../../../../javax/xml/bind/ValidationEventHandler.html" title="interface in javax.xml.bind"><code>ValidationEventHandler</code></a>.</dd>
</dl>
</li>
</ul>
<a name="marshal-java.lang.Object-">
<!-- -->
</a><a name="marshal-BoundType-">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>marshal</h4>
<pre>public abstract&nbsp;<a href="../../../../../javax/xml/bind/annotation/adapters/XmlAdapter.html" title="type parameter in XmlAdapter">ValueType</a>&nbsp;marshal(<a href="../../../../../javax/xml/bind/annotation/adapters/XmlAdapter.html" title="type parameter in XmlAdapter">BoundType</a>&nbsp;v)
throws java.lang.Exception</pre>
<div class="block">Convert a bound type to a value type.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>v</code> - The value to be convereted. Can be null.</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.lang.Exception</code> - if there's an error during the conversion. The caller is responsible for
reporting the error to the user through <a href="../../../../../javax/xml/bind/ValidationEventHandler.html" title="interface in javax.xml.bind"><code>ValidationEventHandler</code></a>.</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="../../../../../javax/xml/bind/annotation/adapters/NormalizedStringAdapter.html" title="class in javax.xml.bind.annotation.adapters"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../../javax/xml/bind/annotation/adapters/XmlJavaTypeAdapter.html" title="annotation in javax.xml.bind.annotation.adapters"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?javax/xml/bind/annotation/adapters/XmlAdapter.html" target="_top">Frames</a></li>
<li><a href="XmlAdapter.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>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</body>
</html>