Coverage Report - org.simpleframework.xml.transform.ByteTransform
 
Classes in this File Line Coverage Branch Coverage Complexity
ByteTransform
100%
3/3
N/A
0
 
 1  
 /*
 2  
  * ByteTransform.java May 2007
 3  
  *
 4  
  * Copyright (C) 2007, Niall Gallagher <niallg@users.sf.net>
 5  
  *
 6  
  * This library is free software; you can redistribute it and/or
 7  
  * modify it under the terms of the GNU Lesser General Public
 8  
  * License as published by the Free Software Foundation.
 9  
  *
 10  
  * This library is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  
  * GNU Lesser General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU Lesser General 
 16  
  * Public License along with this library; if not, write to the 
 17  
  * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
 18  
  * Boston, MA  02111-1307  USA
 19  
  */
 20  
 
 21  
 package org.simpleframework.xml.transform;
 22  
 
 23  
 
 24  
 /**
 25  
  * The <code>ByteTransform</code> object is used to transform byte
 26  
  * values to and from string representations, which will be inserted
 27  
  * in the generated XML document as the value place holder. The
 28  
  * value must be readable and writable in the same format. Fields
 29  
  * and methods annotated with the XML attribute annotation will use
 30  
  * this to persist and retrieve the value to and from the XML source.
 31  
  * <pre>
 32  
  * 
 33  
  *    &#64;Attribute
 34  
  *    private Byte octet;
 35  
  *    
 36  
  * </pre>
 37  
  * As well as the XML attribute values using transforms, fields and
 38  
  * methods annotated with the XML element annotation will use this.
 39  
  * Aside from the obvious difference, the element annotation has an
 40  
  * advantage over the attribute annotation in that it can maintain
 41  
  * any references using the <code>CycleStrategy</code> object. 
 42  
  * 
 43  
  * @author Niall Gallagher
 44  
  */
 45  54
 class ByteTransform implements Transform<Byte> {
 46  
    
 47  
    /**
 48  
     * This method is used to convert the string value given to an
 49  
     * appropriate representation. This is used when an object is
 50  
     * being deserialized from the XML document and the value for
 51  
     * the string representation is required.
 52  
     * 
 53  
     * @param value this is the string representation of the value
 54  
     * 
 55  
     * @return this returns an appropriate instanced to be used
 56  
     */
 57  
    public Byte read(String value) {
 58  20
       return Byte.valueOf(value);
 59  
    }
 60  
    
 61  
    /**
 62  
     * This method is used to convert the provided value into an XML
 63  
     * usable format. This is used in the serialization process when
 64  
     * there is a need to convert a field value in to a string so 
 65  
     * that that value can be written as a valid XML entity.
 66  
     * 
 67  
     * @param value this is the value to be converted to a string
 68  
     * 
 69  
     * @return this is the string representation of the given value
 70  
     */
 71  
    public String write(Byte value) {
 72  26
       return value.toString();
 73  
    }
 74  
 }