FileDocCategorySizeDatePackage
AttributesImpl.javaAPI DocApache Xerces 3.0.110294Fri Sep 14 20:33:58 BST 2007sax.helpers

AttributesImpl

public class AttributesImpl extends Object implements Attributes
An Attributes implementation that can perform more operations than the attribute list helper supplied with the standard SAX2 distribution.

Fields Summary
private ListNode
head
Head node.
private ListNode
tail
Tail node.
private int
length
Length.
Constructors Summary
Methods Summary
public voidaddAttribute(java.lang.String raw, java.lang.String type, java.lang.String value)
Adds an attribute.

        addAttribute(null, null, raw, type, value);
    
public voidaddAttribute(java.lang.String uri, java.lang.String local, java.lang.String raw, java.lang.String type, java.lang.String value)
Adds an attribute.


        ListNode node = new ListNode(uri, local, raw, type, value);
        if (length == 0) {
            head = node;
        }
        else {
            tail.next = node;
        }
        tail = node;
        length++;

    
public intgetIndex(java.lang.String raw)
Returns the index of the specified attribute.

        ListNode place = head;
        int index = 0;
        while (place != null) {
            if (place.raw.equals(raw)) {
                return index;
            }
            index++;
            place = place.next;
        }
        return -1;
    
public intgetIndex(java.lang.String uri, java.lang.String local)
Returns the index of the specified attribute.

        ListNode place = head;
        int index = 0;
        while (place != null) {
            if (place.uri.equals(uri) && place.local.equals(local)) {
                return index;
            }
            index++;
            place = place.next;
        }
        return -1;
    
public intgetLength()
Returns the number of attributes.

        return length;
    
public sax.helpers.AttributesImpl$ListNodegetListNode(java.lang.String uri, java.lang.String local)
Returns the first node with the specified uri and local.


        if (uri != null && local != null) {
            ListNode place = head;
            while (place != null) {
                if (place.uri != null && place.local != null &&
                    place.uri.equals(uri) && place.local.equals(local)) {
                    return place;
                }
                place = place.next;
            }
        }
        return null;

    
private sax.helpers.AttributesImpl$ListNodegetListNode(java.lang.String raw)
Returns the first node with the specified raw name.


        if (raw != null) {
            for (ListNode place = head; place != null; place = place.next) {
                if (place.raw != null && place.raw.equals(raw)) {
                    return place;
                }
            }
        }

        return null;

    
private sax.helpers.AttributesImpl$ListNodegetListNodeAt(int i)
Returns the node at the specified index.


        for (ListNode place = head; place != null; place = place.next) {
            if (--i == -1) {
                return place;
            }
        }

        return null;

    
public java.lang.StringgetLocalName(int index)
Returns the attribute local name by index.


        ListNode node = getListNodeAt(index);
        return node != null ? node.local : null;

    
public java.lang.StringgetQName(int index)
Returns the attribute raw name by index.


        ListNode node = getListNodeAt(index);
        return node != null ? node.raw : null;

    
public java.lang.StringgetType(int index)
Returns the attribute type by index.


        ListNode node = getListNodeAt(index);
        return (node != null) ? node.type : null;

    
public java.lang.StringgetType(java.lang.String uri, java.lang.String local)
Returns the attribute type by uri and local.


        ListNode node = getListNode(uri, local);
        return (node != null) ? node.type : null;

    
public java.lang.StringgetType(java.lang.String raw)
Returns the attribute type by raw name.


        ListNode node = getListNode(raw);
        return (node != null) ? node.type : null;

    
public java.lang.StringgetURI(int index)
Returns the attribute URI by index.


        ListNode node = getListNodeAt(index);
        return node != null ? node.uri : null;

    
public java.lang.StringgetValue(int index)
Returns the attribute value by index.


        ListNode node = getListNodeAt(index);
        return (node != null) ? node.value : null;

    
public java.lang.StringgetValue(java.lang.String uri, java.lang.String local)
Returns the attribute value by uri and local.


        ListNode node = getListNode(uri, local);
        return (node != null) ? node.value : null;

    
public java.lang.StringgetValue(java.lang.String raw)
Returns the attribute value by raw name.


        ListNode node = getListNode(raw);
        return (node != null) ? node.value : null;

    
public voidinsertAttributeAt(int index, java.lang.String raw, java.lang.String type, java.lang.String value)
Inserts an attribute.

        insertAttributeAt(index, null, null, raw, type, value);
    
public voidinsertAttributeAt(int index, java.lang.String uri, java.lang.String local, java.lang.String raw, java.lang.String type, java.lang.String value)
Inserts an attribute.


        // if list is empty, add attribute
        if (length == 0 || index >= length) {
            addAttribute(uri, local, raw, type, value);
            return;
        }

        // insert at beginning of list
        ListNode node = new ListNode(uri, local, raw, type, value);
        if (index < 1) {
            node.next = head;
            head = node;
        }
        else {
            ListNode prev = getListNodeAt(index - 1);
            node.next = prev.next;
            prev.next = node;
        }
        length++;

    
public voidremoveAttribute(java.lang.String raw)
Removes the specified attribute.

        removeAttributeAt(getIndex(raw));
    
public voidremoveAttribute(java.lang.String uri, java.lang.String local)
Removes the specified attribute.

        removeAttributeAt(getIndex(uri, local));
    
public voidremoveAttributeAt(int index)
Removes an attribute.


        if (length == 0) {
            return;
        }

        if (index == 0) {
            head = head.next;
            if (head == null) {
                tail = null;
            }
            length--;
        }
        else {
            ListNode prev = getListNodeAt(index - 1);
            ListNode node = getListNodeAt(index);
            if (node != null) {
                prev.next = node.next;
                if (node == tail) {
                    tail = prev;
                }
                length--;
            }
        }

    
public java.lang.StringtoString()
Returns a string representation of this object.

        StringBuffer str = new StringBuffer();

        str.append('[");
        str.append("len=");
        str.append(length);
        str.append(", {");
        for (ListNode place = head; place != null; place = place.next) {
            str.append(place.toString());
            if (place.next != null) {
                str.append(", ");
            }
        }
        str.append("}]");

        return str.toString();