001: /*
002: * $Id: ListEventConsumer.java,v 1.1 2004/07/14 22:58:58 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.helpers;
035:
036: import java.util.ArrayList;
037: import java.util.List;
038:
039: import javax.xml.stream.XMLStreamException;
040: import javax.xml.stream.events.XMLEvent;
041: import javax.xml.stream.util.XMLEventConsumer;
042:
043: /**
044: * {@link XMLEventConsumer} that stores all added events in a {@link List}.
045: *
046: * @author Christian Niles
047: * @version $Revision: 1.1 $
048: */
049: public class ListEventConsumer implements XMLEventConsumer {
050:
051: /** The list in which to store events. */
052: private List events;
053:
054: public ListEventConsumer() {
055:
056: }
057:
058: /**
059: * Constructs an instance that adds events to the provided list.
060: *
061: * @param events The list to which events will be added, or <code>null</code>.
062: */
063: public ListEventConsumer(List events) {
064:
065: this .events = events;
066:
067: }
068:
069: /**
070: * Adds the event to the internal list.
071: */
072: public void add(XMLEvent event) throws XMLStreamException {
073:
074: if (events == null) {
075:
076: events = new ArrayList();
077:
078: }
079:
080: events.add(event);
081:
082: }
083:
084: /**
085: * Returns the {@link List} of events added to this consumer.
086: *
087: * @return The {@link List} of events added to this consumer.
088: */
089: public List getEvents() {
090:
091: return events;
092:
093: }
094:
095: /**
096: * Sets the {@link List} to which events will be written.
097: *
098: * @param events The {@link List} to which events will be written.
099: */
100: public void setEvents(List events) {
101:
102: this .events = events;
103:
104: }
105:
106: /**
107: * Removes all events from the internal list, making it available for reuse.
108: */
109: public void reset() {
110:
111: if (events != null) {
112:
113: events.clear();
114:
115: }
116:
117: }
118:
119: }
|