Coverage Report - org.simpleframework.xml.ElementList
 
Classes in this File Line Coverage Branch Coverage Complexity
ElementList
N/A
N/A
0
 
 1  
 /*
 2  
  * ElementList.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>ElementList</code> annotation represents a method or
 26  
  * field that is a <code>Collection</code> for storing entries. The
 27  
  * collection object deserialized is typically of the same type as
 28  
  * the field. However, a <code>class</code> attribute can be used to
 29  
  * override the field type, however the type must be assignable.
 30  
  * <pre>
 31  
  * 
 32  
  *    &lt;list class="java.util.ArrayList"&gt;
 33  
  *       &lt;entry name="one"/&gt;
 34  
  *       &lt;entry name="two"/&gt;
 35  
  *       &lt;entry name="three"/&gt;  
 36  
  *    &lt;/list&gt;
 37  
  * 
 38  
  * </pre>
 39  
  * If a <code>class</code> attribute is not provided and the type or
 40  
  * the field or method is abstract, a suitable match is searched for 
 41  
  * from the collections available from the Java collections framework.
 42  
  * This annotation can also compose an inline list of XML elements. 
 43  
  * An inline list contains no parent or containing element.
 44  
  * <pre>
 45  
  *
 46  
  *    &lt;entry name="one"/&gt;
 47  
  *    &lt;entry name="two"/&gt;
 48  
  *    &lt;entry name="three"/&gt;  
 49  
  * 
 50  
  * </pre>
 51  
  * The above XML is an example of the output for an inline list of
 52  
  * XML elements. In such a list the annotated field or method must
 53  
  * not be given a name. Instead the name is acquired from the name of
 54  
  * the entry type. For example if the <code>type</code> attribute of
 55  
  * this was set to an object <code>example.Entry</code> then the name 
 56  
  * of the entry list would be taken as the root name of the object
 57  
  * as taken from the <code>Root</code> annotation for that object.
 58  
  * 
 59  
  * @author Niall Gallagher
 60  
  */
 61  
 @Retention(RetentionPolicy.RUNTIME)
 62  
 public @interface ElementList {
 63  
    
 64  
    /**
 65  
     * This represents the name of the XML element. Annotated fields
 66  
     * can optionally provide the name of the element. If no name is
 67  
     * provided then the name of the annotated field or method will
 68  
     * be used in its place. The name is provided if the field or
 69  
     * method name is not suitable as an XML element name. Also, if
 70  
     * the list is inline then this must not be specified.
 71  
     * 
 72  
     * @return the name of the XML element this represents
 73  
     */
 74  
    String name() default "";
 75  
    
 76  
    /**
 77  
     * This is used to provide a name of the XML element representing
 78  
     * the entry within the list. An entry name is optional and is
 79  
     * used when the name needs to be overridden. This also ensures
 80  
     * that entry, regardless of type has the same root name.   
 81  
     * 
 82  
     * @return this returns the entry XML element for each value
 83  
     */
 84  
    String entry() default "";
 85  
    
 86  
    /**
 87  
     * Represents the type of object the element list contains. This
 88  
     * type is used to deserialize the XML elements from the list. 
 89  
     * The object typically represents the deserialized type, but can
 90  
     * represent a subclass of the type deserialized as determined
 91  
     * by the <code>class</code> attribute value for the list. If 
 92  
     * this is not specified then the type can be determined from the
 93  
     * generic parameter of the annotated <code>Collection</code>.
 94  
     * 
 95  
     * @return the type of the element deserialized from the XML
 96  
     */
 97  
    Class type() default void.class;
 98  
    
 99  
    /**
 100  
     * This is used to determine whether the element data is written
 101  
     * in a CDATA block or not. If this is set to true then the text
 102  
     * is written within a CDATA block, by default the text is output
 103  
     * as escaped XML. Typically this is useful when this annotation
 104  
     * is applied to an array of primitives, such as strings.
 105  
     * 
 106  
     * @return true if entries are to be wrapped in a CDATA block
 107  
     */
 108  
    boolean data() default false;
 109  
    
 110  
    /**
 111  
     * Determines whether the element is required within the XML
 112  
     * document. Any field marked as not required will not have its
 113  
     * value set when the object is deserialized. If an object is to
 114  
     * be serialized only a null attribute will not appear as XML.
 115  
     * 
 116  
     * @return true if the element is required, false otherwise
 117  
     */        
 118  
    boolean required() default true;
 119  
    
 120  
    /**
 121  
     * Determines whether the element list is inlined with respect
 122  
     * to the parent XML element. An inlined element list does not
 123  
     * contain an enclosing element. It is simple a sequence of 
 124  
     * elements that appear one after another within an element.
 125  
     * As such an inline element list must not have a name. 
 126  
     *
 127  
     * @return this returns true if the element list is inline
 128  
     */
 129  
    boolean inline() default false;
 130  
    
 131  
    /**
 132  
     * This is used to determine if an optional field or method can
 133  
     * remain null if it does not exist. If this is false then the
 134  
     * optional element is given an empty list. This is a convenience
 135  
     * attribute which avoids having to check if the element is null
 136  
     * before providing it with a suitable default instance.
 137  
     * 
 138  
     * @return false if an optional element is always instantiated
 139  
     */
 140  
    boolean empty() default true;
 141  
 }