Coverage Report - org.simpleframework.xml.core.FieldDetail
 
Classes in this File Line Coverage Branch Coverage Complexity
FieldDetail
100%
8/8
N/A
1
 
 1  
 /*
 2  
  * FieldDetail.java July 2012
 3  
  *
 4  
  * Copyright (C) 2012, 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.core;
 20  
 
 21  
 import java.lang.annotation.Annotation;
 22  
 import java.lang.reflect.Field;
 23  
 
 24  
 /**
 25  
  * The <code>FieldDetail</code> represents a field and acts as a 
 26  
  * means to cache all of the details associated with the field. 
 27  
  * This is primarily used to cache data associated with the field
 28  
  * as some platforms do not perform well with reflection.
 29  
  * 
 30  
  * @author Niall Gallagher
 31  
  */
 32  
 class FieldDetail {
 33  
 
 34  
    /**
 35  
     * This contains all the annotations declared on the field.
 36  
     */
 37  
    private final Annotation[] list;
 38  
    
 39  
    /**
 40  
     * This is the field that this instance is representing.
 41  
     */
 42  
    private final Field field;
 43  
    
 44  
    /**
 45  
     * This contains the name of the field that is represented.
 46  
     */
 47  
    private final String name;
 48  
    
 49  
    /**
 50  
     * Constructor for the <code>FieldDetail</code> object. This takes
 51  
     * a field that has been extracted from a class. All of the details
 52  
     * such as the annotations and the field name are stored.
 53  
     * 
 54  
     * @param field this is the field that is represented by this
 55  
     */
 56  13908
    public FieldDetail(Field field) {
 57  13908
       this.list = field.getDeclaredAnnotations();
 58  13908
       this.name = field.getName();
 59  13908
       this.field = field;
 60  13908
    }
 61  
    
 62  
    /**
 63  
     * This returns the list of annotations that are associated with 
 64  
     * the field. The annotations are extracted only once and cached
 65  
     * internally, which improves the performance of serialization as
 66  
     * reflection on the field needs to be performed only once.
 67  
     * 
 68  
     * @return this returns the annotations associated with the field
 69  
     */
 70  
    public Annotation[] getAnnotations() {
 71  7487
       return list;
 72  
    }
 73  
    
 74  
    /**
 75  
     * This is the field that is represented by this detail. The field
 76  
     * is provided so that it can be invoked to set or get the data
 77  
     * that is referenced by the field during serialization.
 78  
     * 
 79  
     * @return this returns the field represented by this detail
 80  
     */
 81  
    public Field getField() {
 82  7487
       return field;
 83  
    }
 84  
    
 85  
    /**
 86  
     * This is used to extract the name of the field. The name here
 87  
     * is the actual name of the field rather than the name used by
 88  
     * the XML representation of the field.
 89  
     * 
 90  
     * @return this returns the actual name of the field
 91  
     */
 92  
    public String getName() {
 93  1
       return name;
 94  
    }
 95  
 }