1 package com.wutka.dtd;
2
3 import java.io.*;
4
5 /*** Represents a DTD Attribute in an ATTLIST declaration
6 *
7 * @author Mark Wutka
8 * @version $Revision: 1.16 $ $Date: 2002/07/19 01:20:11 $ by $Author: wutka $
9 */
10
11 public class DTDAttribute implements DTDOutput
12 {
13 /*** The name of the attribute */
14 public String name;
15
16 /*** The type of the attribute (either String, DTDEnumeration or
17 DTDNotationList) */
18 public Object type;
19
20 /*** The attribute's declaration (required, fixed, implied) */
21 public DTDDecl decl;
22
23 /*** The attribute's default value (null if not declared) */
24 public String defaultValue;
25
26 public DTDAttribute()
27 {
28 }
29
30 public DTDAttribute(String aName)
31 {
32 name = aName;
33 }
34
35 /*** Writes this attribute to an output stream */
36 public void write(PrintWriter out)
37 throws IOException
38 {
39 out.print(name+" ");
40 if (type instanceof String)
41 {
42 out.print(type);
43 }
44 else if (type instanceof DTDEnumeration)
45 {
46 DTDEnumeration dtdEnum = (DTDEnumeration) type;
47 dtdEnum.write(out);
48 }
49 else if (type instanceof DTDNotationList)
50 {
51 DTDNotationList dtdnl = (DTDNotationList) type;
52 dtdnl.write(out);
53 }
54
55 if (decl != null)
56 {
57 decl.write(out);
58 }
59
60 if (defaultValue != null)
61 {
62 out.print(" \"");
63 out.print(defaultValue);
64 out.print("\"");
65 }
66
67 }
68
69 public boolean equals(Object ob)
70 {
71 if (ob == this) return true;
72 if (!(ob instanceof DTDAttribute)) return false;
73
74 DTDAttribute other = (DTDAttribute) ob;
75
76 if (name == null)
77 {
78 if (other.name != null) return false;
79 }
80 else
81 {
82 if (!name.equals(other.name)) return false;
83 }
84
85 if (type == null)
86 {
87 if (other.type != null) return false;
88 }
89 else
90 {
91 if (!type.equals(other.type)) return false;
92 }
93
94 if (decl == null)
95 {
96 if (other.decl != null) return false;
97 }
98 else
99 {
100 if (!decl.equals(other.decl)) return false;
101 }
102
103 if (defaultValue == null)
104 {
105 if (other.defaultValue != null) return false;
106 }
107 else
108 {
109 if (!defaultValue.equals(other.defaultValue)) return false;
110 }
111
112 return true;
113 }
114
115 /*** Sets the name of the attribute */
116 public void setName(String aName)
117 {
118 name = aName;
119 }
120
121 /*** Returns the attribute name */
122 public String getName()
123 {
124 return name;
125 }
126
127 /*** Sets the type of the attribute */
128 public void setType(Object aType)
129 {
130 if (!(aType instanceof String) &&
131 !(aType instanceof DTDEnumeration) &&
132 !(aType instanceof DTDNotationList))
133 {
134 throw new IllegalArgumentException(
135 "Must be String, DTDEnumeration or DTDNotationList");
136 }
137
138 type = aType;
139 }
140
141 /*** Gets the type of the attribute */
142 public Object getType()
143 {
144 return type;
145 }
146
147 /*** Sets the declaration (fixed, required, implied) */
148 public void setDecl(DTDDecl aDecl)
149 {
150 decl = aDecl;
151 }
152
153 /*** Returns the declaration */
154 public DTDDecl getDecl()
155 {
156 return decl;
157 }
158
159 /*** Sets the default value */
160 public void setDefaultValue(String aDefaultValue)
161 {
162 defaultValue = aDefaultValue;
163 }
164
165 /*** Returns the default value */
166 public String getDefaultValue()
167 {
168 return defaultValue;
169 }
170 }