|
|
|
|
|
|
|
|
|
|
|
|
|
|
The ins and outs of using Java with Domino (continued)
If you'll be working with Domino Java outside of the Domino environment, you must place the appropriate class files in your CLASSPATH environment variable. You'll need the Notes.jar file for using Domino Java classes.
Our first Domino Java agent Okay, we've taken a look at the basics of utilizing Java in Domino. Let's turn our attention to a simple Domino Java agent. We will construct an agent that accesses all person records in the name and address book (names.nsf) and displays the first and last name of the person(s).
As an example, I've numbered a piece of code. Following the code, you'll find each line explained next to its corresponding number.
1. import lotus.domino.*;
2. import java.io.PrintWriter;
3. public class JavaExample extends AgentBase
{
4. public void NotesMain()
{
5. try
{
6. Session s = this.getSession();
7. PrintWriter pw = this.getAgentOutput();
8. Database db = s.getDatabase("","names.nsf");
9. if (db != null)
{
10. View vw = db.getView("People");
11. if (vw != null)
{
12. Document doc = vw.getFirstDocument();
13. String fname = null;
String lname = null;
14. int c = 0;
15. while (doc != null)
{
16. c += 1;
17. fname = doc.getItemValueString("FirstName");
lname = doc.getItemValueString("LastName");
18. pw.println("Person #" + c + " : " + fname + " " + lname);
19. doc = vw.getNextDocument(doc);
}
20. vw.recycle();
}
21. db.recycle();
}
22. s.recycle();
} catch(Exception e) {
e.printStackTrace();
}
}
}
|
Here's the explanation:
- Make the Domino Java classes available to the agent;
- The PrintWriter class of the Java.io package;
- Class declaration; everything in Java is a class/object;
- The entry point for a Domino Java agent is the NotesMain method;
- Beginning of the try/catch block;
- Create a Session object;
- PrintWriter object is used for output; we can view the output in the Java console;
- Create a Database object; we will use the name and address book;
- Continue only if the database was properly instantiated;
- Create a View object using the list of people in the NAB;
- Continue only if the View object has been properly instantiated;
- Retrieve the first document in the view;
- Declare String objects to be used for field values;
- Declare variable to be used as a counter;
- Loop through all documents in the view;
- Increment the counter variable;
- Retrieve the contents of the FirstName field as a String;
- Display the name and counter variable;
- Get the next document from the view;
- Return the memory used by the View object to the system;
- Return the memory used by the Database object to the system;
- Return the memory used by the Session object to the system.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Advertisement --
Sophisticated Meets Simple For Document Management
Share. Control. Manage.
Documents, emails, and content in the context of how work is done.
Native to Lotus Domino. The User Experience unseen for Lotus Domino.
Do more with less. Really.
See the possibilities Docova unleashes for Lotus Domino. |
-- Advertisement --
Mark your calendar for in-depth Lotus training, May 12-14, Boston
Join experts and peers May 12-14 in Boston for educational and networking events that deliver real-world Lotus training so you can increase productivity and efficiency in your company, advance your skills, and squeeze the most from your current environment. One registration gets you into THE VIEW's Admin2010 and Lotus Developer2010.
Register by April 10 to save $200. |
|
|
|
|
|
|
|
|
|
|