例: Locating a document by ID in Java™ classes

次のエージェントは、ID がベクトルに格納されている文書の取得方法を示します。

import lotus.domino.*;
import java.util.Vector;
import java.util.Enumeration;
public class JavaAgent extends AgentBase {  
  Vector v;
  public void NotesMain() {
    try {
      Session session = getSession();
      AgentContext agentContext = 
           session.getAgentContext();
      // (Your code goes here)       
      Database db = agentContext.getCurrentDatabase();
      saveIDs(db);
      Enumeration e = v.elements();
      while (e.hasMoreElements()) {
        String id = (String)e.nextElement();
        Document doc = db.getDocumentByID(id);
        System.out.println(
            doc.getItemValueString("Subject"));
        }
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
  
  public void saveIDs(Database db) {
    try {
      DocumentCollection dc = db.getAllDocuments();
      v = new Vector();
      Document doc = dc.getFirstDocument();
      while (doc != null) {
        v.addElement(doc.getNoteID());
        doc = dc.getNextDocument(); }
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
}