001: /*
002: * $Id: DummyEvent.java,v 1.2 2006/04/01 06:01:34 jeffsuttor Exp $
003: */
004:
005: /*
006: * The contents of this file are subject to the terms
007: * of the Common Development and Distribution License
008: * (the License). You may not use this file except in
009: * compliance with the License.
010: *
011: * You can obtain a copy of the license at
012: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
013: * See the License for the specific language governing
014: * permissions and limitations under the License.
015: *
016: * When distributing Covered Code, include this CDDL
017: * Header Notice in each file and include the License file
018: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
019: * If applicable, add the following below the CDDL Header,
020: * with the fields enclosed by brackets [] replaced by
021: * you own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * [Name of File] [ver.__] [Date]
025: *
026: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
027: */
028:
029: package com.sun.xml.stream.events;
030:
031: import javax.xml.stream.events.XMLEvent;
032: import javax.xml.stream.events.Characters;
033: import javax.xml.stream.events.EndElement;
034: import javax.xml.stream.events.StartElement;
035: import javax.xml.namespace.QName;
036: import java.io.Writer;
037: import javax.xml.stream.Location;
038:
039: /** DummyEvent is an abstract class. It provides functionality for most of the
040: * function of XMLEvent.
041: *
042: * @author Neeraj Bajaj Sun Microsystems,Inc.
043: * @author K.Venugopal Sun Microsystems,Inc.
044: *
045: */
046:
047: public abstract class DummyEvent implements XMLEvent {
048:
049: /* Event type this event corresponds to */
050: private int fEventType;
051: protected Location fLocation = null;
052:
053: public DummyEvent() {
054:
055: }
056:
057: public DummyEvent(int i) {
058: fEventType = i;
059: }
060:
061: public int getEventType() {
062: return fEventType;
063: }
064:
065: protected void setEventType(int eventType) {
066: fEventType = eventType;
067: }
068:
069: public boolean isStartElement() {
070: return fEventType == XMLEvent.START_ELEMENT;
071: }
072:
073: public boolean isEndElement() {
074: return fEventType == XMLEvent.END_ELEMENT;
075: }
076:
077: public boolean isEntityReference() {
078: return fEventType == XMLEvent.ENTITY_REFERENCE;
079: }
080:
081: public boolean isProcessingInstruction() {
082: return fEventType == XMLEvent.PROCESSING_INSTRUCTION;
083: }
084:
085: public boolean isCharacterData() {
086: return fEventType == XMLEvent.CHARACTERS;
087: }
088:
089: public boolean isStartDocument() {
090: return fEventType == XMLEvent.START_DOCUMENT;
091: }
092:
093: public boolean isEndDocument() {
094: return fEventType == XMLEvent.END_DOCUMENT;
095: }
096:
097: public Location getLocation() {
098: return fLocation;
099: }
100:
101: void setLocation(Location loc) {
102: fLocation = loc;
103: }
104:
105: /** Returns this event as Characters, may result in
106: * a class cast exception if this event is not Characters.
107: */
108: public Characters asCharacters() {
109: return (Characters) this ;
110: }
111:
112: /** Returns this event as an end element event, may result in
113: * a class cast exception if this event is not a end element.
114: */
115: public EndElement asEndElement() {
116: return (EndElement) this ;
117: }
118:
119: /** Returns this event as a start element event, may result in
120: * a class cast exception if this event is not a start element.
121: */
122: public StartElement asStartElement() {
123: return (StartElement) this ;
124: }
125:
126: /** This method is provided for implementations to provide
127: * optional type information about the associated event.
128: * It is optional and will return null if no information
129: * is available.
130: */
131: public QName getSchemaType() {
132: //Base class will take care of providing extra information about this event.
133: return null;
134: }
135:
136: /** A utility function to check if this event is an Attribute.
137: * @see Attribute
138: */
139: public boolean isAttribute() {
140: return fEventType == XMLEvent.ATTRIBUTE;
141: }
142:
143: /** A utility function to check if this event is Characters.
144: * @see Characters
145: */
146: public boolean isCharacters() {
147: return fEventType == XMLEvent.CHARACTERS;
148: }
149:
150: /** A utility function to check if this event is a Namespace.
151: * @see Namespace
152: */
153: public boolean isNamespace() {
154: return fEventType == XMLEvent.NAMESPACE;
155: }
156:
157: /** This method will write the XMLEvent as per the XML 1.0 specification as Unicode characters.
158: * No indentation or whitespace should be outputted.
159: *
160: * Any user defined event type SHALL have this method
161: * called when being written to on an output stream.
162: * Built in Event types MUST implement this method,
163: * but implementations MAY choose not call these methods
164: * for optimizations reasons when writing out built in
165: * Events to an output stream.
166: * The output generated MUST be equivalent in terms of the
167: * infoset expressed.
168: *
169: * @param writer The writer that will output the data
170: * @throws XMLStreamException if there is a fatal error writing the event
171: */
172: public void writeAsEncodedUnicode(Writer writer)
173: throws javax.xml.stream.XMLStreamException {
174: }
175:
176: }
|