Coverage Report - org.simpleframework.xml.core.TemplateLabel
 
Classes in this File Line Coverage Branch Coverage Complexity
TemplateLabel
100%
19/19
N/A
1
 
 1  
 /*
 2  
  * TemplateLabel.java July 2009
 3  
  *
 4  
  * Copyright (C) 2009, 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 org.simpleframework.xml.strategy.Type;
 22  
 
 23  
 /**
 24  
  * The <code>TemplateLabel</code> object is used to provide stock
 25  
  * functions that can be used by all implementations. This ensures
 26  
  * there is a consistent set of behaviours for each label. It also
 27  
  * reduces the number of methods that need to be maintained for
 28  
  * each <void>Label</code> implementation.
 29  
  * 
 30  
  * @author Niall Gallagher
 31  
  */
 32  
 abstract class TemplateLabel implements Label {
 33  
    
 34  
    /**
 35  
     * This is the builder that is used to generate label keys.
 36  
     */
 37  
    private final KeyBuilder builder;
 38  
    
 39  
    /**
 40  
     * Constructor for the <code>TemplateLabel</code> is used to
 41  
     * create a template for other labels. If any of the method
 42  
     * implementations are not as required or they should be
 43  
     * overridden by the subclass.
 44  
     */
 45  6650
    protected TemplateLabel() {
 46  6650
       this.builder = new KeyBuilder(this);
 47  6650
    }
 48  
    
 49  
    /**
 50  
     * This is used to acquire the <code>Type</code> that the type
 51  
     * provided is represented by. Typically this will return the
 52  
     * field or method represented by the label. However, in the 
 53  
     * case of unions this will provide an override type.
 54  
     * 
 55  
     * @param type this is the class to acquire the type for
 56  
     * 
 57  
     * @return this returns the type represented by this class
 58  
     */
 59  
    public Type getType(Class type) throws Exception {
 60  22077
       return getContact();
 61  
    }
 62  
    
 63  
    /**
 64  
     * This is used to acquire the <code>Label</code> that the type
 65  
     * provided is represented by. Typically this will return the
 66  
     * same instance. However, in the case of unions this will
 67  
     * look for an individual label to match the type provided.
 68  
     * 
 69  
     * @param type this is the type to acquire the label for
 70  
     * 
 71  
     * @return this returns the label represented by this type
 72  
     */
 73  
    public Label getLabel(Class type) throws Exception {
 74  419813
       return this;
 75  
    }
 76  
    
 77  
    /**
 78  
     * This returns a <code>Collection</code> of element names. This
 79  
     * will typically contain both the name and path of the label. 
 80  
     * However, if this is a union it can contain many names and
 81  
     * paths. This method should never return null. 
 82  
     * 
 83  
     * @return this returns the names of each of the elements
 84  
     */
 85  
    public String[] getNames() throws Exception {
 86  4961
       String path = getPath();
 87  4961
       String name = getName();
 88  
       
 89  4961
       return new String[] {path, name};
 90  
    }
 91  
    
 92  
    /**
 93  
     * This returns a <code>Collection</code> of element paths. This
 94  
     * will typically contain only the path of the label, which is
 95  
     * composed using the <code>Path</code> annotation and the name
 96  
     * of the label. However, if this is a union it can contain many 
 97  
     * paths. This method should never return null.
 98  
     * 
 99  
     * @return this returns the names of each of the elements
 100  
     */
 101  
    public String[] getPaths() throws Exception {
 102  10483
       String path = getPath();
 103  
       
 104  10483
       return new String[] {path};
 105  
    }
 106  
    
 107  
    /**
 108  
     * This is the key used to represent this label. The key is used
 109  
     * to store the parameter in hash containers. Typically the
 110  
     * key is generated from the paths associated with the label.
 111  
     * 
 112  
     * @return this is the key used to represent the label
 113  
     */
 114  
    public Object getKey() throws Exception {
 115  6044
       return builder.getKey();
 116  
    }
 117  
    
 118  
    /**
 119  
     * This is typically used to acquire the entry value as acquired
 120  
     * from the annotation. However given that the annotation this
 121  
     * represents does not have a entry attribute this will always
 122  
     * provide a null value for the entry string.
 123  
     * 
 124  
     * @return this will always return null for the entry value 
 125  
     */
 126  
    public String getEntry() throws Exception {
 127  12537
       return null;
 128  
    }
 129  
    
 130  
    /**
 131  
     * This is used to acquire the dependent class for this label. 
 132  
     * This returns null as there are no dependents to the element
 133  
     * annotation as it can only hold primitives with no dependents.
 134  
     * 
 135  
     * @return this is used to return the dependent type of null
 136  
     */
 137  
    public Type getDependent() throws Exception {
 138  3786
       return null;
 139  
    }
 140  
    
 141  
    /**
 142  
     * This method is used to determine if the label represents an
 143  
     * attribute. This is used to style the name so that elements
 144  
     * are styled as elements and attributes are styled as required.
 145  
     * 
 146  
     * @return this is used to determine if this is an attribute
 147  
     */
 148  
    public boolean isAttribute() {
 149  9649
       return false;
 150  
    }
 151  
    
 152  
    /**
 153  
     * This is used to determine if the label is a collection. If the
 154  
     * label represents a collection then any original assignment to
 155  
     * the field or method can be written to without the need to 
 156  
     * create a new collection. This allows obscure collections to be
 157  
     * used and also allows initial entries to be maintained.
 158  
     * 
 159  
     * @return true if the label represents a collection value
 160  
     */
 161  
    public boolean isCollection() {
 162  3878
       return false;
 163  
    }
 164  
    
 165  
    /**
 166  
     * This is used to determine whether the label represents an
 167  
     * inline XML entity. The <code>ElementList</code> annotation
 168  
     * and the <code>Text</code> annotation represent inline 
 169  
     * items. This means that they contain no containing element
 170  
     * and so can not specify overrides or special attributes.
 171  
     * 
 172  
     * @return this returns true if the annotation is inline
 173  
     */
 174  
    public boolean isInline() {
 175  809102
       return false;
 176  
    }
 177  
    
 178  
    /**
 179  
     * This is used to determine if the label represents text. If
 180  
     * a label represents text it typically does not have a name,
 181  
     * instead the empty string represents the name. Also text
 182  
     * labels can not exist with other text labels, or elements.
 183  
     * 
 184  
     * @return this returns true if this label represents text
 185  
     */
 186  
    public boolean isText() {
 187  5340
       return false;
 188  
    }
 189  
    
 190  
    /**
 191  
     * This is used to determine if an annotated list is a text 
 192  
     * list. A text list is a list of elements that also accepts
 193  
     * free text. Typically this will be an element list union that
 194  
     * will allow unstructured XML such as XHTML to be parsed.
 195  
     * 
 196  
     * @return returns true if the label represents a text list
 197  
     */
 198  
    public boolean isTextList() {
 199  5253
       return false;
 200  
    }
 201  
    
 202  
    /**
 203  
     * This is used to determine if this label is a union. If this
 204  
     * is true then this label represents a number of labels and
 205  
     * is simply a wrapper for these labels. 
 206  
     * 
 207  
     * @return this returns true if the label represents a union
 208  
     */
 209  
    public boolean isUnion() {
 210  4961
       return false;
 211  
    }
 212  
 }