01: // headerEnumerator.java
02: // $Id: headerEnumerator.java,v 1.4 2000/08/16 21:38:01 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.www.http;
07:
08: import java.util.Dictionary;
09: import java.util.Enumeration;
10: import java.util.Hashtable;
11: import java.util.NoSuchElementException;
12:
13: class headerEnumerator implements Enumeration {
14: HttpMessage message = null;
15: int index = 0;
16: Enumeration extras = null;
17: boolean all = false;
18:
19: /**
20: * Are there more available header descriptions ?
21: * @return A boolean, <strong>true</strong> if more header descriptions
22: * are available.
23: */
24:
25: public boolean hasMoreElements() {
26: // Enumerate standard header descriptions:
27: while (index < HttpMessage.MAX_HEADERS) {
28: if (all || message.values[index] != null)
29: return true;
30: index++;
31: }
32: // Enumerate extra header descriptions:
33: if (extras == null) {
34: if (message.headers == null)
35: return false;
36: if (all)
37: extras = message.factory.keys();
38: else
39: extras = message.headers.keys();
40: }
41: return extras.hasMoreElements();
42: }
43:
44: /**
45: * Get the next header description out of this enumeration.
46: * @return A HeaderDescription.
47: * @exception NoSuchElement If no more header descriptions are available.
48: */
49:
50: public Object nextElement() {
51: if (index < HttpMessage.MAX_HEADERS)
52: return message.descriptors[index++];
53: if (extras == null)
54: throw new NoSuchElementException("Enumeration exhausted.");
55: String key = (String) extras.nextElement();
56: return message.factory.get(key);
57: }
58:
59: headerEnumerator(HttpMessage message, boolean all) {
60: this .message = message;
61: this .index = 0;
62: this.all = all;
63: }
64: }
|