Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You 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
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
  * 
  * 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.
  */
 
 package org.apache.jasper.runtime;
 
 
Pool of tag handlers that can be reused.

Author(s):
Jan Luehe
 
 public class TagHandlerPool {
 
     private Tag[] handlers;
 
     public static final String OPTION_TAGPOOL="tagpoolClassName";
     public static final String OPTION_MAXSIZE="tagpoolMaxSize";
 
     // index of next available tag handler
     private int current;
     protected InstanceManager instanceManager = null;
 
     public static TagHandlerPool getTagHandlerPoolServletConfig config) {
         TagHandlerPool result=null;
 
         String tpClassName=getOptionconfignull);
         iftpClassName != null ) {
             try {
                 Class c=Class.forNametpClassName );
                 result=(TagHandlerPool)c.newInstance();
             } catch (Exception e) {
                 result = null;
             }
         }
         ifresult==null ) result=new PerThreadTagHandlerPool();
         result.init(config);
 
         return result;
     }
 
     protected void initServletConfig config ) {
         int maxSize=-1;
         String maxSizeS=getOption(confignull);
         ifmaxSizeS != null ) {
             try {
                 maxSize=Integer.parseInt(maxSizeS);
             } catchException ex) {
                 maxSize=-1;
             }
         }
         ifmaxSize <0  ) {
             maxSize=.;
         }
         this. = new Tag[maxSize];
         this. = -1;
          = InstanceManagerFactory.getInstanceManager(config);
     }

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

    
Constructs a tag handler pool with the given capacity.

Deprecated:
Use static getTagHandlerPool
Parameters:
capacity Tag handler pool capacity
 
     public TagHandlerPool(int capacity) {
 	this. = new Tag[capacity];
 	this. = -1;
     }

    
Gets the next available tag handler from this tag handler pool, instantiating one if this tag handler pool is empty.

Parameters:
handlerClass Tag handler class
Returns:
Reused or newly instantiated tag handler
Throws:
javax.servlet.jsp.JspException if a tag handler cannot be instantiated
    public Tag get(Class handlerClassthrows JspException {
    	Tag handler;
        synchronizedthis ) {
            if ( >= 0) {
                handler = [--];
                return handler;
            }
        }
        // Out of sync block - there is no need for other threads to
        // wait for us to construct a tag for this thread.
        try {
        		return (Tag.newInstance(handlerClass);
        	} else {
                Tag instance = (TaghandlerClass.newInstance();
                if (.) {
                    .newInstance(instance);
                }
                return instance;
        	}
        } catch (Exception e) {
            throw new JspException(e.getMessage(), e);
        }
    }

    
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.

Parameters:
handler Tag handler to add to this tag handler pool
    public void reuse(Tag handler) {
        synchronizedthis ) {
            if ( < (. - 1)) {
                [++] = handler;
                return;
            }
        }
        // There is no need for other threads to wait for us to release
        handler.release();
            try {
                .destroyInstance(handler);
            } catch (Exception e) {
                // Ignore
            }
        }
    }

    
Calls the release() method of all available tag handlers in this tag handler pool.
    public synchronized void release() {
        for (int i = i >= 0; i--) {
            [i].release();
            if (. || .) {
                try {
                    .destroyInstance([i]);
                } catch (Exception e) {
                    // Ignore
                }
            }
        }
    }
    protected static String getOptionServletConfig configString nameString defaultV) {
        ifconfig == null ) return defaultV;
        String value=config.getInitParameter(name);
        ifvalue != null ) return value;
        ifconfig.getServletContext() ==null )
            return defaultV;
        value=config.getServletContext().getInitParameter(name);
        ifvalue!=null ) return value;
        return defaultV;
    }
New to GrepCode? Check out our FAQ X