/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2003-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: AttributesImplSerializer.java,v 1.2.4.1 2005/09/15 08:15:14 suresh_emailid Exp $
*/
/**
* This class extends org.xml.sax.helpers.AttributesImpl which implements org.
* xml.sax.Attributes. But for optimization this class adds a Hashtable for
* faster lookup of an index by qName, which is commonly done in the stream
* serializer.
*
* @see org.xml.sax.Attributes
*
* @xsl.usage internal
*/
{
/**
* of an attributes qName. qNames are in uppercase in the hash table
* to make the search case insensitive.
*
* The keys to the hashtable to find the index are either
* "prefix:localName" or "{uri}localName".
*/
/**
* This is the number of attributes before switching to the hash table,
* and can be tuned, but 12 seems good for now - Brian M.
*/
/**
* One less than the number of attributes before switching to
* the Hashtable.
*/
/**
* This method gets the index of an attribute given its qName.
* @param qname the qualified name of the attribute, e.g. "prefix1:locName1"
* @return the integer index of the attribute.
* @see org.xml.sax.Attributes#getIndex(String)
*/
{
int index;
{
// if we haven't got too many attributes let the
// super class look it up
return index;
}
// we have too many attributes and the super class is slow
// so find it quickly using our Hashtable.
if (i == null)
index = -1;
else
return index;
}
/**
* the hashtable for fast lookup by getIndex(qName).
* @param uri the URI of the attribute
* @param local the local name of the attribute
* @param qname the qualified name of the attribute
* @param type the type of the attribute
* @param val the value of the attribute
*
* @see org.xml.sax.helpers.AttributesImpl#addAttribute(String, String, String, String, String)
* @see #getIndex(String)
*/
public final void addAttribute(
{
// (index + 1) is now the number of attributes
// so either compare (index+1) to MAX, or compare index to (MAX-1)
{
return;
}
{
}
else
{
/* add the key with the format of "prefix:localName" */
/* we have just added the attibute, its index is the old length */
/* now add with key of the format "{uri}localName" */
}
return;
}
/**
* We are switching over to having a hash table for quick look
* up of attributes, but up until now we haven't kept any
* information in the Hashtable, so we now update the Hashtable.
* Future additional attributes will update the Hashtable as
* they are added.
* @param numAtts
*/
{
{
}
}
/**
* This method clears the accumulated attributes.
*
* @see org.xml.sax.helpers.AttributesImpl#clear()
*/
public final void clear()
{
super.clear();
{
// if we have had enough attributes and are
// using the Hashtable, then clear the Hashtable too.
}
}
/**
* This method sets the attributes, previous attributes are cleared,
* it also keeps the hashtable up to date for quick lookup via
* getIndex(qName).
* @param atts the attributes to copy into these attributes.
* @see org.xml.sax.helpers.AttributesImpl#setAttributes(Attributes)
* @see #getIndex(String)
*/
{
super.setAttributes(atts);
// we've let the super class add the attributes, but
// we need to keep the hash table up to date ourselves for the
}
/**
* This method gets the index of an attribute given its uri and locanName.
* @param uri the URI of the attribute name.
* @param localName the local namer (after the ':' ) of the attribute name.
* @return the integer index of the attribute.
* @see org.xml.sax.Attributes#getIndex(String)
*/
{
int index;
{
// if we haven't got too many attributes let the
// super class look it up
return index;
}
// we have too many attributes and the super class is slow
// so find it quickly using our Hashtable.
// Form the key of format "{uri}localName"
if (i == null)
index = -1;
else
return index;
}
}