Annotation of java/classes/org/w3c/jigsaw/servlet/ServletEnumeration.java, revision 1.6

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

Webmaster