| <!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="../../../../../jakarta/xml/bind/annotation/adapters/NormalizedStringAdapter.html" title="class in jakarta.xml.bind.annotation.adapters"><span class="typeNameLink">Prev Class</span></a></li> |
| <li><a href="../../../../../jakarta/xml/bind/annotation/adapters/XmlJavaTypeAdapter.html" title="annotation in jakarta.xml.bind.annotation.adapters"><span class="typeNameLink">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../../index.html?jakarta/xml/bind/annotation/adapters/XmlAdapter.html" target="_top">Frames</a></li> |
| <li><a href="XmlAdapter.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_top"> |
| <li><a href="../../../../../allclasses-noframe.html">All 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: </li> |
| <li>Nested | </li> |
| <li>Field | </li> |
| <li><a href="#constructor.summary">Constr</a> | </li> |
| <li><a href="#method.summary">Method</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#constructor.detail">Constr</a> | </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">jakarta.xml.bind.annotation.adapters</div> |
| <h2 title="Class XmlAdapter" class="title">Class XmlAdapter<ValueType,BoundType></h2> |
| </div> |
| <div class="contentContainer"> |
| <ul class="inheritance"> |
| <li>java.lang.Object</li> |
| <li> |
| <ul class="inheritance"> |
| <li>jakarta.xml.bind.annotation.adapters.XmlAdapter<ValueType,BoundType></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="../../../../../jakarta/xml/bind/annotation/adapters/CollapsedStringAdapter.html" title="class in jakarta.xml.bind.annotation.adapters">CollapsedStringAdapter</a>, <a href="../../../../../jakarta/xml/bind/annotation/adapters/HexBinaryAdapter.html" title="class in jakarta.xml.bind.annotation.adapters">HexBinaryAdapter</a>, <a href="../../../../../jakarta/ws/rs/core/Link.JaxbAdapter.html" title="class in jakarta.ws.rs.core">Link.JaxbAdapter</a>, <a href="../../../../../jakarta/xml/bind/annotation/adapters/NormalizedStringAdapter.html" title="class in jakarta.xml.bind.annotation.adapters">NormalizedStringAdapter</a></dd> |
| </dl> |
| <hr> |
| <br> |
| <pre>public abstract class <span class="typeNameLabel">XmlAdapter<ValueType,BoundType></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="../../../../../jakarta/xml/bind/annotation/adapters/XmlJavaTypeAdapter.html" title="annotation in jakarta.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> |
| <hashmap> |
| <entry key="id123">this is a value</entry> |
| <entry key="id312">this is another value</entry> |
| ... |
| </hashmap> |
| </code></pre> |
| |
| <p> <b> Step 2: </b> Determine the schema definition that the |
| desired XML representation shown above should follow. |
| |
| <pre><code> |
| |
| <xs:complexType name="myHashMapType"> |
| <xs:sequence> |
| <xs:element name="entry" type="myHashMapEntryType" |
| minOccurs = "0" maxOccurs="unbounded"/> |
| </xs:sequence> |
| </xs:complexType> |
| |
| <xs:complexType name="myHashMapEntryType"> |
| <xs:simpleContent> |
| <xs:extension base="xs:string"> |
| <xs:attribute name="key" type="xs:int"/> |
| </xs:extension> |
| </xs:simpleContent> |
| </xs:complexType> |
| |
| </code></pre> |
| |
| <p> <b> Step 3: </b> Write value types that can generate the above |
| schema definition. |
| |
| <pre> |
| public class MyHashMapType { |
| List<MyHashMapEntryType> entry; |
| } |
| |
| public class MyHashMapEntryType { |
| @XmlAttribute |
| public Integer key; |
| |
| @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<MyHashMapType,HashMap> { ... } |
| |
| </code></pre> |
| |
| <p> <b> Step 5: </b> Use the adapter. |
| |
| <pre> |
| public class Foo { |
| @XmlJavaTypeAdapter(MyHashMapAdapter.class) |
| HashMap hashmap; |
| ... |
| } |
| </pre> |
| |
| The above code fragment will map to the following schema: |
| |
| <pre><code> |
| <xs:complexType name="Foo"> |
| <xs:sequence> |
| <xs:element name="hashmap" type="myHashMapType"> |
| </xs:sequence> |
| </xs:complexType> |
| </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="../../../../../jakarta/xml/bind/annotation/adapters/XmlJavaTypeAdapter.html" title="annotation in jakarta.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"> </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="../../../../../jakarta/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"> </span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd"> </span></span><span id="t3" class="tableTab"><span><a href="javascript:show(4);">Abstract Methods</a></span><span class="tabEnd"> </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="../../../../../jakarta/xml/bind/annotation/adapters/XmlAdapter.html" title="type parameter in XmlAdapter">ValueType</a></code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../jakarta/xml/bind/annotation/adapters/XmlAdapter.html#marshal-BoundType-">marshal</a></span>(<a href="../../../../../jakarta/xml/bind/annotation/adapters/XmlAdapter.html" title="type parameter in XmlAdapter">BoundType</a> 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="../../../../../jakarta/xml/bind/annotation/adapters/XmlAdapter.html" title="type parameter in XmlAdapter">BoundType</a></code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../jakarta/xml/bind/annotation/adapters/XmlAdapter.html#unmarshal-ValueType-">unmarshal</a></span>(<a href="../../../../../jakarta/xml/bind/annotation/adapters/XmlAdapter.html" title="type parameter in XmlAdapter">ValueType</a> 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 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 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 <a href="../../../../../jakarta/xml/bind/annotation/adapters/XmlAdapter.html" title="type parameter in XmlAdapter">BoundType</a> unmarshal(<a href="../../../../../jakarta/xml/bind/annotation/adapters/XmlAdapter.html" title="type parameter in XmlAdapter">ValueType</a> 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="../../../../../jakarta/xml/bind/ValidationEventHandler.html" title="interface in jakarta.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 <a href="../../../../../jakarta/xml/bind/annotation/adapters/XmlAdapter.html" title="type parameter in XmlAdapter">ValueType</a> marshal(<a href="../../../../../jakarta/xml/bind/annotation/adapters/XmlAdapter.html" title="type parameter in XmlAdapter">BoundType</a> 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="../../../../../jakarta/xml/bind/ValidationEventHandler.html" title="interface in jakarta.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="../../../../../jakarta/xml/bind/annotation/adapters/NormalizedStringAdapter.html" title="class in jakarta.xml.bind.annotation.adapters"><span class="typeNameLink">Prev Class</span></a></li> |
| <li><a href="../../../../../jakarta/xml/bind/annotation/adapters/XmlJavaTypeAdapter.html" title="annotation in jakarta.xml.bind.annotation.adapters"><span class="typeNameLink">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../../index.html?jakarta/xml/bind/annotation/adapters/XmlAdapter.html" target="_top">Frames</a></li> |
| <li><a href="XmlAdapter.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_bottom"> |
| <li><a href="../../../../../allclasses-noframe.html">All 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: </li> |
| <li>Nested | </li> |
| <li>Field | </li> |
| <li><a href="#constructor.summary">Constr</a> | </li> |
| <li><a href="#method.summary">Method</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#constructor.detail">Constr</a> | </li> |
| <li><a href="#method.detail">Method</a></li> |
| </ul> |
| </div> |
| <a name="skip.navbar.bottom"> |
| <!-- --> |
| </a></div> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| </body> |
| </html> |