Skip to main content link. Accesskey S
  • Help
  • HCL Logo
  • HCL Notes and Domino Application Development wiki
  • THIS WIKI IS READ-ONLY. Individual names altered for privacy purposes.
  • HCL Forums and Blogs
  • Home
  • Product Documentation
  • Community Articles
  • Learning Center
  • API Documentation
Search
Learning Center > Tutorials > Sample Java program for Notes/Domino
  • Share Show Menu▼
  • Subscribe Show Menu▼

Recent articles by this author

XPage tutorial samples

Small sample programs to get started with XPage development

Sample Java program for Notes/Domino

Full sample program for NotesDomino coding in Java under Eclipse.
Learning Center articleSample Java program for Notes/Domino
Added by ~Laura Desnupulings | Edited by ~Laura Desnupulings on September 22, 2010 | Version 2
  • Actions Show Menu▼
expanded Abstract
collapsed Abstract
Full sample program for Notes/Domino coding in Java under Eclipse.
Tags: Java, programming, Eclipse, tutorials, tutorials
ShowTable of Contents
HideTable of Contents
  • 1 null) throw new NotesException(NotesError.NOTES_ERR_ERROR, "Could not get current session at start of agent.");

                                                                    ac = sess.getAgentContext();

                                                                    if (ac

Here is a full sample program for writing a Java interface to Notes/Domino classes. (This posting builds on a previous one http://www-10.lotus.com/ldd/ddwiki.nsf/dx/08052009082228AMWEBGJ4.htm.)

 
The full source code:

http://www.chc-3.com/downloads/NotesJavaShell.zip

 

Other Notes/Domino downloads: 

http://www.chc-3.com/downloads.php

 

Chuck Connell 
 
++++++++++++++++++ 

 

/*

 * Chuck Connell, www.chc-3.com, June 2010.

 * Example of general shell for Java programming for IBM/Lotus Notes and Domino.

 *

 * The core idea is from Bob Balaban(www.bobzblog.com, bbalaban@gmail.com).

 * I added the configuration database, logging, and more comments.

 */

 

import lotus.domino.*;

 

public class NotesJavaShell extends AgentBase{

 

                Public fields.

               

                Local vars

                private Session session;

                private Database database; 

 

                Constructors

 

                public NotesJavaShell(){    default constructor, without run context

                                }

                public NotesJavaShell(Session s, Database d) { when we know the run context

                                this.session = s;

                                this.database = d;

                                }

 

                Start here when run from Eclipse.

                public static void main(String[] args) {   

 

                                Session sess=null;

                                Database db=null;

                                NotesJavaShell ag;

                               

                                Initialize Notes

                                NotesThread.sinitThread();

                               

                                try {

                                                sess = NotesFactory.createSession();  start a Notes session

                                                db = sess.getDatabase("", Constants.DEFAULT_HOME_DB);  simulate home database for agent

                                                ag = new NotesJavaShell(sess, db);  simulate agent object with session and database

                                                ag.NotesMain();   call main routine of agent

                                                }

                                catch(NotesException ne) {

                                                System.out.println(ne.id + " " + ne.text);

                                                }

                                catch (Exception e)         {

                                                e.printStackTrace();

                                                }

                                finally {

                                                try {

                                                                if (db != null) db.recycle();

                                                                if (sess != null) sess.recycle();

                                                                }

                                                catch (Exception x) {}

                                                NotesThread.stermThread();

                                                }                                             

 

                } end main

               

 

                This routine is called however the code is run: from Eclipse or agent launch within Notes/Domino.

                public void NotesMain()

                {

                                Log notesLog=null;

                                Session sess=null;

                                Database db=null;

                                AgentContext ac=null;

                                Utilities util;

                                int logLevel;

                               

                                try {

                                                if (this.session != null)    Already have an agent context. 

                                                                {

                                                                sess = this.session;

                                                                db = this.database;

                                                                }

                                                else {  Need to get agent context. 

                                                                sess = this.getSession();

                                                                if (sess

null) throw new NotesException(NotesError.NOTES_ERR_ERROR, "Could not get current session at start of agent.");

                                                                ac = sess.getAgentContext();

                                                                if (acnull) throw new NotesException(NotesError.NOTES_ERR_ERROR, "Could not get agent context at start of agent.");

                                                                db = ac.getCurrentDatabase();

                                                                if (db==null) throw new NotesException(NotesError.NOTES_ERR_ERROR, "Could not get current database at start of agent.");

                                                                }

                                                }

                                catch(NotesException ne) {

                                                System.out.println(ne.id + " " + ne.text);

                                                return;

                                                }

                                catch (Exception e)         {

                                                e.printStackTrace();

                                                return;

                                                }

                                finally {};

                               

                                The truly common code, however we are invoked.

                                try {

 

                                                Get utilities.

                                                util = new Utilities();                      

                                               

                                                Record the session so other objects can use it.

                                                util.setSession(sess);

                                               

                                                Find all the runtime parameters.

                                                util.readParameters();

 

                                                Start a Notes log.

                                                notesLog = util.getNotesLog();

                                                logLevel = util.getLogLevel();

                                                if (Constants.CONSOLE_OUTPUT) System.out.println("Agent started. " + Constants.BUILD_STAMP);

                                                if (logLevel >= Constants.LOG_LEVEL_BRIEF) notesLog.logAction ("Agent started. " + Constants.BUILD_STAMP);         

 

                                                ******* Do the real work here ********

 

                                                System.out.println (db.getTitle());  print title of home database, to prove we got the agent context correctly

 

                                                ******* Do the real work here ********

 

                                                All done with no errors.

                                                if (logLevel >= Constants.LOG_LEVEL_BRIEF) notesLog.logAction ("Agent done with no errors.");

                                                if (Constants.CONSOLE_OUTPUT) System.out.println("Agent done with no errors.");

                                                } try

 

 

                                Catch Notes exceptions from main code.

                                catch(NotesException ne) {

                                                if (Constants.CONSOLE_OUTPUT) System.out.println("Notes error code " + ne.id + ". " + ne.text);

                                                try {

                                                                notesLog.logError (ne.id, ne.text);  Notes log may not be valid, but give it a try

                                                                }

                                                catch (Exception x) {}

                      ??                         }

 

                                Catch non-Notes exceptions from main code.

                                catch (Exception x)          {

                                                if (Constants.CONSOLE_OUTPUT) System.out.println("Error: " + x.getMessage());

                                                if (Constants.CONSOLE_OUTPUT)            x.printStackTrace();

                                                try {

                                                                notesLog.logError (NotesError.NOTES_ERR_ERROR, x.getMessage());  Notes log may not be valid, but give it a try

                                                                }

                                                catch (Exception x2) {}

                                                }

 

                                Do cleanup from main code block.

                                finally {

                                                try {

                                                                if (notesLog!=null) notesLog.close();

                                                                if (notesLog!=null) notesLog.recycle();

                                                                cannot recycle the AgentContext, Session or Database, since they may have been passed in by Notes.

                                                                }

                                                catch (Exception x){}

                                                } finally

                               

                } NotesMain

               

               

} main class

 

 

 

 


  • Actions Show Menu▼


expanded Attachments (0)
collapsed Attachments (0)
Edit the article to add or modify attachments.
expanded Versions (2)
collapsed Versions (2)
Version Comparison     
VersionDateChanged by              Summary of changes
This version (2)Sep 22, 2010, 1:44:07 PM~Laura Desnupulings  
1Sep 22, 2010, 1:37:33 PM~Cheryl Quetfanalitakol  
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedAbout
  • HCL Software
  • HCL Digital Solutions community
  • HCL Software support
  • BlogsDigital Solutions blog
  • Community LinkHCL Software forums and blogs
  • About HCL
  • Privacy
  • Accessibility