jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlAnyElement.java
changeset 29839 6d5d546e953b
parent 28887 88470f768658
equal deleted inserted replaced
29838:fe5fd9871a13 29839:6d5d546e953b
    92  *
    92  *
    93  *
    93  *
    94  * <h2>Schema To Java example</h2>
    94  * <h2>Schema To Java example</h2>
    95  *
    95  *
    96  * The following schema would produce the following Java class:
    96  * The following schema would produce the following Java class:
    97  * <pre>
    97  * <pre>{@code
    98  * &lt;xs:complexType name="foo"&gt;
    98  * <xs:complexType name="foo">
    99  *   &lt;xs:sequence&gt;
    99  *   <xs:sequence>
   100  *     &lt;xs:element name="a" type="xs:int" /&gt;
   100  *     <xs:element name="a" type="xs:int" />
   101  *     &lt;xs:element name="b" type="xs:int" /&gt;
   101  *     <xs:element name="b" type="xs:int" />
   102  *     &lt;xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /&gt;
   102  *     <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
   103  *   &lt;/xs:sequence&gt;
   103  *   </xs:sequence>
   104  * &lt;/xs:complexType&gt;
   104  * </xs:complexType>
   105  * </pre>
   105  * }</pre>
   106  *
   106  *
   107  * <pre>
   107  * <pre>
   108  * class Foo {
   108  * class Foo {
   109  *   int a;
   109  *   int a;
   110  *   int b;
   110  *   int b;
   113  * }
   113  * }
   114  * </pre>
   114  * </pre>
   115  *
   115  *
   116  * It can unmarshal instances like
   116  * It can unmarshal instances like
   117  *
   117  *
   118  * <pre>
   118  * <pre>{@code
   119  * &lt;foo xmlns:e="extra"&gt;
   119  * <foo xmlns:e="extra">
   120  *   &lt;a&gt;1&lt;/a&gt;
   120  *   <a>1</a>
   121  *   &lt;e:other /&gt;  // this will be bound to DOM, because unmarshalling is orderless
   121  *   <e:other />  // this will be bound to DOM, because unmarshalling is orderless
   122  *   &lt;b&gt;3&lt;/b&gt;
   122  *   <b>3</b>
   123  *   &lt;e:other /&gt;
   123  *   <e:other />
   124  *   &lt;c&gt;5&lt;/c&gt;     // this will be bound to DOM, because the annotation doesn't remember namespaces.
   124  *   <c>5</c>     // this will be bound to DOM, because the annotation doesn't remember namespaces.
   125  * &lt;/foo&gt;
   125  * </foo>
   126  * </pre>
   126  * }</pre>
   127  *
   127  *
   128  *
   128  *
   129  *
   129  *
   130  * The following schema would produce the following Java class:
   130  * The following schema would produce the following Java class:
   131  * <pre>
   131  * <pre>{@code
   132  * &lt;xs:complexType name="bar"&gt;
   132  * <xs:complexType name="bar">
   133  *   &lt;xs:complexContent&gt;
   133  *   <xs:complexContent>
   134  *   &lt;xs:extension base="foo"&gt;
   134  *   <xs:extension base="foo">
   135  *     &lt;xs:sequence&gt;
   135  *     <xs:sequence>
   136  *       &lt;xs:element name="c" type="xs:int" /&gt;
   136  *       <xs:element name="c" type="xs:int" />
   137  *       &lt;xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /&gt;
   137  *       <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
   138  *     &lt;/xs:sequence&gt;
   138  *     </xs:sequence>
   139  *   &lt;/xs:extension&gt;
   139  *   </xs:extension>
   140  * &lt;/xs:complexType&gt;
   140  * </xs:complexType>
   141  * </pre>
   141  * }</pre>
   142  *
   142  *
   143  * <pre>
   143  * <pre>
   144  * class Bar extends Foo {
   144  * class Bar extends Foo {
   145  *   int c;
   145  *   int c;
   146  *   // Foo.getAny() also represents wildcard content for type definition bar.
   146  *   // Foo.getAny() also represents wildcard content for type definition bar.
   148  * </pre>
   148  * </pre>
   149  *
   149  *
   150  *
   150  *
   151  * It can unmarshal instances like
   151  * It can unmarshal instances like
   152  *
   152  *
   153  * <pre>
   153  * <pre>{@code
   154  * &lt;bar xmlns:e="extra"&gt;
   154  * <bar xmlns:e="extra">
   155  *   &lt;a&gt;1&lt;/a&gt;
   155  *   <a>1</a>
   156  *   &lt;e:other /&gt;  // this will be bound to DOM, because unmarshalling is orderless
   156  *   <e:other />  // this will be bound to DOM, because unmarshalling is orderless
   157  *   &lt;b&gt;3&lt;/b&gt;
   157  *   <b>3</b>
   158  *   &lt;e:other /&gt;
   158  *   <e:other />
   159  *   &lt;c&gt;5&lt;/c&gt;     // this now goes to Bar.c
   159  *   <c>5</c>     // this now goes to Bar.c
   160  *   &lt;e:other /&gt;  // this will go to Foo.any
   160  *   <e:other />  // this will go to Foo.any
   161  * &lt;/bar&gt;
   161  * </bar>
   162  * </pre>
   162  * }</pre>
   163  *
   163  *
   164  *
   164  *
   165  *
   165  *
   166  *
   166  *
   167  * <h2>Using {@link XmlAnyElement} with {@link XmlElementRef}</h2>
   167  * <h2>Using {@link XmlAnyElement} with {@link XmlElementRef}</h2>
   169  * The {@link XmlAnyElement} annotation can be used with {@link XmlElementRef}s to
   169  * The {@link XmlAnyElement} annotation can be used with {@link XmlElementRef}s to
   170  * designate additional elements that can participate in the content tree.
   170  * designate additional elements that can participate in the content tree.
   171  *
   171  *
   172  * <p>
   172  * <p>
   173  * The following schema would produce the following Java class:
   173  * The following schema would produce the following Java class:
   174  * <pre>
   174  * <pre>{@code
   175  * &lt;xs:complexType name="foo"&gt;
   175  * <xs:complexType name="foo">
   176  *   &lt;xs:choice maxOccurs="unbounded" minOccurs="0"&gt;
   176  *   <xs:choice maxOccurs="unbounded" minOccurs="0">
   177  *     &lt;xs:element name="a" type="xs:int" /&gt;
   177  *     <xs:element name="a" type="xs:int" />
   178  *     &lt;xs:element name="b" type="xs:int" /&gt;
   178  *     <xs:element name="b" type="xs:int" />
   179  *     &lt;xs:any namespace="##other" processContents="lax" /&gt;
   179  *     <xs:any namespace="##other" processContents="lax" />
   180  *   &lt;/xs:choice&gt;
   180  *   </xs:choice>
   181  * &lt;/xs:complexType&gt;
   181  * </xs:complexType>
   182  * </pre>
   182  * }</pre>
   183  *
   183  *
   184  * <pre>
   184  * <pre>
   185  * class Foo {
   185  * class Foo {
   186  *   &#64;{@link XmlAnyElement}(lax="true")
   186  *   &#64;{@link XmlAnyElement}(lax="true")
   187  *   &#64;{@link XmlElementRefs}({
   187  *   &#64;{@link XmlElementRefs}({
   202  * </pre>
   202  * </pre>
   203  *
   203  *
   204  * It can unmarshal instances like
   204  * It can unmarshal instances like
   205  *
   205  *
   206  * <pre>
   206  * <pre>
   207  * &lt;foo xmlns:e="extra"&gt;
   207  *{@code <foo xmlns:e="extra">}
   208  *   &lt;a&gt;1&lt;/a&gt;     // this will unmarshal to a {@link JAXBElement} instance whose value is 1.
   208  *{@code   <a>1</a>}     // this will unmarshal to a {@link JAXBElement} instance whose value is 1.
   209  *   &lt;e:other /&gt;  // this will unmarshal to a DOM {@link Element}.
   209  *{@code   <e:other />}  // this will unmarshal to a DOM {@link Element}.
   210  *   &lt;b&gt;3&lt;/b&gt;     // this will unmarshal to a {@link JAXBElement} instance whose value is 1.
   210  *{@code   <b>3</b>}     // this will unmarshal to a {@link JAXBElement} instance whose value is 1.
   211  * &lt;/foo&gt;
   211  *{@code </foo>}
   212  * </pre>
   212  * </pre>
   213  *
   213  *
   214  *
   214  *
   215  *
   215  *
   216  *
   216  *
   223  *   &#64;XmlAnyElement(lax=true)
   223  *   &#64;XmlAnyElement(lax=true)
   224  *   public {@link Object}[] others;
   224  *   public {@link Object}[] others;
   225  * }
   225  * }
   226  * </pre>
   226  * </pre>
   227  * then the following document will unmarshal like this:
   227  * then the following document will unmarshal like this:
   228  * <pre>
   228  * <pre>{@code
   229  * &lt;foo&gt;
   229  * <foo>
   230  *   &lt;unknown /&gt;
   230  *   <unknown />
   231  *   &lt;foo /&gt;
   231  *   <foo />
   232  * &lt;/foo&gt;
   232  * </foo>
   233  *
   233  *
   234  * Foo foo = unmarshal();
   234  * Foo foo = unmarshal();
   235  * // 1 for 'unknown', another for 'foo'
   235  * // 1 for 'unknown', another for 'foo'
   236  * assert foo.others.length==2;
   236  * assert foo.others.length==2;
   237  * // 'unknown' unmarshals to a DOM element
   237  * // 'unknown' unmarshals to a DOM element
   238  * assert foo.others[0] instanceof Element;
   238  * assert foo.others[0] instanceof Element;
   239  * // because of lax=true, the 'foo' element eagerly
   239  * // because of lax=true, the 'foo' element eagerly
   240  * // unmarshals to a Foo object.
   240  * // unmarshals to a Foo object.
   241  * assert foo.others[1] instanceof Foo;
   241  * assert foo.others[1] instanceof Foo;
   242  * </pre>
   242  * }</pre>
   243  *
   243  *
   244  * @author Kohsuke Kawaguchi
   244  * @author Kohsuke Kawaguchi
   245  * @since 1.6, JAXB 2.0
   245  * @since 1.6, JAXB 2.0
   246  */
   246  */
   247 @Retention(RUNTIME)
   247 @Retention(RUNTIME)