01: /*
02: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License version
07: * 2 only, as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful, but
10: * WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * General Public License version 2 for more details (a copy is
13: * included at /legal/license.txt).
14: *
15: * You should have received a copy of the GNU General Public License
16: * version 2 along with this work; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18: * 02110-1301 USA
19: *
20: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
21: * Clara, CA 95054 or visit www.sun.com if you need additional
22: * information or have any questions.
23: */
24:
25: package com.sun.jumpimpl.module.download;
26:
27: /*
28: * A Document wrapper to hold parsed XML output. In
29: * reality all XML is parsed into DocumentElement instances,
30: * including the outermost element which is the document
31: * itself. This is to make it easier while doing the parsing.
32: * This outer class exists mainly to provide a fairly easy
33: * way for someone to iterate through the elements (or nodes)
34: * in the parsed document.
35: */
36:
37: import java.io.CharArrayWriter;
38: import java.util.Iterator;
39:
40: class Document implements Iterator {
41:
42: DocumentElement elementHead = null;
43: DocumentElement currentElement = null;
44: int currentCount = 0;
45:
46: Document(String name, DocumentElement head) {
47: if (head == null) {
48: throw new IllegalArgumentException(
49: "Document cannot have no elements.");
50: }
51: currentElement = elementHead = head;
52: }
53:
54: public String toString() {
55: String elementStr = elementHead.toString();
56: return "document: " + elementHead.name + elementStr;
57: }
58:
59: // Iterator methods
60: public Iterator getIterator() {
61: return this ;
62: }
63:
64: public boolean hasNext() {
65: return currentElement != null
66: && currentCount < currentElement.elements.size();
67: }
68:
69: public Object next() {
70: return currentElement.elements.elementAt(currentCount++);
71: }
72:
73: public void remove() {
74: throw new UnsupportedOperationException();
75: }
76: // End Iterator implementation
77: }
|