1/* Copyright (c) 2003,2004 Stefan Haustein, Oberhausen, Rhld., Germany
2 * Copyright (c) 2006, James Seigel, Calgary, AB., Canada
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The  above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE. */
21
22package org.ksoap2.serialization;
23
24import java.io.*;
25
26import org.xmlpull.v1.*;
27
28public class MarshalFloat implements Marshal {
29
30    public Object readInstance(XmlPullParser parser, String namespace, String name,
31            PropertyInfo propertyInfo)
32            throws IOException, XmlPullParserException {
33        String stringValue = parser.nextText();
34        Object result;
35        if (name.equals("float")) {
36            result = new Float(stringValue);
37        } else if (name.equals("double")) {
38            result = new Double(stringValue);
39        } else if (name.equals("decimal")) {
40            result = new java.math.BigDecimal(stringValue);
41        } else {
42            throw new RuntimeException("float, double, or decimal expected");
43        }
44        return result;
45    }
46
47    public void writeInstance(XmlSerializer writer, Object instance) throws IOException {
48        writer.text(instance.toString());
49    }
50
51    public void register(SoapSerializationEnvelope cm) {
52        cm.addMapping(cm.xsd, "float", Float.class, this);
53        cm.addMapping(cm.xsd, "double", Double.class, this);
54        cm.addMapping(cm.xsd, "decimal", java.math.BigDecimal.class, this);
55    }
56}
57