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 * <xs:complexType name="foo"> |
98 * <xs:complexType name="foo"> |
99 * <xs:sequence> |
99 * <xs:sequence> |
100 * <xs:element name="a" type="xs:int" /> |
100 * <xs:element name="a" type="xs:int" /> |
101 * <xs:element name="b" type="xs:int" /> |
101 * <xs:element name="b" type="xs:int" /> |
102 * <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> |
102 * <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> |
103 * </xs:sequence> |
103 * </xs:sequence> |
104 * </xs:complexType> |
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 * <foo xmlns:e="extra"> |
119 * <foo xmlns:e="extra"> |
120 * <a>1</a> |
120 * <a>1</a> |
121 * <e:other /> // this will be bound to DOM, because unmarshalling is orderless |
121 * <e:other /> // this will be bound to DOM, because unmarshalling is orderless |
122 * <b>3</b> |
122 * <b>3</b> |
123 * <e:other /> |
123 * <e:other /> |
124 * <c>5</c> // 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 * </foo> |
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 * <xs:complexType name="bar"> |
132 * <xs:complexType name="bar"> |
133 * <xs:complexContent> |
133 * <xs:complexContent> |
134 * <xs:extension base="foo"> |
134 * <xs:extension base="foo"> |
135 * <xs:sequence> |
135 * <xs:sequence> |
136 * <xs:element name="c" type="xs:int" /> |
136 * <xs:element name="c" type="xs:int" /> |
137 * <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> |
137 * <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> |
138 * </xs:sequence> |
138 * </xs:sequence> |
139 * </xs:extension> |
139 * </xs:extension> |
140 * </xs:complexType> |
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 * <bar xmlns:e="extra"> |
154 * <bar xmlns:e="extra"> |
155 * <a>1</a> |
155 * <a>1</a> |
156 * <e:other /> // this will be bound to DOM, because unmarshalling is orderless |
156 * <e:other /> // this will be bound to DOM, because unmarshalling is orderless |
157 * <b>3</b> |
157 * <b>3</b> |
158 * <e:other /> |
158 * <e:other /> |
159 * <c>5</c> // this now goes to Bar.c |
159 * <c>5</c> // this now goes to Bar.c |
160 * <e:other /> // this will go to Foo.any |
160 * <e:other /> // this will go to Foo.any |
161 * </bar> |
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 * <xs:complexType name="foo"> |
175 * <xs:complexType name="foo"> |
176 * <xs:choice maxOccurs="unbounded" minOccurs="0"> |
176 * <xs:choice maxOccurs="unbounded" minOccurs="0"> |
177 * <xs:element name="a" type="xs:int" /> |
177 * <xs:element name="a" type="xs:int" /> |
178 * <xs:element name="b" type="xs:int" /> |
178 * <xs:element name="b" type="xs:int" /> |
179 * <xs:any namespace="##other" processContents="lax" /> |
179 * <xs:any namespace="##other" processContents="lax" /> |
180 * </xs:choice> |
180 * </xs:choice> |
181 * </xs:complexType> |
181 * </xs:complexType> |
182 * </pre> |
182 * }</pre> |
183 * |
183 * |
184 * <pre> |
184 * <pre> |
185 * class Foo { |
185 * class Foo { |
186 * @{@link XmlAnyElement}(lax="true") |
186 * @{@link XmlAnyElement}(lax="true") |
187 * @{@link XmlElementRefs}({ |
187 * @{@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 * <foo xmlns:e="extra"> |
207 *{@code <foo xmlns:e="extra">} |
208 * <a>1</a> // 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 * <e:other /> // this will unmarshal to a DOM {@link Element}. |
209 *{@code <e:other />} // this will unmarshal to a DOM {@link Element}. |
210 * <b>3</b> // 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 * </foo> |
211 *{@code </foo>} |
212 * </pre> |
212 * </pre> |
213 * |
213 * |
214 * |
214 * |
215 * |
215 * |
216 * |
216 * |
223 * @XmlAnyElement(lax=true) |
223 * @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 * <foo> |
229 * <foo> |
230 * <unknown /> |
230 * <unknown /> |
231 * <foo /> |
231 * <foo /> |
232 * </foo> |
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) |