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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
package com.wutka.dtd;
import java.io.*;
/** Represents a DTD Attribute in an ATTLIST declaration
*
* @author Mark Wutka
* @version $Revision: 1.16 $ $Date: 2002/07/19 01:20:11 $ by $Author: wutka $
*/
public class DTDAttribute implements DTDOutput
{
/** The name of the attribute */
public String name;
/** The type of the attribute (either String, DTDEnumeration or
DTDNotationList) */
public Object type;
/** The attribute's declaration (required, fixed, implied) */
public DTDDecl decl;
/** The attribute's default value (null if not declared) */
public String defaultValue;
public DTDAttribute()
{
}
public DTDAttribute(String aName)
{
name = aName;
}
/** Writes this attribute to an output stream */
public void write(PrintWriter out)
throws IOException
{
out.print(name+" ");
if (type instanceof String)
{
out.print(type);
}
else if (type instanceof DTDEnumeration)
{
DTDEnumeration dtdEnum = (DTDEnumeration) type;
dtdEnum.write(out);
}
else if (type instanceof DTDNotationList)
{
DTDNotationList dtdnl = (DTDNotationList) type;
dtdnl.write(out);
}
if (decl != null)
{
decl.write(out);
}
if (defaultValue != null)
{
out.print(" \"");
out.print(defaultValue);
out.print("\"");
}
//out.println(">"); Bug!
}
public boolean equals(Object ob)
{
if (ob == this) return true;
if (!(ob instanceof DTDAttribute)) return false;
DTDAttribute other = (DTDAttribute) ob;
if (name == null)
{
if (other.name != null) return false;
}
else
{
if (!name.equals(other.name)) return false;
}
if (type == null)
{
if (other.type != null) return false;
}
else
{
if (!type.equals(other.type)) return false;
}
if (decl == null)
{
if (other.decl != null) return false;
}
else
{
if (!decl.equals(other.decl)) return false;
}
if (defaultValue == null)
{
if (other.defaultValue != null) return false;
}
else
{
if (!defaultValue.equals(other.defaultValue)) return false;
}
return true;
}
/** Sets the name of the attribute */
public void setName(String aName)
{
name = aName;
}
/** Returns the attribute name */
public String getName()
{
return name;
}
/** Sets the type of the attribute */
public void setType(Object aType)
{
if (!(aType instanceof String) &&
!(aType instanceof DTDEnumeration) &&
!(aType instanceof DTDNotationList))
{
throw new IllegalArgumentException(
"Must be String, DTDEnumeration or DTDNotationList");
}
type = aType;
}
/** Gets the type of the attribute */
public Object getType()
{
return type;
}
/** Sets the declaration (fixed, required, implied) */
public void setDecl(DTDDecl aDecl)
{
decl = aDecl;
}
/** Returns the declaration */
public DTDDecl getDecl()
{
return decl;
}
/** Sets the default value */
public void setDefaultValue(String aDefaultValue)
{
defaultValue = aDefaultValue;
}
/** Returns the default value */
public String getDefaultValue()
{
return defaultValue;
}
}
|