1 /*
   2  * Copyright (c) 2004, 2015, 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  *
  59  * <p><b>Example 1:</b> Customize name of XML namespace to which
  60  * package is mapped.</p>
  61  *
  62  * <pre>
  63  *    @javax.xml.bind.annotation.XmlSchema (
  64  *      namespace = "http://www.example.com/MYPO1"
  65  *    )
  66  *
  67  *    &lt;!-- XML Schema fragment --&gt;
  68  *    &lt;schema
  69  *      xmlns=...
  70  *      xmlns:po=....
  71  *      targetNamespace="http://www.example.com/MYPO1"
  72  *    &gt;
  73  *    &lt;!-- prefixes generated by default are implementation
  74  *            depedenent --&gt;
  75  * </pre>
  76  *
  77  * <p><b>Example 2:</b> Customize namespace prefix, namespace URI
  78  * mapping</p>
  79  *
  80  * <pre>
  81  *    // Package level annotation
  82  *    @javax.xml.bind.annotation.XmlSchema (
  83  *      xmlns = {
  84  *        @javax.xml.bind.annotation.XmlNs(prefix = "po",
  85  *                   namespaceURI="http://www.example.com/myPO1"),
  86  *
  87  *        @javax.xml.bind.annotation.XmlNs(prefix="xs",
  88  *                   namespaceURI="http://www.w3.org/2001/XMLSchema")
  89  *      )
  90  *    )
  91  *
  92  *    &lt;!-- XML Schema fragment --&gt;
  93  *    &lt;schema
  94  *        xmlns:xs="http://www.w3.org/2001/XMLSchema"
  95  *        xmlns:po="http://www.example.com/PO1"
  96  *        targetNamespace="http://www.example.com/PO1"&gt;
  97  *
  98  * </pre>
  99  *
 100  * <p><b>Example 3:</b> Customize elementFormDefault</p>
 101  * <pre>
 102  *    @javax.xml.bind.annotation.XmlSchema (
 103  *      elementFormDefault=XmlNsForm.UNQUALIFIED
 104  *      ...
 105  *    )
 106  *
 107  *    &lt;!-- XML Schema fragment --&gt;
 108  *    &lt;schema
 109  *        xmlns="http://www.w3.org/2001/XMLSchema"
 110  *        xmlns:po="http://www.example.com/PO1"
 111  *        elementFormDefault="unqualified"&gt;
 112  *
 113  * </pre>
 114 
 115  * @author Sekhar Vajjhala, Sun Microsystems, Inc.
 116  * @since 1.6, JAXB 2.0
 117  */
 118 
 119 @Retention(RUNTIME) @Target(PACKAGE)
 120 public @interface XmlSchema {
 121 
 122     /**
 123      * Customize the namespace URI, prefix associations. By default,
 124      * the namespace prefixes for a XML namespace are generated by a
 125      * JAXB Provider in an implementation dependent way.
 126      */
 127     XmlNs[]  xmlns() default {};
 128 
 129     /**
 130      * Name of the XML namespace.
 131      */
 132     String namespace() default "";
 133 
 134     /**
 135      * Namespace qualification for elements. By default, element
 136      * default attribute will be absent from the XML Schema fragment.
 137      */
 138     XmlNsForm elementFormDefault() default XmlNsForm.UNSET;
 139 
 140     /**
 141      * Namespace qualification for attributes. By default,
 142      * attributesFormDefault will be absent from the XML Schema fragment.
 143      */
 144     XmlNsForm attributeFormDefault() default XmlNsForm.UNSET;
 145 
 146     /**
 147      * Indicates that this namespace (specified by {@link #namespace()})
 148      * has a schema already available exeternally, available at this location.
 149      *
 150      * <p>
 151      * This instructs the JAXB schema generators to simply refer to
 152      * the pointed schema, as opposed to generating components into the schema.
 153      * This schema is assumed to match what would be otherwise produced
 154      * by the schema generator (same element names, same type names...)
 155      *
 156      * <p>
 157      * This feature is intended to be used when a set of the Java classes
 158      * is originally generated from an existing schema, hand-written to
 159      * match externally defined schema, or the generated schema is modified
 160      * manually.
 161      *
 162      * <p>
 163      * Value could be any absolute URI, like <tt>http://example.org/some.xsd</tt>.
 164      * It is also possible to specify the empty string, to indicate
 165      * that the schema is externally available but the location is
 166      * unspecified (and thus it's the responsibility of the reader of the generate
 167      * schema to locate it.) Finally, the default value of this property
 168      * <tt>"##generate"</tt> indicates that the schema generator is going
 169      * to generate components for this namespace (as it did in JAXB 2.0.)
 170      *
 171      * <p>
 172      * Multiple {@link XmlSchema} annotations on multiple packages are allowed
 173      * to govern the same {@link #namespace()}. In such case, all of them
 174      * must have the same {@link #location()} values.
 175      *
 176      *
 177      * <h3>Note to implementor</h3>
 178      * <p>
 179      * More precisely, the value must be either <tt>""</tt>, <tt>"##generate"</tt>, or
 180      * <a href="http://www.w3.org/TR/xmlschema-2/#anyURI">
 181      * a valid lexical representation of <tt>xs:anyURI</tt></a> that begins
 182      * with <tt>&lt;scheme&gt;:</tt>.
 183      *
 184      * <p>
 185      * A schema generator is expected to generate a corresponding
 186      * <tt>&lt;xs:import namespace="..." schemaLocation="..."/&gt;</tt> (or
 187      * no <tt>schemaLocation</tt> attribute at all if the empty string is specified.)
 188      * However, the schema generator is allowed to use a different value in
 189      * the <tt>schemaLocation</tt> attribute (including not generating
 190      * such attribute), for example so that the user can specify a local
 191      * copy of the resource through the command line interface.
 192      *
 193      * @since 1.6, JAXB 2.1
 194      */
 195     String location() default NO_LOCATION;
 196 
 197     /**
 198      * The default value of the {@link #location()} attribute,
 199      * which indicates that the schema generator will generate
 200      * components in this namespace.
 201      */
 202     // the actual value is chosen because ## is not a valid
 203     // sequence in xs:anyURI.
 204     static final String NO_LOCATION = "##generate";
 205 }