6
|
1 |
/*
|
|
2 |
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.xml.internal.stream.events ;
|
|
27 |
|
|
28 |
|
|
29 |
import javax.xml.stream.events.XMLEvent;
|
|
30 |
import javax.xml.stream.events.Characters;
|
|
31 |
import javax.xml.stream.events.EndElement;
|
|
32 |
import javax.xml.stream.events.StartElement;
|
|
33 |
import javax.xml.namespace.QName;
|
|
34 |
import java.io.Writer;
|
|
35 |
import javax.xml.stream.Location;
|
|
36 |
|
|
37 |
/** DummyEvent is an abstract class. It provides functionality for most of the
|
|
38 |
* function of XMLEvent.
|
|
39 |
*
|
|
40 |
* @author Neeraj Bajaj Sun Microsystems,Inc.
|
|
41 |
* @author K.Venugopal Sun Microsystems,Inc.
|
|
42 |
*
|
|
43 |
*/
|
|
44 |
|
|
45 |
public abstract class DummyEvent implements XMLEvent {
|
|
46 |
// Make sure that getLocation() never returns null. Instead, return this dummy location
|
|
47 |
// that indicates "nowhere" as effectively as possible.
|
|
48 |
private static DummyLocation nowhere = new DummyLocation();
|
|
49 |
|
|
50 |
/* Event type this event corresponds to */
|
|
51 |
private int fEventType;
|
|
52 |
protected Location fLocation = (Location) nowhere;
|
|
53 |
|
|
54 |
public DummyEvent() {
|
|
55 |
}
|
|
56 |
|
|
57 |
public DummyEvent(int i) {
|
|
58 |
fEventType = i;
|
|
59 |
}
|
|
60 |
|
|
61 |
public int getEventType() {
|
|
62 |
return fEventType;
|
|
63 |
}
|
|
64 |
|
|
65 |
protected void setEventType(int eventType){
|
|
66 |
fEventType = eventType;
|
|
67 |
}
|
|
68 |
|
|
69 |
|
|
70 |
public boolean isStartElement() {
|
|
71 |
return fEventType == XMLEvent.START_ELEMENT;
|
|
72 |
}
|
|
73 |
|
|
74 |
public boolean isEndElement() {
|
|
75 |
return fEventType == XMLEvent.END_ELEMENT;
|
|
76 |
}
|
|
77 |
|
|
78 |
public boolean isEntityReference() {
|
|
79 |
return fEventType == XMLEvent.ENTITY_REFERENCE;
|
|
80 |
}
|
|
81 |
|
|
82 |
public boolean isProcessingInstruction() {
|
|
83 |
return fEventType == XMLEvent.PROCESSING_INSTRUCTION;
|
|
84 |
}
|
|
85 |
|
|
86 |
public boolean isCharacterData() {
|
|
87 |
return fEventType == XMLEvent.CHARACTERS;
|
|
88 |
}
|
|
89 |
|
|
90 |
public boolean isStartDocument() {
|
|
91 |
return fEventType == XMLEvent.START_DOCUMENT;
|
|
92 |
}
|
|
93 |
|
|
94 |
public boolean isEndDocument() {
|
|
95 |
return fEventType == XMLEvent.END_DOCUMENT;
|
|
96 |
}
|
|
97 |
|
|
98 |
public Location getLocation(){
|
|
99 |
return fLocation;
|
|
100 |
}
|
|
101 |
|
|
102 |
void setLocation(Location loc){
|
|
103 |
if (loc == null) {
|
|
104 |
fLocation = nowhere;
|
|
105 |
} else {
|
|
106 |
fLocation = loc;
|
|
107 |
}
|
|
108 |
}
|
|
109 |
|
|
110 |
/** Returns this event as Characters, may result in
|
|
111 |
* a class cast exception if this event is not Characters.
|
|
112 |
*/
|
|
113 |
public Characters asCharacters() {
|
|
114 |
return (Characters)this;
|
|
115 |
}
|
|
116 |
|
|
117 |
/** Returns this event as an end element event, may result in
|
|
118 |
* a class cast exception if this event is not a end element.
|
|
119 |
*/
|
|
120 |
public EndElement asEndElement() {
|
|
121 |
return (EndElement)this;
|
|
122 |
}
|
|
123 |
|
|
124 |
/** Returns this event as a start element event, may result in
|
|
125 |
* a class cast exception if this event is not a start element.
|
|
126 |
*/
|
|
127 |
public StartElement asStartElement() {
|
|
128 |
return (StartElement)this;
|
|
129 |
}
|
|
130 |
|
|
131 |
/** This method is provided for implementations to provide
|
|
132 |
* optional type information about the associated event.
|
|
133 |
* It is optional and will return null if no information
|
|
134 |
* is available.
|
|
135 |
*/
|
|
136 |
public QName getSchemaType() {
|
|
137 |
//Base class will take care of providing extra information about this event.
|
|
138 |
return null;
|
|
139 |
}
|
|
140 |
|
|
141 |
/** A utility function to check if this event is an Attribute.
|
|
142 |
* @see Attribute
|
|
143 |
*/
|
|
144 |
public boolean isAttribute() {
|
|
145 |
return fEventType == XMLEvent.ATTRIBUTE;
|
|
146 |
}
|
|
147 |
|
|
148 |
/** A utility function to check if this event is Characters.
|
|
149 |
* @see Characters
|
|
150 |
*/
|
|
151 |
public boolean isCharacters() {
|
|
152 |
return fEventType == XMLEvent.CHARACTERS;
|
|
153 |
}
|
|
154 |
|
|
155 |
/** A utility function to check if this event is a Namespace.
|
|
156 |
* @see Namespace
|
|
157 |
*/
|
|
158 |
public boolean isNamespace() {
|
|
159 |
return fEventType == XMLEvent.NAMESPACE;
|
|
160 |
}
|
|
161 |
|
|
162 |
/** This method will write the XMLEvent as per the XML 1.0 specification as Unicode characters.
|
|
163 |
* No indentation or whitespace should be outputted.
|
|
164 |
*
|
|
165 |
* Any user defined event type SHALL have this method
|
|
166 |
* called when being written to on an output stream.
|
|
167 |
* Built in Event types MUST implement this method,
|
|
168 |
* but implementations MAY choose not call these methods
|
|
169 |
* for optimizations reasons when writing out built in
|
|
170 |
* Events to an output stream.
|
|
171 |
* The output generated MUST be equivalent in terms of the
|
|
172 |
* infoset expressed.
|
|
173 |
*
|
|
174 |
* @param writer The writer that will output the data
|
|
175 |
* @throws XMLStreamException if there is a fatal error writing the event
|
|
176 |
*/
|
|
177 |
public void writeAsEncodedUnicode(Writer writer) throws javax.xml.stream.XMLStreamException {
|
|
178 |
}
|
|
179 |
|
|
180 |
static class DummyLocation implements Location {
|
|
181 |
public DummyLocation() {
|
|
182 |
}
|
|
183 |
|
|
184 |
public int getCharacterOffset() {
|
|
185 |
return -1;
|
|
186 |
}
|
|
187 |
|
|
188 |
public int getColumnNumber() {
|
|
189 |
return -1;
|
|
190 |
}
|
|
191 |
|
|
192 |
public int getLineNumber() {
|
|
193 |
return -1;
|
|
194 |
}
|
|
195 |
|
|
196 |
public String getPublicId() {
|
|
197 |
return null;
|
|
198 |
}
|
|
199 |
|
|
200 |
public String getSystemId() {
|
|
201 |
return null;
|
|
202 |
}
|
|
203 |
}
|
|
204 |
}
|