001: /*
002: * $Id: EndElementEvent.java,v 1.3 2004/07/15 02:11:02 cniles Exp $
003: *
004: * Copyright (c) 2004, Christian Niles, unit12.net
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions are met:
009: *
010: * * Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * * Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: *
017: * * Neither the name of Christian Niles, Unit12, nor the names of its
018: * contributors may be used to endorse or promote products derived from
019: * this software without specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
022: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
023: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
024: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
025: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
026: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
027: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
028: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
029: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
030: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
031: * POSSIBILITY OF SUCH DAMAGE.
032: *
033: */
034: package javanet.staxutils.events;
035:
036: import java.util.ArrayList;
037: import java.util.Collection;
038: import java.util.Collections;
039: import java.util.Iterator;
040: import java.util.List;
041:
042: import javax.xml.namespace.QName;
043: import javax.xml.stream.Location;
044: import javax.xml.stream.events.EndElement;
045: import javax.xml.stream.events.Namespace;
046:
047: /**
048: * {@link EndElement} event implementation.
049: *
050: * @author Christian Niles
051: * @version $Revision: 1.3 $
052: */
053: public class EndElementEvent extends AbstractXMLEvent implements
054: EndElement {
055:
056: /** The element name. */
057: protected QName name;
058:
059: /** A collection of {@link Namespace}s going out of scope. */
060: protected Collection namespaces;
061:
062: public EndElementEvent(QName name, Iterator namespaces) {
063:
064: this (name, namespaces, null, null);
065:
066: }
067:
068: public EndElementEvent(QName name, Iterator namespaces,
069: Location location) {
070:
071: this (name, namespaces, location, null);
072:
073: }
074:
075: public EndElementEvent(QName name, Iterator namespaces,
076: Location location, QName schemaType) {
077:
078: super (location, schemaType);
079:
080: this .name = name;
081: if (namespaces != null && namespaces.hasNext()) {
082:
083: List nsList = new ArrayList();
084: do {
085:
086: Namespace ns = (Namespace) namespaces.next();
087: nsList.add(ns);
088:
089: } while (namespaces.hasNext());
090:
091: }
092:
093: }
094:
095: public EndElementEvent(EndElement that) {
096:
097: super (that);
098: this .name = that.getName();
099:
100: Iterator namespaces = that.getNamespaces();
101: if (namespaces != null && namespaces.hasNext()) {
102:
103: List nsList = new ArrayList();
104: do {
105:
106: Namespace ns = (Namespace) namespaces.next();
107: nsList.add(ns);
108:
109: } while (namespaces.hasNext());
110:
111: }
112:
113: }
114:
115: /**
116: * Returns {@link #END_ELEMENT}.
117: */
118: public int getEventType() {
119:
120: return END_ELEMENT;
121:
122: }
123:
124: public QName getName() {
125:
126: return name;
127:
128: }
129:
130: public Iterator getNamespaces() {
131:
132: if (namespaces != null) {
133:
134: return namespaces.iterator();
135:
136: } else {
137:
138: return Collections.EMPTY_LIST.iterator();
139:
140: }
141:
142: }
143:
144: }
|