Source code: org/mule/util/IteratorAdapter.java
1 /* The Apache Software License, Version 1.1
2 *
3 * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
4 * reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * 3. The end-user documentation included with the redistribution, if
19 * any, must include the following acknowlegement:
20 * "This product includes software developed by the
21 * Apache Software Foundation (http://www.apache.org/)."
22 * Alternately, this acknowlegement may appear in the software itself,
23 * if and wherever such third-party acknowlegements normally appear.
24 *
25 * 4. The names "The Jakarta Project", "Struts", and "Apache Software
26 * Foundation" must not be used to endorse or promote products derived
27 * from this software without prior written permission. For written
28 * permission, please contact apache@apache.org.
29 *
30 * 5. Products derived from this software may not be called "Apache"
31 * nor may "Apache" appear in their names without prior written
32 * permission of the Apache Group.
33 *
34 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
35 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
38 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
41 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
42 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
43 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
44 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * SUCH DAMAGE.
46 * ====================================================================
47 *
48 * This software consists of voluntary contributions made by many
49 * individuals on behalf of the Apache Software Foundation. For more
50 * information on the Apache Software Foundation, please see
51 * <http://www.apache.org/>.
52 *
53 */
54 package org.mule.util;
55
56 import java.util.Iterator;
57 import java.util.NoSuchElementException;
58
59 /**
60 * Utility method for converting Enumeration to an Iterator
61 * class. If you attempt to remove() an Object from the iterator, it will
62 * throw an UnsupportedOperationException. Added for use by TagLib so
63 * Enumeration can be supported
64 *
65 * @author Sean Kelly
66 * @author Rob Leland
67 * @version $Revision: 1.4 $ $Date: 2003/10/20 21:44:38 $
68 */
69
70 public class IteratorAdapter implements Iterator
71 {
72 private java.util.Enumeration enum;
73
74 public IteratorAdapter(java.util.Enumeration enum)
75 {
76 this.enum = enum;
77 }
78
79 public boolean hasNext()
80 {
81 return enum.hasMoreElements();
82 }
83
84 public Object next()
85 {
86 if (!enum.hasMoreElements())
87 {
88 throw new NoSuchElementException("IteratorAdaptor.next() has no more elements");
89 }
90 return enum.nextElement();
91 }
92 public void remove()
93 {
94 throw new java.lang.UnsupportedOperationException("Method IteratorAdaptor.remove() not implemented");
95 }
96 }