View Javadoc

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