📄 basedatatagiteratorcollection.java
字号:
package jsp.tags.dapact.tags.data;
import java.util.Collection;
import java.util.Iterator;
import jsp.tags.dapact.conf.UserClassFactory;
import jsp.tags.dapact.tags.ChainedJspException;
/**
* Title: Data Aware Processing And Control Tags
* Description: Tag library for the processing and controlling the input and output of data.
* Copyright: LGPL (http://www.gnu.org/copyleft/lesser.html)
* Compile Date: @compile_date@
* @author Allen M Servedio
* @amp_sign@version @VERSION@
*/
/**
* Data tag iterator that iterates over a collection (supplied by the subclass... if you want
* it supplied by doing a lookup, use jsp.tags.dapact.tags.data.DataTagIteratorUsingAssignData).
* It uses its name as the key to the value (i.e. when a call to
* {@link #retrieveValueByName(Object, String)} comes in, it only returns a value if
* the name parameter matches the name property.
*/
public abstract class BaseDataTagIteratorCollection extends BaseDataTagIterator
{
/**
* Default constructor...
*/
public BaseDataTagIteratorCollection()
{
}
/**
* Called when the starting tag is found - if an exception occurs while processing
* the super class, this will call the close() method or if there is nothing to iterate
* over, it will call the close() method.
*
* @return EVAL_BODY_TAG so that it processes what ever is in the body or SKIP_BODY
* if no collection (or iterator from the collection) is supplied or it is empty.
*/
public int doStartTag() throws ChainedJspException
{
super.doStartTag();
int result = SKIP_BODY;
Collection collection = getCollection();
if (collection != null)
{
iterator = collection.iterator();
if ((iterator != null) && (iterator.hasNext()))
{
result = EVAL_BODY_TAG;
value = iterator.next();
}
}
// If the result is to skip the body, close any open resources.
if (result == SKIP_BODY)
{
try
{
close();
}
catch (DataException ex)
{
UserClassFactory.getLogger().log("Exception while closing resources because there was no data to process.", ex);
}
}
return result;
}
/**
* Called by objects that want to request a value by its name, it only returns a value if
* the name parameter matches the name property.
*
* @param requestor the object requesting the value or the object that the value
* is being requested for (like with a lookup: you would pass the TagSupport
* object, not the lookup which is what actually calls this function).
* @param name the name of the value to retrieve.
*
* @return the value that was found by the name supplied.
*/
public Object retrieveValueByName(Object requestor, String name)
{
Object result = null;
if (getName().equals(name))
{
result = value;
}
return result;
}
/**
* When there is an exception or the result set has been processed, this method will be called.
*/
public void close() throws DataException
{
iterator = null;
value = null;
setDone(true);
}
/**
* This function is called to get the next entry in the collection.
*
* @return this function returns <code>true</code> until there is no more data,
* then it returns <code>false</code>.
*/
public boolean next() throws DataException
{
boolean result = false;
if ((iterator != null) && (iterator.hasNext()) && (!isDone()))
{
value = iterator.next();
result = true;
}
setDone(!result);
return result;
}
/**
* Called by the container to free the tag's resources - super class calls the close()
* method from the RetrieveValueByNameIteratorInf interface to close any open resources.
*/
public void release()
{
super.release();
iterator = null;
value = null;
}
/**
* Method that must be implemented by sub classes to return the collection to be
* iterated over - this will be called in the doStartTag() function.
*
* @return collection to be iterated over.
*/
protected abstract Collection getCollection();
private Iterator iterator;
private Object value;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -