Access Domino object with Java (1)

xiaoxiao2021-03-06  38

Use Java to access objects in Domino, such as databases, views, documents, and more. This article briefly describes the basic programming method of accessing the Domino object with Java. The content in this article is mainly written according to Lotus Domino / Notes 6, which is slightly different when using R5.

Java's access to the Domino object is made by calling the Lotus.domino bag. In the operating environment, the interface in the Lotus.domino package is implemented by two packages:

Lotus.domino.local - Supports local calls.domino.cso on the computer where Notes / Domino is located - supports remote connections to the Domino server

For local connections, the Java program will run in the computer where the Notes client or the Domino server is located, using JNI to access the NOTES / DOMINO code.

For remote connections, the Java program accesses the services provided by Domino via CORBA. Remote access consists of two processes:

The client obtains the initial object of the server via the HTTP protocol, and the IOR (Interoperable Object Reference) client further obtains other objects on the server via the IIOP protocol.

In Lotus.Domino, the NotesFactory class provides CreateSession and other methods to start Java applications or servlets to Domino objects. Different call methods determine that access is local or remote.

To compile the Java program using the Lotus.domino package, you must include Notes.jar (local) or ncso.jar (remote) in the classpath (ClassPath). E.g:

Set classpath =% classpath%; c: /lotus/domino/notes.jar

or

Set classpath =% classpath%; C: /lotus/domino/data/domino/java/ncso.jar

Where notes.jar can be found in the NOTES / DOMINO installation program directory. Ncso.jar In the Domino / Java subdirectory in Domino Server or Domino Designer.

Local call

When using CreateSession, there is no parameters, the first parameter is null, or the first parameter is a null string represents a local call. The following code is equivalent:

Session s = notesfactory.creatession () session s = notesfactory.createsis ((string) null session s = notesfactory.createsis ("")

To perform local calls from the application and servlet, the Path (PATH) must contain the NOTES / DOMINO program, and NOTES.jar must be included in the classpath (Classpath). For example, when Domino is installed in "C: / Lotus / Domino":

Set path: =% path%; C: / Lotus / Domino set classpath: =% classpath%; C: /lotus/domino/notes.jar Notes.jar contains Lotus.domino and Lotus.Domino.local package.

Local calls require the use of the Notesthread class to manage threads. The Notesthread class expands Java.lang.Thread that includes initialization and termination code specifically for Domino. You can have three different ways to use it: through inheritance to perform threads through the runnable interface to perform threads through static methods

Implement thread by inheritance

To perform threads by inheritance, you need to extend NOTESTHREAD (instead of thread), including the Runnotes method (not the RUN method). The NotSthread thread can be started by the START method as other threads. This approach is more useful, it is not more likely to be wrong.

Import lotus.domino. *; public class myclass extends notesthread {public static void main (string argv []) {myclass t = new myclass (); t.start ();} public void runnotes () // entry point for not Notes Thread {Try {session s = notesfactory.createsis (); // Operational code goes here} catch (exception e) {E.printStackTrace ();}}}

Execute threads through the runnable interface

To perform threads through the runnable interface, you need to implement runnable and include the RUN method, which is exactly the same as those using threads. This approach can be used when you need to extend other classes and cannot extend the Notesthread class.

import lotus.domino *;. public class myClass implements Runnable {public static void main (String argv []) {myClass t = new myClass (); NotesThread nt = new NotesThread ((Runnable) t); nt.start (); } Public void run () // entry point for thread {try {session s = notesfactory.createsis (); // Operational code goes here} catch (exception e) {E.PrintStackTrace ();}}} (Source IBM official website)

转载请注明原文地址:https://www.9cbs.com/read-62250.html

New Post(0)