001/* 002 * Namespace.java July 2008 003 * 004 * Copyright (C) 2008, Niall Gallagher <niallg@users.sf.net> 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 015 * implied. See the License for the specific language governing 016 * permissions and limitations under the License. 017 */ 018 019package org.simpleframework.xml; 020 021import java.lang.annotation.Retention; 022import java.lang.annotation.RetentionPolicy; 023 024/** 025 * The <code>Namespace</code> annotation is used to set a namespace 026 * on an element or attribute. By annotating a method, field or 027 * class with this annotation that entity assumes the XML namespace 028 * provided. When used on a class the annotation describes the 029 * namespace that should be used, this however can be overridden by 030 * an annotated field or method declaration of that type. 031 * <pre> 032 * 033 * <book:book xmlns:book="http://www.example.com/book"> 034 * <author>saurabh</author> 035 * <title>example title</title> 036 * <isbn>ISB-16728-10</isbn> 037 * </book:book> 038 * 039 * </pre> 040 * In the above XML snippet a namespace has been declared with the 041 * prefix "book" and the reference "http://www.example.com/book". If 042 * such a namespace is applied to a class, method, or field then 043 * that element will contain the namespace and the element name will 044 * be prefixed with a namespace qualifier, which is "book" here. 045 * <pre> 046 * 047 * <example xmlns="http://www.example.com/root"> 048 * <child> 049 * <text xmlns="">text element</text> 050 * </child> 051 * </example> 052 * 053 * </pre> 054 * In order for a namespace to be inherited it must be specified as 055 * a default namespace. A default namespace is one that does not have 056 * a prefix. All elements that do not have an explicit namespace will 057 * inherit the last default namespace in scope. For details see 058 * <a href='http://www.w3.org/TR/xml-names/#defaulting'>Section 6.2</a> 059 * of the namespaces in XML 1.0 specification. To remove the default 060 * namespace simply specify a namespace with no prefix or reference, 061 * such as the "text" element in the above example. 062 * 063 * @author Niall Gallagher 064 */ 065@Retention(RetentionPolicy.RUNTIME) 066public @interface Namespace { 067 068 /** 069 * This is used to specify the unique reference URI that is used 070 * to define the namespace within the document. This is typically 071 * a URI as this is a well know universally unique identifier. 072 * It can be anything unique, but typically should be a unique 073 * URI reference. If left as the empty string then this will 074 * signify that the anonymous namespace will be used. 075 * 076 * @return this returns the reference used by this namespace 077 */ 078 String reference() default ""; 079 080 /** 081 * This is used to specify the prefix used for the namespace. If 082 * no prefix is specified then the reference becomes the default 083 * namespace for the enclosing element. This means that all 084 * attributes and elements that do not contain a prefix belong 085 * to the namespace declared by this annotation. 086 * 087 * @return this returns the prefix used for this namespace 088 */ 089 String prefix() default ""; 090}