1
23package org.jzuul.dtdparser;
24
25import java.util.ArrayList;
26import java.util.List;
27
28
29
37public class DTDAttribute extends DTDEntry {
38 public static final int CDATA = 2;
39 public static final int ENUMERATION = 4;
40
41 public static final int REQUIRED = 10;
42 public static final int IMPLIED = 20;
43 public static final int FIXED = 30;
44
45 protected DTDElement element;
46 protected int type;
47 protected List enumValues;
48 protected String defaultValue;
49 protected int flag;
50 protected String elementName;
51
52 public DTDAttribute(String name) {
53 super(name);
54 type = ENUMERATION;
55 enumValues = new ArrayList();
56 }
57
58 public String getDefaultValue() {
59 return defaultValue;
60 }
61
62 public List getEnumeration() {
63 return enumValues;
64 }
65
66 public int getType() {
67 return type;
68 }
69
70 public void setType(int type) {
71 this.type = type;
72 }
73
74 public void assignElement(DTDElement e) {
75 if (e == null) throw new IllegalArgumentException("DTDElement must not be null");
76 element = e;
77 element.addAttribute(this);
78 }
79
80 public boolean hasDefaultValue() {
81 return (defaultValue != null);
82 }
83
84 public void addEnumValue(String value) {
85 enumValues.add(value);
86 }
87
88 public DTDElement getElement() {
89 return this.element;
90 }
91
92 public void setDefaultValue(String defaultValue) {
93 this.defaultValue = defaultValue;
94 }
95
96 protected void setFlag(String flag) {
97 if (flag.equalsIgnoreCase("#REQUIRED")) setFlag(REQUIRED);
98 if (flag.equalsIgnoreCase("#IMPLIED")) setFlag(IMPLIED);
99 if (flag.equalsIgnoreCase("#FIXED")) setFlag(FIXED);
00 }
01
02 public void setFlag(int flag) {
03 this.flag = flag;
04 }
05
06 public int getFlag() {
07 return this.flag;
08 }
09
10 public String toString(int indent) {
11 String retval = "";
12 for (int i=0; i <= indent; i++) retval += " ";
13 retval += " :" + getName();
14 if (this.hasDefaultValue()) retval += "=" + getDefaultValue();
15 if (this.getType() == CDATA) {
16 retval += " CDATA";
17 }
18 if (this.getType() == ENUMERATION) {
19 retval += " ENUMERATION";
20 }
21 if (this.getFlag() == REQUIRED) {
22 retval += " REQUIRED";
23 }
24 if (this.getFlag() == IMPLIED) {
25 retval += " IMPLIED";
26 }
27 if (this.getFlag() == FIXED) {
28 retval += " FIXED";
29 }
30
31
32 retval += "\n";
33
34 return retval;
35 }
36
37 public String getElementName() {
38 return this.elementName;
39 }
40
41 public void setElementName(String name) {
42 this.elementName = name;
43 }
44
45}
46