Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/com/sun/xml/internal/stream/events/EndElementEvent.java
86414 views
/*1* Copyright (c) 2005, 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 com.sun.xml.internal.stream.events ;2627import java.util.List;28import java.util.ArrayList;2930import javax.xml.namespace.QName;31import javax.xml.stream.events.EndElement;32import javax.xml.stream.events.Namespace;33import java.io.Writer;34import java.util.Iterator;35import javax.xml.stream.events.XMLEvent;36import com.sun.xml.internal.stream.util.ReadOnlyIterator;3738/** Implementation of EndElement event.39*40* @author Neeraj Bajaj Sun Microsystems,Inc.41* @author K.Venugopal Sun Microsystems,Inc.42*/4344public class EndElementEvent extends DummyEvent45implements EndElement {4647List fNamespaces = null;48QName fQName ;4950public EndElementEvent() {51init();52}5354protected void init() {55setEventType(XMLEvent.END_ELEMENT);56fNamespaces = new ArrayList();57}585960public EndElementEvent(String prefix, String uri, String localpart) {61this(new QName(uri,localpart,prefix));62}6364public EndElementEvent(QName qname) {65this.fQName = qname;66init();67}6869public QName getName() {70return fQName;71}7273public void setName(QName qname) {74this.fQName = qname;75}7677protected void writeAsEncodedUnicodeEx(java.io.Writer writer)78throws java.io.IOException79{80writer.write("</");81String prefix = fQName.getPrefix();82if (prefix != null && prefix.length() > 0) {83writer.write(prefix);84writer.write(':');85}86writer.write(fQName.getLocalPart());87writer.write('>');88}8990/** Returns an Iterator of namespaces that have gone out91* of scope. Returns an empty iterator if no namespaces have gone92* out of scope.93* @return an Iterator over Namespace interfaces, or an94* empty iterator95*/96public Iterator getNamespaces() {97if(fNamespaces != null)98fNamespaces.iterator();99return new ReadOnlyIterator();100}101102void addNamespace(Namespace attr){103if(attr != null){104fNamespaces.add(attr);105}106}107108public String toString() {109String s = "</" + nameAsString();110s = s + ">";111return s;112}113114public String nameAsString() {115if("".equals(fQName.getNamespaceURI()))116return fQName.getLocalPart();117if(fQName.getPrefix() != null)118return "['" + fQName.getNamespaceURI() + "']:" + fQName.getPrefix() + ":" + fQName.getLocalPart();119else120return "['" + fQName.getNamespaceURI() + "']:" + fQName.getLocalPart();121}122123}124125126