|
1 /* |
|
2 * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package javax.xml.bind.annotation; |
|
27 |
|
28 import java.lang.annotation.Retention; |
|
29 import java.lang.annotation.Target; |
|
30 |
|
31 import static java.lang.annotation.ElementType.*; |
|
32 import static java.lang.annotation.RetentionPolicy.*; |
|
33 |
|
34 /** |
|
35 * <p> Maps a package name to a XML namespace. </p> |
|
36 * |
|
37 * <h3>Usage</h3> |
|
38 * <p> |
|
39 * The XmlSchema annotation can be used with the following program |
|
40 * elements: |
|
41 * <ul> |
|
42 * <li>package</li> |
|
43 * </ul> |
|
44 * |
|
45 * <p> |
|
46 * This is a package level annotation and follows the recommendations |
|
47 * and restrictions contained in JSR 175, section III, "Annotations". |
|
48 * Thus the usage is subject to the following constraints and |
|
49 * recommendations. |
|
50 * <ul> |
|
51 * <li> There can only be one package declaration as noted in JSR |
|
52 * 175, section III, "Annotations". </li> |
|
53 * <li> JSR 175 recommends package-info.java for package level |
|
54 * annotations. JAXB Providers that follow this recommendation |
|
55 * will allow the package level annotations to be defined in |
|
56 * package-info.java. |
|
57 * </ul> |
|
58 * <p> |
|
59 * |
|
60 * <p><b>Example 1:</b> Customize name of XML namespace to which |
|
61 * package is mapped.</p> |
|
62 * |
|
63 * <pre> |
|
64 * @javax.xml.bind.annotation.XmlSchema ( |
|
65 * namespace = "http://www.example.com/MYPO1" |
|
66 * ) |
|
67 * |
|
68 * <!-- XML Schema fragment --> |
|
69 * <schema |
|
70 * xmlns=... |
|
71 * xmlns:po=.... |
|
72 * targetNamespace="http://www.example.com/MYPO1" |
|
73 * > |
|
74 * <!-- prefixes generated by default are implementation |
|
75 * depedenent --> |
|
76 * </pre> |
|
77 * |
|
78 * <p><b>Example 2:</b> Customize namespace prefix, namespace URI |
|
79 * mapping</p> |
|
80 * |
|
81 * <pre> |
|
82 * // Package level annotation |
|
83 * @javax.xml.bind.annotation.XmlSchema ( |
|
84 * xmlns = { |
|
85 * @javax.xml.bind.annotation.XmlNs(prefix = "po", |
|
86 * namespaceURI="http://www.example.com/myPO1"), |
|
87 * |
|
88 * @javax.xml.bind.annotation.XmlNs(prefix="xs", |
|
89 * namespaceURI="http://www.w3.org/2001/XMLSchema") |
|
90 * ) |
|
91 * ) |
|
92 * |
|
93 * <!-- XML Schema fragment --> |
|
94 * <schema |
|
95 * xmlns:xs="http://www.w3.org/2001/XMLSchema" |
|
96 * xmlns:po="http://www.example.com/PO1" |
|
97 * targetNamespace="http://www.example.com/PO1"> |
|
98 * |
|
99 * </pre> |
|
100 * |
|
101 * <p><b>Example 3:</b> Customize elementFormDefault</p> |
|
102 * <pre> |
|
103 * @javax.xml.bind.annotation.XmlSchema ( |
|
104 * elementFormDefault=XmlNsForm.UNQUALIFIED |
|
105 * ... |
|
106 * ) |
|
107 * |
|
108 * <!-- XML Schema fragment --> |
|
109 * <schema |
|
110 * xmlns="http://www.w3.org/2001/XMLSchema" |
|
111 * xmlns:po="http://www.example.com/PO1" |
|
112 * elementFormDefault="unqualified"> |
|
113 * |
|
114 * </pre> |
|
115 |
|
116 * @author Sekhar Vajjhala, Sun Microsystems, Inc. |
|
117 * @since JAXB2.0 |
|
118 */ |
|
119 |
|
120 @Retention(RUNTIME) @Target(PACKAGE) |
|
121 public @interface XmlSchema { |
|
122 |
|
123 /** |
|
124 * Customize the namespace URI, prefix associations. By default, |
|
125 * the namespace prefixes for a XML namespace are generated by a |
|
126 * JAXB Provider in an implementation dependent way. |
|
127 */ |
|
128 XmlNs[] xmlns() default {}; |
|
129 |
|
130 /** |
|
131 * Name of the XML namespace. |
|
132 */ |
|
133 String namespace() default ""; |
|
134 |
|
135 /** |
|
136 * Namespace qualification for elements. By default, element |
|
137 * default attribute will be absent from the XML Schema fragment. |
|
138 */ |
|
139 XmlNsForm elementFormDefault() default XmlNsForm.UNSET; |
|
140 |
|
141 /** |
|
142 * Namespace qualification for attributes. By default, |
|
143 * attributesFormDefault will be absent from the XML Schema fragment. |
|
144 */ |
|
145 XmlNsForm attributeFormDefault() default XmlNsForm.UNSET; |
|
146 |
|
147 /** |
|
148 * Indicates that this namespace (specified by {@link #namespace()}) |
|
149 * has a schema already available exeternally, available at this location. |
|
150 * |
|
151 * <p> |
|
152 * This instructs the JAXB schema generators to simply refer to |
|
153 * the pointed schema, as opposed to generating components into the schema. |
|
154 * This schema is assumed to match what would be otherwise produced |
|
155 * by the schema generator (same element names, same type names...) |
|
156 * |
|
157 * <p> |
|
158 * This feature is intended to be used when a set of the Java classes |
|
159 * is originally generated from an existing schema, hand-written to |
|
160 * match externally defined schema, or the generated schema is modified |
|
161 * manually. |
|
162 * |
|
163 * <p> |
|
164 * Value could be any absolute URI, like <tt>http://example.org/some.xsd</tt>. |
|
165 * It is also possible to specify the empty string, to indicate |
|
166 * that the schema is externally available but the location is |
|
167 * unspecified (and thus it's the responsibility of the reader of the generate |
|
168 * schema to locate it.) Finally, the default value of this property |
|
169 * <tt>"##generate"</tt> indicates that the schema generator is going |
|
170 * to generate components for this namespace (as it did in JAXB 2.0.) |
|
171 * |
|
172 * <p> |
|
173 * Multiple {@link XmlSchema} annotations on multiple packages are allowed |
|
174 * to govern the same {@link #namespace()}. In such case, all of them |
|
175 * must have the same {@link #location()} values. |
|
176 * |
|
177 * |
|
178 * <h3>Note to implementor</h3> |
|
179 * <p> |
|
180 * More precisely, the value must be either <tt>""</tt>, <tt>"##generate"</tt>, or |
|
181 * <a href="http://www.w3.org/TR/xmlschema-2/#anyURI"> |
|
182 * a valid lexical representation of <tt>xs:anyURI</tt></a> that begins |
|
183 * with <tt><scheme>:</tt>. |
|
184 * |
|
185 * <p> |
|
186 * A schema generator is expected to generate a corresponding |
|
187 * <tt><xs:import namespace="..." schemaLocation="..."/></tt> (or |
|
188 * no <tt>schemaLocation</tt> attribute at all if the empty string is specified.) |
|
189 * However, the schema generator is allowed to use a different value in |
|
190 * the <tt>schemaLocation</tt> attribute (including not generating |
|
191 * such attribute), for example so that the user can specify a local |
|
192 * copy of the resource through the command line interface. |
|
193 * |
|
194 * @since JAXB2.1 |
|
195 */ |
|
196 String location() default NO_LOCATION; |
|
197 |
|
198 /** |
|
199 * The default value of the {@link #location()} attribute, |
|
200 * which indicates that the schema generator will generate |
|
201 * components in this namespace. |
|
202 */ |
|
203 // the actual value is chosen because ## is not a valid |
|
204 // sequence in xs:anyURI. |
|
205 static final String NO_LOCATION = "##generate"; |
|
206 } |