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