jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/adapters/XmlAdapter.java
changeset 29839 6d5d546e953b
parent 28887 88470f768658
child 32795 5a5710ee05a0
equal deleted inserted replaced
29838:fe5fd9871a13 29839:6d5d546e953b
    73  * <tt>&#64;XmlAdapter</tt> and <tt>&#64;XmlJavaTypeAdapter</tt> to
    73  * <tt>&#64;XmlAdapter</tt> and <tt>&#64;XmlJavaTypeAdapter</tt> to
    74  * customize the mapping of a <tt>HashMap</tt>.
    74  * customize the mapping of a <tt>HashMap</tt>.
    75  *
    75  *
    76  * <p> <b> Step 1: </b> Determine the desired XML representation for HashMap.
    76  * <p> <b> Step 1: </b> Determine the desired XML representation for HashMap.
    77  *
    77  *
    78  * <pre>
    78  * <pre>{@code
    79  *     &lt;hashmap&gt;
    79  *     <hashmap>
    80  *         &lt;entry key="id123"&gt;this is a value&lt;/entry&gt;
    80  *         <entry key="id123">this is a value</entry>
    81  *         &lt;entry key="id312"&gt;this is another value&lt;/entry&gt;
    81  *         <entry key="id312">this is another value</entry>
    82  *         ...
    82  *         ...
    83  *       &lt;/hashmap&gt;
    83  *     </hashmap>
    84  * </pre>
    84  * }</pre>
    85  *
    85  *
    86  * <p> <b> Step 2: </b> Determine the schema definition that the
    86  * <p> <b> Step 2: </b> Determine the schema definition that the
    87  * desired XML representation shown above should follow.
    87  * desired XML representation shown above should follow.
    88  *
    88  *
    89  * <pre>
    89  * <pre>{@code
    90  *
    90  *
    91  *     &lt;xs:complexType name="myHashMapType"&gt;
    91  *     <xs:complexType name="myHashMapType">
    92  *       &lt;xs:sequence&gt;
    92  *       <xs:sequence>
    93  *         &lt;xs:element name="entry" type="myHashMapEntryType"
    93  *         <xs:element name="entry" type="myHashMapEntryType"
    94  *                        minOccurs = "0" maxOccurs="unbounded"/&gt;
    94  *                        minOccurs = "0" maxOccurs="unbounded"/>
    95  *       &lt;/xs:sequence&gt;
    95  *       </xs:sequence>
    96  *     &lt;/xs:complexType&gt;
    96  *     </xs:complexType>
    97  *
    97  *
    98  *     &lt;xs:complexType name="myHashMapEntryType"&gt;
    98  *     <xs:complexType name="myHashMapEntryType">
    99  *       &lt;xs:simpleContent&gt;
    99  *       <xs:simpleContent>
   100  *         &lt;xs:extension base="xs:string"&gt;
   100  *         <xs:extension base="xs:string">
   101  *           &lt;xs:attribute name="key" type="xs:int"/&gt;
   101  *           <xs:attribute name="key" type="xs:int"/>
   102  *         &lt;/xs:extension&gt;
   102  *         </xs:extension>
   103  *       &lt;/xs:simpleContent&gt;
   103  *       </xs:simpleContent>
   104  *     &lt;/xs:complexType&gt;
   104  *     </xs:complexType>
   105  *
   105  *
   106  * </pre>
   106  * }</pre>
   107  *
   107  *
   108  * <p> <b> Step 3: </b> Write value types that can generate the above
   108  * <p> <b> Step 3: </b> Write value types that can generate the above
   109  * schema definition.
   109  * schema definition.
   110  *
   110  *
   111  * <pre>
   111  * <pre>
   123  * </pre>
   123  * </pre>
   124  *
   124  *
   125  * <p> <b> Step 4: </b> Write the adapter that adapts the value type,
   125  * <p> <b> Step 4: </b> Write the adapter that adapts the value type,
   126  * MyHashMapType to a bound type, HashMap, used by the application.
   126  * MyHashMapType to a bound type, HashMap, used by the application.
   127  *
   127  *
   128  * <pre>
   128  * <pre>{@code
   129  *     public final class MyHashMapAdapter extends
   129  *     public final class MyHashMapAdapter extends
   130  *                        XmlAdapter&lt;MyHashMapType,HashMap&gt; { ... }
   130  *                        XmlAdapter<MyHashMapType,HashMap> { ... }
   131  *
   131  *
   132  * </pre>
   132  * }</pre>
   133  *
   133  *
   134  * <p> <b> Step 5: </b> Use the adapter.
   134  * <p> <b> Step 5: </b> Use the adapter.
   135  *
   135  *
   136  * <pre>
   136  * <pre>
   137  *     public class Foo {
   137  *     public class Foo {
   141  *     }
   141  *     }
   142  * </pre>
   142  * </pre>
   143  *
   143  *
   144  * The above code fragment will map to the following schema:
   144  * The above code fragment will map to the following schema:
   145  *
   145  *
   146  * <pre>
   146  * <pre>{@code
   147  *     &lt;xs:complexType name="Foo"&gt;
   147  *     <xs:complexType name="Foo">
   148  *       &lt;xs:sequence&gt;
   148  *       <xs:sequence>
   149  *         &lt;xs:element name="hashmap" type="myHashMapType"&gt;
   149  *         <xs:element name="hashmap" type="myHashMapType">
   150  *       &lt;/xs:sequence&gt;
   150  *       </xs:sequence>
   151  *     &lt;/xs:complexType&gt;
   151  *     </xs:complexType>
   152  * </pre>
   152  * }</pre>
   153  *
   153  *
   154  * @param <BoundType>
   154  * @param <BoundType>
   155  *      The type that JAXB doesn't know how to handle. An adapter is written
   155  *      The type that JAXB doesn't know how to handle. An adapter is written
   156  *      to allow this type to be used as an in-memory representation through
   156  *      to allow this type to be used as an in-memory representation through
   157  *      the <tt>ValueType</tt>.
   157  *      the <tt>ValueType</tt>.