Coverage Report - org.simpleframework.xml.convert.Converter
 
Classes in this File Line Coverage Branch Coverage Complexity
Converter
N/A
N/A
1
 
 1  
 /*
 2  
  * Converter.java January 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.convert;
 20  
 
 21  
 import org.simpleframework.xml.stream.InputNode;
 22  
 import org.simpleframework.xml.stream.OutputNode;
 23  
 
 24  
 /**
 25  
  * The <code>Converter</code> object is used to convert an object
 26  
  * to XML by intercepting the normal serialization process. When
 27  
  * serializing an object the <code>write</code> method is invoked.
 28  
  * This is provided with the object instance to be serialized and
 29  
  * the <code>OutputNode</code> to use to write the XML. Values
 30  
  * can be taken from the instance and transferred to the node.
 31  
  * <p>
 32  
  * For deserialization the <code>read</code> method is invoked.
 33  
  * This is provided with the <code>InputNode</code>, which can be
 34  
  * used to read the elements and attributes representing the 
 35  
  * member data of the object being deserialized. Once the object
 36  
  * has been instantiated it must be returned. 
 37  
  * 
 38  
  * @author Niall Gallagher
 39  
  * 
 40  
  * @see org.simpleframework.xml.convert.AnnotationStrategy
 41  
  * @see org.simpleframework.xml.convert.RegistryStrategy
 42  
  */
 43  
 public interface Converter<T> {
 44  
 
 45  
    /**
 46  
     * This <code>read</code> method is used to deserialize an object
 47  
     * from the source XML. The deserialization is performed using 
 48  
     * the XML node provided. This node can be used to read the XML
 49  
     * elements and attributes in any format required. Once all of 
 50  
     * the data has been extracted an instance must be returned.
 51  
     * 
 52  
     * @param node this is the node to deserialize the object from
 53  
     * 
 54  
     * @return the object instance resulting from the deserialization
 55  
     */
 56  
    T read(InputNode node) throws Exception; 
 57  
 
 58  
    /**
 59  
     * This <code>write</code> method is used to serialize an object
 60  
     * to XML. The serialization should be performed in such a way
 61  
     * that all of the objects values are represented by an element
 62  
     * or attribute of the provided node. This ensures that it can
 63  
     * be fully deserialized at a later time.
 64  
     * 
 65  
     * @param node this is the node to serialized to object to
 66  
     * @param value this is the value that is to be serialized
 67  
     */
 68  
    void write(OutputNode node, T value) throws Exception;
 69  
 }