Coverage Report - org.simpleframework.xml.core.Section
 
Classes in this File Line Coverage Branch Coverage Complexity
Section
N/A
N/A
1
 
 1  
 /*
 2  
  * Section.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  
 /**
 22  
  * The <code>Section</code> interface is used to represent a section
 23  
  * of XML that is to be generated. A section is a tree structure in
 24  
  * that it can contain other sections. Each section contains the
 25  
  * elements and attributes associated with it. This is used so that
 26  
  * complex XML structures can be written for a single object.
 27  
  * <p>
 28  
  * For convenience all the element names, including other section
 29  
  * names, can be iterated over. Element and section names can be
 30  
  * differentiated using the source section.
 31  
  * 
 32  
  * @author Niall Gallagher
 33  
  * 
 34  
  * @see org.simpleframework.xml.core.Structure
 35  
  */
 36  
 interface Section extends Iterable<String> {
 37  
    
 38  
    /**
 39  
     * This is used to return the name of the section. The name is 
 40  
     * must be a valid XML element name. It is used when a style
 41  
     * is applied to a path as the section name must be styled.
 42  
     * 
 43  
     * @return this returns the name of this section instance
 44  
     */
 45  
    String getName();
 46  
    
 47  
    /**
 48  
     * This is used to acquire the path prefix for the section. The
 49  
     * path prefix is used when the section is transformed in to an
 50  
     * XML structure. This ensures that the XML element created to
 51  
     * represent the section contains the optional prefix.
 52  
     * 
 53  
     * @return this returns the prefix for this section
 54  
     */
 55  
    String getPrefix();
 56  
 
 57  
    /**
 58  
     * This is used to acquire the text label for this section if 
 59  
     * one has been specified. A text label can only exist in a
 60  
     * section if there are no elements associated with the section
 61  
     * and the section is not composite, as in it does not contain
 62  
     * any further sections.
 63  
     * 
 64  
     * @return this returns the text label for this section
 65  
     */
 66  
    Label getText() throws Exception; 
 67  
 
 68  
    /**
 69  
     * Returns a <code>LabelMap</code> that contains the details for
 70  
     * all fields and methods marked with XML annotations. All of the
 71  
     * element annotations are considered and gathered by name in 
 72  
     * this map. Also, if there is an associated <code>Style</code> 
 73  
     * for serialization the element names are renamed with this.
 74  
     * 
 75  
     * @return returns the elements associated with this section
 76  
     */
 77  
    LabelMap getElements() throws Exception;
 78  
    
 79  
    /**
 80  
     * Returns a <code>LabelMap</code> that contains the details for
 81  
     * all fields and methods marked with XML annotations. All of the
 82  
     * attribute annotations are considered and gathered by name in 
 83  
     * this map. Also, if there is an associated <code>Style</code> 
 84  
     * for serialization the attribute names are renamed with this.
 85  
     * 
 86  
     * @return returns the attributes associated with this section
 87  
     */
 88  
    LabelMap getAttributes() throws Exception;
 89  
    
 90  
    /**
 91  
     * Returns the named element as a <code>Label</code> object.
 92  
     * For convenience this method is provided so that when iterating
 93  
     * over the names of the elements in the section a specific one
 94  
     * of interest can be acquired.
 95  
     * <p>
 96  
     * To ensure that elements of the same name are not referenced
 97  
     * more than once this will remove the element once acquired. 
 98  
     * This ensures that they are visited only once in serialization.      
 99  
     * 
 100  
     * @param name the name of the element that is to be acquired
 101  
     * 
 102  
     * @return this returns the label associated with the name
 103  
     */
 104  
    Label getElement(String name) throws Exception;
 105  
    
 106  
    /**
 107  
     * Returns the named section as a <code>Section</code> object.
 108  
     * For convenience this method is provided so that when iterating
 109  
     * over the names of the elements in the section a specific one
 110  
     * of interest can be acquired. 
 111  
     * <p>
 112  
     * To ensure that models of the same name are not referenced
 113  
     * more than once this will remove the model once acquired. 
 114  
     * This ensures that they are visited only once in serialization.
 115  
     * 
 116  
     * @param name the name of the element that is to be acquired
 117  
     * 
 118  
     * @return this returns the section associated with the name
 119  
     */
 120  
    Section getSection(String name) throws Exception;
 121  
    
 122  
    /**
 123  
     * This is used to acquire the full element path for this
 124  
     * section. The element path is simply the fully qualified
 125  
     * path for this expression with the provided name appended.
 126  
     * If this is an empty path, the provided name is returned.
 127  
     * 
 128  
     * @param name this is the name of the element to be used
 129  
     * 
 130  
     * @return a fully qualified path for the specified name
 131  
     */
 132  
    String getPath(String name) throws Exception;
 133  
    
 134  
    /**
 135  
     * This is used to acquire the full attribute path for this 
 136  
     * section. The attribute path is simply the fully qualified
 137  
     * path for this expression with the provided name appended.
 138  
     * If this is an empty path, the provided name is returned.
 139  
     * 
 140  
     * @param name this is the name of the attribute to be used
 141  
     * 
 142  
     * @return a fully qualified path for the specified name
 143  
     */
 144  
    String getAttribute(String name) throws Exception;
 145  
    
 146  
    /**
 147  
     * To differentiate between a section and an element this can be
 148  
     * used. When iterating over the elements within the section the
 149  
     * names of both elements and sections are provided. So in order
 150  
     * to determine how to interpret the structure this can be used.
 151  
     * 
 152  
     * @param name this is the name of the element to be determined
 153  
     * 
 154  
     * @return this returns true if the name represents a section
 155  
     */
 156  
    boolean isSection(String name) throws Exception;
 157  
 }