KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > io > xml > JDomDriver


1 package com.thoughtworks.xstream.io.xml;
2
3 import java.io.Reader JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.Writer JavaDoc;
6
7 import org.jdom.Document;
8 import org.jdom.JDOMException;
9 import org.jdom.input.SAXBuilder;
10
11 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
12 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
13 import com.thoughtworks.xstream.io.StreamException;
14 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
15
16 /**
17  * @author Laurent Bihanic
18  */

19 public class JDomDriver implements HierarchicalStreamDriver {
20
21     public HierarchicalStreamReader createReader(Reader JavaDoc reader) {
22         try {
23             SAXBuilder builder = new SAXBuilder();
24             Document document = builder.build(reader);
25             return new JDomReader(document);
26         } catch (IOException JavaDoc e) {
27             throw new StreamException(e);
28         } catch (JDOMException e) {
29             throw new StreamException(e);
30         }
31     }
32
33     public HierarchicalStreamWriter createWriter(Writer JavaDoc out) {
34         return new PrettyPrintWriter(out);
35     }
36
37 }
38
39
Popular Tags