< prev index next >

src/java.xml.bind/share/classes/javax/xml/bind/annotation/adapters/XmlAdapter.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 74,118 **** * customize the mapping of a <tt>HashMap</tt>. * * <p> <b> Step 1: </b> Determine the desired XML representation for HashMap. * * <pre> ! * &lt;hashmap> ! * &lt;entry key="id123">this is a value&lt;/entry> ! * &lt;entry key="id312">this is another value&lt;/entry> * ... ! * &lt;/hashmap> * </pre> * * <p> <b> Step 2: </b> Determine the schema definition that the * desired XML representation shown above should follow. * * <pre> * ! * &lt;xs:complexType name="myHashMapType"> ! * &lt;xs:sequence> * &lt;xs:element name="entry" type="myHashMapEntryType" ! * minOccurs = "0" maxOccurs="unbounded"/> ! * &lt;/xs:sequence> ! * &lt;/xs:complexType> ! * ! * &lt;xs:complexType name="myHashMapEntryType"> ! * &lt;xs:simpleContent> ! * &lt;xs:extension base="xs:string"> ! * &lt;xs:attribute name="key" type="xs:int"/> ! * &lt;/xs:extension> ! * &lt;/xs:simpleContent> ! * &lt;/xs:complexType> * * </pre> * * <p> <b> Step 3: </b> Write value types that can generate the above * schema definition. * * <pre> * public class MyHashMapType { ! * List&lt;MyHashMapEntryType> entry; * } * * public class MyHashMapEntryType { * @XmlAttribute * public Integer key; --- 74,118 ---- * customize the mapping of a <tt>HashMap</tt>. * * <p> <b> Step 1: </b> Determine the desired XML representation for HashMap. * * <pre> ! * &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; * </pre> * * <p> <b> Step 2: </b> Determine the schema definition that the * desired XML representation shown above should follow. * * <pre> * ! * &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; * * </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 { * @XmlAttribute * public Integer key;
*** 125,135 **** * <p> <b> Step 4: </b> Write the adapter that adapts the value type, * MyHashMapType to a bound type, HashMap, used by the application. * * <pre> * public final class MyHashMapAdapter extends ! * XmlAdapter&lt;MyHashMapType,HashMap> { ... } * * </pre> * * <p> <b> Step 5: </b> Use the adapter. * --- 125,135 ---- * <p> <b> Step 4: </b> Write the adapter that adapts the value type, * MyHashMapType to a bound type, HashMap, used by the application. * * <pre> * public final class MyHashMapAdapter extends ! * XmlAdapter&lt;MyHashMapType,HashMap&gt; { ... } * * </pre> * * <p> <b> Step 5: </b> Use the adapter. *
*** 142,156 **** * </pre> * * The above code fragment will map to the following schema: * * <pre> ! * &lt;xs:complexType name="Foo"> ! * &lt;xs:sequence> ! * &lt;xs:element name="hashmap" type="myHashMapType" ! * &lt;/xs:sequence> ! * &lt;/xs:complexType> * </pre> * * @param <BoundType> * 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 --- 142,156 ---- * </pre> * * The above code fragment will map to the following schema: * * <pre> ! * &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; * </pre> * * @param <BoundType> * 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
< prev index next >