("Body", body);
email. send(false);
} catch(Exception e) {
e.printStackTrace();
}
}
}
在IBM Lotus Domino Designer中使用Java构建应用程序(8)
时间:2011-01-24 IBM Oscar Hernandez
LotusScript 中代码到此结束了,但是在 Java 代理中还有一些工作要做。特别是,在 Java 中,我们必须对所有 Domino 对象调用 recycle(请参见清单 8)。调用 recycle 确保分配给这些对象的内存都得以释放。有关 recycle 方法的更多信息,请参见第 4 部分的“recycle() 方法”一段。
清单 8. 对 Domino 对象调用 recycle
import lotus.domino. *;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
//(Your code goes here)
Database database;
Document email;
String sendto;
String subject;
String body;
database = agentContext.getCurrentDatabase();
email = database.createDocument();
sendto = "Enter_Email_Address_Here";
subject = "Email sent by Java code";
body = "Text in body of email sent by Java code";
email.replaceItemValue("Form", "Memo");
email.replaceItemValue(" SendTo", sendto);
email.replaceItemValue(" Subject", subject);
email.replaceItemValue("Body", body);
email. send(false);
//recycle Java Domino objects
if (session !=null)
session.recycle();
if (agentContext !=null)
agentContext.recycle();
if (database !=null)
database.recycle();
if (email !=null)
email.recycle();
} catch(Exception e) {
e.printStackTrace();
}
}
}
表 6 汇总了两种语言的比较。
表 6. 示例 1 两种语言之间的比较
LotusScript |
Java |
示例 1:发送电子邮件
Dim session As New NotesSession
Dim database As NotesDatabase
Dim email As NotesDocument
Dim sendto As String
Dim subject As String
Dim body As String
Set database = session.CurrentDatabase
Set email = database.CreateDocument
sendto = "Enter_Email_Address_Here"
subject = "Email sent by LotusScript code"
body = "Text in body of email sent byLotusScript code"
Call email.ReplaceItemValue("Form", "Memo")
Call email.ReplaceItemValue("SendTo", sendto)
Call email.ReplaceItemValue("Subject", subject)
Call email.ReplaceItemValue("Body", body)
Call email.Send(False) |
|
示例 1:发送电子邮件
Session session = getSession();
AgentContext agentContext =session.getAgentContext();
Database database;
Document email;
String sendto;
String subject;
String body;
database = agentContext.getCurrentDatabase();
email = database.createDocument();
sendto = "Enter_Email_Address_Here";
subject = "Email sent by Java code";
body = "Text in body of email sent by Javacode";
email.replaceItemValue("Form", "Memo");
email.replaceItemValue("SendTo", sendto);
email.replaceItemValue("Subject", subject);
email.replaceItemValue("Body", body);
email.send(false);
//recycle Java Domino objects
if (session !=null)
session.recycle();
if (agentContext !=null)
agentContext.recycle();
if (database !=null)
database.recycle();
if (email !=null)
email.recycle();
|
|