次のエージェントは、多様な URL 構成方法でデータベース URL を解釈します。import lotus.domino.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
// (Your code goes here)
Database db = agentContext.getCurrentDatabase();
// Construct URL using getURL
String theURL = db.getURL();
System.out.println(theURL + " - using getURL");
Database target = (Database)session.resolve(theURL);
System.out.println(target.getTitle());
// Construct URL using getFileName
theURL = "notes:///" + db.getFileName() + "?OpenDatabase";
System.out.println(theURL + " - using getFileName");
target = (Database)session.resolve(theURL);
System.out.println(target.getTitle());
// Construct URL using getReplicaID
theURL = "notes:///" + db.getReplicaID() + "?OpenDatabase";
System.out.println(theURL + " - using getReplicaID");
target = (Database)session.resolve(theURL);
System.out.println(target.getTitle());
// Construct URL using literal database name
theURL = "notes:///Document+examples+2?OpenDatabase";
// Also OK: "notes:///Document examples 2?OpenDatabase"
// Also OK: "notes:///Document+examples+2.nsf?OpenDatabase"
// Also OK: "notes:///Document examples 2.nsf?OpenDatabase"
System.out.println(theURL + " - using literal database name");
target = (Database)session.resolve(theURL);
System.out.println(target.getTitle());
// Construct URL using literal replica ID
theURL = "notes:///__8525690D006AC34D.nsf?OpenDatabase";
// Also OK: "notes:///8525690D006AC34D?OpenDatabase";
System.out.println(theURL + " - using literal replica ID");
target = (Database)session.resolve(theURL);
System.out.println(target.getTitle());
} catch(NotesException e) {
System.out.println(e.id + e.text);
e.printStackTrace();
}
}
}