01: // ServletNamesEnumeration.java
02: // $Id: ServletNamesEnumeration.java,v 1.3 2001/11/12 14:04:36 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 ServletNamesEnumeration implements Enumeration {
19: Enumeration children = null;
20: String next = null;
21: ServletDirectoryFrame dir = null;
22:
23: ServletNamesEnumeration(ServletDirectoryFrame dir,
24: Enumeration children) {
25: this .dir = dir;
26: this .children = children; //was null ???
27: }
28:
29: private final synchronized String computeNext() {
30: if (next != null)
31: return next;
32: while (children.hasMoreElements()) {
33: next = (String) children.nextElement();
34: // if (dir.getServlet(next) != null)
35: if (dir.isServletLoaded(next)) {
36: return next;
37: } else {
38: next = null;
39: }
40: }
41: return null;
42: }
43:
44: public synchronized boolean hasMoreElements() {
45: return (next != null) || ((next = computeNext()) != null);
46: }
47:
48: public synchronized Object nextElement() {
49: if (next == null) {
50: next = computeNext();
51: }
52: if (next != null) {
53: Object ret = next;
54: next = null;
55: return ret;
56: } else {
57: throw new NoSuchElementException("NextElement");
58: }
59: }
60: }
|