AgentBase (Java™)
Notes/Domino agents must extend AgentBase and use NotesMain() as the entry point for their functional code. Use getSession() to create a Session object. For output to browsers as well as Notes® clients (the Java™ debug console), create a PrintWriter object with getAgentOutput().
Skeleton for Java™ agents
Domino® Designer generates the following skeleton code when you create a Java™ agent. If you import the agent, you must supply similar code yourself. Minimally you must create a class that extends AgentBase, provide a function called NotesMain(), and call AgentBase.getSession() to create a Session object. The code in NotesMain() executes when the agent is launched.
import lotus.domino.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
// (Your code goes here)
} catch(Exception e) {
e.printStackTrace();
}
}
}
You may wish to modify the skeleton to deal specifically with NotesException exceptions. For example:
} catch(NotesException ne) {
System.out.println(ne.id + " " + ne.text);
} catch(Exception e) {
E.printStackTrace();
Instead of:
} catch(Exception e) {
E.printStackTrace();
Print output
For Notes® clients, System.out and System.err output from foreground agents goes to the Java™ debug console, which you can access as a separate task through Tools - Show Java™ Debug Console. Background agents print to the Domino® log.
To print to a browser from an agent started by the OpenAgent URL command, you must call AgentBase.getAgentOutput() to get a java.io.PrintWriter object. Print output from this object goes to browsers as well as the Notes® client.
The following code fragment shows how to open a view in the current database by printing the URL command to a browser. (The code replaces backslashes with forward slashes and spaces with plus signs, and encloses the URL command in brackets.)
import java.io.PrintWriter;
PrintWriter pw = getAgentOutput();
Database db = agentContext.getCurrentDatabase();
String n = db.getFileName();
n = n.replace('\\', '/').replace(' ', '+');
pw.println("[/" + n + "/Main+View?OpenView]");
Specification of AgentBase
The specification (public methods) of the AgentBase class is as follows:
public class AgentBase extends NotesThread {
protected Session m_session;
public AgentBase();
public final void startup(AgentInfo info);
public final void runNotes() throws NotesException;
public void NotesMain();
public Session getSession();
public boolean isRestricted();
public PrintWriter getAgentOutput();
public void setDebug(boolean debug);
public void setTrace(boolean trace);
public void dbgMsg(String msg, PrintStream ps);
public void dbgMsg(String msg, PrintWriter pw);
public void dbgMsg(String msg);
}