< prev index next >

src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlSchema.java

Print this page


   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


  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  *    &lt;!-- XML Schema fragment -->
  69  *    &lt;schema
  70  *      xmlns=...
  71  *      xmlns:po=....
  72  *      targetNamespace="http://www.example.com/MYPO1"
  73  *    >
  74  *    &lt;!-- 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  *    &lt;!-- XML Schema fragment -->
  94  *    &lt;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  *    &lt;!-- XML Schema fragment -->
 109  *    &lt;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 1.6, JAXB 2.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      */


 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>&lt;scheme>:</tt>.
 184      *
 185      * <p>
 186      * A schema generator is expected to generate a corresponding
 187      * <tt>&lt;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 1.6, JAXB 2.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 }
   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


  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      */


 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 }
< prev index next >