73 * <tt>@XmlAdapter</tt> and <tt>@XmlJavaTypeAdapter</tt> to |
73 * <tt>@XmlAdapter</tt> and <tt>@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 * <hashmap> |
79 * <hashmap> |
80 * <entry key="id123">this is a value</entry> |
80 * <entry key="id123">this is a value</entry> |
81 * <entry key="id312">this is another value</entry> |
81 * <entry key="id312">this is another value</entry> |
82 * ... |
82 * ... |
83 * </hashmap> |
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 * <xs:complexType name="myHashMapType"> |
91 * <xs:complexType name="myHashMapType"> |
92 * <xs:sequence> |
92 * <xs:sequence> |
93 * <xs:element name="entry" type="myHashMapEntryType" |
93 * <xs:element name="entry" type="myHashMapEntryType" |
94 * minOccurs = "0" maxOccurs="unbounded"/> |
94 * minOccurs = "0" maxOccurs="unbounded"/> |
95 * </xs:sequence> |
95 * </xs:sequence> |
96 * </xs:complexType> |
96 * </xs:complexType> |
97 * |
97 * |
98 * <xs:complexType name="myHashMapEntryType"> |
98 * <xs:complexType name="myHashMapEntryType"> |
99 * <xs:simpleContent> |
99 * <xs:simpleContent> |
100 * <xs:extension base="xs:string"> |
100 * <xs:extension base="xs:string"> |
101 * <xs:attribute name="key" type="xs:int"/> |
101 * <xs:attribute name="key" type="xs:int"/> |
102 * </xs:extension> |
102 * </xs:extension> |
103 * </xs:simpleContent> |
103 * </xs:simpleContent> |
104 * </xs:complexType> |
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<MyHashMapType,HashMap> { ... } |
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 * <xs:complexType name="Foo"> |
147 * <xs:complexType name="Foo"> |
148 * <xs:sequence> |
148 * <xs:sequence> |
149 * <xs:element name="hashmap" type="myHashMapType"> |
149 * <xs:element name="hashmap" type="myHashMapType"> |
150 * </xs:sequence> |
150 * </xs:sequence> |
151 * </xs:complexType> |
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>. |