Path: blob/master/src/java.xml/share/classes/javax/xml/stream/events/XMLEvent.java
40955 views
/*1* Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.xml.stream.events;2627import java.io.Writer;28import javax.xml.namespace.QName;29/**30* This is the base event interface for handling markup events.31* Events are value objects that are used to communicate the32* XML 1.0 InfoSet to the Application. Events may be cached33* and referenced after the parse has completed.34*35* @version 1.036* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.37* @see javax.xml.stream.XMLEventReader38* @see Characters39* @see ProcessingInstruction40* @see StartElement41* @see EndElement42* @see StartDocument43* @see EndDocument44* @see EntityReference45* @see EntityDeclaration46* @see NotationDeclaration47* @since 1.648*/49public interface XMLEvent extends javax.xml.stream.XMLStreamConstants {5051/**52* Returns an integer code for this event.53* @return the event type54* @see #START_ELEMENT55* @see #END_ELEMENT56* @see #CHARACTERS57* @see #ATTRIBUTE58* @see #NAMESPACE59* @see #PROCESSING_INSTRUCTION60* @see #COMMENT61* @see #START_DOCUMENT62* @see #END_DOCUMENT63* @see #DTD64*/65public int getEventType();6667/**68* Return the location of this event. The Location69* returned from this method is non-volatile and70* will retain its information.71* @return the location of the event72* @see javax.xml.stream.Location73*/74javax.xml.stream.Location getLocation();7576/**77* A utility function to check if this event is a StartElement.78* @return true if the event is {@code StartElement}, false otherwise79* @see StartElement80*/81public boolean isStartElement();8283/**84* A utility function to check if this event is an Attribute.85* @return true if the event is {@code Attribute}, false otherwise86* @see Attribute87*/88public boolean isAttribute();8990/**91* A utility function to check if this event is a Namespace.92* @return true if the event is {@code Namespace}, false otherwise93* @see Namespace94*/95public boolean isNamespace();969798/**99* A utility function to check if this event is a EndElement.100* @return true if the event is {@code EndElement}, false otherwise101* @see EndElement102*/103public boolean isEndElement();104105/**106* A utility function to check if this event is an EntityReference.107* @return true if the event is {@code EntityReference}, false otherwise108* @see EntityReference109*/110public boolean isEntityReference();111112/**113* A utility function to check if this event is a ProcessingInstruction.114* @return true if the event is {@code ProcessingInstruction}, false otherwise115* @see ProcessingInstruction116*/117public boolean isProcessingInstruction();118119/**120* A utility function to check if this event is Characters.121* @return true if the event is {@code Characters}, false otherwise122* @see Characters123*/124public boolean isCharacters();125126/**127* A utility function to check if this event is a StartDocument.128* @return true if the event is {@code StartDocument}, false otherwise129* @see StartDocument130*/131public boolean isStartDocument();132133/**134* A utility function to check if this event is an EndDocument.135* @return true if the event is {@code EndDocument}, false otherwise136* @see EndDocument137*/138public boolean isEndDocument();139140/**141* Returns this event as a start element event, may result in142* a class cast exception if this event is not a start element.143* @return a {@code StartElement} event144*/145public StartElement asStartElement();146147/**148* Returns this event as an end element event, may result in149* a class cast exception if this event is not a end element.150* @return a {@code EndElement} event151*/152public EndElement asEndElement();153154/**155* Returns this event as Characters, may result in156* a class cast exception if this event is not Characters.157* @return a {@code Characters} event158*/159public Characters asCharacters();160161/**162* This method is provided for implementations to provide163* optional type information about the associated event.164* It is optional and will return null if no information165* is available.166* @return the type of the event, null if not available167*/168public QName getSchemaType();169170/**171* This method will write the XMLEvent as per the XML 1.0 specification as Unicode characters.172* No indentation or whitespace should be outputted.173*174* Any user defined event type SHALL have this method175* called when being written to on an output stream.176* Built in Event types MUST implement this method,177* but implementations MAY choose not call these methods178* for optimizations reasons when writing out built in179* Events to an output stream.180* The output generated MUST be equivalent in terms of the181* infoset expressed.182*183* @param writer The writer that will output the data184* @throws javax.xml.stream.XMLStreamException if there is a fatal error writing the event185*/186public void writeAsEncodedUnicode(Writer writer)187throws javax.xml.stream.XMLStreamException;188189}190191192