]> oss.titaniummirror.com Git - msp430-gcc.git/blobdiff - libjava/org/xml/sax/helpers/AttributesImpl.java
Imported gcc-4.4.3
[msp430-gcc.git] / libjava / org / xml / sax / helpers / AttributesImpl.java
diff --git a/libjava/org/xml/sax/helpers/AttributesImpl.java b/libjava/org/xml/sax/helpers/AttributesImpl.java
deleted file mode 100644 (file)
index b714f39..0000000
+++ /dev/null
@@ -1,606 +0,0 @@
-// AttributesImpl.java - default implementation of Attributes.\r
-// Written by David Megginson, sax@megginson.com\r
-// NO WARRANTY!  This class is in the public domain.\r
-\r
-// $Id: AttributesImpl.java,v 1.2 2001/05/31 16:03:17 garyp Exp $\r
-\r
-\r
-package org.xml.sax.helpers;\r
-\r
-import org.xml.sax.Attributes;\r
-\r
-\r
-/**\r
- * Default implementation of the Attributes interface.\r
- *\r
- * <blockquote>\r
- * <em>This module, both source code and documentation, is in the\r
- * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>\r
- * </blockquote>\r
- *\r
- * <p>This class provides a default implementation of the SAX2\r
- * {@link org.xml.sax.Attributes Attributes} interface, with the \r
- * addition of manipulators so that the list can be modified or \r
- * reused.</p>\r
- *\r
- * <p>There are two typical uses of this class:</p>\r
- *\r
- * <ol>\r
- * <li>to take a persistent snapshot of an Attributes object\r
- *  in a {@link org.xml.sax.ContentHandler#startElement startElement} event; or</li>\r
- * <li>to construct or modify an Attributes object in a SAX2 driver or filter.</li>\r
- * </ol>\r
- *\r
- * <p>This class replaces the now-deprecated SAX1 {@link \r
- * org.xml.sax.helpers.AttributeListImpl AttributeListImpl}\r
- * class; in addition to supporting the updated Attributes\r
- * interface rather than the deprecated {@link org.xml.sax.AttributeList\r
- * AttributeList} interface, it also includes a much more efficient \r
- * implementation using a single array rather than a set of Vectors.</p>\r
- *\r
- * @since SAX 2.0\r
- * @author David Megginson, \r
- *         <a href="mailto:sax@megginson.com">sax@megginson.com</a>\r
- * @version 2.0\r
- */\r
-public class AttributesImpl implements Attributes\r
-{\r
-\r
-\f\r
-    ////////////////////////////////////////////////////////////////////\r
-    // Constructors.\r
-    ////////////////////////////////////////////////////////////////////\r
-\r
-\r
-    /**\r
-     * Construct a new, empty AttributesImpl object.\r
-     */\r
-    public AttributesImpl ()\r
-    {\r
-       length = 0;\r
-       data = null;\r
-    }\r
-\r
-\r
-    /**\r
-     * Copy an existing Attributes object.\r
-     *\r
-     * <p>This constructor is especially useful inside a\r
-     * {@link org.xml.sax.ContentHandler#startElement startElement} event.</p>\r
-     *\r
-     * @param atts The existing Attributes object.\r
-     */\r
-    public AttributesImpl (Attributes atts)\r
-    {\r
-       setAttributes(atts);\r
-    }\r
-\r
-\r
-\f\r
-    ////////////////////////////////////////////////////////////////////\r
-    // Implementation of org.xml.sax.Attributes.\r
-    ////////////////////////////////////////////////////////////////////\r
-\r
-\r
-    /**\r
-     * Return the number of attributes in the list.\r
-     *\r
-     * @return The number of attributes in the list.\r
-     * @see org.xml.sax.Attributes#getLength\r
-     */\r
-    public int getLength ()\r
-    {\r
-       return length;\r
-    }\r
-\r
-\r
-    /**\r
-     * Return an attribute's Namespace URI.\r
-     *\r
-     * @param index The attribute's index (zero-based).\r
-     * @return The Namespace URI, the empty string if none is\r
-     *         available, or null if the index is out of range.\r
-     * @see org.xml.sax.Attributes#getURI\r
-     */\r
-    public String getURI (int index)\r
-    {\r
-       if (index >= 0 && index < length) {\r
-           return data[index*5];\r
-       } else {\r
-           return null;\r
-       }\r
-    }\r
-\r
-\r
-    /**\r
-     * Return an attribute's local name.\r
-     *\r
-     * @param index The attribute's index (zero-based).\r
-     * @return The attribute's local name, the empty string if \r
-     *         none is available, or null if the index if out of range.\r
-     * @see org.xml.sax.Attributes#getLocalName\r
-     */\r
-    public String getLocalName (int index)\r
-    {\r
-       if (index >= 0 && index < length) {\r
-           return data[index*5+1];\r
-       } else {\r
-           return null;\r
-       }\r
-    }\r
-\r
-\r
-    /**\r
-     * Return an attribute's qualified (prefixed) name.\r
-     *\r
-     * @param index The attribute's index (zero-based).\r
-     * @return The attribute's qualified name, the empty string if \r
-     *         none is available, or null if the index is out of bounds.\r
-     * @see org.xml.sax.Attributes#getQName\r
-     */\r
-    public String getQName (int index)\r
-    {\r
-       if (index >= 0 && index < length) {\r
-           return data[index*5+2];\r
-       } else {\r
-           return null;\r
-       }\r
-    }\r
-\r
-\r
-    /**\r
-     * Return an attribute's type by index.\r
-     *\r
-     * @param index The attribute's index (zero-based).\r
-     * @return The attribute's type, "CDATA" if the type is unknown, or null\r
-     *         if the index is out of bounds.\r
-     * @see org.xml.sax.Attributes#getType(int)\r
-     */\r
-    public String getType (int index)\r
-    {\r
-       if (index >= 0 && index < length) {\r
-           return data[index*5+3];\r
-       } else {\r
-           return null;\r
-       }\r
-    }\r
-\r
-\r
-    /**\r
-     * Return an attribute's value by index.\r
-     *\r
-     * @param index The attribute's index (zero-based).\r
-     * @return The attribute's value or null if the index is out of bounds.\r
-     * @see org.xml.sax.Attributes#getValue(int)\r
-     */\r
-    public String getValue (int index)\r
-    {\r
-       if (index >= 0 && index < length) {\r
-           return data[index*5+4];\r
-       } else {\r
-           return null;\r
-       }\r
-    }\r
-\r
-\r
-    /**\r
-     * Look up an attribute's index by Namespace name.\r
-     *\r
-     * <p>In many cases, it will be more efficient to look up the name once and\r
-     * use the index query methods rather than using the name query methods\r
-     * repeatedly.</p>\r
-     *\r
-     * @param uri The attribute's Namespace URI, or the empty\r
-     *        string if none is available.\r
-     * @param localName The attribute's local name.\r
-     * @return The attribute's index, or -1 if none matches.\r
-     * @see org.xml.sax.Attributes#getIndex(java.lang.String,java.lang.String)\r
-     */\r
-    public int getIndex (String uri, String localName)\r
-    {\r
-       int max = length * 5;\r
-       for (int i = 0; i < max; i += 5) {\r
-           if (data[i].equals(uri) && data[i+1].equals(localName)) {\r
-               return i / 5;\r
-           }\r
-       } \r
-       return -1;\r
-    }\r
-\r
-\r
-    /**\r
-     * Look up an attribute's index by qualified (prefixed) name.\r
-     *\r
-     * @param qName The qualified name.\r
-     * @return The attribute's index, or -1 if none matches.\r
-     * @see org.xml.sax.Attributes#getIndex(java.lang.String)\r
-     */\r
-    public int getIndex (String qName)\r
-    {\r
-       int max = length * 5;\r
-       for (int i = 0; i < max; i += 5) {\r
-           if (data[i+2].equals(qName)) {\r
-               return i / 5;\r
-           }\r
-       } \r
-       return -1;\r
-    }\r
-\r
-\r
-    /**\r
-     * Look up an attribute's type by Namespace-qualified name.\r
-     *\r
-     * @param uri The Namespace URI, or the empty string for a name\r
-     *        with no explicit Namespace URI.\r
-     * @param localName The local name.\r
-     * @return The attribute's type, or null if there is no\r
-     *         matching attribute.\r
-     * @see org.xml.sax.Attributes#getType(java.lang.String,java.lang.String)\r
-     */\r
-    public String getType (String uri, String localName)\r
-    {\r
-       int max = length * 5;\r
-       for (int i = 0; i < max; i += 5) {\r
-           if (data[i].equals(uri) && data[i+1].equals(localName)) {\r
-               return data[i+3];\r
-           }\r
-       } \r
-       return null;\r
-    }\r
-\r
-\r
-    /**\r
-     * Look up an attribute's type by qualified (prefixed) name.\r
-     *\r
-     * @param qName The qualified name.\r
-     * @return The attribute's type, or null if there is no\r
-     *         matching attribute.\r
-     * @see org.xml.sax.Attributes#getType(java.lang.String)\r
-     */\r
-    public String getType (String qName)\r
-    {\r
-       int max = length * 5;\r
-       for (int i = 0; i < max; i += 5) {\r
-           if (data[i+2].equals(qName)) {\r
-               return data[i+3];\r
-           }\r
-       }\r
-       return null;\r
-    }\r
-\r
-\r
-    /**\r
-     * Look up an attribute's value by Namespace-qualified name.\r
-     *\r
-     * @param uri The Namespace URI, or the empty string for a name\r
-     *        with no explicit Namespace URI.\r
-     * @param localName The local name.\r
-     * @return The attribute's value, or null if there is no\r
-     *         matching attribute.\r
-     * @see org.xml.sax.Attributes#getValue(java.lang.String,java.lang.String)\r
-     */\r
-    public String getValue (String uri, String localName)\r
-    {\r
-       int max = length * 5;\r
-       for (int i = 0; i < max; i += 5) {\r
-           if (data[i].equals(uri) && data[i+1].equals(localName)) {\r
-               return data[i+4];\r
-           }\r
-       }\r
-       return null;\r
-    }\r
-\r
-\r
-    /**\r
-     * Look up an attribute's value by qualified (prefixed) name.\r
-     *\r
-     * @param qName The qualified name.\r
-     * @return The attribute's value, or null if there is no\r
-     *         matching attribute.\r
-     * @see org.xml.sax.Attributes#getValue(java.lang.String)\r
-     */\r
-    public String getValue (String qName)\r
-    {\r
-       int max = length * 5;\r
-       for (int i = 0; i < max; i += 5) {\r
-           if (data[i+2].equals(qName)) {\r
-               return data[i+4];\r
-           }\r
-       }\r
-       return null;\r
-    }\r
-\r
-\r
-\f\r
-    ////////////////////////////////////////////////////////////////////\r
-    // Manipulators.\r
-    ////////////////////////////////////////////////////////////////////\r
-\r
-\r
-    /**\r
-     * Clear the attribute list for reuse.\r
-     *\r
-     * <p>Note that no memory is actually freed by this call:\r
-     * the current arrays are kept so that they can be \r
-     * reused.</p>\r
-     */\r
-    public void clear ()\r
-    {\r
-       length = 0;\r
-    }\r
-\r
-\r
-    /**\r
-     * Copy an entire Attributes object.\r
-     *\r
-     * <p>It may be more efficient to reuse an existing object\r
-     * rather than constantly allocating new ones.</p>\r
-     * \r
-     * @param atts The attributes to copy.\r
-     */\r
-    public void setAttributes (Attributes atts)\r
-    {\r
-       clear();\r
-       length = atts.getLength();\r
-       data = new String[length*5]; \r
-       for (int i = 0; i < length; i++) {\r
-           data[i*5] = atts.getURI(i);\r
-           data[i*5+1] = atts.getLocalName(i);\r
-           data[i*5+2] = atts.getQName(i);\r
-           data[i*5+3] = atts.getType(i);\r
-           data[i*5+4] = atts.getValue(i);\r
-       }\r
-    }\r
-\r
-\r
-    /**\r
-     * Add an attribute to the end of the list.\r
-     *\r
-     * <p>For the sake of speed, this method does no checking\r
-     * to see if the attribute is already in the list: that is\r
-     * the responsibility of the application.</p>\r
-     *\r
-     * @param uri The Namespace URI, or the empty string if\r
-     *        none is available or Namespace processing is not\r
-     *        being performed.\r
-     * @param localName The local name, or the empty string if\r
-     *        Namespace processing is not being performed.\r
-     * @param qName The qualified (prefixed) name, or the empty string\r
-     *        if qualified names are not available.\r
-     * @param type The attribute type as a string.\r
-     * @param value The attribute value.\r
-     */\r
-    public void addAttribute (String uri, String localName, String qName,\r
-                             String type, String value)\r
-    {\r
-       ensureCapacity(length+1);\r
-       data[length*5] = uri;\r
-       data[length*5+1] = localName;\r
-       data[length*5+2] = qName;\r
-       data[length*5+3] = type;\r
-       data[length*5+4] = value;\r
-       length++;\r
-    }\r
-\r
-\r
-    /**\r
-     * Set an attribute in the list.\r
-     *\r
-     * <p>For the sake of speed, this method does no checking\r
-     * for name conflicts or well-formedness: such checks are the\r
-     * responsibility of the application.</p>\r
-     *\r
-     * @param index The index of the attribute (zero-based).\r
-     * @param uri The Namespace URI, or the empty string if\r
-     *        none is available or Namespace processing is not\r
-     *        being performed.\r
-     * @param localName The local name, or the empty string if\r
-     *        Namespace processing is not being performed.\r
-     * @param qName The qualified name, or the empty string\r
-     *        if qualified names are not available.\r
-     * @param type The attribute type as a string.\r
-     * @param value The attribute value.\r
-     * @exception java.lang.ArrayIndexOutOfBoundsException When the\r
-     *            supplied index does not point to an attribute\r
-     *            in the list.\r
-     */\r
-    public void setAttribute (int index, String uri, String localName,\r
-                             String qName, String type, String value)\r
-    {\r
-       if (index >= 0 && index < length) {\r
-           data[index*5] = uri;\r
-           data[index*5+1] = localName;\r
-           data[index*5+2] = qName;\r
-           data[index*5+3] = type;\r
-           data[index*5+4] = value;\r
-       } else {\r
-           badIndex(index);\r
-       }\r
-    }\r
-\r
-\r
-    /**\r
-     * Remove an attribute from the list.\r
-     *\r
-     * @param index The index of the attribute (zero-based).\r
-     * @exception java.lang.ArrayIndexOutOfBoundsException When the\r
-     *            supplied index does not point to an attribute\r
-     *            in the list.\r
-     */\r
-    public void removeAttribute (int index)\r
-    {\r
-       if (index >= 0 && index < length) {\r
-           data[index*5] = null;\r
-           data[index*5+1] = null;\r
-           data[index*5+2] = null;\r
-           data[index*5+3] = null;\r
-           data[index*5+4] = null;\r
-           if (index < length - 1) {\r
-               System.arraycopy(data, (index+1)*5, data, index*5,\r
-                                (length-index-1)*5);\r
-           }\r
-           length--;\r
-       } else {\r
-           badIndex(index);\r
-       }\r
-    }\r
-\r
-\r
-    /**\r
-     * Set the Namespace URI of a specific attribute.\r
-     *\r
-     * @param index The index of the attribute (zero-based).\r
-     * @param uri The attribute's Namespace URI, or the empty\r
-     *        string for none.\r
-     * @exception java.lang.ArrayIndexOutOfBoundsException When the\r
-     *            supplied index does not point to an attribute\r
-     *            in the list.\r
-     */\r
-    public void setURI (int index, String uri)\r
-    {\r
-       if (index >= 0 && index < length) {\r
-           data[index*5] = uri;\r
-       } else {\r
-           badIndex(index);\r
-       }\r
-    }\r
-\r
-\r
-    /**\r
-     * Set the local name of a specific attribute.\r
-     *\r
-     * @param index The index of the attribute (zero-based).\r
-     * @param localName The attribute's local name, or the empty\r
-     *        string for none.\r
-     * @exception java.lang.ArrayIndexOutOfBoundsException When the\r
-     *            supplied index does not point to an attribute\r
-     *            in the list.\r
-     */\r
-    public void setLocalName (int index, String localName)\r
-    {\r
-       if (index >= 0 && index < length) {\r
-           data[index*5+1] = localName;\r
-       } else {\r
-           badIndex(index);\r
-       }\r
-    }\r
-\r
-\r
-    /**\r
-     * Set the qualified name of a specific attribute.\r
-     *\r
-     * @param index The index of the attribute (zero-based).\r
-     * @param qName The attribute's qualified name, or the empty\r
-     *        string for none.\r
-     * @exception java.lang.ArrayIndexOutOfBoundsException When the\r
-     *            supplied index does not point to an attribute\r
-     *            in the list.\r
-     */\r
-    public void setQName (int index, String qName)\r
-    {\r
-       if (index >= 0 && index < length) {\r
-           data[index*5+2] = qName;\r
-       } else {\r
-           badIndex(index);\r
-       }\r
-    }\r
-\r
-\r
-    /**\r
-     * Set the type of a specific attribute.\r
-     *\r
-     * @param index The index of the attribute (zero-based).\r
-     * @param type The attribute's type.\r
-     * @exception java.lang.ArrayIndexOutOfBoundsException When the\r
-     *            supplied index does not point to an attribute\r
-     *            in the list.\r
-     */\r
-    public void setType (int index, String type)\r
-    {\r
-       if (index >= 0 && index < length) {\r
-           data[index*5+3] = type;\r
-       } else {\r
-           badIndex(index);\r
-       }\r
-    }\r
-\r
-\r
-    /**\r
-     * Set the value of a specific attribute.\r
-     *\r
-     * @param index The index of the attribute (zero-based).\r
-     * @param value The attribute's value.\r
-     * @exception java.lang.ArrayIndexOutOfBoundsException When the\r
-     *            supplied index does not point to an attribute\r
-     *            in the list.\r
-     */\r
-    public void setValue (int index, String value)\r
-    {\r
-       if (index >= 0 && index < length) {\r
-           data[index*5+4] = value;\r
-       } else {\r
-           badIndex(index);\r
-       }\r
-    }\r
-\r
-\r
-\f\r
-    ////////////////////////////////////////////////////////////////////\r
-    // Internal methods.\r
-    ////////////////////////////////////////////////////////////////////\r
-\r
-\r
-    /**\r
-     * Ensure the internal array's capacity.\r
-     *\r
-     * @param n The minimum number of attributes that the array must\r
-     *        be able to hold.\r
-     */\r
-    private void ensureCapacity (int n)\r
-    {\r
-       if (n > 0 && data == null) {\r
-           data = new String[25];\r
-       }\r
-\r
-       int max = data.length;\r
-       if (max >= n * 5) {\r
-           return;\r
-       }\r
-\r
-\r
-       while (max < n * 5) {\r
-           max *= 2;\r
-       }\r
-       String newData[] = new String[max];\r
-       System.arraycopy(data, 0, newData, 0, length*5);\r
-       data = newData;\r
-    }\r
-\r
-\r
-    /**\r
-     * Report a bad array index in a manipulator.\r
-     *\r
-     * @param index The index to report.\r
-     * @exception java.lang.ArrayIndexOutOfBoundsException Always.\r
-     */\r
-    private void badIndex (int index)\r
-       throws ArrayIndexOutOfBoundsException\r
-    {\r
-       String msg =\r
-           "Attempt to modify attribute at illegal index: " + index;\r
-       throw new ArrayIndexOutOfBoundsException(msg);\r
-    }\r
-\r
-\r
-\f\r
-    ////////////////////////////////////////////////////////////////////\r
-    // Internal state.\r
-    ////////////////////////////////////////////////////////////////////\r
-\r
-    int length;\r
-    String data [];\r
-\r
-}\r
-\r
-// end of AttributesImpl.java\r
-\r