1 29 30 package com.caucho.xml.stream.events; 31 32 import javax.xml.namespace.NamespaceContext ; 33 import javax.xml.namespace.QName ; 34 import javax.xml.stream.XMLStreamException; 35 import javax.xml.stream.events.Attribute; 36 import javax.xml.stream.events.Namespace; 37 import javax.xml.stream.events.StartElement; 38 import java.io.IOException ; 39 import java.io.Writer ; 40 import java.util.HashMap ; 41 import java.util.Iterator ; 42 43 public class StartElementImpl extends XMLEventImpl implements StartElement { 44 private final QName _name; 45 private final HashMap <QName , Attribute> _attributes; 46 private final HashMap <String , Namespace> _namespaces; 47 private final NamespaceContext _namespaceContext; 48 49 public StartElementImpl(QName name, HashMap <QName , Attribute> attributes, 50 HashMap <String , Namespace> namespaces, 51 NamespaceContext namespaceContext) 52 { 53 _name = name; 54 _attributes = attributes; 55 _namespaces = namespaces; 56 _namespaceContext = namespaceContext; 57 } 58 59 public Attribute getAttributeByName(QName name) 60 { 61 return _attributes.get(name); 62 } 63 64 public Iterator getAttributes() 65 { 66 return _attributes.values().iterator(); 67 } 68 69 public QName getName() 70 { 71 return _name; 72 } 73 74 public NamespaceContext getNamespaceContext() 75 { 76 return _namespaceContext; 77 } 78 79 public Iterator getNamespaces() 80 { 81 return _namespaces.values().iterator(); 82 } 83 84 public String getNamespaceURI(String prefix) 85 { 86 return _namespaces.get(prefix).getNamespaceURI(); 87 } 88 89 public int getEventType() 90 { 91 return START_ELEMENT; 92 } 93 94 public void writeAsEncodedUnicode(Writer writer) 95 throws XMLStreamException 96 { 97 try { 98 writer.write("<" + _name + ">"); 99 100 for (Attribute attribute : _attributes.values()) 101 attribute.writeAsEncodedUnicode(writer); 102 } 103 catch (IOException e) { 104 throw new XMLStreamException(e); 105 } 106 } 107 108 public String toString() 109 { 110 return "StartElement[" + _name + "]"; 111 } 112 } 113 114 | Popular Tags |