Coverage Report - org.simpleframework.xml.transform.FileTransform
 
Classes in this File Line Coverage Branch Coverage Complexity
FileTransform
100%
3/3
N/A
0
 
 1  
 /*
 2  
  * FileTransform.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  
 import java.io.File;
 24  
 
 25  
 /**
 26  
  * The <code>FileTransform</code> object is used to transform file
 27  
  * paths to and from string representations, which will be inserted
 28  
  * in the generated XML document as the value place holder. The
 29  
  * value must be readable and writable in the same format. Fields
 30  
  * and methods annotated with the XML attribute annotation will use
 31  
  * this to persist and retrieve the value to and from the XML source.
 32  
  * <pre>
 33  
  * 
 34  
  *    &#64;Attribute
 35  
  *    private File file;
 36  
  *    
 37  
  * </pre>
 38  
  * As well as the XML attribute values using transforms, fields and
 39  
  * methods annotated with the XML element annotation will use this.
 40  
  * Aside from the obvious difference, the element annotation has an
 41  
  * advantage over the attribute annotation in that it can maintain
 42  
  * any references using the <code>CycleStrategy</code> object. 
 43  
  * 
 44  
  * @author Niall Gallagher
 45  
  */
 46  1
 class FileTransform implements Transform<File> {
 47  
                
 48  
    /**
 49  
     * This method is used to convert the string value given to an
 50  
     * appropriate representation. This is used when an object is
 51  
     * being deserialized from the XML document and the value for
 52  
     * the string representation is required.
 53  
     * 
 54  
     * @param path this is the string representation of the path
 55  
     * 
 56  
     * @return this returns an appropriate instanced to be used
 57  
     */
 58  
    public File read(String path) {
 59  1
       return new File(path);
 60  
    }
 61  
    
 62  
    /**
 63  
     * This method is used to convert the provided value into an XML
 64  
     * usable format. This is used in the serialization process when
 65  
     * there is a need to convert a field value in to a string so 
 66  
     * that that value can be written as a valid XML entity.
 67  
     * 
 68  
     * @param path this is the value to be converted to a string
 69  
     * 
 70  
     * @return this is the string representation of the given value
 71  
     */
 72  
    public String write(File path) {
 73  1
       return path.getPath();
 74  
    }
 75  
 }