1 package tsukuba_bunko.resource;
2
3 import org.xml.sax.SAXException;
4
5
6 /***
7 * <code>java.lang.Number</code> 系の値をデシリアライズする <code>ResourceDeserializer</code> です.
8 * @author $Author: ppoi $
9 */
10 public class NumberDeserializer extends SimpleDeserializer {
11
12 /***
13 * 型
14 */
15 private String _type = null;
16
17 /***
18 * <code>NumberDeserializer</code> のインスタンスを作成します.
19 */
20 public NumberDeserializer()
21 {
22 super();
23 }
24
25
26
27
28
29 protected Object convertValue( String source )
30 throws SAXException
31 {
32 try {
33 String type = getTypeName();
34 Number value = null;
35 if( type.equals("integer") ) {
36 value = Integer.valueOf( source );
37 }
38 else if( type.equals("long") ) {
39 value = Long.valueOf( source );
40 }
41 else if( type.equals("double") ) {
42 value = Double.valueOf( source );
43 }
44 else if( type.equals("float") ) {
45 value = Float.valueOf( source );
46 }
47 else if( type.equals("short") ) {
48 value = Short.valueOf( source );
49 }
50 else if( type.equals("byte") ) {
51 value = Byte.valueOf( source );
52 }
53 else {
54 throw new SAXException( "unsupported type \"" + _type + "\"" );
55 }
56 return value;
57 }
58 catch( NumberFormatException nfe ) {
59 System.err.println( "[hogehgoe]" );
60 nfe.printStackTrace();
61 throw new SAXException( nfe );
62 }
63 }
64 }