jdk/src/share/classes/javax/swing/text/html/parser/AttributeList.java
author darcy
Sun, 23 Mar 2014 13:49:48 -0700
changeset 23697 e556a715949f
parent 5506 202f599c92aa
child 24494 67129b9360d2
permissions -rw-r--r--
8034169: Fix serial lint warnings in javax.swing Reviewed-by: alanb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 5506
diff changeset
     2
 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.text.html.parser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * This class defines the attributes of an SGML element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * as described in a DTD using the ATTLIST construct.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * An AttributeList can be obtained from the Element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * class using the getAttributes() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * It is actually an element in a linked list. Use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * getNext() method repeatedly to enumerate all the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * of an element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @see         Element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author      Arthur Van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 5506
diff changeset
    47
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public final
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
class AttributeList implements DTDConstants, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public Vector<?> values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public int modifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public String value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public AttributeList next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    AttributeList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Create an attribute list element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public AttributeList(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Create an attribute list element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public AttributeList(String name, int type, int modifier, String value, Vector<?> values, AttributeList next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        this.modifier = modifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        this.values = values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        this.next = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @return attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @return attribute type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @see DTDConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @return attribute modifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @see DTDConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public int getModifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return modifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @return possible attribute values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public Enumeration<?> getValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return (values != null) ? values.elements() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @return default attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public String getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @return the next attribute in the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public AttributeList getNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @return string representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Create a hashtable of attribute types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   133
    static Hashtable<Object, Object> attributeTypes = new Hashtable<Object, Object>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    static void defineAttributeType(String nm, int val) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   136
        Integer num = Integer.valueOf(val);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        attributeTypes.put(nm, num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        attributeTypes.put(num, nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        defineAttributeType("CDATA", CDATA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        defineAttributeType("ENTITY", ENTITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        defineAttributeType("ENTITIES", ENTITIES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        defineAttributeType("ID", ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        defineAttributeType("IDREF", IDREF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        defineAttributeType("IDREFS", IDREFS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        defineAttributeType("NAME", NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        defineAttributeType("NAMES", NAMES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        defineAttributeType("NMTOKEN", NMTOKEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        defineAttributeType("NMTOKENS", NMTOKENS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        defineAttributeType("NOTATION", NOTATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        defineAttributeType("NUMBER", NUMBER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        defineAttributeType("NUMBERS", NUMBERS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        defineAttributeType("NUTOKEN", NUTOKEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        defineAttributeType("NUTOKENS", NUTOKENS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   158
        attributeTypes.put("fixed", Integer.valueOf(FIXED));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   159
        attributeTypes.put("required", Integer.valueOf(REQUIRED));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   160
        attributeTypes.put("current", Integer.valueOf(CURRENT));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   161
        attributeTypes.put("conref", Integer.valueOf(CONREF));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   162
        attributeTypes.put("implied", Integer.valueOf(IMPLIED));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public static int name2type(String nm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        Integer i = (Integer)attributeTypes.get(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return (i == null) ? CDATA : i.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public static String type2name(int tp) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   171
        return (String)attributeTypes.get(Integer.valueOf(tp));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
}