Coverage Report - org.simpleframework.xml.Namespace
 
Classes in this File Line Coverage Branch Coverage Complexity
Namespace
N/A
N/A
0
 
 1  
 /*
 2  
  * Namespace.java July 2008
 3  
  *
 4  
  * Copyright (C) 2008, Niall Gallagher <niallg@users.sf.net>
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 15  
  * implied. See the License for the specific language governing 
 16  
  * permissions and limitations under the License.
 17  
  */
 18  
 
 19  
 package org.simpleframework.xml;
 20  
 
 21  
 import java.lang.annotation.Retention;
 22  
 import java.lang.annotation.RetentionPolicy;
 23  
 
 24  
 /**
 25  
  * The <code>Namespace</code> annotation is used to set a namespace
 26  
  * on an element or attribute. By annotating a method, field or 
 27  
  * class with this annotation that entity assumes the XML namespace
 28  
  * provided. When used on a class the annotation describes the
 29  
  * namespace that should be used, this however can be overridden by
 30  
  * an annotated field or method declaration of that type.
 31  
  * <pre>
 32  
  *  
 33  
  *    &lt;book:book xmlns:book="http://www.example.com/book"&gt;
 34  
  *       &lt;author&gt;saurabh&lt;/author&gt;
 35  
  *       &lt;title&gt;example title&lt;/title&gt;
 36  
  *       &lt;isbn&gt;ISB-16728-10&lt;/isbn&gt;
 37  
  *    &lt;/book:book&gt;
 38  
  *
 39  
  * </pre>
 40  
  * In the above XML snippet a namespace has been declared with the
 41  
  * prefix "book" and the reference "http://www.example.com/book". If
 42  
  * such a namespace is applied to a class, method, or field then 
 43  
  * that element will contain the namespace and the element name will
 44  
  * be prefixed with a namespace qualifier, which is "book" here.
 45  
  * <pre>
 46  
  *
 47  
  *    &lt;example xmlns="http://www.example.com/root"&gt;
 48  
  *       &lt;child&gt;
 49  
  *          &lt;text xmlns=""&gt;text element&lt;/text&gt;
 50  
  *       &lt;/child&gt;
 51  
  *    &lt;/example&gt;
 52  
  *
 53  
  * </pre>
 54  
  * In order for a namespace to be inherited it must be specified as
 55  
  * a default namespace. A default namespace is one that does not have
 56  
  * a prefix. All elements that do not have an explicit namespace will
 57  
  * inherit the last default namespace in scope. For details see
 58  
  * <a href='http://www.w3.org/TR/xml-names/#defaulting'>Section 6.2</a>
 59  
  * of the namespaces in XML 1.0 specification. To remove the default
 60  
  * namespace simply specify a namespace with no prefix or reference,
 61  
  * such as the "text" element in the above example.  
 62  
  *
 63  
  * @author Niall Gallagher
 64  
  */ 
 65  
 @Retention(RetentionPolicy.RUNTIME)
 66  
 public @interface Namespace {
 67  
 
 68  
    /**
 69  
     * This is used to specify the unique reference URI that is used 
 70  
     * to define the namespace within the document. This is typically
 71  
     * a URI as this is a well know universally unique identifier. 
 72  
     * It can be anything unique, but typically should be a unique
 73  
     * URI reference. If left as the empty string then this will
 74  
     * signify that the anonymous namespace will be used.
 75  
     *
 76  
     * @return this returns the reference used by this namespace    
 77  
     */         
 78  
    String reference() default "";
 79  
 
 80  
    /**
 81  
     * This is used to specify the prefix used for the namespace. If
 82  
     * no prefix is specified then the reference becomes the default
 83  
     * namespace for the enclosing element. This means that all 
 84  
     * attributes and elements that do not contain a prefix belong
 85  
     * to the namespace declared by this annotation.
 86  
     *
 87  
     * @return this returns the prefix used for this namespace
 88  
     */ 
 89  
    String prefix() default "";
 90  
 }