⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basedatatagiterator.java

📁 这是一个mvc模式
💻 JAVA
字号:
package jsp.tags.dapact.tags.data;

import java.io.IOException;
import javax.servlet.jsp.JspException;
import jsp.tags.dapact.BaseDataBodyTagSupport;
import jsp.tags.dapact.conf.UserClassFactory;
import jsp.tags.dapact.tags.ChainedJspException;
import jsp.tags.dapact.util.TagUtil;
/**
 * 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@
 */

/**
 * Base class for tag iterators that will iterate over the data for a tag until either
 * an exception is hit or the next() function returns false. Subclasses should set the
 * done property when they are done processing.
 */
public abstract class BaseDataTagIterator extends BaseDataBodyTagSupport implements RetrieveValueByNameIteratorInf
{
  /**
   * Default constructor...
   */
  public BaseDataTagIterator()
  {
  }

  /**
   * Called when the starting tag is found - if an exception occurrs while processing
   * the super class, this will call the close() method.
   *
   * @return EVAL_BODY_TAG so that it processes what ever is in the body.
   */
  public int doStartTag() throws ChainedJspException
  {
    try
    {
      super.doStartTag();
    }
    catch (JspException e)
    {
      try
      {
        close();
      }
      catch (DataException ex)
      {
        UserClassFactory.getLogger().log("Exception calling close in doStartTag().", ex);
      }
      throw new ChainedJspException("Exception occured in start tag of data iterator.", e);
    }
    currentIteration = 0;
    return EVAL_BODY_TAG;
  }

  /**
   * Called once at the beginning of the body - Sets the display body content
   * ({@link #setDisplayBodyContent(boolean)}) to true.
   *
   * @exception ChainedJspException general JSP exception.
   */
  public void doInitBody() throws ChainedJspException
  {
    try
    {
      super.doInitBody();
    }
    catch (JspException e)
    {
      try
      {
        close();
      }
      catch (DataException ex)
      {
        UserClassFactory.getLogger().log("Exception calling close in doInitBody().", ex);
      }
      throw new ChainedJspException("Exception occured in initializing body of data iterator.", e);
    }

    setDisplayBodyContent(true);
  }

  /**
   * Called at the end of each iteration through the body - keeps cycling until the
   * data has been processed.
   *
   * @exception ChainedJspException general JSP exception.
   *
   * @return returns <code>EVAL_BODY_TAG</code> until all data has been processed,
   *   then it returns <code>SKIP_BODY</code>.
   */
  public int doAfterBody() throws ChainedJspException
  {
    try
    {
      int result = super.doAfterBody();
      try
      {
        if (((maxIterations == 0) || (++currentIteration < maxIterations)) && (next()))
        {
          result = EVAL_BODY_TAG;
        }
        else
        {
          result = SKIP_BODY;
          try
          {
            close();
          }
          catch (DataException e)
          {
            UserClassFactory.getLogger().log("Exception calling close in doAfterBody().", e);
          }
        }
      }
      catch (DataException e)
      {
        try
        {
          close();
        }
        catch (DataException ex)
        {
          UserClassFactory.getLogger().log("Exception calling close in doAfterBody().", ex);
        }
        throw new ChainedJspException("Exception while retrieving data for a data iterator tag.", e);
      }
      return result;
    }
    catch (JspException e)
    {
      try
      {
        close();
      }
      catch (DataException ex)
      {
        UserClassFactory.getLogger().log("Exception calling close in doAfterBody().", ex);
      }
      throw new ChainedJspException("Exception occured in after body of data iterator.", e);
    }
  }

  /**
   * Called at the end of the tag. Will output the end body tag text and return that
   * it wants to have the rest of the page processed. It will only display the body
   * content if {@link #getDisplayBodyContent()} returns true.
   *
   * @exception ChainedJspException general JSP exception.
   *
   * @return EVAL_PAGE so that it continues to process the rest of the page.
   */
  public int doEndTag() throws ChainedJspException
  {
    try
    {
      super.doEndTag();
      // Only display the body content if the property is true.
      if (getDisplayBodyContent())
      {
        try
        {
          try
          {
            getBodyContent().writeOut(getPreviousOut());
          }
          catch (NullPointerException e)
          {}
        }
        catch (IOException e)
        {
          try
          {
            close();
          }
          catch (DataException ex)
          {
            UserClassFactory.getLogger().log("Exception calling close in doEndTag().", ex);
          }
          throw new ChainedJspException("IO exception occured in end tag of data iterator.", e);
        }
      }
    }
    catch (JspException e)
    {
      try
      {
        close();
      }
      catch (DataException ex)
      {
        UserClassFactory.getLogger().log("Exception calling close in doEndTag().", ex);
      }
      throw new ChainedJspException("Exception occured in end tag of data iterator.", e);
    }
    return EVAL_PAGE;
  }

  /**
   * Called by the container to free the tag's resources - also calls the close()
   * method from the RetrieveValueByNameIteratorInf interface to close any open resources.
   */
  public void release()
  {
    super.release();
    try
    {
      close();
    }
    catch (DataException ex)
    {
      UserClassFactory.getLogger().log("Exception calling close in release().", ex);
    }
    displayBodyContent = false;
    done = false;
    maxIterations = 0;
    currentIteration = 0;
  }

  /**
   * Override the finalize method so that resources can be closed (calls the close()
   * method).
   */
  public void finalize() throws Throwable
  {
    try
    {
      super.finalize();
    }
    finally
    {
      close();
    }
  }

  /*=============================================================================*/
  /*                           PROPERTIES/ATTRIBUTES                             */
  /*=============================================================================*/
  /**
   * Get the value of the displayBodyContent property - if true, this body content
   * will be displayed when the end tag is hit, otherwise it will be discarded.
   *
   * @return the value of the displayBodyContent property.
   */
  public boolean getDisplayBodyContent()
  {
    return displayBodyContent;
  }
  /**
   * Set the value of the displayBodyContent property - if true, this body content
   * will be displayed when the end tag is hit, otherwise it will be discarded.
   *
   * @param value the value of the displayBodyContent property.
   */
  public void setDisplayBodyContent(boolean value)
  {
    displayBodyContent = value;
  }

  /**
   * Returns <code>true</code> if this is done processing the data, otherwise
   * <code>false</code>.
   */
  public boolean isDone()
  {
    return done;
  }
  /**
   * Sets if the system is done processing or not - subclasses should call this when
   * they are done processing.
   */
  protected void setDone(boolean done)
  {
    this.done = done;
  }

  /**
   * Returns the maximum number of iterations that this tag should perform - if it
   * returns zero, it will iterate over all of them.
   */
  public int getMaxIterations()
  {
    return maxIterations;
  }
  /**
   * Set the maximum number of iterations that the tag should perform - if set to zero
   * it will iterate over all of them.
   */
  public void setMaxIterations(int maxIterations)
  {
    this.maxIterations = maxIterations;
  }

  private boolean displayBodyContent;
  private boolean done;
  private int maxIterations;
  private int currentIteration;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -