001: /*
002: * $Id: EndElementEvent.java,v 1.2 2006/04/01 06:01:34 jeffsuttor Exp $
003: */
004:
005: /*
006: * The contents of this file are subject to the terms
007: * of the Common Development and Distribution License
008: * (the License). You may not use this file except in
009: * compliance with the License.
010: *
011: * You can obtain a copy of the license at
012: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
013: * See the License for the specific language governing
014: * permissions and limitations under the License.
015: *
016: * When distributing Covered Code, include this CDDL
017: * Header Notice in each file and include the License file
018: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
019: * If applicable, add the following below the CDDL Header,
020: * with the fields enclosed by brackets [] replaced by
021: * you own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * [Name of File] [ver.__] [Date]
025: *
026: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
027: */
028:
029: package com.sun.xml.stream.events;
030:
031: import java.util.List;
032: import java.util.ArrayList;
033:
034: import javax.xml.namespace.QName;
035: import javax.xml.stream.events.EndElement;
036: import javax.xml.stream.events.Namespace;
037: import java.io.Writer;
038: import java.util.Iterator;
039: import javax.xml.stream.events.XMLEvent;
040: import com.sun.xml.stream.util.ReadOnlyIterator;
041:
042: /** Implementation of EndElement event.
043: *
044: * @author Neeraj Bajaj Sun Microsystems,Inc.
045: * @author K.Venugopal Sun Microsystems,Inc.
046: */
047:
048: public class EndElementEvent extends DummyEvent implements EndElement {
049:
050: List fNamespaces = null;
051: QName fQName;
052:
053: public EndElementEvent() {
054: init();
055: }
056:
057: protected void init() {
058: setEventType(XMLEvent.END_ELEMENT);
059: fNamespaces = new ArrayList();
060: }
061:
062: public EndElementEvent(String prefix, String uri, String localpart) {
063: this (new QName(uri, localpart, prefix));
064: }
065:
066: public EndElementEvent(QName qname) {
067: this .fQName = qname;
068: init();
069: }
070:
071: public QName getName() {
072: return fQName;
073: }
074:
075: public void setName(QName qname) {
076: this .fQName = qname;
077: }
078:
079: /** This method will write the XMLEvent as per the XML 1.0 specification as Unicode characters.
080: * No indentation or whitespace should be outputted.
081: *
082: * Any user defined event type SHALL have this method
083: * called when being written to on an output stream.
084: * Built in Event types MUST implement this method,
085: * but implementations MAY choose not call these methods
086: * for optimizations reasons when writing out built in
087: * Events to an output stream.
088: * The output generated MUST be equivalent in terms of the
089: * infoset expressed.
090: *
091: * @param writer The writer that will output the data
092: * @throws XMLStreamException if there is a fatal error writing the event
093: */
094: public void writeAsEncodedUnicode(Writer writer)
095: throws javax.xml.stream.XMLStreamException {
096: }
097:
098: /** Returns an Iterator of namespaces that have gone out
099: * of scope. Returns an empty iterator if no namespaces have gone
100: * out of scope.
101: * @return an Iterator over Namespace interfaces, or an
102: * empty iterator
103: */
104: public Iterator getNamespaces() {
105: if (fNamespaces != null)
106: fNamespaces.iterator();
107: return new ReadOnlyIterator();
108: }
109:
110: void addNamespace(Namespace attr) {
111: if (attr != null) {
112: fNamespaces.add(attr);
113: }
114: }
115:
116: public String toString() {
117: String s = "</" + nameAsString();
118: s = s + ">";
119: return s;
120: }
121:
122: public String nameAsString() {
123: if ("".equals(fQName.getNamespaceURI()))
124: return fQName.getLocalPart();
125: if (fQName.getPrefix() != null)
126: return "['" + fQName.getNamespaceURI() + "']:"
127: + fQName.getPrefix() + ":" + fQName.getLocalPart();
128: else
129: return "['" + fQName.getNamespaceURI() + "']:"
130: + fQName.getLocalPart();
131: }
132:
133: }
|