| Method from org.apache.jasper.runtime.TagHandlerPool Detail: |
public Tag get(Class handlerClass) throws JspException {
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.
try {
Tag instance = (Tag) handlerClass.newInstance();
AnnotationHelper.postConstruct(annotationProcessor, instance);
return instance;
} catch (Exception e) {
throw new JspException(e.getMessage(), e);
}
}
Gets the next available tag handler from this tag handler pool,
instantiating one if this tag handler pool is empty. |
protected static String getOption(ServletConfig config,
String name,
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 TagHandlerPool getTagHandlerPool(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 void init(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.annotationProcessor =
(AnnotationProcessor) config.getServletContext().getAttribute(AnnotationProcessor.class.getName());
}
|
public synchronized void release() {
for (int i = current; i >= 0; i--) {
handlers[i].release();
if (annotationProcessor != null) {
try {
AnnotationHelper.preDestroy(annotationProcessor, handlers[i]);
} catch (Exception e) {
log.warn("Error processing preDestroy on tag instance of "
+ handlers[i].getClass().getName(), e);
}
}
}
}
Calls the release() method of all available tag handlers in this tag
handler pool. |
public void reuse(Tag handler) {
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();
if (annotationProcessor != null) {
try {
AnnotationHelper.preDestroy(annotationProcessor, handler);
} catch (Exception e) {
log.warn("Error processing preDestroy on tag instance of "
+ handler.getClass().getName(), 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. |