1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.xolite.utils;
17
18
19 import net.sf.xolite.XMLEventParser;
20 import net.sf.xolite.XMLParseException;
21 import net.sf.xolite.XMLSerializable;
22 import net.sf.xolite.XMLSerializeException;
23 import net.sf.xolite.XMLSerializer;
24
25
26
27
28
29
30 public class RootHolder implements XMLSerializable {
31
32
33 private XMLSerializable root;
34 private String rootURI;
35 private String rootTag;
36
37
38 public XMLSerializable getRoot() {
39 return root;
40 }
41
42
43
44
45
46
47
48
49
50
51 public void startElement(String uri, String localName, XMLEventParser parser) throws XMLParseException {
52 if (root != null) throw new IllegalStateException("Root!=null");
53 rootURI = uri;
54 rootTag = localName;
55 root = parser.parseElement(uri, localName);
56 }
57
58
59
60
61
62 public void endElement(String uri, String localName, XMLEventParser parser) throws XMLParseException {
63 if ((rootURI != null) && !rootURI.equals(uri)) parser.throwUnexpectedNamespaceException(rootURI);
64 if (!rootTag.equals(localName)) parser.throwUnexpectedElementException(rootTag);
65 }
66
67
68
69
70
71 public void serialize(XMLSerializer serializer) throws XMLSerializeException {
72 if (root == null) throw new XMLSerializeException("Empty RootHolder cannot be serialized");
73 root.serialize(serializer);
74 }
75
76
77 }