1 package com.wutka.dtd;
2
3 import java.io.*;
4 import java.util.*;
5
6 /*** Represents an item that may contain other items (such as a
7 * DTDChoice or a DTDSequence)
8 *
9 * @author Mark Wutka
10 * @version $Revision: 1.16 $ $Date: 2002/07/19 01:20:11 $ by $Author: wutka $
11 */
12 public abstract class DTDContainer extends DTDItem
13 {
14 protected Vector items;
15
16 /*** Creates a new DTDContainer */
17 public DTDContainer()
18 {
19 items = new Vector();
20 }
21
22 /*** Adds an element to the container */
23 public void add(DTDItem item)
24 {
25 items.addElement(item);
26 }
27
28 /*** Removes an element from the container */
29 public void remove(DTDItem item)
30 {
31 items.removeElement(item);
32 }
33
34 /*** Returns the elements as a vector (not a clone!) */
35 public Vector getItemsVec()
36 {
37 return items;
38 }
39
40 /*** Returns the elements as an array of items */
41 public DTDItem[] getItems()
42 {
43 DTDItem[] retval = new DTDItem[items.size()];
44 items.copyInto(retval);
45 return retval;
46 }
47
48 public boolean equals(Object ob)
49 {
50 if (ob == this) return true;
51 if (!(ob instanceof DTDContainer)) return false;
52
53 if (!super.equals(ob)) return false;
54
55 DTDContainer other = (DTDContainer) ob;
56
57 return items.equals(other.items);
58 }
59
60 /*** Stores items in the container */
61 public void setItem(DTDItem[] newItems)
62 {
63 items = new Vector(newItems.length);
64 for (int i=0; i < newItems.length; i++)
65 {
66 items.addElement(newItems[i]);
67 }
68 }
69
70 /*** Retrieves the items in the container */
71 public DTDItem[] getItem()
72 {
73 DTDItem[] retval = new DTDItem[items.size()];
74 items.copyInto(retval);
75
76 return retval;
77 }
78
79 /*** Stores an item in the container */
80 public void setItem(DTDItem anItem, int i)
81 {
82 items.setElementAt(anItem, i);
83 }
84
85 /*** Retrieves an item from the container */
86 public DTDItem getItem(int i)
87 {
88 return (DTDItem) items.elementAt(i);
89 }
90
91 public abstract void write(PrintWriter out)
92 throws IOException;
93 }