001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.xml.annotation;
014
015import static java.lang.annotation.ElementType.*;
016import static java.lang.annotation.RetentionPolicy.*;
017
018import java.lang.annotation.*;
019
020/**
021 * Identifies the default XML namespaces at the package level.
022 *
023 * <h5 class='section'>See Also:</h5><ul>
024 *    <li class='link'><a class="doclink" href="../../../../../index.html#jm.XmlDetails">XML Details</a>
025 * </ul>
026 */
027@Documented
028@Target(PACKAGE)
029@Retention(RUNTIME)
030@Inherited
031public @interface XmlSchema {
032
033   /**
034    * Sets the default XML namespace URL for all classes in this and child packages.
035    *
036    * <p>
037    * Must either be matched with a {@link #prefix()} annotation, or an {@link #xmlNs()} mapping with the same
038    * {@link XmlNs#namespaceURI() @XmlNs(namespaceURI)} value.
039    *
040    * @return The annotation value.
041    */
042   public String namespace() default "";
043
044   /**
045    * Sets the default XML prefix for all classes in this and child packages.
046    *
047    * <p>
048    * Must either be matched with a {@link #namespace()} annotation, or an {@link #xmlNs()} mapping with the same
049    * {@link XmlNs#prefix} value.
050    *
051    * @return The annotation value.
052    */
053   public String prefix() default "";
054
055   /**
056    * Lists all namespace mappings to be used on all classes within this package.
057    *
058    * <p>
059    * The purpose of this annotation is to allow namespace mappings to be defined in a single location and referred
060    * to by name through just the {@link Xml#prefix() @Xml(prefix)} annotation.
061    *
062    * <p>
063    * Inherited by child packages.
064    *
065    * <h5 class='section'>Example:</h5>
066    * <p>
067    * Contents of <c>package-info.java</c>...
068    * <p class='bjava'>
069    *    <jc>// XML namespaces used within this package.</jc>
070    *    <ja>@XmlSchema</ja>(prefix=<js>"ab"</js>,
071    *       namespaces={
072    *          <ja>@XmlNs</ja>(prefix=<js>"ab"</js>, namespaceURI=<js>"http://www.apache.org/addressBook/"</js>),
073    *          <ja>@XmlNs</ja>(prefix=<js>"per"</js>, namespaceURI=<js>"http://www.apache.org/person/"</js>),
074    *          <ja>@XmlNs</ja>(prefix=<js>"addr"</js>, namespaceURI=<js>"http://www.apache.org/address/"</js>),
075    *          <ja>@XmlNs</ja>(prefix=<js>"mail"</js>, namespaceURI="<js>http://www.apache.org/mail/"</js>)
076    *       }
077    *    )
078    *    <jk>package</jk> org.apache.juneau.examples.addressbook;
079    *    <jk>import</jk> org.apache.juneau.xml.annotation.*;
080    * </p>
081    *
082    * <p>
083    * Class in package using defined namespaces...
084    * <p class='bjava'>
085    *    <jk>package</jk> corg.apache.juneau.examples.addressbook;
086    *
087    *    <jc>// Bean class, override "ab" namespace on package.</jc>
088    *    <ja>@Xml</ja>(prefix=<js>"addr"</js>)
089    *    <jk>public class</jk> Address {
090    *
091    *       <jc>// Bean property, use "addr" namespace on class.</jc>
092    *       <jk>public int</jk> <jf>id</jf>;
093    *
094    *       <jc>// Bean property, override with "mail" namespace.</jc>
095    *       <ja>@Xml</ja>(prefix=<js>"mail"</js>)
096    *       <jk>public</jk> String <jf>street</jf>, <jf>city</jf>, <jf>state</jf>;
097    *    }
098    * </p>
099    *
100    * @return The annotation value.
101    */
102   public XmlNs[] xmlNs() default {};
103}