jaxp/src/share/classes/org/xml/sax/ext/Attributes2Impl.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 6 7f561c08de6b
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * Copyright 2004-2005 Sun Microsystems, Inc.  All Rights Reserved.
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
 * have any questions.
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
// Attributes2Impl.java - extended AttributesImpl
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
// http://www.saxproject.org
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
// Public Domain: no warranty.
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
// $Id: Attributes2Impl.java,v 1.3 2005/02/24 11:20:18 gg156739 Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
package org.xml.sax.ext;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import org.xml.sax.Attributes;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import org.xml.sax.helpers.AttributesImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * SAX2 extension helper for additional Attributes information,
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 * implementing the {@link Attributes2} interface.
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * <blockquote>
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * <em>This module, both source code and documentation, is in the
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 * </blockquote>
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * <p>This is not part of core-only SAX2 distributions.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * <p>The <em>specified</em> flag for each attribute will always
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 * be true, unless it has been set to false in the copy constructor
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
 * or using {@link #setSpecified}.
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 * Similarly, the <em>declared</em> flag for each attribute will
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 * always be false, except for defaulted attributes (<em>specified</em>
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 * is false), non-CDATA attributes, or when it is set to true using
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 * {@link #setDeclared}.
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 * If you change an attribute's type by hand, you may need to modify
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 * its <em>declared</em> flag to match.
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 * </p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 * @since SAX 2.0 (extensions 1.1 alpha)
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
 * @author David Brownell
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
public class Attributes2Impl extends AttributesImpl implements Attributes2
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
    private boolean     declared [];
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
    private boolean     specified [];
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
     * Construct a new, empty Attributes2Impl object.
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
    public Attributes2Impl () {
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
        specified = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
        declared = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
     * Copy an existing Attributes or Attributes2 object.
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
     * If the object implements Attributes2, values of the
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
     * <em>specified</em> and <em>declared</em> flags for each
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
     * attribute are copied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
     * Otherwise the flag values are defaulted to assume no DTD was used,
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
     * unless there is evidence to the contrary (such as attributes with
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
     * type other than CDATA, which must have been <em>declared</em>).
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
     * <p>This constructor is especially useful inside a
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
     * {@link org.xml.sax.ContentHandler#startElement startElement} event.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
     * @param atts The existing Attributes object.
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
    public Attributes2Impl (Attributes atts)
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
        super (atts);
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
    ////////////////////////////////////////////////////////////////////
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
    // Implementation of Attributes2
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
    ////////////////////////////////////////////////////////////////////
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
     * Returns the current value of the attribute's "declared" flag.
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    // javadoc mostly from interface
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
    public boolean isDeclared (int index)
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
        if (index < 0 || index >= getLength ())
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
            throw new ArrayIndexOutOfBoundsException (
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
                "No attribute at index: " + index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
        return declared [index];
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
     * Returns the current value of the attribute's "declared" flag.
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
    // javadoc mostly from interface
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    public boolean isDeclared (String uri, String localName)
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
        int index = getIndex (uri, localName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
        if (index < 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
            throw new IllegalArgumentException (
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
                "No such attribute: local=" + localName
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
                + ", namespace=" + uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
        return declared [index];
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
     * Returns the current value of the attribute's "declared" flag.
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
    // javadoc mostly from interface
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
    public boolean isDeclared (String qName)
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
        int index = getIndex (qName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
        if (index < 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
            throw new IllegalArgumentException (
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
                "No such attribute: " + qName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
        return declared [index];
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
     * Returns the current value of an attribute's "specified" flag.
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
     * @param index The attribute index (zero-based).
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
     * @return current flag value
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
     * @exception java.lang.ArrayIndexOutOfBoundsException When the
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
     *            supplied index does not identify an attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
    public boolean isSpecified (int index)
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
        if (index < 0 || index >= getLength ())
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
            throw new ArrayIndexOutOfBoundsException (
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
                "No attribute at index: " + index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
        return specified [index];
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
     * Returns the current value of an attribute's "specified" flag.
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
     * @param uri The Namespace URI, or the empty string if
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
     *        the name has no Namespace URI.
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
     * @param localName The attribute's local name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
     * @return current flag value
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
     * @exception java.lang.IllegalArgumentException When the
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
     *            supplied names do not identify an attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
    public boolean isSpecified (String uri, String localName)
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
        int index = getIndex (uri, localName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
        if (index < 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
            throw new IllegalArgumentException (
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
                "No such attribute: local=" + localName
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
                + ", namespace=" + uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
        return specified [index];
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
     * Returns the current value of an attribute's "specified" flag.
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
     * @param qName The XML qualified (prefixed) name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
     * @return current flag value
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
     * @exception java.lang.IllegalArgumentException When the
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
     *            supplied name does not identify an attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    public boolean isSpecified (String qName)
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
        int index = getIndex (qName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
        if (index < 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
            throw new IllegalArgumentException (
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
                "No such attribute: " + qName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
        return specified [index];
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
    ////////////////////////////////////////////////////////////////////
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
    // Manipulators
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
    ////////////////////////////////////////////////////////////////////
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
     * Copy an entire Attributes object.  The "specified" flags are
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
     * assigned as true, and "declared" flags as false (except when
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
     * an attribute's type is not CDATA),
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
     * unless the object is an Attributes2 object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
     * In that case those flag values are all copied.
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
     * @see AttributesImpl#setAttributes
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
    public void setAttributes (Attributes atts)
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
        int length = atts.getLength ();
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
        super.setAttributes (atts);
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
        declared = new boolean [length];
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
        specified = new boolean [length];
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
        if (atts instanceof Attributes2) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
            Attributes2 a2 = (Attributes2) atts;
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
            for (int i = 0; i < length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
                declared [i] = a2.isDeclared (i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
                specified [i] = a2.isSpecified (i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
            for (int i = 0; i < length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
                declared [i] = !"CDATA".equals (atts.getType (i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
                specified [i] = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
     * Add an attribute to the end of the list, setting its
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
     * "specified" flag to true.  To set that flag's value
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
     * to false, use {@link #setSpecified}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
     * <p>Unless the attribute <em>type</em> is CDATA, this attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
     * is marked as being declared in the DTD.  To set that flag's value
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
     * to true for CDATA attributes, use {@link #setDeclared}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
     * @see AttributesImpl#addAttribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
    public void addAttribute (String uri, String localName, String qName,
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
                              String type, String value)
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
        super.addAttribute (uri, localName, qName, type, value);
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
        int length = getLength ();
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
        if(specified==null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
            specified = new boolean[length];
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
            declared = new boolean[length];
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
        } else if (length > specified.length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
            boolean     newFlags [];
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
            newFlags = new boolean [length];
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
            System.arraycopy (declared, 0, newFlags, 0, declared.length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
            declared = newFlags;
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
            newFlags = new boolean [length];
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
            System.arraycopy (specified, 0, newFlags, 0, specified.length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
            specified = newFlags;
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
        specified [length - 1] = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
        declared [length - 1] = !"CDATA".equals (type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
    // javadoc entirely from superclass
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
    public void removeAttribute (int index)
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
        int origMax = getLength () - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
        super.removeAttribute (index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
        if (index != origMax) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
            System.arraycopy (declared, index + 1, declared, index,
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
                    origMax - index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
            System.arraycopy (specified, index + 1, specified, index,
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
                    origMax - index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
     * Assign a value to the "declared" flag of a specific attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
     * This is normally needed only for attributes of type CDATA,
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
     * including attributes whose type is changed to or from CDATA.
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
     * @param index The index of the attribute (zero-based).
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
     * @param value The desired flag value.
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
     * @exception java.lang.ArrayIndexOutOfBoundsException When the
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
     *            supplied index does not identify an attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
     * @see #setType
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
    public void setDeclared (int index, boolean value)
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
        if (index < 0 || index >= getLength ())
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
            throw new ArrayIndexOutOfBoundsException (
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
                "No attribute at index: " + index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
        declared [index] = value;
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
     * Assign a value to the "specified" flag of a specific attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
     * This is the only way this flag can be cleared, except clearing
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
     * by initialization with the copy constructor.
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
     * @param index The index of the attribute (zero-based).
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
     * @param value The desired flag value.
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
     * @exception java.lang.ArrayIndexOutOfBoundsException When the
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
     *            supplied index does not identify an attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
    public void setSpecified (int index, boolean value)
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
        if (index < 0 || index >= getLength ())
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
            throw new ArrayIndexOutOfBoundsException (
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
                "No attribute at index: " + index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
        specified [index] = value;
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
}