1:
37:
38: package ;
39:
40: import ;
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51:
52:
57: public class StartElementImpl
58: extends XMLEventImpl
59: implements StartElement
60: {
61:
62: protected final QName name;
63: protected final List attributes;
64: protected final List namespaces;
65: protected final NamespaceContext namespaceContext;
66:
67: protected StartElementImpl(Location location,
68: QName name, List attributes, List namespaces,
69: NamespaceContext namespaceContext)
70: {
71: super(location);
72: this.name = name;
73: this.attributes = attributes;
74: this.namespaces = namespaces;
75: this.namespaceContext = namespaceContext;
76: }
77:
78: public int getEventType()
79: {
80: return START_ELEMENT;
81: }
82:
83: public QName getName()
84: {
85: return name;
86: }
87:
88: public Iterator getAttributes()
89: {
90: return attributes.iterator();
91: }
92:
93: public Iterator getNamespaces()
94: {
95: return namespaces.iterator();
96: }
97:
98: public Attribute getAttributeByName(QName name)
99: {
100: for (Iterator i = attributes.iterator(); i.hasNext(); )
101: {
102: Attribute attr = (Attribute) i.next();
103: if (name.equals(attr.getName()))
104: return attr;
105: }
106: return null;
107: }
108:
109: public NamespaceContext getNamespaceContext()
110: {
111: return namespaceContext;
112: }
113:
114: public String getNamespaceURI(String prefix)
115: {
116: return namespaceContext.getNamespaceURI(prefix);
117: }
118:
119: public void writeAsEncodedUnicode(Writer writer)
120: throws XMLStreamException
121: {
122: try
123: {
124: writer.write('<');
125: String prefix = name.getPrefix();
126: if (prefix != null && !"".equals(prefix))
127: {
128: writer.write(prefix);
129: writer.write(':');
130: }
131: writer.write(name.getLocalPart());
132: for (Iterator i = namespaces.iterator(); i.hasNext(); )
133: {
134: writer.write(' ');
135: ((Namespace) i.next()).writeAsEncodedUnicode(writer);
136: }
137: for (Iterator i = attributes.iterator(); i.hasNext(); )
138: {
139: writer.write(' ');
140: ((Attribute) i.next()).writeAsEncodedUnicode(writer);
141: }
142: writer.write('>');
143: }
144: catch (IOException e)
145: {
146: XMLStreamException e2 = new XMLStreamException(e.getMessage());
147: e2.initCause(e);
148: throw e2;
149: }
150: }
151:
152: }