| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Converter |
|
| 1.0;1 |
| 1 | /* | |
| 2 | * Converter.java July 2006 | |
| 3 | * | |
| 4 | * Copyright (C) 2006, 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.load; | |
| 22 | ||
| 23 | import org.simpleframework.xml.stream.InputNode; | |
| 24 | import org.simpleframework.xml.stream.OutputNode; | |
| 25 | ||
| 26 | /** | |
| 27 | * The <code>Converter</code> object serializes and deserializes XML | |
| 28 | * elements. Serialization of lists, primitives, and compound types | |
| 29 | * are performed using a converter. Any object read from a converter | |
| 30 | * will produce a fully deserialized object will all its fields. | |
| 31 | * The objects written to an XML element populate that element with | |
| 32 | * attributes an elements according to the objects annotations. | |
| 33 | * | |
| 34 | * @author Niall Gallagher | |
| 35 | */ | |
| 36 | interface Converter { | |
| 37 | ||
| 38 | /** | |
| 39 | * The <code>read</code> method reads an object to a specific type | |
| 40 | * from the provided node. If the node provided is an attribute | |
| 41 | * then the object must be a primitive such as a string, integer, | |
| 42 | * boolean, or any of the other Java primitive types. | |
| 43 | * | |
| 44 | * @param node contains the details used to deserialize the object | |
| 45 | * | |
| 46 | * @return a fully deserialized object will all its fields | |
| 47 | * | |
| 48 | * @throws Exception if a deserialized type cannot be instantiated | |
| 49 | */ | |
| 50 | public Object read(InputNode node) throws Exception; | |
| 51 | ||
| 52 | /** | |
| 53 | * The <code>validate</code> method is used to validate the class | |
| 54 | * XML schema against an input source. This will traverse the class | |
| 55 | * fields and methods ensuring that the input XML document contains | |
| 56 | * a valid structure when compared against the class XML schema. | |
| 57 | * | |
| 58 | * @param node contains the details used to validate the object | |
| 59 | * | |
| 60 | * @return true if the document matches the class XML schema | |
| 61 | * | |
| 62 | * @throws Exception if the class XML schema does not fully match | |
| 63 | */ | |
| 64 | public boolean validate(InputNode node) throws Exception; | |
| 65 | ||
| 66 | /** | |
| 67 | * The <code>write</code> method writes the fields from the given | |
| 68 | * object to the XML element. After this has finished the element | |
| 69 | * contains all attributes and sub-elements from the object. | |
| 70 | * | |
| 71 | * @param object this is the object to be written to the element | |
| 72 | * @param node this is the element that is to be pobulated | |
| 73 | * | |
| 74 | * @throws Exception throw if the object cannot be serialized | |
| 75 | */ | |
| 76 | public void write(OutputNode node, Object object) throws Exception; | |
| 77 | } |