01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.util;
06:
07: import com.opensymphony.xwork.Action;
08:
09: import java.util.ArrayList;
10: import java.util.Iterator;
11: import java.util.List;
12:
13: /**
14: * A bean that takes several iterators and outputs them in sequence
15: *
16: * @author Rickard Öberg (rickard@middleware-company.com)
17: * @version $Revision: 2338 $
18: * @see com.opensymphony.webwork.components.AppendIterator
19: * @see com.opensymphony.webwork.views.jsp.iterator.AppendIteratorTag
20: */
21: public class AppendIteratorFilter extends IteratorFilterSupport
22: implements Iterator, Action {
23:
24: List iterators = new ArrayList();
25:
26: // Attributes ----------------------------------------------------
27: List sources = new ArrayList();
28:
29: // Public --------------------------------------------------------
30: public void setSource(Object anIterator) {
31: sources.add(anIterator);
32: }
33:
34: // Action implementation -----------------------------------------
35: public String execute() {
36: // Make source transformations
37: for (int i = 0; i < sources.size(); i++) {
38: Object source = sources.get(i);
39: iterators.add(getIterator(source));
40: }
41:
42: return SUCCESS;
43: }
44:
45: // Iterator implementation ---------------------------------------
46: public boolean hasNext() {
47: if (iterators.size() > 0) {
48: return (((Iterator) iterators.get(0)).hasNext());
49: } else {
50: return false;
51: }
52: }
53:
54: public Object next() {
55: try {
56: return ((Iterator) iterators.get(0)).next();
57: } finally {
58: if (iterators.size() > 0) {
59: if (!((Iterator) iterators.get(0)).hasNext()) {
60: iterators.remove(0);
61: }
62: }
63: }
64: }
65:
66: public void remove() {
67: throw new UnsupportedOperationException();
68: }
69: }
|