Coverage Report - org.simpleframework.xml.stream.CamelCaseStyle
 
Classes in this File Line Coverage Branch Coverage Complexity
CamelCaseStyle
57%
8/14
N/A
1
 
 1  
 /*
 2  
  * CamelCaseStyle.java July 2008
 3  
  *
 4  
  * Copyright (C) 2008, 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.stream;
 20  
 
 21  
 /**
 22  
  * The <code>CamelCaseStyle</code> is used to represent an XML style
 23  
  * that can be applied to a serialized object. A style can be used to
 24  
  * modify the element and attribute names for the generated document.
 25  
  * This styles can be used to generate camel case XML.
 26  
  * <pre>
 27  
  * 
 28  
  *    &lt;ExampleElement&gt;
 29  
  *        &lt;ChildElement exampleAttribute='example'&gt;
 30  
  *           &lt;InnerElement&gt;example&lt;/InnerElement&gt;
 31  
  *        &lt;/ChildElement&gt;
 32  
  *     &lt;/ExampleElement&gt;
 33  
  *     
 34  
  * </pre>
 35  
  * Above the camel case XML elements and attributes can be generated
 36  
  * from a style implementation. Styles enable the same objects to be
 37  
  * serialized in different ways, generating different styles of XML
 38  
  * without having to modify the class schema for that object.    
 39  
  * 
 40  
  * @author Niall Gallagher
 41  
  */
 42  
 public class CamelCaseStyle implements Style {
 43  
    
 44  
    /**
 45  
     * This is used to perform the actual building of tokens.
 46  
     */
 47  
    private final Builder builder;
 48  
    
 49  
    /**
 50  
     * This is the strategy used to generate the style tokens.
 51  
     */
 52  
    private final Style style;
 53  
    
 54  
    /**
 55  
     * Constructor for the <code>CamelCaseStyle</code> object. This 
 56  
     * is used to create a style that will create camel case XML 
 57  
     * attributes and elements allowing a consistent format for 
 58  
     * generated XML. By default the elements have an upper case 
 59  
     * initial character and a lower case attribute. 
 60  
     */
 61  
    public CamelCaseStyle() {
 62  18
       this(true, false);
 63  18
    }
 64  
    
 65  
    /**
 66  
     * Constructor for the <code>CamelCaseStyle</code> object. This 
 67  
     * is used to create a style that will create camel case XML 
 68  
     * attributes and elements allowing a consistent format for 
 69  
     * generated XML. By default the attributes have a lower case 
 70  
     * initial character and an configurable element.
 71  
     * 
 72  
     * @param element if true the element will start as upper case
 73  
     */
 74  
    public CamelCaseStyle(boolean element) {
 75  0
       this(element, false);
 76  0
    }
 77  
    
 78  
    /**
 79  
     * Constructor for the <code>CamelCaseStyle</code> object. This 
 80  
     * is used to create a style that will create camel case XML 
 81  
     * attributes and elements allowing a consistent format for 
 82  
     * generated XML. Both the attribute an elements are configurable.
 83  
     * 
 84  
     * @param element if true the element will start as upper case
 85  
     * @param attribute if true the attribute starts as upper case
 86  
     */
 87  243
    public CamelCaseStyle(boolean element, boolean attribute) {
 88  243
       this.style = new CamelCaseBuilder(element, attribute);
 89  243
       this.builder = new Builder(style);
 90  243
    }
 91  
 
 92  
    /**
 93  
     * This is used to generate the XML attribute representation of 
 94  
     * the specified name. Attribute names should ensure to keep the
 95  
     * uniqueness of the name such that two different names will
 96  
     * be styled in to two different strings.
 97  
     * 
 98  
     * @param name this is the attribute name that is to be styled
 99  
     * 
 100  
     * @return this returns the styled name of the XML attribute
 101  
     */
 102  
    public String getAttribute(String name) {
 103  3922
       return builder.getAttribute(name); 
 104  
    }
 105  
 
 106  
    /**
 107  
     * This is used to set the attribute values within this builder.
 108  
     * Overriding the attribute values ensures that the default
 109  
     * algorithm does not need to determine each of the values. It
 110  
     * allows special behaviour that the user may require for XML.
 111  
     * 
 112  
     * @param name the name of the XML attribute to be overridden
 113  
     * @param value the value that is to be used for that attribute
 114  
     */
 115  
    public void setAttribute(String name, String value) {
 116  0
       builder.setAttribute(name, value);
 117  0
    }
 118  
    
 119  
    /**
 120  
     * This is used to generate the XML element representation of 
 121  
     * the specified name. Element names should ensure to keep the
 122  
     * uniqueness of the name such that two different names will
 123  
     * be styled in to two different strings.
 124  
     * 
 125  
     * @param name this is the element name that is to be styled
 126  
     * 
 127  
     * @return this returns the styled name of the XML element
 128  
     */
 129  
    public String getElement(String name) {
 130  23434
       return builder.getElement(name);
 131  
    }
 132  
 
 133  
    /**
 134  
     * This is used to set the element values within this builder.
 135  
     * Overriding the element values ensures that the default
 136  
     * algorithm does not need to determine each of the values. It
 137  
     * allows special behaviour that the user may require for XML.
 138  
     * 
 139  
     * @param name the name of the XML element to be overridden
 140  
     * @param value the value that is to be used for that element
 141  
     */
 142  
    public void setElement(String name, String value) {
 143  0
       builder.setElement(name, value);
 144  0
    }
 145  
 }