Search DominoPower's 11,441 Lotus-related article archive 
Home
EasyPrint
News details Click here for the RSS feed's XML code. This is not a browser URL.
Articles-only Click here for the RSS feed's XML code. This is not a browser URL.
Twitter Feed Click here for the Twitter feed.
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:

  1. Make the Domino Java classes available to the agent;
  2. The PrintWriter class of the Java.io package;
  3. Class declaration; everything in Java is a class/object;
  4. The entry point for a Domino Java agent is the NotesMain method;
  5. Beginning of the try/catch block;
  6. Create a Session object;
  7. PrintWriter object is used for output; we can view the output in the Java console;
  8. Create a Database object; we will use the name and address book;
  9. Continue only if the database was properly instantiated;
  10. Create a View object using the list of people in the NAB;
  11. Continue only if the View object has been properly instantiated;
  12. Retrieve the first document in the view;
  13. Declare String objects to be used for field values;
  14. Declare variable to be used as a counter;
  15. Loop through all documents in the view;
  16. Increment the counter variable;
  17. Retrieve the contents of the FirstName field as a String;
  18. Display the name and counter variable;
  19. Get the next document from the view;
  20. Return the memory used by the View object to the system;
  21. Return the memory used by the Database object to the system;
  22. Return the memory used by the Session object to the system.


« Previous  ·  1  ·  2  ·  3  ·  4  ·  Next »
Other articles you might like
Home > Lotus Technologies > Domino (77 articles)
   More about Domino log files
   Why your log.nsf might not be purging properly
   Sloppy analysis at the core of another Domino vs. SharePoint report
Home > Internet Technologies > Java (6 articles)
   FlowBuilder 3.0: Domino's bridge into J2EE
   Post-Lotusphere 2004 report: gaining understanding and perspective
   Using a reusable code approach to HTML select option lists
Get Weekly Email Updates
Subscribe to our regular weekly email newsletter. It's packed with tips, reviews, deep analysis, and the latest news.
 
Recent DominoPower Articles
Application development, William Shatner, and the origin of the universe
Learn Domino Designer 8.5 for free
The (near) future of Sametime, Quickr, Connections, and Symphony
Inside the IBM Innovations lab
Lotusphere 2010: Hot fixes and cool news for Notes, Domino, and LotusLive
Lotusphere 2010: mobility and collaboration
2010: A Lotusphere of change
Latest Lotus Headlines
Xpages not loading? JVM errors? - Solution
How to implement an iCalendar feed into your Notes calendar with XPages
DWA Hotfixes for Domino 8.5.1FP1 - A Gotcha
IBM Adds DB2 to Lotus Foundations SMB Package
SNTT : XPages onclick Ghosts in the machine
Ports used by Lotus Sametime 8.5 servers
Exploring a Domino Date Bug
>> Read all the news
More from the ZATZ journals
Computing Unplugged: The iPad defenders have spoken
David Gewirtz Online: CNN commentary and analysis
OutlookPower: More about disappearing text
-- 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.
ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 1998-2010, ZATZ Publishing. All rights reserved worldwide.
Editor's Login