Debian Codegraph @

net/sf/saxon/event/Event.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.event;
9
10 import net.sf.saxon.expr.parser.Location;
11 import net.sf.saxon.om.Item;
12 import net.sf.saxon.om.NamespaceBindingSet;
13 import net.sf.saxon.om.NodeName;
14 import net.sf.saxon.trans.XPathException;
15 import net.sf.saxon.type.SchemaType;
16 import net.sf.saxon.type.SimpleType;
17
18 /**
19 * An event is an object representing one of the events that can be passed to a receiver: for example, a startElement,
20 * endElement, characters, or comment event. Sufficient information is retained in order to enable a stored event to
21 * be "replayed" later.
22 */
23 public abstract class Event {
24
25 /**
26 * Send the event to a receiver
27 * @param out the receiver to which the event is to be sent
28 * @throws XPathException the the receiver reports an error
29 */
30
31 public abstract void replay(Receiver out) throws XPathException;
32
33 /**
34 * Event representing start of document
35 */
36
37 public static class StartDocument extends Event {
38 int properties;
39 public StartDocument(int properties) {
40 this.properties = properties;
41 }
42 @Override
43 public void replay(Receiver out) throws XPathException {
44 out.startDocument(properties);
45 }
46 }
47
48 /**
49 * Event representing end of document
50 */
51
52 public static class EndDocument extends Event {
53 public EndDocument() {
54 }
55
56 @Override
57 public void replay(Receiver out) throws XPathException {
58 out.endDocument();
59 }
60 }
61
62 /**
63 * Event representing the start of an element (not including attributes or namespaces)
64 */
65
66 public static class StartElement extends Event {
67 NodeName name;
68 SchemaType type;
69 Location location;
70 int properties;
71
72 public StartElement(NodeName name, SchemaType type, Location location, int properties) {
73 this.name = name;
74 this.type = type;
75 this.location = location;
76 this.properties = properties;
77 }
78
79 @Override
80 public void replay(Receiver out) throws XPathException {
81 out.startElement(name, type, location, properties);
82 }
83 }
84
85 /**
86 * Event representing the end of an element
87 */
88
89 public static class EndElement extends Event {
90 public EndElement() {
91 }
92
93 @Override
94 public void replay(Receiver out) throws XPathException {
95 out.endElement();
96 }
97 }
98
99 /**
100 * Event representing an attribute node
101 */
102
103 public static class Attribute extends Event {
104 NodeName name;
105 SimpleType type;
106 Location location;
107 String value;
108 int properties;
109
110 public Attribute(NodeName name, SimpleType type, Location location, CharSequence value, int properties) {
111 this.name = name;
112 this.type = type;
113 this.location = location;
114 this.value = value.toString();
115 this.properties = properties;
116 }
117
118 @Override
119 public void replay(Receiver out) throws XPathException {
120 out.attribute(name, type, value, location, properties);
121 }
122 }
123
124 /**
125 * Event representing a set of namespace bindings
126 */
127
128 public static class Namespace extends Event {
129
130 NamespaceBindingSet bindings;
131 int properties;
132
133 public Namespace(NamespaceBindingSet bindings, int properties) {
134 this.bindings = bindings;
135 this.properties = properties;
136 }
137 @Override
138 public void replay(Receiver out) throws XPathException {
139 out.namespace(bindings, properties);
140 }
141 }
142
143 /**
144 * Event representing the end of a start tag, that is, indicating that no more attributes or
145 * namespaces are expected for the current element
146 */
147
148 public static class StartContent extends Event {
149
150 public StartContent(){}
151
152 public void replay(Receiver out) throws XPathException {
153 out.startContent();
154 }
155 }
156
157 /**
158 * Event representing a text node
159 */
160
161 public static class Text extends Event {
162
163 String content;
164 Location location;
165 int properties;
166
167 public Text(CharSequence content, Location location, int properties) {
168 this.content = content.toString();
169 this.location = location;
170 this.properties = properties;
171 }
172
173 @Override
174 public void replay(Receiver out) throws XPathException {
175 out.characters(content, location, properties);
176 }
177 }
178
179 /**
180 * Event representing a comment node
181 */
182
183 public static class Comment extends Event {
184
185 String content;
186 Location location;
187 int properties;
188
189 public Comment(CharSequence content, Location location, int properties) {
190 this.content = content.toString();
191 this.location = location;
192 this.properties = properties;
193 }
194
195 @Override
196 public void replay(Receiver out) throws XPathException {
197 out.comment(content, location, properties);
198 }
199 }
200
201 /**
202 * Event representing a processing instruction node
203 */
204
205 public static class ProcessingInstruction extends Event {
206 String target;
207 String content;
208 Location location;
209 int properties;
210
211 public ProcessingInstruction(String target, CharSequence content, Location location, int properties) {
212 this.target = target;
213 this.content = content.toString();
214 this.location = location;
215 this.properties = properties;
216 }
217
218 @Override
219 public void replay(Receiver out) throws XPathException {
220 out.processingInstruction(target, content, location, properties);
221 }
222 }
223
224 /**
225 * Event representing an arbitrary item being sent to the event stream in composed form. Perhaps
226 * an atomic value, perhaps an entire element or document in composed form.
227 */
228
229 public static class Append extends Event {
230 Item item;
231 Location location;
232 int properties;
233
234 public Append(Item item, Location location, int properties) {
235 this.item = item;
236 this.location = location;
237 this.properties = properties;
238 }
239
240 @Override
241 public void replay(Receiver out) throws XPathException {
242 out.append(item, location, properties);
243 }
244 }
245 }
246
247