1 38 39 package com.sun.xml.fastinfoset.stax.events ; 40 41 import java.util.List ; 42 import java.util.ArrayList ; 43 44 import javax.xml.namespace.QName ; 45 import javax.xml.stream.events.EndElement; 46 import javax.xml.stream.events.Namespace; 47 import java.io.Writer ; 48 import java.util.Iterator ; 49 import javax.xml.stream.XMLStreamConstants; 50 import com.sun.xml.fastinfoset.util.EmptyIterator; 51 52 53 public class EndElementEvent extends EventBase implements EndElement { 54 55 List _namespaces = null; 56 QName _qname ; 57 58 public void reset() { 59 if (_namespaces != null) _namespaces.clear(); 60 } 61 62 public EndElementEvent() { 63 setEventType(END_ELEMENT); 64 } 65 66 public EndElementEvent(String namespaceURI, String localpart, String prefix) { 67 _qname = getQName(namespaceURI,localpart,prefix); 68 setEventType(END_ELEMENT); 69 } 70 71 public EndElementEvent(QName qname) { 72 _qname = qname; 73 setEventType(END_ELEMENT); 74 } 75 76 80 public QName getName() { 81 return _qname; 82 } 83 84 public void setName(QName qname) { 85 _qname = qname; 86 } 87 88 89 95 public Iterator getNamespaces() { 96 if(_namespaces != null) 97 return _namespaces.iterator(); 98 return EmptyIterator.getInstance(); 99 } 100 101 public void addNamespace(Namespace namespace){ 102 if (_namespaces == null) { 103 _namespaces = new ArrayList (); 104 } 105 _namespaces.add(namespace); 106 } 107 108 public String toString() { 109 StringBuffer sb = new StringBuffer (); 110 sb.append("</").append(nameAsString()); 111 Iterator namespaces = getNamespaces(); 112 while(namespaces.hasNext()) { 113 sb.append(" ").append(namespaces.next().toString()); 114 } 115 sb.append(">"); 116 return sb.toString(); 117 } 118 119 120 private String nameAsString() { 121 if("".equals(_qname.getNamespaceURI())) 122 return _qname.getLocalPart(); 123 if(_qname.getPrefix() != null) 124 return "['" + _qname.getNamespaceURI() + "']:" + _qname.getPrefix() + ":" + _qname.getLocalPart(); 125 else 126 return "['" + _qname.getNamespaceURI() + "']:" + _qname.getLocalPart(); 127 } 128 private QName getQName(String uri, String localPart, String prefix){ 129 QName qn = null; 130 if(prefix != null && uri != null) 131 qn = new QName (uri, localPart, prefix); 132 else if(prefix == null && uri != null) 133 qn = new QName (uri, localPart); 134 else if(prefix == null && uri == null) 135 qn = new QName (localPart); 136 return qn; 137 } 138 } 139 | Popular Tags |