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