jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlMixed.java
changeset 29839 6d5d546e953b
parent 28887 88470f768658
equal deleted inserted replaced
29838:fe5fd9871a13 29839:6d5d546e953b
    54  * <li>Unknown content that is not be bound to a JAXB mapped class is inserted
    54  * <li>Unknown content that is not be bound to a JAXB mapped class is inserted
    55  * as {@link Element}. (Assumes property annotated with &#64;XmlAnyElement)</li>
    55  * as {@link Element}. (Assumes property annotated with &#64;XmlAnyElement)</li>
    56  * </ul>
    56  * </ul>
    57  *
    57  *
    58  * Below is an example of binding and creation of mixed content.
    58  * Below is an example of binding and creation of mixed content.
    59  * <pre>
    59  * <pre>{@code
    60  *  &lt;!-- schema fragment having  mixed content --&gt;
    60  *
    61  *  &lt;xs:complexType name="letterBody" mixed="true"&gt;
    61  *  <!-- schema fragment having  mixed content -->
    62  *    &lt;xs:sequence&gt;
    62  *  <xs:complexType name="letterBody" mixed="true">
    63  *      &lt;xs:element name="name" type="xs:string"/&gt;
    63  *    <xs:sequence>
    64  *      &lt;xs:element name="quantity" type="xs:positiveInteger"/&gt;
    64  *      <xs:element name="name" type="xs:string"/>
    65  *      &lt;xs:element name="productName" type="xs:string"/&gt;
    65  *      <xs:element name="quantity" type="xs:positiveInteger"/>
    66  *      &lt;!-- etc. --&gt;
    66  *      <xs:element name="productName" type="xs:string"/>
    67  *    &lt;/xs:sequence&gt;
    67  *      <!-- etc. -->
    68  *  &lt;/xs:complexType&gt;
    68  *    </xs:sequence>
    69  *  &lt;xs:element name="letterBody" type="letterBody"/&gt;
    69  *  </xs:complexType>
       
    70  *  <xs:element name="letterBody" type="letterBody"/>
    70  *
    71  *
    71  * // Schema-derived Java code:
    72  * // Schema-derived Java code:
    72  * // (Only annotations relevant to mixed content are shown below,
    73  * // (Only annotations relevant to mixed content are shown below,
    73  * //  others are ommitted.)
    74  * //  others are omitted.)
    74  * import java.math.BigInteger;
    75  * import java.math.BigInteger;
    75  * public class ObjectFactory {
    76  * public class ObjectFactory {
    76  *      // element instance factories
    77  *      // element instance factories
    77  *      JAXBElement&lt;LetterBody&gt; createLetterBody(LetterBody value);
    78  *      JAXBElement<LetterBody> createLetterBody(LetterBody value);
    78  *      JAXBElement&lt;String&gt;     createLetterBodyName(String value);
    79  *      JAXBElement<String>     createLetterBodyName(String value);
    79  *      JAXBElement&lt;BigInteger&gt; createLetterBodyQuantity(BigInteger value);
    80  *      JAXBElement<BigInteger> createLetterBodyQuantity(BigInteger value);
    80  *      JAXBElement&lt;String&gt;     createLetterBodyProductName(String value);
    81  *      JAXBElement<String>     createLetterBodyProductName(String value);
    81  *      // type instance factory
    82  *      // type instance factory
    82  *      LetterBody createLetterBody();
    83  *      LetterBody createLetterBody();
    83  * }
    84  * }
    84  * </pre>
    85  * }</pre>
    85  * <pre>
    86  * <pre>
    86  * public class LetterBody {
    87  * public class LetterBody {
    87  *      // Mixed content can contain instances of Element classes
    88  *      // Mixed content can contain instances of Element classes
    88  *      // Name, Quantity and ProductName. Text data is represented as
    89  *      // Name, Quantity and ProductName. Text data is represented as
    89  *      // java.util.String for text.
    90  *      // java.util.String for text.
    94  *              &#64;XmlElementRef(name="name", type=JAXBElement.class)})
    95  *              &#64;XmlElementRef(name="name", type=JAXBElement.class)})
    95  *      List getContent(){...}
    96  *      List getContent(){...}
    96  * }
    97  * }
    97  * </pre>
    98  * </pre>
    98  * The following is an XML instance document with mixed content
    99  * The following is an XML instance document with mixed content
    99  * <pre>
   100  * <pre>{@code
   100  * &lt;letterBody&gt;
   101  * <letterBody>
   101  * Dear Mr.&lt;name&gt;Robert Smith&lt;/name&gt;
   102  * Dear Mr.<name>Robert Smith</name>
   102  * Your order of &lt;quantity&gt;1&lt;/quantity&gt; &lt;productName&gt;Baby
   103  * Your order of <quantity>1</quantity> <productName>Baby
   103  * Monitor&lt;/productName&gt; shipped from our warehouse. ....
   104  * Monitor</productName> shipped from our warehouse. ....
   104  * &lt;/letterBody&gt;
   105  * </letterBody>
   105  * </pre>
   106  * }</pre>
   106  * that can be constructed using following JAXB API calls.
   107  * that can be constructed using following JAXB API calls.
   107  * <pre>
   108  * <pre>{@code
   108  * LetterBody lb = ObjectFactory.createLetterBody();
   109  * LetterBody lb = ObjectFactory.createLetterBody();
   109  * JAXBElement&lt;LetterBody&gt; lbe = ObjectFactory.createLetterBody(lb);
   110  * JAXBElement<LetterBody> lbe = ObjectFactory.createLetterBody(lb);
   110  * List gcl = lb.getContent();  //add mixed content to general content property.
   111  * List gcl = lb.getContent();  //add mixed content to general content property.
   111  * gcl.add("Dear Mr.");  // add text information item as a String.
   112  * gcl.add("Dear Mr.");  // add text information item as a String.
   112  *
   113  *
   113  * // add child element information item
   114  * // add child element information item
   114  * gcl.add(ObjectFactory.createLetterBodyName("Robert Smith"));
   115  * gcl.add(ObjectFactory.createLetterBodyName("Robert Smith"));
   117  * // add children element information items
   118  * // add children element information items
   118  * gcl.add(ObjectFactory.
   119  * gcl.add(ObjectFactory.
   119  *                      createLetterBodyQuantity(new BigInteger("1")));
   120  *                      createLetterBodyQuantity(new BigInteger("1")));
   120  * gcl.add(ObjectFactory.createLetterBodyProductName("Baby Monitor"));
   121  * gcl.add(ObjectFactory.createLetterBodyProductName("Baby Monitor"));
   121  * gcl.add("shipped from our warehouse");  // add text information item
   122  * gcl.add("shipped from our warehouse");  // add text information item
   122  * </pre>
   123  * }</pre>
   123  *
   124  *
   124  * <p>See "Package Specification" in javax.xml.bind.package javadoc for
   125  * <p>See "Package Specification" in javax.xml.bind.package javadoc for
   125  * additional common information.</p>
   126  * additional common information.</p>
   126  * @author Kohsuke Kawaguchi
   127  * @author Kohsuke Kawaguchi
   127  * @since 1.6, JAXB 2.0
   128  * @since 1.6, JAXB 2.0