FileDocCategorySizeDatePackage
TagHandlerPool.javaAPI DocGlassfish v2 API6683Fri May 04 22:32:54 BST 2007org.apache.jasper.runtime

TagHandlerPool

public class TagHandlerPool extends Object
Pool of tag handlers that can be reused.
author
Jan Luehe

Fields Summary
public static final String
OPTION_TAGPOOL
public static final String
OPTION_MAXSIZE
private javax.servlet.jsp.tagext.Tag[]
handlers
private ResourceInjector
resourceInjector
private int
current
Constructors Summary
public TagHandlerPool()
Constructs a tag handler pool with the default capacity.

	// Nothing - jasper generated servlets call the other constructor,
        // this should be used in future + init .
    
public TagHandlerPool(int capacity)
Constructs a tag handler pool with the given capacity.

param
capacity Tag handler pool capacity
deprecated
Use static getTagHandlerPool

	this.handlers = new Tag[capacity];
	this.current = -1;
    
Methods Summary
public javax.servlet.jsp.tagext.Tagget(java.lang.Class handlerClass)
Gets the next available tag handler from this tag handler pool, instantiating one if this tag handler pool is empty.

param
handlerClass Tag handler class
return
Reused or newly instantiated tag handler
throws
JspException if a tag handler cannot be instantiated

	Tag handler = null;
        synchronized( this ) {
            if (current >= 0) {
                handler = handlers[current--];
                return handler;
            }
        }

        // Out of sync block - there is no need for other threads to
        // wait for us to construct a tag for this thread.
        Tag tagHandler = null;
        try {
            tagHandler = (Tag) handlerClass.newInstance();
            if (resourceInjector != null) {
                resourceInjector.inject(tagHandler);
            }
        } catch (Exception e) {
            throw new JspException(e.getMessage(), e);
        }

        return tagHandler;
    
protected static java.lang.StringgetOption(javax.servlet.ServletConfig config, java.lang.String name, java.lang.String defaultV)

        if( config == null ) return defaultV;

        String value=config.getInitParameter(name);
        if( value != null ) return value;
        if( config.getServletContext() ==null )
            return defaultV;
        value=config.getServletContext().getInitParameter(name);
        if( value!=null ) return value;
        return defaultV;
    
public static org.apache.jasper.runtime.TagHandlerPoolgetTagHandlerPool(javax.servlet.ServletConfig config)


          
        TagHandlerPool result=null;

        String tpClassName=getOption( config, OPTION_TAGPOOL, null);
        if( tpClassName != null ) {
            try {
                Class c=Class.forName( tpClassName );
                result=(TagHandlerPool)c.newInstance();
            } catch (Exception e) {
                e.printStackTrace();
                result=null;
            }
        }
        if( result==null ) result=new TagHandlerPool();
        result.init(config);

        return result;
    
protected voidinit(javax.servlet.ServletConfig config)

        int maxSize=-1;
        String maxSizeS=getOption(config, OPTION_MAXSIZE, null);
        if( maxSizeS != null ) {
            try {
                maxSize=Integer.parseInt(maxSizeS);
            } catch( Exception ex) {
                maxSize=-1;
            }
        }
        if( maxSize <0  ) {
            maxSize=Constants.MAX_POOL_SIZE;
        }
        this.handlers = new Tag[maxSize];
        this.current = -1;

        this.resourceInjector = (ResourceInjector)
            config.getServletContext().getAttribute(
                Constants.JSP_RESOURCE_INJECTOR_CONTEXT_ATTRIBUTE);
    
public synchronized voidrelease()
Calls the release() method of all available tag handlers in this tag handler pool.

	for (int i=current; i>=0; i--) {
	    handlers[i].release();
	}
    
public voidreuse(javax.servlet.jsp.tagext.Tag handler)
Adds the given tag handler to this tag handler pool, unless this tag handler pool has already reached its capacity, in which case the tag handler's release() method is called.

param
handler Tag handler to add to this tag handler pool

        synchronized( this ) {
            if (current < (handlers.length - 1)) {
                handlers[++current] = handler;
                return;
            }
        }
        // There is no need for other threads to wait for us to release
        handler.release();