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