Coverage Report - org.simpleframework.xml.core.Structure
 
Classes in this File Line Coverage Branch Coverage Complexity
Structure
100%
16/16
100%
2/2
1.286
 
 1  
 /*
 2  
  * Structure.java November 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 org.simpleframework.xml.Version;
 22  
 
 23  
 /**
 24  
  * The <code>Structure</code> object represents the XML structure of
 25  
  * an annotated class schema. A structure instance is an immutable
 26  
  * object that contains all the criteria used in reading and writing
 27  
  * and object. It provides a <code>Section</code> representing a tree
 28  
  * structure of elements and attributes. Each section returned by
 29  
  * the structure is a styled copy of the structured contents.
 30  
  * 
 31  
  * @author Niall Gallagher
 32  
  * 
 33  
  * @see org.simpleframework.xml.core.StructureBuilder
 34  
  * @see org.simpleframework.xml.core.Section
 35  
  */
 36  
 class Structure {
 37  
    
 38  
    /**
 39  
     * This is the instantiator that is used to create instances.
 40  
     */
 41  
    private final Instantiator factory;
 42  
    
 43  
    /**
 44  
     * This is the label representing the version of the class.
 45  
     */
 46  
    private final Label version;
 47  
    
 48  
    /**
 49  
     * This is contains any text field or method in the class.
 50  
     */
 51  
    private final Label text;
 52  
    
 53  
    /**
 54  
     * This contains the tree of XML elements and attributes used.
 55  
     */
 56  
    private final Model model;
 57  
    
 58  
    /**
 59  
     * This is used to determine if the structure is a primitive.
 60  
     */
 61  
    private final boolean primitive;
 62  
    
 63  
    /**
 64  
     * Constructor for the <code>Structure</code> object. A structure
 65  
     * is created using all the established criteria for a schema
 66  
     * that represents an annotated class. Once created the structure
 67  
     * is immutable and is used to build XML sections.
 68  
     * 
 69  
     * @param factory this is used to create new object instances
 70  
     * @param model the model representing the tree of XML elements
 71  
     * @param version this is the version associated with the class
 72  
     * @param text this represents any text field or method
 73  
     * @param primitive used to determine if this is primitive
 74  
     */
 75  2347
    public Structure(Instantiator factory, Model model, Label version, Label text, boolean primitive) {
 76  2347
       this.primitive = primitive;
 77  2347
       this.factory = factory;
 78  2347
       this.version = version;
 79  2347
       this.model = model;
 80  2347
       this.text = text;      
 81  2347
    }
 82  
    
 83  
    /**
 84  
     * This is used to acquire the instantiator for the type. This is
 85  
     * used to create object instances based on the constructors that
 86  
     * have been annotated. If no constructors have been annotated
 87  
     * then this can be used to create default no argument instances.
 88  
     * 
 89  
     * @return this instantiator responsible for creating instances
 90  
     */
 91  
    public Instantiator getInstantiator() {
 92  932149
       return factory;
 93  
    }
 94  
    
 95  
    /**
 96  
     * This is used to acquire the <code>Section</code> representing
 97  
     * the class schema. A section is a tree like XML structure that
 98  
     * contains all the details of the attributes and elements that
 99  
     * form a section of the schema class. The context is provided 
 100  
     * to that the names can be styled if required. 
 101  
     * 
 102  
     * @return a section representing an XML section
 103  
     */
 104  
    public Section getSection() {
 105  932171
       return new ModelSection(model);
 106  
    }
 107  
    
 108  
    /**
 109  
     * This is used to determine whether the schema class represents
 110  
     * a primitive type. A primitive type is a type that contains no
 111  
     * XML annotations and so cannot be serialized with an XML form.
 112  
     * Instead primitives a serialized using transformations.
 113  
     * 
 114  
     * @return this returns true if no XML annotations were found
 115  
     */
 116  
    public boolean isPrimitive() {
 117  932146
       return primitive;
 118  
    }
 119  
    
 120  
    /**
 121  
     * This is the <code>Version</code> for the scanned class. It 
 122  
     * allows the deserialization process to be configured such that
 123  
     * if the version is different from the schema class none of
 124  
     * the fields and methods are required and unmatched elements
 125  
     * and attributes will be ignored.
 126  
     * 
 127  
     * @return this returns the version of the schema class
 128  
     */
 129  
    public Version getRevision() {
 130  932157
       if(version != null) {
 131  24
          Contact contact = version.getContact();
 132  24
          return contact.getAnnotation(Version.class);
 133  
       }
 134  932133
       return null;
 135  
    }
 136  
    
 137  
    
 138  
    /**
 139  
     * This returns the <code>Label</code> that represents the version
 140  
     * annotation for the schema class. Only a single version can
 141  
     * exist within the class if more than one exists an exception is
 142  
     * thrown. This will read only floating point types such as double.
 143  
     * 
 144  
     * @return this returns the label used for reading the version
 145  
     */
 146  
    public Label getVersion() {
 147  932146
       return version;
 148  
    }
 149  
    
 150  
    /**
 151  
     * This returns the <code>Label</code> that represents the text
 152  
     * annotation for the schema class. Only a single text annotation
 153  
     * can be used per class, so this returns only a single label
 154  
     * rather than a <code>LabelMap</code> object. Also if this is
 155  
     * not null then the section returned must be empty.
 156  
     * 
 157  
     * @return this returns the text label for the schema class
 158  
     */
 159  
    public Label getText() {
 160  932149
       return text;
 161  
    }
 162  
 }