1 /* 2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.xml.internal.stream.events ; 27 28 import java.util.List; 29 import java.util.ArrayList; 30 31 import javax.xml.namespace.QName; 32 import javax.xml.stream.events.EndElement; 33 import javax.xml.stream.events.Namespace; 34 import java.io.Writer; 35 import java.util.Iterator; 36 import javax.xml.stream.events.XMLEvent; 37 import com.sun.xml.internal.stream.util.ReadOnlyIterator; 38 39 /** Implementation of EndElement event. 40 * 41 * @author Neeraj Bajaj Sun Microsystems,Inc. 42 * @author K.Venugopal Sun Microsystems,Inc. 43 */ 44 45 public class EndElementEvent extends DummyEvent 46 implements EndElement { 47 48 List fNamespaces = null; 49 QName fQName ; 50 51 public EndElementEvent() { 52 init(); 53 } 54 55 protected void init() { 56 setEventType(XMLEvent.END_ELEMENT); 57 fNamespaces = new ArrayList(); 58 } 59 60 61 public EndElementEvent(String prefix, String uri, String localpart) { 62 this(new QName(uri,localpart,prefix)); 63 } 64 65 public EndElementEvent(QName qname) { 66 this.fQName = qname; 67 init(); 68 } 69 70 public QName getName() { 71 return fQName; 72 } 73 74 public void setName(QName qname) { 75 this.fQName = qname; 76 } 77 78 protected void writeAsEncodedUnicodeEx(java.io.Writer writer) 79 throws java.io.IOException 80 { 81 writer.write("</"); 82 String prefix = fQName.getPrefix(); 83 if (prefix != null && prefix.length() > 0) { 84 writer.write(prefix); 85 writer.write(':'); 86 } 87 writer.write(fQName.getLocalPart()); 88 writer.write('>'); 89 } 90 91 /** Returns an Iterator of namespaces that have gone out 92 * of scope. Returns an empty iterator if no namespaces have gone 93 * out of scope. 94 * @return an Iterator over Namespace interfaces, or an 95 * empty iterator 96 */ 97 public Iterator getNamespaces() { 98 if(fNamespaces != null) 99 fNamespaces.iterator(); 100 return new ReadOnlyIterator(); 101 } 102 103 void addNamespace(Namespace attr){ 104 if(attr != null){ 105 fNamespaces.add(attr); 106 } 107 } 108 109 public String toString() { 110 String s = "</" + nameAsString(); 111 s = s + ">"; 112 return s; 113 } 114 115 public String nameAsString() { 116 if("".equals(fQName.getNamespaceURI())) 117 return fQName.getLocalPart(); 118 if(fQName.getPrefix() != null) 119 return "['" + fQName.getNamespaceURI() + "']:" + fQName.getPrefix() + ":" + fQName.getLocalPart(); 120 else 121 return "['" + fQName.getNamespaceURI() + "']:" + fQName.getLocalPart(); 122 } 123 124 }