001: /*
002: * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
003: * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
004: */
005:
006: package javax.xml.bind.annotation;
007:
008: import java.lang.annotation.Retention;
009: import java.lang.annotation.Target;
010:
011: import static java.lang.annotation.ElementType.*;
012: import static java.lang.annotation.RetentionPolicy.*;
013:
014: /**
015: * <p> Maps a package name to a XML namespace. </p>
016: *
017: * <h3>Usage</h3>
018: * <p>
019: * The XmlSchema annotation can be used with the following program
020: * elements:
021: * <ul>
022: * <li>package</li>
023: * </ul>
024: *
025: * <p>
026: * This is a package level annotation and follows the recommendations
027: * and restrictions contained in JSR 175, section III, "Annotations".
028: * Thus the usage is subject to the following constraints and
029: * recommendations.
030: * <ul>
031: * <li> There can only be one package declaration as noted in JSR
032: * 175, section III, "Annotations". </li>
033: * <li> JSR 175 recommends package-info.java for package level
034: * annotations. JAXB Providers that follow this recommendation
035: * will allow the package level annotations to be defined in
036: * package-info.java.
037: * </ul>
038: * <p>
039: *
040: * <p><b>Example 1:</b> Customize name of XML namespace to which
041: * package is mapped.</p>
042: *
043: * <pre>
044: * @javax.xml.bind.annotation.XmlSchema (
045: * namespace = "http://www.example.com/MYPO1"
046: * )
047: *
048: * <!-- XML Schema fragment -->
049: * <schema
050: * xmlns=...
051: * xmlns:po=....
052: * targetNamespace="http://www.example.com/MYPO1"
053: * >
054: * <!-- prefixes generated by default are implementation
055: * depedenent -->
056: * </pre>
057: *
058: * <p><b>Example 2:</b> Customize namespace prefix, namespace URI
059: * mapping</p>
060: *
061: * <pre>
062: * // Package level annotation
063: * @javax.xml.bind.annotation.XmlSchema (
064: * xmlns = {
065: * @javax.xml.bind.annotation.XmlNs(prefix = "po",
066: * namespaceURI="http://www.example.com/myPO1"),
067: *
068: * @javax.xml.bind.annotation.XmlNs(prefix="xs",
069: * namespaceURI="http://www.w3.org/2001/XMLSchema")
070: * )
071: * )
072: *
073: * <!-- XML Schema fragment -->
074: * <schema
075: * xmlns:xs="http://www.w3.org/2001/XMLSchema"
076: * xmlns:po="http://www.example.com/PO1"
077: * targetNamespace="http://www.example.com/PO1">
078: *
079: * </pre>
080: *
081: * <p><b>Example 3:</b> Customize elementFormDefault</p>
082: * <pre>
083: * @javax.xml.bind.annotation.XmlSchema (
084: * elementFormDefault=XmlNsForm.UNQUALIFIED
085: * ...
086: * )
087: *
088: * <!-- XML Schema fragment -->
089: * <schema
090: * xmlns="http://www.w3.org/2001/XMLSchema"
091: * xmlns:po="http://www.example.com/PO1"
092: * elementFormDefault="unqualified">
093: *
094: * </pre>
095:
096: * @author Sekhar Vajjhala, Sun Microsystems, Inc.
097: * @since JAXB2.0
098: * @version $Revision: 1.10 $
099: */
100:
101: @Retention(RUNTIME)
102: @Target(PACKAGE)
103: public @interface XmlSchema {
104:
105: /**
106: * Customize the namespace URI, prefix associations. By default,
107: * the namespace prefixes for a XML namespace are generated by a
108: * JAXB Provider in an implementation dependent way.
109: */
110: XmlNs[] xmlns() default {};
111:
112: /**
113: * Name of the XML namespace.
114: */
115: String namespace() default "";
116:
117: /**
118: * Namespace qualification for elements. By default, element
119: * default attribute will be absent from the XML Schema fragment.
120: */
121: XmlNsForm elementFormDefault() default XmlNsForm.UNSET;
122:
123: /**
124: * Namespace qualification for attributes. By default,
125: * attributesFormDefault will be absent from the XML Schema fragment.
126: */
127: XmlNsForm attributeFormDefault() default XmlNsForm.UNSET;
128:
129: /**
130: * Indicates that this namespace (specified by {@link #namespace()})
131: * has a schema already available exeternally, available at this location.
132: *
133: * <p>
134: * This instructs the JAXB schema generators to simply refer to
135: * the pointed schema, as opposed to generating components into the schema.
136: * This schema is assumed to match what would be otherwise produced
137: * by the schema generator (same element names, same type names...)
138: *
139: * <p>
140: * This feature is intended to be used when a set of the Java classes
141: * is originally generated from an existing schema, hand-written to
142: * match externally defined schema, or the generated schema is modified
143: * manually.
144: *
145: * <p>
146: * Value could be any absolute URI, like <tt>http://example.org/some.xsd</tt>.
147: * It is also possible to specify the empty string, to indicate
148: * that the schema is externally available but the location is
149: * unspecified (and thus it's the responsibility of the reader of the generate
150: * schema to locate it.) Finally, the default value of this property
151: * <tt>"##generate"</tt> indicates that the schema generator is going
152: * to generate components for this namespace (as it did in JAXB 2.0.)
153: *
154: * <p>
155: * Multiple {@link XmlSchema} annotations on multiple packages are allowed
156: * to govern the same {@link #namespace()}. In such case, all of them
157: * must have the same {@link #location()} values.
158: *
159: *
160: * <h3>Note to implementor</h3>
161: * <p>
162: * More precisely, the value must be either <tt>""</tt>, <tt>"##generate"</tt>, or
163: * <a href="http://www.w3.org/TR/xmlschema-2/#anyURI">
164: * a valid lexical representation of <tt>xs:anyURI</tt></a> that begins
165: * with <tt><scheme>:</tt>.
166: *
167: * <p>
168: * A schema generator is expected to generate a corresponding
169: * <tt><xs:import namespace="..." schemaLocation="..."/></tt> (or
170: * no <tt>schemaLocation</tt> attribute at all if the empty string is specified.)
171: * However, the schema generator is allowed to use a different value in
172: * the <tt>schemaLocation</tt> attribute (including not generating
173: * such attribute), for example so that the user can specify a local
174: * copy of the resource through the command line interface.
175: *
176: * @since JAXB2.1
177: */
178: String location() default NO_LOCATION;
179:
180: /**
181: * The default value of the {@link #location()} attribute,
182: * which indicates that the schema generator will generate
183: * components in this namespace.
184: */
185: // the actual value is chosen because ## is not a valid
186: // sequence in xs:anyURI.
187: static final String NO_LOCATION = "##generate";
188: }
|