01: // ServletEnumeration.java
02: // $Id: ServletEnumeration.java,v 1.5 2000/08/16 21:37:45 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.jigsaw.servlet;
07:
08: import java.util.Enumeration;
09: import java.util.NoSuchElementException;
10:
11: import javax.servlet.Servlet;
12:
13: /**
14: * @author Alexandre Rafalovitch <alex@access.com.au>
15: * @author Anselm Baird-Smith <abaird@w3.org>
16: */
17:
18: public class ServletEnumeration implements Enumeration {
19: Enumeration children = null;
20: Servlet next = null;
21: ServletDirectoryFrame dir = null;
22:
23: ServletEnumeration(ServletDirectoryFrame dir, Enumeration children) {
24: this .dir = dir;
25: this .children = children; //was null ???
26: }
27:
28: private final synchronized Servlet computeNext() {
29: if (next != null)
30: return next;
31: while (children.hasMoreElements()) {
32: next = dir.getServlet((String) children.nextElement());
33: if (next != null)
34: return next;
35: }
36: return null;
37: }
38:
39: public synchronized boolean hasMoreElements() {
40: return (next != null) || ((next = computeNext()) != null);
41: }
42:
43: public synchronized Object nextElement() {
44: if (next == null)
45: next = computeNext();
46: if (next != null) {
47: Object ret = next;
48: next = null;
49: return ret;
50: } else {
51: throw new NoSuchElementException("NextElement");
52: }
53: }
54: }
|