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

📄 sampledataiterator1.java

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

import java.util.ArrayList;
import java.util.Hashtable;
import jsp.tags.dapact.tags.data.DataException;
import jsp.tags.dapact.tags.data.RetrieveValueByNameIteratorInf;
/**
 * 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@
 */

/**
 * Sample class to show how to implement the RetrieveValueByNameIteratorInf interface
 * to be used with the DataTagIteratorUsingAssignData tag.
 */
public class SampleDataIterator1 implements RetrieveValueByNameIteratorInf
{
  /**
   * The name of the position in the iteration.
   */
  public static final String POS = "pos";

  /**
   * Default constructor...
   */
  public SampleDataIterator1()
  {
    list = new ArrayList(5);
    for (int i=0; i < 5; i++)
    {
      Hashtable table = new Hashtable(20);
      for (int j=0; j < 20; j++)
      {
        table.put("key-"+j, "value="+j);
      }
      list.add(table);
    }
    listSize = list.size();
  }

  /**
   * This function is called to tell the sub class to advance to the next group of
   * data.
   *
   * @return this function should return <code>true</code> until there is no more data,
   *   then it should return <code>false</code>.
   */
  public boolean next() throws DataException
  {
    if (listPos < list.size())
    {
      listPos++;
    }
    return (listPos < list.size());
  }

  /**
   * This function should be called when processing is done or is aborted (so that sub
   * classes can close their resources). This function should be able to handle multiple
   * calls to it without causing an error (so, it the iterator calls it and then the
   * finalize() method calls it, the only exceptions that should occur are in the first
   * call when it tries to close the resources). Subsequent calls should probably be
   * ignored, unless there is a reason to try again.
   */
  public void close() throws DataException
  {
    listPos = 0;
  }

  /**
   * Called by objects that want to request a value by its name.
   *
   * @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)
  {
    if (POS.equals(name))
    {
      return Integer.toString(listPos);
    }
    else
    {
      Hashtable ht = (Hashtable)list.get(listPos);
      return ht.get(name);
    }
  }

  /**
   * @return Get the name of the object to see if we should use it to look up values.
   */
  public String getName()
  {
    return name;
  }

  /**
   * Set the name of the object to see if we should use it to look up values.
   */
  public void setName(String name)
  {
    this.name = name;
  }

  private String name;
  private ArrayList list;
  private int listPos;
  private int listSize;
}

⌨️ 快捷键说明

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