View Javadoc

1   package com.wutka.dtd;
2   
3   import java.util.*;
4   import java.io.*;
5   
6   /*** Represents an ATTLIST declaration in the DTD. Although attributes are
7    *  associated with elements, the ATTLIST is here to allow the DTD object
8    *  to write out the DTD in roughly the original form. Because the ATTLIST
9    *  may appear somewhere other than immediately after the ELEMENT, this object
10   *  is used to keep track of where it is.
11   *
12   * @author Mark Wutka
13   * @version $Revision: 1.16 $ $Date: 2002/07/19 01:20:11 $ by $Author: wutka $
14   */
15  public class DTDAttlist implements DTDOutput
16  {
17  /*** The name of the element */
18      public String name;
19  
20  /*** The attlist's attributes */
21      public Vector attributes;
22  
23      public DTDAttlist()
24      {
25          attributes = new Vector();
26      }
27  
28      public DTDAttlist(String aName)
29      {
30          name = aName;
31  
32          attributes = new Vector();
33      }
34  
35  /*** Writes out an ATTLIST declaration */
36      public void write(PrintWriter out)
37          throws IOException
38      {
39          out.print("<!ATTLIST ");
40          out.println(name);
41  
42          Iterator itr = attributes.iterator();
43  
44          while (itr.hasNext())
45          {
46              out.print("           ");
47              DTDAttribute attr = (DTDAttribute) itr.next();
48              attr.write(out);
49              if (itr.hasNext())
50              {
51                  out.println();
52              }
53              else
54              {
55                  out.println(">");
56              }
57          }
58      }
59  
60      public boolean equals(Object ob)
61      {
62          if (ob == this) return true;
63          if (!(ob instanceof DTDAttlist)) return false;
64  
65          DTDAttlist other = (DTDAttlist) ob;
66  
67          if ((name == null) && (other.name != null)) return false;
68          if ((name != null) && !name.equals(other.name)) return false;
69  
70          return attributes.equals(other.attributes);
71      }
72  
73  /*** Returns the entity name of this attlist */
74      public String getName()
75      {
76          return name;
77      }
78  
79  /*** Sets the entity name of this attlist */
80      public void setName(String aName)
81      {
82          name = aName;
83      }
84  
85  /*** Returns the attributes in this list */
86      public DTDAttribute[] getAttribute()
87      {
88          DTDAttribute attrs[] = new DTDAttribute[attributes.size()];
89          attributes.copyInto(attrs);
90  
91          return attrs;
92      }
93  
94  /*** Sets the list of attributes */
95      public void setAttribute(DTDAttribute[] attrs)
96      {
97          attributes = new Vector(attrs.length);
98          for (int i=0; i < attrs.length; i++)
99          {
100             attributes.addElement(attrs[i]);
101         }
102     }
103 
104 /*** Returns a specific attribute from the list */
105     public DTDAttribute getAttribute(int i)
106     {
107         return (DTDAttribute) attributes.elementAt(i);
108     }
109 
110 /*** Sets a specific attribute in the list */
111     public void setAttribute(DTDAttribute attr, int i)
112     {
113         attributes.setElementAt(attr, i);
114     }
115 }