| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| IntegerTransform |
|
| 0.0;0 |
| 1 | /* | |
| 2 | * IntegerTransform.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>IntegerTransform</code> is used to transform integer | |
| 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 | * @Attribute | |
| 34 | * private Integer number; | |
| 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 | 40473 | class IntegerTransform implements Transform<Integer> { |
| 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 Integer read(String value) { | |
| 58 | 30194 | return Integer.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(Integer value) { | |
| 72 | 10226 | return value.toString(); |
| 73 | } | |
| 74 | } |