src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/stax/events/EventBase.java

changeset 0
373ffda63c9a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/stax/events/EventBase.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,220 @@
     1.4 +/*
     1.5 + * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + *
    1.28 + * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
    1.29 + */
    1.30 +
    1.31 +package com.sun.xml.internal.fastinfoset.stax.events ;
    1.32 +
    1.33 +import javax.xml.stream.Location;
    1.34 +import javax.xml.stream.events.XMLEvent;
    1.35 +import javax.xml.stream.events.Characters;
    1.36 +import javax.xml.stream.events.EndElement;
    1.37 +import javax.xml.stream.events.StartElement;
    1.38 +import javax.xml.namespace.QName;
    1.39 +import java.io.Writer;
    1.40 +import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
    1.41 +
    1.42 +
    1.43 +public abstract class EventBase implements XMLEvent {
    1.44 +
    1.45 +    /* Event type this event corresponds to */
    1.46 +    protected int _eventType;
    1.47 +    protected Location _location = null;
    1.48 +
    1.49 +    public EventBase() {
    1.50 +
    1.51 +    }
    1.52 +
    1.53 +    public EventBase(int eventType) {
    1.54 +        _eventType = eventType;
    1.55 +    }
    1.56 +
    1.57 +    /**
    1.58 +    * Returns an integer code for this event.
    1.59 +    */
    1.60 +    public int getEventType() {
    1.61 +        return _eventType;
    1.62 +    }
    1.63 +
    1.64 +    protected void setEventType(int eventType){
    1.65 +        _eventType = eventType;
    1.66 +    }
    1.67 +
    1.68 +
    1.69 +    public boolean isStartElement() {
    1.70 +        return _eventType == START_ELEMENT;
    1.71 +    }
    1.72 +
    1.73 +    public boolean isEndElement() {
    1.74 +        return _eventType == END_ELEMENT;
    1.75 +    }
    1.76 +
    1.77 +    public boolean isEntityReference() {
    1.78 +        return _eventType == ENTITY_REFERENCE;
    1.79 +    }
    1.80 +
    1.81 +    public boolean isProcessingInstruction() {
    1.82 +        return _eventType == PROCESSING_INSTRUCTION;
    1.83 +    }
    1.84 +
    1.85 +    public boolean isStartDocument() {
    1.86 +        return _eventType == START_DOCUMENT;
    1.87 +    }
    1.88 +
    1.89 +    public boolean isEndDocument() {
    1.90 +        return _eventType == END_DOCUMENT;
    1.91 +    }
    1.92 +
    1.93 +  /**
    1.94 +   * Return the location of this event.  The Location
    1.95 +   * returned from this method is non-volatile and
    1.96 +   * will retain its information.
    1.97 +   * @see javax.xml.stream.Location
    1.98 +   */
    1.99 +    public Location getLocation(){
   1.100 +        return _location;
   1.101 +    }
   1.102 +
   1.103 +    public void setLocation(Location loc){
   1.104 +        _location = loc;
   1.105 +    }
   1.106 +    public String getSystemId() {
   1.107 +        if(_location == null )
   1.108 +            return "";
   1.109 +        else
   1.110 +            return _location.getSystemId();
   1.111 +    }
   1.112 +
   1.113 +    /** Returns this event as Characters, may result in
   1.114 +     * a class cast exception if this event is not Characters.
   1.115 +     */
   1.116 +    public Characters asCharacters() {
   1.117 +        if (isCharacters()) {
   1.118 +            return (Characters)this;
   1.119 +        } else
   1.120 +            throw new ClassCastException(CommonResourceBundle.getInstance().getString("message.charactersCast", new Object[]{getEventTypeString()}));
   1.121 +    }
   1.122 +
   1.123 +    /** Returns this event as an end  element event, may result in
   1.124 +     * a class cast exception if this event is not a end element.
   1.125 +     */
   1.126 +    public EndElement asEndElement() {
   1.127 +        if (isEndElement()) {
   1.128 +            return (EndElement)this;
   1.129 +        } else
   1.130 +            throw new ClassCastException(CommonResourceBundle.getInstance().getString("message.endElementCase", new Object[]{getEventTypeString()}));
   1.131 +    }
   1.132 +
   1.133 +  /**
   1.134 +   * Returns this event as a start element event, may result in
   1.135 +   * a class cast exception if this event is not a start element.
   1.136 +   */
   1.137 +    public StartElement asStartElement() {
   1.138 +        if (isStartElement()) {
   1.139 +            return (StartElement)this;
   1.140 +        } else
   1.141 +            throw new ClassCastException(CommonResourceBundle.getInstance().getString("message.startElementCase", new Object[]{getEventTypeString()}));
   1.142 +    }
   1.143 +
   1.144 +    /**
   1.145 +    * This method is provided for implementations to provide
   1.146 +    * optional type information about the associated event.
   1.147 +    * It is optional and will return null if no information
   1.148 +    * is available.
   1.149 +    */
   1.150 +    public QName getSchemaType() {
   1.151 +        return null;
   1.152 +    }
   1.153 +
   1.154 +    /** A utility function to check if this event is an Attribute.
   1.155 +     * @see javax.xml.stream.events.Attribute
   1.156 +     */
   1.157 +    public boolean isAttribute() {
   1.158 +        return _eventType == ATTRIBUTE;
   1.159 +    }
   1.160 +
   1.161 +    /** A utility function to check if this event is Characters.
   1.162 +     * @see javax.xml.stream.events.Characters
   1.163 +     */
   1.164 +    public boolean isCharacters() {
   1.165 +        return _eventType == CHARACTERS;
   1.166 +    }
   1.167 +
   1.168 +    /** A utility function to check if this event is a Namespace.
   1.169 +     * @see javax.xml.stream.events.Namespace
   1.170 +     */
   1.171 +    public boolean isNamespace() {
   1.172 +        return _eventType == NAMESPACE;
   1.173 +    }
   1.174 +
   1.175 +
   1.176 +    /**
   1.177 +    * This method will write the XMLEvent as per the XML 1.0 specification as Unicode characters.
   1.178 +    * No indentation or whitespace should be outputted.
   1.179 +    *
   1.180 +    * Any user defined event type SHALL have this method
   1.181 +    * called when being written to on an output stream.
   1.182 +    * Built in Event types MUST implement this method,
   1.183 +    * but implementations MAY choose not call these methods
   1.184 +    * for optimizations reasons when writing out built in
   1.185 +    * Events to an output stream.
   1.186 +    * The output generated MUST be equivalent in terms of the
   1.187 +    * infoset expressed.
   1.188 +    *
   1.189 +    * @param writer The writer that will output the data
   1.190 +    * @throws XMLStreamException if there is a fatal error writing the event
   1.191 +    */
   1.192 +    public void writeAsEncodedUnicode(Writer writer) throws javax.xml.stream.XMLStreamException {
   1.193 +    }
   1.194 +
   1.195 +    private String getEventTypeString() {
   1.196 +        switch (_eventType){
   1.197 +            case START_ELEMENT:
   1.198 +                return "StartElementEvent";
   1.199 +            case END_ELEMENT:
   1.200 +                return "EndElementEvent";
   1.201 +            case PROCESSING_INSTRUCTION:
   1.202 +                return "ProcessingInstructionEvent";
   1.203 +            case CHARACTERS:
   1.204 +                return "CharacterEvent";
   1.205 +            case COMMENT:
   1.206 +                return "CommentEvent";
   1.207 +            case START_DOCUMENT:
   1.208 +                return "StartDocumentEvent";
   1.209 +            case END_DOCUMENT:
   1.210 +                return "EndDocumentEvent";
   1.211 +            case ENTITY_REFERENCE:
   1.212 +                return "EntityReferenceEvent";
   1.213 +            case ATTRIBUTE:
   1.214 +                return "AttributeBase";
   1.215 +            case DTD:
   1.216 +                return "DTDEvent";
   1.217 +            case CDATA:
   1.218 +                return "CDATA";
   1.219 +        }
   1.220 +        return "UNKNOWN_EVENT_TYPE";
   1.221 +    }
   1.222 +
   1.223 +}

mercurial