1
2
3
4
5
6
7
8
9
10 package tsukuba_bunko.resource;
11
12 import org.xml.sax.Attributes;
13 import org.xml.sax.SAXException;
14
15
16 /***
17 * 階層構造を持たない,シンプルな値のデシリアライズを行う <code>ResourceDeserializer</code> です.
18 * @author $Author
19 */
20 public abstract class SimpleDeserializer extends BasicDeserializer {
21
22 /***
23 * テキストバッファ
24 */
25 protected StringBuffer _text = null;
26
27
28 /***
29 * <code>SimpleDeserializer</code> のインスタンスを作成します.
30 */
31 protected SimpleDeserializer()
32 {
33 super();
34 }
35
36 /***
37 * 文字列から適切な型のオブジェクトへ変換します.
38 * @param source 変換元の文字列
39 * @return 変換結果
40 * @exception SAXException 変換に失敗した場合
41 */
42 protected abstract Object convertValue( String source )
43 throws SAXException;
44
45
46
47
48
49 public void startElement( String namespaceURI, String localName, String qName, Attributes attrs )
50 throws SAXException
51 {
52 if( _text == null ) {
53 _text = new StringBuffer();
54 }
55 else {
56 throw new SAXException( "illegal structure.(nested element was illegal structure)" );
57 }
58 }
59
60 public void endElement( String namespaceURI, String localName, String qName )
61 throws SAXException
62 {
63 setValue( convertValue(new String(_text)) );
64 _text = null;
65 }
66
67 public void characters( char[] ch, int begin, int length )
68 {
69 if( _text != null ) {
70 _text.append( ch, begin, length );
71 }
72 }
73 }