FileDocCategorySizeDatePackage
AttributeList.javaAPI DocJava SE 6 API5441Tue Jun 10 00:22:32 BST 2008com.sun.org.apache.xalan.internal.xsltc.runtime

AttributeList

public class AttributeList extends Object implements Attributes
author
Morten Jorgensen

Fields Summary
private static final String
EMPTYSTRING
private static final String
CDATASTRING
private Hashtable
_attributes
private Vector
_names
private Vector
_qnames
private Vector
_values
private Vector
_uris
private int
_length
Constructors Summary
public AttributeList()
AttributeList constructor


           
      
	/*
	_attributes = new Hashtable();
	_names  = new Vector();
	_values = new Vector();
	_qnames = new Vector();
	_uris   = new Vector();
	*/
	_length = 0;
    
public AttributeList(Attributes attributes)
Attributes clone constructor

	this();
	if (attributes != null) {
	    final int count = attributes.getLength();
	    for (int i = 0; i < count; i++) {
		add(attributes.getQName(i),attributes.getValue(i));
	    }
	}
    
Methods Summary
public voidadd(java.lang.String qname, java.lang.String value)
Adds an attribute to the list

	// Initialize the internal vectors at the first usage.
	if (_attributes == null)
	    alloc();
	
	// Stuff the QName into the names vector & hashtable
	Integer obj = (Integer)_attributes.get(qname);
	if (obj == null) {
	    _attributes.put(qname, obj = new Integer(_length++));
	    _qnames.addElement(qname);
	    _values.addElement(value);
	    int col = qname.lastIndexOf(':");
	    if (col > -1) {
		_uris.addElement(qname.substring(0,col));
		_names.addElement(qname.substring(col+1));
	    }
	    else {
		_uris.addElement(EMPTYSTRING);
		_names.addElement(qname);
	    }
	}
	else {
	    final int index = obj.intValue();
	    _values.set(index, value);
	}
    
private voidalloc()
Allocate memory for the AttributeList %OPT% Use on-demand allocation for the internal vectors. The memory is only allocated when there is an attribute. This reduces the cost of creating many small RTFs.

	_attributes = new Hashtable();
	_names  = new Vector();
	_values = new Vector();
	_qnames = new Vector();
	_uris   = new Vector();        
    
public voidclear()
Clears the attribute list

	_length = 0;
	if (_attributes != null) {
	    _attributes.clear();
	    _names.removeAllElements();
	    _values.removeAllElements();
	    _qnames.removeAllElements();
	    _uris.removeAllElements();
	}
    
public intgetIndex(java.lang.String qname)
SAX2: Look up the index of an attribute by XML 1.0 qualified name.

	return(-1);
    
public intgetIndex(java.lang.String namespaceURI, java.lang.String localPart)
SAX2: Look up the index of an attribute by Namespace name.

	return(-1);
    
public intgetLength()
SAX2: Return the number of attributes in the list.

	return(_length);
    
public java.lang.StringgetLocalName(int index)
SAX2: Look up an attribute's local name by index.

	if (index < _length)
	    return((String)_names.elementAt(index));
	else
	    return(null);
    
public java.lang.StringgetQName(int pos)
Return the name of an attribute in this list (by position).

	if (pos < _length)
	    return((String)_qnames.elementAt(pos));
	else
	    return(null);
    
public java.lang.StringgetType(java.lang.String uri, java.lang.String localName)
SAX2: Look up an attribute's type by Namespace name.

	return(CDATASTRING);
    
public java.lang.StringgetType(java.lang.String qname)
SAX2: Look up an attribute's type by qname.

	return(CDATASTRING);
    
public java.lang.StringgetType(int index)
SAX2: Look up an attribute's type by index.

	return(CDATASTRING);
    
public java.lang.StringgetURI(int index)
SAX2: Look up an attribute's Namespace URI by index.

	if (index < _length)
	    return((String)_uris.elementAt(index));
	else
	    return(null);
    
public java.lang.StringgetValue(int pos)
SAX2: Look up an attribute's value by index.

	if (pos < _length)
	    return((String)_values.elementAt(pos));
	else
	    return(null);
    
public java.lang.StringgetValue(java.lang.String qname)
SAX2: Look up an attribute's value by qname.

	if (_attributes != null) {
	    final Integer obj = (Integer)_attributes.get(qname);
	    if (obj == null) return null;
	    return(getValue(obj.intValue()));
	}
	else
	    return null;
    
public java.lang.StringgetValue(java.lang.String uri, java.lang.String localName)
SAX2: Look up an attribute's value by Namespace name - SLOW!

	return(getValue(uri+':"+localName));