Coverage Report - org.simpleframework.xml.core.OverrideType
 
Classes in this File Line Coverage Branch Coverage Complexity
OverrideType
71%
5/7
N/A
1
 
 1  
 /*
 2  
  * OverrideType.java January 2010
 3  
  *
 4  
  * Copyright (C) 2010, 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  
 
 23  
 import org.simpleframework.xml.strategy.Type;
 24  
 
 25  
 /**
 26  
  * The <code>OverrideType</code> is used to represent a type as class
 27  
  * other than that defined in a containing type. This can be used to
 28  
  * ensure that a union type does not have to have an attribute
 29  
  * defining its type serialized in to the resulting XML.
 30  
  * 
 31  
  * @author Niall Gallagher
 32  
  */
 33  
 class OverrideType implements Type {
 34  
    
 35  
    /**
 36  
     * This is the override that is used to represent the type.
 37  
     */
 38  
    private final Class override;
 39  
    
 40  
    /**
 41  
     * This is the type associated with this override type.
 42  
     */
 43  
    private final Type type;
 44  
    
 45  
    /**
 46  
     * Constructor for the <code>OverrideType</code> object. This is
 47  
     * used to create a type object that has an override type which
 48  
     * is can be used to ensure serialization does not require any
 49  
     * extra data containing the class name of the type instance.
 50  
     * 
 51  
     * @param type this is the type used internally for this
 52  
     * @param override this is the override type to use
 53  
     */
 54  2571
    public OverrideType(Type type, Class override) {
 55  2571
       this.override = override;
 56  2571
       this.type = type;
 57  2571
    }
 58  
    
 59  
    /**
 60  
     * This is the annotation associated with the method or field
 61  
     * that has been annotated. If this represents an entry to a 
 62  
     * Java collection such as a <code>java.util.List</code> then
 63  
     * this will return null for any annotation requested.
 64  
     * 
 65  
     * @param label this is the type of the annotation to acquire
 66  
     *
 67  
     * @return this provides the annotation associated with this
 68  
     */
 69  
    public <T extends Annotation> T getAnnotation(Class<T> label) {
 70  0
       return type.getAnnotation(label);
 71  
    }
 72  
 
 73  
    /**
 74  
     * This will provide the method or field type. The type is the
 75  
     * class that is to be read and written on the object. Typically 
 76  
     * the type will be a serializable object or a primitive type.
 77  
     *
 78  
     * @return this returns the type for this method o field
 79  
     */
 80  
    public Class getType() {
 81  3357
       return override;
 82  
    }
 83  
    
 84  
    /**
 85  
     * This is used to describe the type as it exists within the
 86  
     * owning class. This is used to provide error messages that can
 87  
     * be used to debug issues that occur when processing.  
 88  
     * 
 89  
     * @return this returns a string representation of the type
 90  
     */
 91  
    public String toString() {
 92  0
       return type.toString();
 93  
    }
 94  
 }