Coverage Report - org.simpleframework.xml.Element
 
Classes in this File Line Coverage Branch Coverage Complexity
Element
N/A
N/A
0
 
 1  
 /*
 2  
  * Element.java July 2006
 3  
  *
 4  
  * Copyright (C) 2006, 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.RetentionPolicy;
 22  
 import java.lang.annotation.Retention;
 23  
 
 24  
 /**
 25  
  * The <code>Element</code> annotation is used to represent a field
 26  
  * or method that appears as an XML element. Fields or methods that
 27  
  * are annotated with this can be either primitive or compound, that
 28  
  * is, represent an object that can be serialized and deserialized.
 29  
  * Below is an example of the serialized format for a compound object.
 30  
  * <p>
 31  
  * If this annotates a type that contains no XML annotations then
 32  
  * this will look for a suitable <code>Transform</code> for the type
 33  
  * using the <code>Transformer</code>. For instance, all primitives 
 34  
  * and primitive arrays that are annotated with this will make use 
 35  
  * of a transform in order to convert its value to and from suitable 
 36  
  * XML representations.
 37  
  * <pre>
 38  
  * 
 39  
  *    &lt;example class="demo.Example"&gt;
 40  
  *       &lt;data/&gt;
 41  
  *    &lt;example&gt;
 42  
  * 
 43  
  * </pre>
 44  
  * Each element may have any number of attributes and sub-elements
 45  
  * representing fields or methods of that compound object. Attribute
 46  
  * and element names can be acquired from the annotation or, if the
 47  
  * annotation does not explicitly declare a name, it is taken from
 48  
  * the annotated field or method. There are exceptions in some cases,
 49  
  * for example, the <code>class</code> attribute is reserved by the
 50  
  * serialization framework to represent the serialized type. 
 51  
  * 
 52  
  * @author Niall Gallagher
 53  
  */ 
 54  
 @Retention(RetentionPolicy.RUNTIME)
 55  
 public @interface Element {
 56  
    
 57  
    /**
 58  
     * This represents the name of the XML element. Annotated fields
 59  
     * can optionally provide the name of the element. If no name is
 60  
     * provided then the name of the annotated field or method will
 61  
     * be used in its place. The name is provided if the field or
 62  
     * method name is not suitable as an XML element name.
 63  
     * 
 64  
     * @return the name of the XML element this represents
 65  
     */
 66  
    String name() default "";
 67  
    
 68  
    /**
 69  
     * This is used to determine whether the element data is written
 70  
     * in a CDATA block or not. If this is set to true then the text
 71  
     * is written within a CDATA block, by default the text is output
 72  
     * as escaped XML. Typically this is useful for primitives only.
 73  
     * 
 74  
     * @return true if the data is to be wrapped in a CDATA block
 75  
     */
 76  
    boolean data() default false;
 77  
    
 78  
    /**
 79  
     * Determines whether the element is required within the XML
 80  
     * document. Any field marked as not required will not have its
 81  
     * value set when the object is deserialized. If an object is to
 82  
     * be serialized only a null attribute will not appear as XML.
 83  
     * 
 84  
     * @return true if the element is required, false otherwise
 85  
     */
 86  
    boolean required() default true; 
 87  
    
 88  
    /**
 89  
     * This represents an explicit type that should be used for the
 90  
     * annotated field or method. Typically this is used when the
 91  
     * element forms part of a union group. It allows the union
 92  
     * to distinguish the annotation to use based on the type.
 93  
     * 
 94  
     * @return this returns the explicit type to use for this
 95  
     */
 96  
    Class type() default void.class;
 97  
 }