KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > text > html > parser > AttributeList


1 /*
2  * @(#)AttributeList.java 1.11 04/05/05
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.swing.text.html.parser;
9
10 import java.util.Vector JavaDoc;
11 import java.util.Hashtable JavaDoc;
12 import java.util.Enumeration JavaDoc;
13 import java.io.*;
14
15 /**
16  * This class defines the attributes of an SGML element
17  * as described in a DTD using the ATTLIST construct.
18  * An AttributeList can be obtained from the Element
19  * class using the getAttributes() method.
20  * <p>
21  * It is actually an element in a linked list. Use the
22  * getNext() method repeatedly to enumerate all the attributes
23  * of an element.
24  *
25  * @see Element
26  * @author Arthur Van Hoff
27  * @version 1.11 05/05/04
28  *
29  */

30 public final
31 class AttributeList implements DTDConstants JavaDoc, Serializable {
32     public String JavaDoc name;
33     public int type;
34     public Vector JavaDoc<?> values;
35     public int modifier;
36     public String JavaDoc value;
37     public AttributeList JavaDoc next;
38
39     AttributeList() {
40     }
41
42     /**
43      * Create an attribute list element.
44      */

45     public AttributeList(String JavaDoc name) {
46     this.name = name;
47     }
48
49     /**
50      * Create an attribute list element.
51      */

52     public AttributeList(String JavaDoc name, int type, int modifier, String JavaDoc value, Vector JavaDoc<?> values, AttributeList JavaDoc next) {
53     this.name = name;
54     this.type = type;
55     this.modifier = modifier;
56     this.value = value;
57     this.values = values;
58     this.next = next;
59     }
60
61     /**
62      * @return attribute name
63      */

64     public String JavaDoc getName() {
65     return name;
66     }
67
68     /**
69      * @return attribute type
70      * @see DTDConstants
71      */

72     public int getType() {
73     return type;
74     }
75
76     /**
77      * @return attribute modifier
78      * @see DTDConstants
79      */

80     public int getModifier() {
81     return modifier;
82     }
83
84     /**
85      * @return possible attribute values
86      */

87     public Enumeration JavaDoc<?> getValues() {
88     return (values != null) ? values.elements() : null;
89     }
90
91     /**
92      * @return default attribute value
93      */

94     public String JavaDoc getValue() {
95     return value;
96     }
97
98     /**
99      * @return the next attribute in the list
100      */

101     public AttributeList JavaDoc getNext() {
102     return next;
103     }
104
105     /**
106      * @return string representation
107      */

108     public String JavaDoc toString() {
109     return name;
110     }
111
112     /**
113      * Create a hashtable of attribute types.
114      */

115     static Hashtable JavaDoc attributeTypes = new Hashtable JavaDoc();
116
117     static void defineAttributeType(String JavaDoc nm, int val) {
118     Integer JavaDoc num = new Integer JavaDoc(val);
119     attributeTypes.put(nm, num);
120     attributeTypes.put(num, nm);
121     }
122
123     static {
124     defineAttributeType("CDATA", CDATA);
125     defineAttributeType("ENTITY", ENTITY);
126     defineAttributeType("ENTITIES", ENTITIES);
127     defineAttributeType("ID", ID);
128     defineAttributeType("IDREF", IDREF);
129     defineAttributeType("IDREFS", IDREFS);
130     defineAttributeType("NAME", NAME);
131     defineAttributeType("NAMES", NAMES);
132     defineAttributeType("NMTOKEN", NMTOKEN);
133     defineAttributeType("NMTOKENS", NMTOKENS);
134     defineAttributeType("NOTATION", NOTATION);
135     defineAttributeType("NUMBER", NUMBER);
136     defineAttributeType("NUMBERS", NUMBERS);
137     defineAttributeType("NUTOKEN", NUTOKEN);
138     defineAttributeType("NUTOKENS", NUTOKENS);
139
140     attributeTypes.put("fixed", new Integer JavaDoc(FIXED));
141     attributeTypes.put("required", new Integer JavaDoc(REQUIRED));
142     attributeTypes.put("current", new Integer JavaDoc(CURRENT));
143     attributeTypes.put("conref", new Integer JavaDoc(CONREF));
144     attributeTypes.put("implied", new Integer JavaDoc(IMPLIED));
145     }
146
147     public static int name2type(String JavaDoc nm) {
148     Integer JavaDoc i = (Integer JavaDoc)attributeTypes.get(nm);
149     return (i == null) ? CDATA : i.intValue();
150     }
151
152     public static String JavaDoc type2name(int tp) {
153     return (String JavaDoc)attributeTypes.get(new Integer JavaDoc(tp));
154     }
155 }
156
Popular Tags