Coverage Report - org.simpleframework.xml.stream.HyphenStyle
 
Classes in this File Line Coverage Branch Coverage Complexity
HyphenStyle
60%
6/10
N/A
1
 
 1  
 /*
 2  
  * HyphenStyle.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>HyphenStyle</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 hyphenated XML.
 26  
  * <pre>
 27  
  * 
 28  
  *    &lt;example-element&gt;
 29  
  *        &lt;child-element example-attribute='example'&gt;
 30  
  *           &lt;inner-element&gt;example&lt;/inner-element&gt;
 31  
  *        &lt;/child-element&gt;
 32  
  *     &lt;/example-element&gt;
 33  
  *     
 34  
  * </pre>
 35  
  * Above the hyphenated 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 HyphenStyle 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>HyphenStyle</code> object. This is
 56  
     * used to create a style that will hyphenate XML attributes
 57  
     * and elements allowing a consistent format for generated XML.
 58  
     */
 59  231
    public HyphenStyle() {
 60  231
       this.style = new HyphenBuilder();
 61  231
       this.builder = new Builder(style);
 62  231
    }
 63  
 
 64  
    /**
 65  
     * This is used to generate the XML attribute representation of 
 66  
     * the specified name. Attribute names should ensure to keep the
 67  
     * uniqueness of the name such that two different names will
 68  
     * be styled in to two different strings.
 69  
     * 
 70  
     * @param name this is the attribute name that is to be styled
 71  
     * 
 72  
     * @return this returns the styled name of the XML attribute
 73  
     */
 74  
    public String getAttribute(String name) {
 75  3846
       return builder.getAttribute(name); 
 76  
    }
 77  
    
 78  
    /**
 79  
     * This is used to set the attribute values within this builder.
 80  
     * Overriding the attribute values ensures that the default
 81  
     * algorithm does not need to determine each of the values. It
 82  
     * allows special behaviour that the user may require for XML.
 83  
     * 
 84  
     * @param name the name of the XML attribute to be overridden
 85  
     * @param value the value that is to be used for that attribute
 86  
     */
 87  
    public void setAttribute(String name, String value) {
 88  0
       builder.setAttribute(name, value);
 89  0
    }
 90  
 
 91  
    /**
 92  
     * This is used to generate the XML element representation of 
 93  
     * the specified name. Element names should ensure to keep the
 94  
     * uniqueness of the name such that two different names will
 95  
     * be styled in to two different strings.
 96  
     * 
 97  
     * @param name this is the element name that is to be styled
 98  
     * 
 99  
     * @return this returns the styled name of the XML element
 100  
     */
 101  
    public String getElement(String name) {
 102  23072
       return builder.getElement(name);
 103  
    }
 104  
 
 105  
    /**
 106  
     * This is used to set the element values within this builder.
 107  
     * Overriding the element values ensures that the default
 108  
     * algorithm does not need to determine each of the values. It
 109  
     * allows special behaviour that the user may require for XML.
 110  
     * 
 111  
     * @param name the name of the XML element to be overridden
 112  
     * @param value the value that is to be used for that element
 113  
     */
 114  
    public void setElement(String name, String value) {
 115  0
       builder.setElement(name, value);
 116  0
    }
 117  
 }