src/share/jaxws_classes/javax/xml/bind/annotation/XmlElementDecl.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 397
b99d7e355d4b
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

ohair@286 1 /*
ohair@286 2 * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package javax.xml.bind.annotation;
ohair@286 27
ohair@286 28 import java.lang.annotation.Retention;
ohair@286 29 import java.lang.annotation.Target;
ohair@286 30
ohair@286 31 import static java.lang.annotation.RetentionPolicy.RUNTIME;
ohair@286 32 import static java.lang.annotation.ElementType.METHOD;
ohair@286 33
ohair@286 34 /**
ohair@286 35 * Maps a factory method to a XML element.
ohair@286 36 *
ohair@286 37 * <p> <b>Usage</b> </p>
ohair@286 38 *
ohair@286 39 * The annotation creates a mapping between an XML schema element
ohair@286 40 * declaration and a <i> element factory method </i> that returns a
ohair@286 41 * JAXBElement instance representing the element
ohair@286 42 * declaration. Typically, the element factory method is generated
ohair@286 43 * (and annotated) from a schema into the ObjectFactory class in a
ohair@286 44 * Java package that represents the binding of the element
ohair@286 45 * declaration's target namespace. Thus, while the annotation syntax
ohair@286 46 * allows &#64;XmlElementDecl to be used on any method, semantically
ohair@286 47 * its use is restricted to annotation of element factory method.
ohair@286 48 *
ohair@286 49 * The usage is subject to the following constraints:
ohair@286 50 *
ohair@286 51 * <ul>
ohair@286 52 * <li> The class containing the element factory method annotated
ohair@286 53 * with &#64;XmlElementDecl must be marked with {@link
ohair@286 54 * XmlRegistry}. </li>
ohair@286 55 * <li> The element factory method must take one parameter
ohair@286 56 * assignable to {@link Object}.</li>
ohair@286 57 * </ul>
ohair@286 58 *
ohair@286 59 * <p><b>Example 1: </b>Annotation on a factory method
ohair@286 60 * <pre>
ohair@286 61 * // Example: code fragment
ohair@286 62 * &#64;XmlRegistry
ohair@286 63 * class ObjectFactory {
ohair@286 64 * &#64;XmlElementDecl(name="foo")
ohair@286 65 * JAXBElement&lt;String> createFoo(String s) { ... }
ohair@286 66 * }
ohair@286 67 * </pre>
ohair@286 68 * <pre>
ohair@286 69 * &lt;!-- XML input -->
ohair@286 70 * &lt;foo>string</foo>
ohair@286 71 *
ohair@286 72 * // Example: code fragment corresponding to XML input
ohair@286 73 * JAXBElement<String> o =
ohair@286 74 * (JAXBElement<String>)unmarshaller.unmarshal(aboveDocument);
ohair@286 75 * // print JAXBElement instance to show values
ohair@286 76 * System.out.println(o.getName()); // prints "{}foo"
ohair@286 77 * System.out.println(o.getValue()); // prints "string"
ohair@286 78 * System.out.println(o.getValue().getClass()); // prints "java.lang.String"
ohair@286 79 *
ohair@286 80 * &lt;!-- Example: XML schema definition -->
ohair@286 81 * &lt;xs:element name="foo" type="xs:string"/>
ohair@286 82 * </pre>
ohair@286 83 *
ohair@286 84 * <p><b>Example 2: </b> Element declaration with non local scope
ohair@286 85 * <p>
ohair@286 86 * The following example illustrates the use of scope annotation
ohair@286 87 * parameter in binding of element declaration in schema derived
ohair@286 88 * code.
ohair@286 89 * <p>
ohair@286 90 * The following example may be replaced in a future revision of
ohair@286 91 * this javadoc.
ohair@286 92 *
ohair@286 93 * <pre>
ohair@286 94 * &lt;!-- Example: XML schema definition -->
ohair@286 95 * &lt;xs:schema>
ohair@286 96 * &lt;xs:complexType name="pea">
ohair@286 97 * &lt;xs:choice maxOccurs="unbounded">
ohair@286 98 * &lt;xs:element name="foo" type="xs:string"/>
ohair@286 99 * &lt;xs:element name="bar" type="xs:string"/>
ohair@286 100 * &lt;/xs:choice>
ohair@286 101 * &lt;/xs:complexType>
ohair@286 102 * &lt;xs:element name="foo" type="xs:int"/>
ohair@286 103 * &lt;/xs:schema>
ohair@286 104 * </pre>
ohair@286 105 * <pre>
ohair@286 106 * // Example: expected default binding
ohair@286 107 * class Pea {
ohair@286 108 * &#64;XmlElementRefs({
ohair@286 109 * &#64;XmlElementRef(name="foo",type=JAXBElement.class)
ohair@286 110 * &#64;XmlElementRef(name="bar",type=JAXBElement.class)
ohair@286 111 * })
ohair@286 112 * List&lt;JAXBElement&lt;String>> fooOrBar;
ohair@286 113 * }
ohair@286 114 *
ohair@286 115 * &#64;XmlRegistry
ohair@286 116 * class ObjectFactory {
ohair@286 117 * &#64;XmlElementDecl(scope=Pea.class,name="foo")
ohair@286 118 * JAXBElement<String> createPeaFoo(String s);
ohair@286 119 *
ohair@286 120 * &#64;XmlElementDecl(scope=Pea.class,name="bar")
ohair@286 121 * JAXBElement<String> createPeaBar(String s);
ohair@286 122 *
ohair@286 123 * &#64;XmlElementDecl(name="foo")
ohair@286 124 * JAXBElement<Integer> createFoo(Integer i);
ohair@286 125 * }
ohair@286 126 *
ohair@286 127 * </pre>
ohair@286 128 * Without scope createFoo and createPeaFoo would become ambiguous
ohair@286 129 * since both of them map to a XML schema element with the same local
ohair@286 130 * name "foo".
ohair@286 131 *
ohair@286 132 * @see XmlRegistry
ohair@286 133 * @since JAXB 2.0
ohair@286 134 */
ohair@286 135 @Retention(RUNTIME)
ohair@286 136 @Target({METHOD})
ohair@286 137 public @interface XmlElementDecl {
ohair@286 138 /**
ohair@286 139 * scope of the mapping.
ohair@286 140 *
ohair@286 141 * <p>
ohair@286 142 * If this is not {@link XmlElementDecl.GLOBAL}, then this element
ohair@286 143 * declaration mapping is only active within the specified class.
ohair@286 144 */
ohair@286 145 Class scope() default GLOBAL.class;
ohair@286 146
ohair@286 147 /**
ohair@286 148 * namespace name of the XML element.
ohair@286 149 * <p>
ohair@286 150 * If the value is "##default", then the value is the namespace
ohair@286 151 * name for the package of the class containing this factory method.
ohair@286 152 *
ohair@286 153 * @see #name()
ohair@286 154 */
ohair@286 155 String namespace() default "##default";
ohair@286 156
ohair@286 157 /**
ohair@286 158 * local name of the XML element.
ohair@286 159 *
ohair@286 160 * <p>
ohair@286 161 * <b> Note to reviewers: </b> There is no default name; since
ohair@286 162 * the annotation is on a factory method, it is not clear that the
ohair@286 163 * method name can be derived from the factory method name.
ohair@286 164 * @see #namespace()
ohair@286 165 */
ohair@286 166 String name();
ohair@286 167
ohair@286 168 /**
ohair@286 169 * namespace name of a substitution group's head XML element.
ohair@286 170 * <p>
ohair@286 171 * This specifies the namespace name of the XML element whose local
ohair@286 172 * name is specified by <tt>substitutionHeadName()</tt>.
ohair@286 173 * <p>
ohair@286 174 * If <tt>susbtitutionHeadName()</tt> is "", then this
ohair@286 175 * value can only be "##default". But the value is ignored since
ohair@286 176 * since this element is not part of susbtitution group when the
ohair@286 177 * value of <tt>susbstitutionHeadName()</tt> is "".
ohair@286 178 * <p>
ohair@286 179 * If <tt>susbtitutionHeadName()</tt> is not "" and the value is
ohair@286 180 * "##default", then the namespace name is the namespace name to
ohair@286 181 * which the package of the containing class, marked with {@link
ohair@286 182 * XmlRegistry }, is mapped.
ohair@286 183 * <p>
ohair@286 184 * If <tt>susbtitutionHeadName()</tt> is not "" and the value is
ohair@286 185 * not "##default", then the value is the namespace name.
ohair@286 186 *
ohair@286 187 * @see #substitutionHeadName()
ohair@286 188 */
ohair@286 189 String substitutionHeadNamespace() default "##default";
ohair@286 190
ohair@286 191 /**
ohair@286 192 * XML local name of a substitution group's head element.
ohair@286 193 * <p>
ohair@286 194 * If the value is "", then this element is not part of any
ohair@286 195 * substitution group.
ohair@286 196 *
ohair@286 197 * @see #substitutionHeadNamespace()
ohair@286 198 */
ohair@286 199 String substitutionHeadName() default "";
ohair@286 200
ohair@286 201 /**
ohair@286 202 * Default value of this element.
ohair@286 203 *
ohair@286 204 * <p>
ohair@286 205 * The <pre>'\u0000'</pre> value specified as a default of this annotation element
ohair@286 206 * is used as a poor-man's substitute for null to allow implementations
ohair@286 207 * to recognize the 'no default value' state.
ohair@286 208 */
ohair@286 209 String defaultValue() default "\u0000";
ohair@286 210
ohair@286 211 /**
ohair@286 212 * Used in {@link XmlElementDecl#scope()} to
ohair@286 213 * signal that the declaration is in the global scope.
ohair@286 214 */
ohair@286 215 public final class GLOBAL {}
ohair@286 216 }

mercurial