1 /*
2  *  CVS: $Id: DTDAttribute.java,v 1.5 2004/07/16 16:22:34 marcus Exp $
3  * 
4  *  This file is part of zuul.
5  *
6  *  zuul is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10 *
11 *  zuul is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with zuul; if not, write to the Free Software
18 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 * 
20 *  Copyrigth 2004 by marcus, leh
21 * 
22 */
23package org.jzuul.dtdparser;
24
25import java.util.ArrayList;
26import java.util.List;
27
28
29/**
30 * TODO Document new class
31 * 
32 * Created on Jun 7, 2004
33 * 
34 * 
35 * @version $Revision: 1.5 $
36 */
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