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