Coverage Report - org.simpleframework.xml.Attribute
 
Classes in this File Line Coverage Branch Coverage Complexity
Attribute
N/A
N/A
0
 
 1  
 /*
 2  
  * Attribute.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>Attribute</code> annotation represents a serializable XML
 26  
  * attribute within an XML element. An object annotated with this is
 27  
  * typically a primitive or enumerated type. Conversion from the 
 28  
  * attribute to primitive type is done with a <code>Transform</code>
 29  
  * object. If a suitable transform can be found then this will convert
 30  
  * the attribute string value to an object instance, which can be 
 31  
  * assigned to the annotated field, or passed to the annotated method.
 32  
  * 
 33  
  * @author Niall Gallagher
 34  
  * 
 35  
  * @see org.simpleframework.xml.transform.Transformer
 36  
  */ 
 37  
 @Retention(RetentionPolicy.RUNTIME)
 38  
 public @interface Attribute {
 39  
 
 40  
    /**
 41  
     * This represents the name of the XML attribute. Annotated fields
 42  
     * or methods can optionally provide the name of the XML attribute
 43  
     * they represent. If a name is not provided then the field or 
 44  
     * method name is used in its place. A name can be specified if 
 45  
     * the field or method name is not suitable for the XML attribute.
 46  
     * 
 47  
     * @return the name of the XML attribute this represents
 48  
     */
 49  
    String name() default "";
 50  
    
 51  
    /**
 52  
     * This is used to provide a default value for the attribute if
 53  
     * the annotated field or method is null. This ensures the the
 54  
     * serialization process writes the attribute with a value even
 55  
     * if the value is null, and allows deserialization to determine
 56  
     * whether the value within the object was null or not.
 57  
     * 
 58  
     * @return this returns the default attribute value to use
 59  
     */
 60  
    String empty() default "";
 61  
 
 62  
    /**
 63  
     * Determines whether the attribute is required within an XML
 64  
     * element. Any field marked as not required will not have its
 65  
     * value set when the object is deserialized. If an object is to
 66  
     * be serialized only a null attribute will not appear as XML.
 67  
     * 
 68  
     * @return true if the attribute is required, false otherwise
 69  
     */
 70  
    boolean required() default true;   
 71  
 }