1 package com.wutka.dtd;
2
3 import java.util.*;
4 import java.io.*;
5
6 /*** Represents an element defined with the ELEMENT DTD tag
7 *
8 * @author Mark Wutka
9 * @version $Revision: 1.16 $ $Date: 2002/07/19 01:20:11 $ by $Author: wutka $
10 */
11 public class DTDElement implements DTDOutput
12 {
13 /*** The name of the element */
14 public String name;
15
16 /*** The element's attributes */
17 public Hashtable attributes;
18
19 /*** The element's content */
20 public DTDItem content;
21
22 public DTDElement()
23 {
24 attributes = new Hashtable();
25 }
26
27 public DTDElement(String aName)
28 {
29 name = aName;
30
31 attributes = new Hashtable();
32 }
33
34 /*** Writes out an element declaration and an attlist declaration (if necessary)
35 for this element */
36 public void write(PrintWriter out)
37 throws IOException
38 {
39 out.print("<!ELEMENT ");
40 out.print(name);
41 out.print(" ");
42 if (content != null)
43 {
44 content.write(out);
45 }
46 else
47 {
48 out.print("ANY");
49 }
50 out.println(">");
51 out.println();
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 }
74
75 public boolean equals(Object ob)
76 {
77 if (ob == this) return true;
78 if (!(ob instanceof DTDElement)) return false;
79
80 DTDElement other = (DTDElement) ob;
81
82 if (name == null)
83 {
84 if (other.name != null) return false;
85 }
86 else
87 {
88 if (!name.equals(other.name)) return false;
89 }
90
91 if (attributes == null)
92 {
93 if (other.attributes != null) return false;
94 }
95 else
96 {
97 if (!attributes.equals(other.attributes)) return false;
98 }
99
100 if (content == null)
101 {
102 if (other.content != null) return false;
103 }
104 else
105 {
106 if (!content.equals(other.content)) return false;
107 }
108
109 return true;
110 }
111
112 /*** Sets the name of this element */
113 public void setName(String aName)
114 {
115 name = aName;
116 }
117
118 /*** Returns the name of this element */
119 public String getName()
120 {
121 return name;
122 }
123
124 /*** Stores an attribute in this element */
125 public void setAttribute(String attrName, DTDAttribute attr)
126 {
127 attributes.put(attrName, attr);
128 }
129
130 /*** Gets an attribute for this element */
131 public DTDAttribute getAttribute(String attrName)
132 {
133 return (DTDAttribute) attributes.get(attrName);
134 }
135
136 /*** Sets the content type of this element */
137 public void setContent(DTDItem theContent)
138 {
139 content = theContent;
140 }
141
142 /*** Returns the content type of this element */
143 public DTDItem getContent()
144 {
145 return content;
146 }
147 }