37
IBM VisualAge ® for Java , Version 3.5 Domino AgentRunner

Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

Embed Size (px)

Citation preview

Page 1: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

IBM VisualAge® for Java™, Version 3.5

Domino AgentRunner

���

Page 2: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

Edition notice

This edition applies to Version 3.5 of IBM VisualAge for Java and to all subsequent releases and modifications untilotherwise indicated in new editions.

© Copyright International Business Machines Corporation 1998, 2000. All rights reserved.US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contractwith IBM Corp.

Note!Before using this information and the product it supports, be sure to read the generalinformation under Notices.

Page 3: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

Contents

Chapter 1. Domino support . . . . . . 1Domino AgentRunner . . . . . . . . . . . 1

Chapter 2. Accessing Domino databases 3Running and debugging Domino agents using theDomino AgentRunner . . . . . . . . . . . 3

Setting up for the Domino AgentRunner . . . . 3Importing or creating an agent . . . . . . . 5Generating an AgentContext document . . . . 6Running and debugging your agent . . . . . 7Creating the production agent . . . . . . . 8

Chapter 3. Domino samples - overview 9Sample: intro . . . . . . . . . . . . . . 11

Sample: todo . . . . . . . . . . . . . . 12Sample: subjectsearch . . . . . . . . . . . 15Sample: mailquery . . . . . . . . . . . . 18Sample: dabsample . . . . . . . . . . . . 21Sample: displayvalues . . . . . . . . . . . 22Sample: db2andnotes . . . . . . . . . . . 26Sample: servlet . . . . . . . . . . . . . 27

Notices . . . . . . . . . . . . . . 29

Programming interface information . . 31

Trademarks and service marks . . . . 33

© Copyright IBM Corp. 1998, 2000 iii

Page 4: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

iv Domino AgentRunner

Page 5: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

Chapter 1. Domino support

Domino AgentRunnerThe Domino AgentRunner is a tool that helps you build, run and debug Dominoagents in VisualAge for Java. It uses a set of debug classes that access Lotus Notescontext information so that you can run and debug an agent in the VisualAge forJava Integrated Development Environment (IDE).

To use the AgentRunner, create an agent that extends DebugAgentBase in VisualAgefor Java, and then export the .class file to the file system. Create an agent in LotusNotes and import the .class file to run the agent. When you run the agent, it willgenerate an AgentContext document in the AgentRunner.nsf file. Now you can runthe agent inside the IDE with the AgentRunner. It accesses the AgentContextdocument to make the program behave as if it were running as a real agent in aLotus Notes environment.

When you have finished debugging your agent using the integrated debugger, youcan create the production agent simply by editing your class so that it extendsAgentBase, and then reimporting the class file to your agent in Lotus Notes.

See also “Sample: Intro.”

Integrated Debugger

Using the Domino AgentRunnerSample: Intro

© Copyright IBM Corp. 1998, 2000 1

Page 6: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

2 Domino AgentRunner

Page 7: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

Chapter 2. Accessing Domino databases

Running and debugging Domino agents using the DominoAgentRunner

The Domino AgentRunner makes it easy to run and debug your Domino agents inthe VisualAge for Java IDE. To use the Domino AgentRunner, you must haveDomino 4.6 or higher installed on your system.

Note: If you have Domino 4.6.x installed, you must work with Lotus Domino Javalibrary 4.6.1. If you have Domino 5.0.x installed, you must work with LotusDomino Java library 5.0.x.

Important! If you have the Lotus Domino Java library installed, then you cannotalso install the WebSphere Test Environment. In other words, the Lotus DominoJava library cannot co-exist with the WebSphere Test Environment in the IDE.

Your task flow will resemble the following:1. Set up for using the Domino AgentRunner.2. Create an agent that extends DebugAgentBase.3. Generate an AgentContext document in Lotus Notes.4. Debug your agent in VisualAge for Java.5. Create the production agent.

See also “Sample: intro.”

Domino AgentRunner

Setting up for the Domino AgentRunnerImporting or creating an agentGenerating an AgentContext documentRunning and debugging your agentCreating the production agentSample: intro

Setting up for the Domino AgentRunnerFor Domino 4.6, complete the following steps to set up your Domino environmentto support the Domino AgentRunner:1. Add the IVJAgentRunner.jar file to the JavaUserClasses statement in your

notes.ini file. If you do not already have a JavaUserClasses statement in yournotes.ini file, you can cut and paste the following statement to the end of yournotes.ini file:JavaUserClasses=X:\IBMVJava\eab\runtime30\domino\ar\IVJAgentRunner.jarwhere X :\IBMVJava is the installation path of VisualAge for Java. Because youhave edited the notes.ini file, you must shut down and restart Lotus Notes sothat your changes take effect.

2. Set your PATH to point to your Domino directory in your computer’s systemssettings.

© Copyright IBM Corp. 1998, 2000 3

Page 8: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

3. Copy the AgentRunner.nsf file from theX:\IBMVJava\eab\runtime30\domino\ar directory (where X:\IBMVJava is theinstallation path of VisualAge for Java) to your Domino \data directory.

For Domino 5.0.x, set your PATH to point to the Domino directory in yourcomputer’s systems settings.

Note: The AgentRunner.nsf file is packaged with Domino 5.0.x. (This file exists inyour Domino \data directory.)

Your Lotus Notes environment is now set up to support the AgentRunner.

When AgentRunner runs an agent that dynamically loads some classes, the IDEclasspath should be set to find those classes in the file system. For example, inorder for the AgentRunner to find DB2 so that it can run the sample agents thatuse DB2, do the following:1. From the Workbench, select Window> Options.2. Select the Resource option from the panel on the left side of the screen.3. Click the Editbutton.4. Click the Add Jar/Zip button.5. In the File Selection dialog, locate and select your db2java.zip file. Click Open.6. Click Apply.7. Click OK.8. Click OK to close the Options window.

Next, you have to set up your VisualAge for Java environment.

Add the Domino Java classes to the WorkbenchTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you mustadd the Domino Java class library to your Workspace.

For both Domino 4.6 and Domino 5.0.x, complete the following steps:1. From the Workbench, select the File menu, then Quick Start.2. Select Features from the list of categories on the left side of the window.3. Select Add Feature from the list of tasks on the right side of the window.4. Click OK.5. In the Selection Required window, select Lotus Domino Java library 4.6.1 (or

Domino Java class library 5.0.x, depending on which version of Domino youare working with).

6. Click OK.

A new project will appear on the All Projects view of the Workbench calledDomino Java class library. This project contains a lotus.notes package with all theJava Classes for Notes Object Interface/Domino 4.6 (or Java Classes for NotesObject Interface/Domino 5.0.x), and additional Debug classes that support theDomino AgentRunner. You can now use these classes when running or debuggingan agent in the IDE.

Now you are ready to import or create an agent. See “Importing or creating anagent.”

Domino AgentRunner

4 Domino AgentRunner

Page 9: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

Importing or creating an agentGenerating an AgentContext documentRunning and debugging your agentCreating the production agent

Importing or creating an agentCreate a project in the Workbench into which you will import your agent.

Creating a project in the IDETo create a project, do the following:1. Go to the Projects page of the Workbench.2. Right-click on an empty space in the All Projects view.3. Select Add> Project. The Add Project SmartGuide will open.4. Select the Create a new project named radio button.5. Enter a name such as Domino Agents in the text field.6. Click Finish.

When the SmartGuide closes, you will have a new project in the Workbench calledDomino Agents.

You are now ready to import an agent from your file system, or create a new agentin the IDE.

Importing an agentTo import an agent from your file system into your Domino Agents project, do thefollowing:1. Right-click the Domino Agents project.2. Select Import.A SmartGuide will open.3. Select Directory as your import source.4. Click Next.5. Fill in the Directory field with the path that contains your agent’s .java file.6. Select the .java checkbox.7. Click the Details button beside .java and select the java file that you want to

import. Click OK.8. Click Finish.9. Then, in your Java source code, change

public class Intro extends AgentBasetopublic class Intro extends DebugAgentBase

10. Save your code.

The imported Java code is compiled and any unresolved problems that areintroduced are added to the All Problems page.

Your .java file will appear under your Domino Agents project in the Workbench.

Creating an agentTo create a new agent in VisualAge for Java:1. Right-click on your Domino Agents project.2. Select Add, then Class. The Create Class SmartGuide will open.

Chapter 2. Accessing Domino databases 5

Page 10: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

3. Enter a package name in the Package text field.4. Select the Create a new class radio button. The Create Class SmartGuide opens.5. Enter a class name for you agent, and select DebugAgentBase as your

Superclass.6. Click Finish.

Your new package and class will appear under your Domino Agents project in theWorkbench. Left-click on your class. In the Source window of the Workbench,write the code for your agent. (For a detailed description for Domino 4.6, see theJava Programmer’s Guide in the Lotus Notes 4.6 instructions; for Domino 5.0.x, seeJava Classes, under “Domino 5 Designer Help.”)

When you have finished writing your agent, you should generate an AgentContextdocument so that you can run your agent in the IDE. See “Generating anAgentContext document.”

Domino AgentRunnerProjects and other program elements

Creating a classWriting and formatting source codeSaving changes to codeSetting up for the Domino AgentRunnerGenerating an AgentContext documentRunning and debugging your agentCreating the production agent

Generating an AgentContext documentBefore you can generate the AgentContext document you have to export youragent’s .class file from the IDE to the file system, so that it can be read by LotusNotes.

Exporting your .class file to the file systemTo export your agent’s .class file from the Workbench, complete the following:1. Select your agent, and right-click.2. Select Export.3. Select the Directory radio button. The Export to a directory SmartGuide opens.4. Enter the path where you want to export the file in the text field.5. Select the .class check box.6. Click the Detailsbutton beside the .class check box.7. Select the .class file that you want to export.8. Click OK.9. Click Finish.

Your agent’s .class file is now in the file system. Next, you should generate yourAgentContext document in a Lotus Notes database.

Generating an AgentContext documentFor Domino 4.6, to create a Java agent in a Lotus Notes database, complete thefollowing:

6 Domino AgentRunner

Page 11: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

1. Open Lotus Domino 4.6.2. Create your agent in the appropriate database.3. Fill in the particulars for your agent.4. Select the Java radio button for What should this agent run5. Click Import Class Files.6. Select the file you exported from VisualAge for Java. Click OK.7. Save your agent, and then run it.

For Domino 5.0.x, to create a Java agent in a Lotus Notes database, complete thefollowing:1. Open Lotus Domino 5.0.x.2. Create your agent in the appropriate database.3. Fill in the particulars for your agent.4. In the Run field, select Imported Java from the drop-down menu.5. Click Import Class Files.6. Select the file you exported from VisualAge for Java. Click OK.7. Save your agent, and then run it.

The AgentContext document is automatically generated in the AgentRunner.nsfwhen you run your agent in Lotus Notes from an agent class that extendsDebugAgentBase. A call to getSession() will, after generating an AgentContextdocument, return null.

When you have generated an AgentContext document, you are ready to run anddebug your agent in the VisualAge for Java IDE. See “Running and debuggingyour agent.”

Domino AgentRunner

Exporting bytecodeSetting up for the Domino AgentRunnerImporting or creating an agentRunning and debugging your agentCreating the production agent

Running and debugging your agentFollow these steps to run and debug your agent in the IDE:1. Set one or more breakpoints in the NotesMain() method of your agent.2. Right-click to select your agent.3. Select Tools > Domino AgentRunner.

You have the following two options:v You can modify your AgentContext or select a different AgentContext:

1. Select Properties. The AgentRunner window opens.2. Select the AgentContext that you wish to use, and then click Run Agent.3. To modify your agent, click Update Agent Context. You can change the

Agent Runs on and Search Criteria fields to generate the

Chapter 2. Accessing Domino databases 7

Page 12: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

UnprocessedDocuments collection that you would like to use for debuggingpurposes. You must supply this information because it cannot be determinedfrom running the agent.

4. When you have finished updating your AgentContext, click the UpdateAgentContext Document button.

5. Close the window.6. Click Run Agent to run the agent or click Save Selection first to make your

new AgentContext the default choice.v You can run your agent with the default AgentContext document by selecting

Run.Attention: This is either the last AgentContext that you ran or the last one yousaved.If you have set any breakpoints or have errors in your code, the Debuggerwindow will open and allow you to step through your code.

When your code is error-free, you can create the production agent. See “Creatingthe production agent.”

Domino AgentRunnerIntegrated Debugger

Debugging during the development cycle with the Integrated DebuggerSetting breakpoints in the source codeSetting up for the Domino AgentRunnerImporting or creating an agentGenerating an AgentContext documentCreating the production agent

Creating the production agentWhen you have finished developing your agent and you want to move your agentto Lotus Notes, complete these steps in VisualAge for Java:1. Change the Base class for your agent to extend AgentBase instead of

DebugAgentBase.2. Export the .class file to the file system.

Open the agent in Lotus Notes and reimport the .class file from the file system.You can now run your agent in Lotus Notes.

Domino AgentRunner

Writing and formatting source codeSaving changes to codeExporting bytecodeSetting up for the Domino AgentRunnerImporting or creating an agentGenerating an AgentContext documentRunning and debugging your agent

8 Domino AgentRunner

Page 13: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

Chapter 3. Domino samples - overview

The samples listed at the end of this document demonstrate how to use agents,applications and applets as well as VisualAge for Java tools to connect to yourDomino or DB2 database.

Important! For these samples, you must have Domino 5.0.x or higher installed.These samples replace the ones that were packaged with the VisualAge for Java,Version 3.0 release.

Environment setupTo run all of the Domino samples, you must follow these steps to set up yourenvironment:1. Add the projects from the repository to your workspace. The easiest way to

add them is by using Quick Start:a. From the Workbench, select File> Quick Start.b. Select Feature from list of categories on the left side of the Quick Start

window.c. Select Add Feature from the list of options on the right side of the Quick

Start window.d. Click OK. The Selection Required window opens.e. Select all of the following features by left-clicking (to select multiple

features, hold down the Ctrl key as you select each of the features):v Lotus Domino Java library 5.0.xv Data Access Beansv IBM Domino Examplesv RMI Access Builder (for the countsdocclient sample)

f. Click OK. An information window with a progress bar will show what youare adding to your workspace. When it is finished, the features that youselected will appear as projects in your Workbench window.

g. Open the IBM Domino Examples project to see the Domino samples that areavailable.

2. For some of the samples, you must have the DeptDesc.nsf, the EmployeeSample.nsf, or the SampleMailDB.nsf set up in your Dominoenvironment. Using the command line, copy these files from theX:\IBMVJava\eab\samples\domino directory (where X:\IBMVJava is the driveand directory where you installed VisualAge for Java) into yourY:\Lotus\notes\data directory (where Y is the drive onto which you installedLotus Notes).

3. Ensure that JavaDlgSettings is in your notes.ini file and that JavaUserClassesincludes a path to your SQLLIB directory. If you are missing these settings, youcan cut the following lines and paste them at the end of your notes.inifile. Make sure that you change the JavaUserClasses path to that of yourdirectory.JavaDlgSettings=*.class|*.jar,*.cab,*.zip|*.jpg,*.gif,*.au|*.java|1JavaUserClasses=d:\sqllib\java\db2java.zip

4. After you have changed your notes.ini file, you must close and reopen LotusNotes for the changes to take effect.

© Copyright IBM Corp. 1998, 2000 9

Page 14: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

5. Set a pointer to Y:\Lotus\notes in your PATH statement in your computer’ssystem settings.

6. If you are using the AgentRunner, you must also follow the other setup stepsdescribed in Setting up for the AgentRunner.

7. If you are going to run the samples outside the IDE, set your classpath to pointto your db2java.zip file and your notes.jar file in your system’s settings.

Preparation for DB2For the samples that access DB2, you must add the DB2 class library to the IDEand to your classpath.

To create a project for the DB2 class library, do the following:1. Right-click on a project or package in the Workbench.2. Select Add> Project. The Add Project SmartGuide will open.3. Select the Create a new project named: radio button and enter the name DB2

Class Library in the text field.4. Click Finish. The project will be added to the Workbench.

To add the classes to the Workbench, do the following:1. Select File > Import. The Import SmartGuide will open.2. Select the Jar file radio button.3. Click Next.4. Enter the path to your db2java.zip file or use the Browse option to find the file.5. Select the class radio button, then click the Details button beside it.6. Select all of the classes, and click OK.7. Click Finish.

The classes will be added to your DB2 Class Library project.

When you use DB2, you must ensure that the DB2 Class Library is in the classpathfor that sample.

Building the samplesSome of the samples include build instructions that you can follow to actuallybuild the sample yourself. Before you build a sample, you have to create a projectto put it in:1. In the Workbench window, right-click in the All Projects pane.2. Select Add> Project. The Add Project SmartGuide will open.3. Select the Create a new project named radio button and enter MySamples as

the project name.4. Click OK. The SmartGuide will close and the project will appear in your

Workbench.

The samplesClick on a sample name to access the run and build instructions.1. Sample: Intro This sample demonstrates how to use the Domino AgentRunner

with a simple agent.2. Sample: todo This sample demonstrates how to create an agent that uses the

Lotus Domino API.3. Sample: subjectsearch This sample is an agent which runs against a database

retrieving all documents that have the same subject as the document youinvoke the agent against.

10 Domino AgentRunner

Page 15: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

4. Sample: mailquery This sample shows how an agent can access multipledatabases.

5. Sample: dabsample This sample demonstrates how to use Data Access Beans toaccess a Domino database.

6. Sample: displayvalues This sample demonstrates an application that connects toLotus Notes using the Lotus Domino API.

7. Sample: db2andnotes This sample shows the use of the database support usingthe JTable class and associated classes.

8. Sample: servlet This sample is a servlet that takes parameters and returnsinformation from a Domino database.

Sample: introObjectiveThe objective of this sample is to demonstrate how to use the DominoAgentRunner.

Time requiredAllow 20 minutes to build and run this sample.

Before you beginTo build and run this sample, you need to have Domino 5.0.x or higher installed.

Set up your Workbench for using the samples by following the steps in theDomino samples - overview.

Set up your Lotus Notes and VisualAge for Java environments to support theDomino AgentRunner by following the steps in the task file Setting up for theAgentRunner. Then, return to this sample.

DescriptionThis sample is a simple agent that will tell you the title of the database on whichthe agent is running.

Running the sampleOnce you have set up your Lotus Notes and VisualAge for Java environments youhave to do the following:1. Export your class file to the file system.2. Create and run the agent in notes to create an AgentContext document.3. Return to the AgentRunner to run and debug the agent.

1. Export the .class fileTo export the .class file from the com.ibm.ivj.examples.domino.intro package inVisualAge for Java to the file system, so that it can be read by Lotus Notes:1. Open the IBM Domino Examples project in the Workbench and expand the

com.ibm.ivj.domino.samples.agents.intro package.2. Right-click the Intro class.3. Select Export. The Export SmartGuide will open.4. Select the Directory radio button as your export destination. Click Next.5. In the Directory text field, enter a location in the file system where you want to

export the .class file.6. Select the .class checkbox and click Details.

Chapter 3. Domino samples - overview 11

Page 16: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

7. Select the IBM Domino Examples and theIntro::com.ibm.ivj.domino.samples.agents.intro checkboxes. Click OK.

8. Deselect the .java and resource checkboxes if they are selected.9. Click Finish.

When you export files to the file system, the directory path of the file ismaintained. For example, if you entered X:\VAJexport as your export destination,the Intro.class file will be inX:\VAJexport\com\ibm\ivj\domino\samples\agents\intro.

2. Create the agent in Lotus NotesFor the AgentRunner to work in the IDE, you have to provide it with a context forrunning your agent. To create an AgentContext document, do the following:1. Open any database.2. From the Create menu, select Agent.3. Enter a name for your agent, such as MyIntro.4. From the When should this agent run? drop-down menu, select Manually

From Actions Menu.5. From the Which document(s) should it act on? drop-down menu, select All

documents in database.6. From the Run drop-down menu, select Imported Java.7. Click the Import Class Files button.8. Locate and select the Intro.class file that you exported from VisualAge for

Java. Click Add/Replace All.9. Click OK.

10. Press the Esc key to close the Create Agent window. You will be asked if youwant to save your changes. Click Yes.

Running the agent in Lotus NotesFrom the Actions menu of the Domino database, select MyIntro. The agent willrun but the session will return Null. An AgentContext document will be created inthe AgentRunner.nsf database.

3. Run the agent in the IDE using Domino AgentRunnerNow you are ready to run the agent in the Domino AgentRunner.

To run your agent from the Workbench, do the following:1. Open the Console window by selecting Window > Console. This window will

show the status of your agent.2. In the Projects workspace, right-click the Intro class.3. In the pop-up menu, select Tools > Domino AgentRunner > Run.

The Domino AgentRunner will run your agent using the AgentContext documentthat you created in Lotus Notes. The Console will display a message indicatingthat the Intro Agent is running. When it has run against your Lotus Notesdatabase, it will return the title of the database in which you created the agent inLotus Notes.

Sample: todoObjectiveThe objective of this sample is to create a Lotus Notes agent that uses the LotusDomino Java API.

12 Domino AgentRunner

Page 17: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

Time requiredAllow 30 minutes to run this sample with its supplied content and look over theoutput.

Before you beginTo run this sample you need the following products:v VisualAge for Javav Domino 5.0.x or higher running as a clientv Domino 5.0.x or higher running as a server - this is not needed if you initiate

your agent manually, for example from the Actions menu.

Follow the steps in the Domino samples - overview to prepare for the sample. Ifyou want to use the Domino AgentRunner, you also have to follow the steps inSetting up for the AgentRunner. Then, return to this sample.

DescriptionThis sample automatically checks a databases’s to-do list once per day for anyitems that are due. A mail message will then be sent to the current Notes user ofthe due items reminding them what tasks are due that day. For the purpose ofmaking the samples run relatively quickly we have provided a database calledSample Mail Database (SampleMailDB.nsf). Using this database will be much fastersince it is most likely smaller than your own mail database. (This file should belocated in the X:\Lotus\notes\data directory, where X:\Lotus is where youinstalled Domino 5.0.x. If it is not, you must copy the file into this directory inorder for it to be visible in Lotus Notes.)

Export the .class fileTo export the .class file from the com.ibm.ivj.examples.domino.todoagent packagein VisualAge for Java to the file system so that it can be read by Lotus Notes, dothe following:1. Open the IBM Domino Examples project in the Workbench and expand the

com.ibm.ivj.domino.samples.agents.todo package.2. Right-click on the ToDo class.3. Select Export. The Export SmartGuide will open.4. Select the Directory radio button as your export destination. Click Next.5. In the Directory text field, enter a location in the file system where you want to

export the .class file.6. Select the .class checkbox and click Details.7. Select the IBM Domino Examples and then the

ToDo::com.ibm.ivj.domino.samples.agents.todo checkboxes. Click OK.8. Deselect the .java and resource checkboxes if they are selected.9. Click Finish.

When you export files to the file system, the directory path of the file ismaintained. For example, if you entered X:\VAJexport as your export destination,the ToDoAgent.class file will be inX:\VAJexport\com\ibm\ivj\domino\samples\agents\todo.

Create the agent in Notes

1. Open the provided mail database Sample Mail Database (SampleMailDB.nsf).This database should be visible to you in Lotus Notes if you copied it into the\notes\data\ directory. You may also use your own mail database (this maytake longer, depending on the size of your mail database).

Chapter 3. Domino samples - overview 13

Page 18: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

2. From the Create menu, select Agent.3. Enter a name for the agent, such as CheckTodo.4. From the drop-down list When should this agent run?, select On Schedule

Daily.5. Click the Schedule button.6. From the Schedule window, enter a time for the agent to run, select the Don’t

run on weekends checkbox, and have the agent run on your local database.7. Click OK.8. From the Which documents should it act on? pull-down menu, select All

documents in database.9. Click the Add Search button.

10. From the Condition drop-down list, select By Form Used. In the Form field,select To Do. Click OK.

11. From the Run drop-down list, select Imported Java. Then, click the ImportClass Files button located in the bottom-left corner.

12. Locate the ToDo.class file, and select it.13. Click Add/Replace All.14. Click OK.15. Press the Esc key to close the Create Agent window. You will be asked if you

want to save your changes.16. Click Yes.

Run the agent in Notes to create AgentContextSince this agent is not run manually from the drop-down list, we will have to startit another way.1. The database should still be open. From the View menu, select Agents. The

agent window will open.2. Scroll down until you find the CheckTodo agent.3. Right-click CheckTodo, and select Run from the drop-down menu.4. The agent will run and display the results. Click OK.

Run the agent in the IDE using AgentRunnerTo run your agent from the Workbench, do the following:1. Open the Console window by selecting Window > Console. This window will

show the status of your agent.2. In the Projects workspace, right-click the ToDo class.3. Select Tools > Domino AgentRunner > Run.

The Domino AgentRunner will run your agent using the AgentContext documentthat you created in Lotus Notes.

Updating your AgentContextTo change which documents you want the agent to run against, do the following:1. Right-click the ToDo class.2. Select Tools > Domino AgentRunner > Properties. The Properties window will

open.3. Click the Update Agent Context button.4. Select which documents you want the agent to run against like you would in

Lotus Notes.5. Add a description so you can identify your context.

14 Domino AgentRunner

Page 19: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

6. Click Update Agent Context Document.7. Close the window.8. Select your new agent context.9. Click the Run Agent button from the AgentRunner window.

The Domino AgentRunner will run your agent with your updated agent context.

Creating the production agentWhen your agent runs without errors, you can create the production agent bytaking it out of ’Debug’ mode.

Open your ToDo agent class file in the Workbench. In the Source window, changewhat the class extends from DebugAgentBase to AgentBase. Click your ToDo class inthe All Projects window. You will be asked if you want to save your changes. ClickYes.

Export the .class fileYour agent is now in its completed state and can be run in Lotus Notes. Export the.class file to the file system using the Export SmartGuide. Open your agent inLotus Notes and reimport the ToDo.class file.

Running the agentYou now have an agent that will check a database’s to-do list for any tasks that aredue today.

To test the agent, create a task and set the due date as today’s date. Create anothertask with some other day as the due date. When the agent runs manually or at thetime you specified, the current Notes user will receive a mail reminder that thetask is due that day.

Sample: subjectsearchObjectiveThe objective of this sample is to create an agent that searches the documents in aDomino database.

Time requiredAllow 30 minutes to create and run this agent.

Before you beginTo build and run this sample, you need to have Domino 5.0.x or higher installed.

To prepare for the sample, follow the steps in Domino samples - overview. If youwant to use the Domino AgentRunner, you also have to follow the steps in Settingup for the AgentRunner. Then, return to this sample.

DescriptionThis sample takes the Subject of the current document against which the agent isrun, and searches all other document for subjects containing the current documentssubject. A mail message will then be sent to the user running the agent with a listof all documents with matching subjects; a link to each document will be provided.

For example, if you select a document with the subject ’Hello World’ and theninvoke the agent, a list of all the documents that contain the string ’Hello World’ inthe subject field will be returned in a mail message, with a link to eachdocument. The Domino database called Sample Mail Database (SampleMailDB.nsf)

Chapter 3. Domino samples - overview 15

Page 20: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

is provided. Using this database will be much faster since it is most likely smallerthan your own mail database. (This file should be located in theX:\Lotus\notes\data directory, where X:\Lotus is where you installed Domino5.0.x. If it is not, you must copy the file into this directory in order for it to bevisible in Lotus Notes.)

Export the .class fileTo export the .class file from the com.ibm.ivj.examples.simpleagent package inVisualAge for Java to the file system so that it can be read by Lotus Notes:1. Open the IBM Domino Examples project in the Workbench and expand the

com.ibm.ivj.domino.samples.agents.subjectsearch package.2. Right-click the SubjectSearch class.3. Select Export. The Export SmartGuide will open.4. Select the Directory radio button as your export destination. Click Next.5. In the Directory text field, enter a location in the file system where you want to

export the .class file.6. Select the .class checkbox and click Details.7. Select the IBM Domino Examples and then the

SubjectSearch::com.ibm.ivj.domino.samples.agents.subjectsearch checkboxes.Click OK.

8. Deselect the .java and resource checkboxes if they are selected.9. Click Finish.

When you export files to the file system, the directory path of the file ismaintained. For example, if you entered X:\VAJexport as your export destination,the SimpleAgent.class file will be inX:\VAJexport\com\ibm\ivj\domino\samples\agents\subjectsearch.

Create the agent in Lotus NotesFor the AgentRunner to work in the IDE, you must provide it with a context forrunning your agent. In this sample, you run the agent in your Lotus Notes maildatabase but you can create the agent in any database. To create an AgentContextdocument, do the following:1. Open the provided mail database Sample Mail Database (SampleMailDB.nsf).

This database should be visible to you in Lotus Notes if you copied it into the\notes\data\ directory. You may also use your own mail database (this maytake longer, depending on the size of your mail database).

2. From the Create menu, select Agent.3. Enter a name for the agent, such as FindRelatedDocuments.4. From the When should this agent run? pull-down menu, select Manually

from Actions Menu.5. From the Which documents should it act on? pull-down menu, select All

documents in database.6. From the Run drop-down list, select Imported Java. Then, click the Import

Class Files button located in the bottom-left corner.7. Locate the SubjectSearch.class file, and select it.8. Click Add/Replace All.9. Click OK.

10. Press the Esc key to close the Create Agent window. You will be prompted tosave your changes.

11. Click Yes.

16 Domino AgentRunner

Page 21: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

Run the agent in Lotus Notes to create the AgentContextOpen the Java Console in Lotus Notes by selecting File > Tools >Show JavaDebug Console so you can monitor your agent. Select a document that has as itssubject the text string you want your agent to search for. From the Actions menuof the Domino database, select FindRelatedDocuments. The agent will run but thesession will return Null. An AgentContext document will be created in theAgentRunner.nsf

Run the agent in the IDE using AgentRunnerYou are now ready to run the agent in the AgentRunner. To run your agent fromthe Workbench, do the following:1. Open the Console window by selecting Window > Console. This window will

show the status of your agent.2. Right-click the SubjectSearch class.3. Select Tools > Domino AgentRunner > Run.

The Domino AgentRunner will run your agent using the AgentContext documentthat you created in Lotus Notes.

Updating your AgentContext (optional)To change which documents you want the agent to run against, do the following:1. In the Project workspace of the IDE, right-click the SubjectSearch class.2. Select Tools > Domino AgentRunner > Properties. The Properties window will

open.3. Click the Update Agent Context button.4. Select which documents you want the agent to run against as you would in

Lotus Notes.5. Add a description so that you can identify your context.6. Click Update Agent Context Document.7. Close the window.8. Select your new agent context.9. Click the Run Agent button from the AgentRunner window.

The Domino AgentRunner will run your agent with your updated agent context.

Creating the production agentWhen your agent runs without errors, you can create the production agent bytaking it out of ’Debug’ mode.

Open your SimpleAgent class file in the Workbench. In the Source window, changewhat the class extends from DebugAgentBase to AgentBase. Click your SubjectSearchclass in the All Projects window. You will be prompted to save your changes. ClickYes.

Exporting the .class fileYour agent is now in its completed state and can be run in Lotus Notes. Export the.class file to the file system using the Export SmartGuide. Open your agent inLotus Notes and reimport the SimpleAgent.class file.

Running the agent in Lotus NotesTo run the agent, select a mail document with a common subject. Select your agentfrom the Actions menu. The agent will run and send you a mail message that

Chapter 3. Domino samples - overview 17

Page 22: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

contains all the documents in the database that contain the subject of the documentyou ran the agent against. Open the mail message and select the links to therelated documents.

Sample: mailqueryObjectivesThe following are the objectives of this sample:v To show Domino Lotus Objects and DB2 togetherv To use Lotus Notes API’s to format a message.

Time requiredAllow 30 minutes to create and run this sample.

Before you beginTo build and run this sample you need the following:v VisualAge for Javav DB2v Domino 5.0.x or higher running as both client and server

Follow the steps in the Domino samples - overview to prepare for the sample. Ifyou want to use the Domino AgentRunner, you also have to follow the steps inSetting up for the AgentRunner. Then, return to this sample.

Preparing for DB2To set your DB2 userid and password in the source code, do the following:1. Expand the IBM Domino Examples project.2. Expand the com.ibm.ivj.domino.samples.agents.mailquery package.3. Expand the mailquery class4. Select the processDB2(String) method.5. Find the line connectObject = DriverManager.getConnection(url, “USERID”,

“PASSWORD”);

6. Change the parameters USERID and PASSWORD to the userid and password thatyou use to connect to DB2.

7. Save your changes.

Set your workspace classpathThis agent can run against Lotus Notes and/or DB2 databases. To run against DB2,you need access to the DB2 class library. This needs to be added to yourworkspace classpath.1. Select Window > Options.2. Select Resources.3. Click on the Edit button.4. Click on the Add Jar/Zip button.5. Locate the db2java.zip file (for example, X:\SQLLIB\Java\db2java.zip)6. Click OK and then OK again.

Ensure that DB2 Java net support is running by entering db2jstrt 8888 on acommand line.

DescriptionThis sample shows a Lotus Notes agent that runs automatically when new mailarrives. It checks the incoming mail to see if it is a special mail request that

18 Domino AgentRunner

Page 23: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

matches a certain format. If so, the mail is read and a database query is run. Theresults of the query are sent back to the current Lotus Notes user. The Dominodatabase called Sample Mail Database (SampleMailDB.nsf) is provided. Using thisdatabase will be much faster since it is most likely smaller than your own maildatabase. (This file should be located in the X:\Lotus\notes\data directory, whereX:\Lotus is where you installed Domino 5.0.x. If it is not, you must copy the fileinto this directory in order for it to be visible in Lotus Notes.)

Export the .class File

1. Open the IBM Domino Examples project in the Workbench and expand thecom.ibm.ivj.domino.samples.agents.mailquery package.

2. Right-click the mailquery class.3. Select Export. The Export SmartGuide will open.4. Select the Directory radio button as your export destination. Click Next.5. In the Directory text field, enter a location in the file system where you want to

export the .class file.6. Select the .class checkbox, and click Details.

7. Select the IBM Domino Examples and then themailquery::com.ibm.ivj.domino.samples.agents.mailquery checkboxes. ClickOK.

8. Deselect the .java and resource checkboxes if they are selected.9. Click Finish.

When you export files to the file system, the directory path of the file ismaintained. For example, if you entered X:\VAJexport as your export destination,the mailquery.class file will be inX:\VAJexport\com\ibm\ivj\domino\samples\agents\mailquery.

Set up Lotus Notes to run the agent

1. Open the provided mail database Sample Mail Database (SampleMailDB.nsf).This database should be visible to you in Lotus Notes if you copied it into the\notes\data\ directory. You may also use your own mail database (this maytake longer, depending on the size of your mail database).

2. Select Create > Agent.3. Enter a name for the agent, such as CheckMail.4. From the When should this agent run? drop-down list, select After New Mail

Has Arrived.5. From the Run drop-down list, select Imported Java. Then, click the Import

Class Files button located in the bottom-left corner.6. Locate the mailquery.class file, and select it.7. Click Add/Replace All.8. Click OK.9. Press the Esc key to close the Create Agent window. You will be asked if you

want to save your changes. Click Yes.

Run the agent in Lotus Notes to create AgentContextIf you used the SampleMailDB.nsf, then there are already two files in the inboxwith the following:

This mail message will query the Lotus Notes database:

Chapter 3. Domino samples - overview 19

Page 24: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

DBQUERY as the subjectDATABASE: NOTES DeptDesc.nsfQUERY: SELECT Deptno,Deptname WHERE Deptno=’E11’ as the body of the

message.

This mail message will query the DB2 databse:

DBQUERY as the subject andDATABASE: DB2 JDBC:DB2://localhost:8888/SAMPLE

QUERY: Select * from Employee as the body of the message.

If you used your own mail database:1. To query your DB2 database, send yourself a mail message exactly like the

second file above.2. To query your Notes database, send yourself a mail message exactly like the

first file above.3. To query both databases, send yourself both mail messages.

Since this agent is not run manually from the pull-down list, we will have to startit another way. The database should still be open.1. Select View > Agents. And the agent window should open.2. Scroll down until you find the CheckMail agent.3. Right-click the CheckMail agent, and select Run.4. The agent will run and create an AgentContext, and display the results.5. Click OK.

Run the agent in the IDE using AgentRunnerYou are now ready to run the agent in the Domino AgentRunner. To run youragent from the Workbench, do the following:1. Open the Console window by selecting Window > Console. This window will

show the status of your agent.2. Right-click the mailquery class.3. Select Tools > Domino AgentRunner > Run.

The agent will run and query the specified databases. The results will be mailed tothe current Lotus Notes user.

Updating your AgentContextTo change which documents you want the agent to run against, do the following:1. Right-click the mailquery class.2. Select Tools > Domino AgentRunner > Properties. The Properties window will

open.3. Click the Update Agent Context button.4. Select which documents you want the agent to run against as you would in

Lotus Notes.5. Add a description so that you can identify your context.6. Click Update Agent Context Document.7. Close the window.8. Select your new agent context.9. Click the Run Agent button from the AgentRunner window.

The Domino AgentRunner will run your agent with your updated agent context.

20 Domino AgentRunner

Page 25: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

Create the production agentWhen your agent runs without errors, you can create the production agent bytaking it out of ’Debug’ mode.

Open your mailquery class file in the Workbench. In the Source window, changewhat the class extends from DebugAgentBase to AgentBase. Click your mailqueryclass in the All Projects window. You will be asked if you want to save yourchanges. Click Yes.

Export the .class fileYour agent is now in its completed state and can be run in Lotus Notes. Export the.class file to the file system using the Export SmartGuide. Open your agent inLotus Notes and reimport the mailquery.class file.

Running the agentTo query your Lotus Notes database, send yourself a mail message withDBQUERY as the subject andDATABASE: NOTES DeptDesc.nsf

QUERY: SELECT Deptno,Deptname WHERE Deptno='E11'

as the body of the message.

To query your DB2 database, send yourself a mail message with DBQUERY as thesubject andDATABASE: DB2 JDBC:DB2://localhost:888/SAMPLE

QUERY: Select * from Employee

as the body of the message.

The results of the query will be sent to you as a mail message.

Sample: dabsampleObjectiveThis sample shows how to use Data Access Beans to access a Domino database.

Time requiredTo run the sample with its supplied content and take time to review the output,allow yourself 20 to 30 minutes.

Before you beginYou need to have the following tools:v VisualAge for Javav Domino 5.0.x or higherv Lotus Domino driver for JDBC - this can be downloaded from the Lotus Web

site.

Follow the steps in Domino samples - overview for setting up your Lotus Notesand VisualAge for Java environments.

DescriptionThis sample retrieves information from a Domino database using the LotusDomino Driver for JDBC that is accessed with Java using the Data Access Beans,and displayed using Swing beans. The database that is used is the providedDeptDesc.nsf database. This sample is located in the IBM Domino Examples

Chapter 3. Domino samples - overview 21

Page 26: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

project and resides under thecom.ibm.ivj.domino.samples.applications.dabsample package.

Set up the workspace class path

1. Select Window > Options.2. Click on Resources.3. In the workspace class path, type in the path to the JdbcDomino.jar or click on

the Edit button to locate it. The path may resemble the following:X:\Lotus\notes\JdbcSql\Lib\JdbcDomino.jar;where X:\Lotus is the drive and directory in which you installed Domino 5.0.x.

4. Click OK.

Run the application1. In the Project workspace, expand the

com.ibm.domino.samples.applications.dabsample package.2. Right-click the DAApp class.3. Select Run > Run main. The application will open.4. Use the toolbar at the bottom of the application to scroll through the members

of the department. On the toolbar, the button with the person icon on it is usedto start the application, and grab the first query result. Click the person iconfirst. Use the arrow buttons to navigate through the database. Click the lastbutton to refresh the information.

Sample: displayvaluesObjectives

v To create an application that retrieves information from a Domino database.v To create a GUI application that uses a non-visual Domino database bean.v To connect to Lotus Notes using the Lotus Domino API.

Time requiredAllow yourself one hour to create and run this sample. If you simply want to runthe sample with its supplied content and then review the output, allow yourself 20to 30 minutes.

Before you beginTo build and run this sample, you need the following tools:v VisualAge for Javav Domino 5.0.x

Follow the steps in the Domino samples - overview for setting up your LotusNotes and VisualAge for Java environments.

This sample is contained in the packagecom.ibm.ivj.domino.samples.applications.displayvalues.

DescriptionThis sample uses the VisualAge for Java Visual Builder Lotus Domino API tocreate an application. The application retrieves data from a Domino database usingthe Lotus Domino API.

This sample allows you to do the following:v Create a GUI using the Visual Composition Editor beans palette.

22 Domino AgentRunner

Page 27: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

v Connect to the database using the Lotus Domino API.v Add user code to classes and methods.v Perform a query and receive information from the DeptDesc.nsf database.

This application runs inside and outside VisualAge for Java.

Running the sample

1. In the Workbench, expand the IBM Domino Examples project.2. Expand the com.ibm.ivj.domino.samples.applications.displayvalues package.3. Right-click the DisplayFieldValue class.4. Select Run > Run main.

Select a field from the choice list. Press the GetValue button to return the value ofthe field that you selected.

Building the sampleTo see the GUI that you are going to recreate, double-click the DisplayFieldValueclass located in the com.ibm.ivj.domino.samples.applications.displayvalues project.Keep this window open for reference.

Creating the GUICreate a new package called GetValue to be contained within a new project called,for example, MySamples.1. Right-click on the GetValue package, and select Add > Class. The Create Class

SmartGuide will open.2. Select the Create a new class radio button.3. Enter Mydisplay as the class name.4. Click the Browse button, and select Frame as your superclass.5. Select java.awt as the package name.6. Click OK.7. Select the Compose the class visually check box.8. Click Finish.

The Visual Composition Editor will open. The Composition Editor pane willcontain your Mydisplay frame bean. The dispose() method is automaticallygenerated.

From the bean selection panel, select AWT. You will see the beans that areavailable for you to use. Add the following beans to your canvas:v four labelsv one buttonv one text fieldv one choice list

Name and align these fields in the same format as they appear in theDisplayFieldValue bean. See the VisualAge for Java online help for detaileddescriptions on how to manipulate the beans.

Creating a methodBefore you create the connections, you must create the getAnswer(),createConnection(), and terminateConnection() methods.

To create the getAnswer() method, follow these steps:

Chapter 3. Domino samples - overview 23

Page 28: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

1. From the Workbench, right-click on your Mydisplay class.2. Select Add > Method. The Create Method SmartGuide will open.3. Select the Create a new method radio button.4. Create a new method called with the method name String getAnswer (String

field).5. Click Next, and then click Next again to add an exception.6. From the Attributes window, select the Add button beside What exceptions

may this method throw?

7. From the list, choose NotesException and lotus.domino as the package.8. Click Add.9. Click Close to close the Exceptions window.

10. Click Finish to close the SmartGuide and create the method.

The method will appear under your Mydisplay class in the Workbench.

You can either write your own createConnection() and terminateConnection()methods or you can copy them from the sample provided.

To create the createConnection() and terminateConnection() methods, do thefollowing:1. From the Workbench, right-click on your Mydisplay class.2. Select Add > Method. The Create Method SmartGuide will open.3. Select the Create a new method radio button.4. Enter void createConnection() in the text field.5. Click Finish to close the SmartGuide, and create the method.

Repeat these steps but enter void terminateConnection() in the text field. ThecreateConnection() and terminateConenction() methods will be created in theWorkbench. Select the methods and write the code in the source pane or copy thecontents of the methods in the sample provided.

To copy the contents of the createConnection() and terminateConnection() methods,do the following:1. Expand the DisplayFieldValue class in the

com.ibm.ivj.domino.samples.applications.displayvalues package of the IBMDomino Examples project.

2. Left-click the createConnection() method. The source code will appear in thesource pane.

3. Highlight all of the text in the source pane.4. From the Edit menu, select Copy.5. Expand your Mydisplay class from the GetValue package.6. Left-click the createConnection() method.7. Highlight all of the text in the source pane.8. From the Edit menu, select Paste.9. Click on any package or class in the All Projects pane. A window will open that

asks if you want to save your method. Click Yes.

Repeat these steps for the terminateConnection() method.

Making the connectionsNow that you have created the methods that you need, you can use them toconnect your beans in the Visual Composition Editor.

24 Domino AgentRunner

Page 29: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

1. To create an event-to-code connection between the frame and the Dominodatabase using the windowOpened event and the createConnection() method:a. Right-click on the frame.b. Select event to code from the pop-up menu. The Event-to-Code connection

window will open.c. Select windowOpened as the Mydisplay event.d. Select createConnection() as the method.e. Select Mydisplay as the Method class.f. Click OK. The window will close and you will see a green line connecting

the frame to the createConnection() method in the Visual CompositionEditor.

2. Create an event-to-code connection between the getValue button and theDomino database, using the mouseClicked event and the getAnswer() method.Ensure that the Pass event data checkbox is selected. Note that the Dominodatabase does not have a visible bean. You connect to this database by linkingto the area outside the Mydisplay bean. The physical connection is made in thecode.

3. Right-click the connection. Select Connect > field. Create a connection to thechoice list and select selectedItem from the pop-up menu. This connection willbe shown as a purple line.

4. Create an event-to-code connection between the original connection and thetext box. Select the connection, and then select Connect > normalResult andcreate a connection to the text box. Select the setText method.

5. Create an event-to-code connection between the frame and the Dominodatabase using the windowClosing and the terminateConnection() method.

Save your bean and close the Visual Composition Editor.

Adding user codeAdd the following code between the User Code Begin and User Code End commentlines in the given class files. You can cut and paste this code from the originalsample.1. At the beginning of the Mydisplay class, add the line import lotus.domino.*;

and the following definitions of Lotus variables:private Database db = null;private DocumentCollection dc = null;private Document doc = null;private Session s = null;

These definitions must be placed exactly as they appear in theDisplayFieldValue class source code (this class comes with the sampleprovided).

2. Locate and double-click the getAnswer() method source code in the Workbench.Add the following code, which will return the answer:

public String getAnswer(String field) throws lotus.domino.NotesException{

String answer = “—ERROR—”;try {

answer = doc.getItemValueString(field);} catch(java.lang.Throwable exc) { }

return answer;}

Chapter 3. Domino samples - overview 25

Page 30: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

3. Save the method and class that you changed. You are now ready to run yoursample.

Sample: db2andnotesObjectiveThis sample shows the use of the database support in Swing, and uses the JTableclass to display the results from a domino and DB2 query.

Time requiredAllow 30 minutes to run this sample.

Before you beginTo run this sample, you need to have the following tools installed and configuredfor your machine:v VisualAge for Javav DB2 - This sample uses data from the DB2 SAMPLE database, which you can

create by walking through DB2’s First Steps. (On Windows NT, from your Startmenu, select Programs > DB2 for Windows NT > First Steps.)

v Lotus Domino driver for JDBC - this can be downloaded from the Lotus Website.

Follow the instructions in the Domino samples - overview to set up your DB2 andLotus Notes environments.

DescriptionThis sample retrieves information from a Domino and DB2 database, and displaysit in a window created with JTable.

Setting DB2 password and useridTo run this sample on your machine, you need to make a few small changes. Openthe IBM Domino Examples project and expand thecom.ibm.ivj.domino.samples.application.db2andnotes package. Select theEmplTable class that is located within this package. The source code of this classwill appear in the source window. Change the following statements to your ownmachine variables:1. static String uid = “userid”, where userid is the userid that you use to

connect to DB2.2. static String pwd = “PASSWORD”, where PASSWORD is the password that you

use to connect to DB2.

Select your parametersBecause this sample runs as both an application and an applet, you can add theproperties for both.1. Expand the com.ibm.ivj.domino.samples.applications.db2andnotes package.2. Right-click DB2andNotes, and select Properties from the drop-down menu.3. Select the Program tab to set the properties for the application.4. In the Command line arguments text field, enter DANIEL SMITH. (Valid names

for the parameters include any of the names that are contained in the DB2SAMPLE database.)

5. Click OK.

26 Domino AgentRunner

Page 31: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

Ensure that the DB2 and Lotus Notes drivers are in the workspace classpath.Ensure that DB2 Java net support is running by entering db2jstrt 8888 on acommand line.

Run the application1. Right-click the DB2andNotes class in the Workbench.2. Select Run > Run main. The application will open with the information for

Daniel Smith.

Sample: servletObjectiveThe objective of this sample is to demonstrate how to use a servlet to access,retrieve, and format Lotus Notes data.

Time requiredAllow 30 minutes to run this sample.

Before you beginTo run this sample, you need the following tools:v VisualAge for Java, Version 3.0v Domino 5.0.xv Netscape Navigator

To set up your VisualAge for Java and Notes environments, follow the instructionsin the Domino samples - overview.

For this sample, you need the Sun JSDK class libraries and the Servlet API Classes.These class libraries are packaged in VisualAge for Java with the Servlet Builder. Ifyou installed the entire product, the class libraries will be available in therepository. If you did a custom install, and did not choose to install the ServletBuilder, you must do another custom install by selecting only the Servlet Builder.This will not affect the features that you have already installed. The classes for theServlet Builder — including the Sun JSDK class libraries and the Servlet APIClasses — will be added to the workspace.

When the Sun JSDK class libraries project gets added to your workspace, it iscreated as an empty project. You must import the webserver.jar file in order to addthe packages, and then add the xml.jar file to get rid of compile errors:1. In your workspace, select the project Sun JSDK class libraries, and then select

File > Import. Then, select Jar file, and click Next. In the Filename field, enterthe full path for the webserver.jar file (i.e.X:\IBMVJava\IDE\project_resources\Sun JSDK class libraries\webserver.jar,where X:\IBMVJava is the directory in which VisualAge for Java is installed).

2. Ensure that both .class and resource are selected, and that Sun JSDK classlibraries is entered in the Project field. Click Finish.

3. Follow the steps above to import the xml.jar file.

DescriptionThis sample uses the HTML <FORM> tag to display a form in which you enter aserver and database. When you click the Start button, the server runs theNotesList Java servlet. This servlet connects to the Lotus Notes server and database

Chapter 3. Domino samples - overview 27

Page 32: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

that you have specified, and retrieves a list of all the documents in the database. Itgets the subject line of each document and displays them in a dynamicallygenerated Web page.

This Web page also includes a FORM where you can enter a document numberand click the Getdocument button. This action runs the same servlet, but adifferent parameter is passed. The servlet now gets the body of the document thatyou have requested and displays that in another dynamically generated Web page.

This servlet sample does not use the Servlet Builder tool. The code washand-written. The NotesList class is the main interface and the NotesUtils classdoes work for NotesList.

Running the sampleTo set the class path and run the server, do the following:1. In the Project workspace, expand the Sun JSDK Class Libraries project.2. Expand the com.sun.web.shell package.3. Right-click the Startup class.4. Select Properties from the popup menu.5. Click the Program tab and enter -v in the parameters field. This parameter

causes output from the server to be displayed in the Console, so that you knowthe server is running.

6. Click the Class Path tab and ensure that the IBM Domino Examples, LotusDomino Java library, and the Servlet API Classes projects are included.

7. Save these settings and exit the Properties notebook.8. Right-click the Startup class.9. Select Run > Run main. This will start the server. You will see some output in

the Console.

To start the servlet, do the following:1. Enter the following URL in your Web browser’s Location field:

file://X:/IBMVJava/ide/features/com-ibm-ivj-examples-domino/project_resources/IBM Domino Examples/MyServlet.htmlwhere X:/IBMVJava is the drive and directory where you installed VisualAgefor Java.

2. Press Enter to load the MyServlet.html file into your browser.3. Enter a server name in the first text field, and a database name in the second.

To use the local Lotus Notes server, leave the server name blank.4. Click Start. A request is sent to the server to get a list of documents, which is

sent back to Netscape as an HTML page.5. From this page, enter a document number in the entry field.6. Click the Get Document button. Another request is sent to the server to get the

specific document, which is returned to Netscape as an HTML page.

To stop the server, do the following:1. Expand the Sun JSDK Class Library project.2. Expand the com.sun.web.shell package.3. Right-click the Shutdown class.4. Select Run > Run main. This will shutdown the server. You will see some

output in the Console.

28 Domino AgentRunner

Page 33: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

Notices

Note to U.S. Government Users Restricted Rights — Use, duplication or disclosurerestricted by GSA ADP Schedule Contract with IBM Corp.

This information was developed for products and services offered in the U.S.A.IBM may not offer the products, services, or features discussed in this document inother countries. Consult your local IBM representative for information on theproducts and services currently available in your area. Any reference to an IBMproduct, program, or service is not intended to state or imply that only that IBMproduct, program, or service may be used. Any functionally equivalent product,program, or service that does not infringe any IBM intellectual property right maybe used instead. However, it is the user’s responsibility to evaluate and verify theoperation of any non-IBM product, program, or service.IBM may have patents or pending patent applications covering subject matterdescribed in this document. The furnishing of this document does not give youany license to these patents. You can send license inquiries, in writing, to:

IBM Director of LicensingIBM CorporationNorth Castle DriveArmonk, NY 10504-1785U.S.A.

For license inquiries regarding double-byte (DBCS) information, contact the IBMIntellectual Property Department in your country or send inquiries, in writing, to:IBM World Trade Asia CorporationLicensing2-31 Roppongi 3-chome, Minato-kuTokyo 106, Japan

The following paragraph does not apply to the United Kingdom or any othercountry where such provisions are inconsistent with local law:INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THISPUBLICATION “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHEREXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OR CONDITIONS OF NON-INFRINGEMENT,MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some statesdo not allow disclaimer of express or implied warranties in certain transactions,therefore, this statement may not apply to you.This information could include technical inaccuracies or typographical errors.Changes are periodically made to the information herein; these changes will beincorporated in new editions of the publication. IBM may make improvementsand/or changes in the product(s) and/or the program(s) described in thispublication at any time without notice.

Any references in this information to non-IBM Web sites are provided forconvenience only and do not in any manner serve as an endorsement of those Websites. The materials at those Web sites are not part of the materials for this IBMproduct and use of those Web sites is at your own risk.

IBM may use or distribute any of the information you supply in any way itbelieves appropriate without incurring any obligation to you.

© Copyright IBM Corp. 1998, 2000 29

Page 34: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

Licensees of this program who wish to have information about it for the purposeof enabling: (i) the exchange of information between independently createdprograms and other programs (including this one) and (ii) the mutual use of theinformation which has been exchanged, should contact:

Lab DirectorIBM Canada Ltd.1150 Eglinton Avenue EastToronto, Ontario M3C 1H7Canada

Such information may be available, subject to appropriate terms and conditions,including in some cases, payment of a fee.The licensed program described in this document and all licensed materialavailable for it are provided by IBM under terms of the IBM Customer Agreement,IBM International Program License Agreement or any equivalent agreementbetween us.

Information concerning non-IBM products was obtained from the suppliers ofthose products, their published announcements or other publicly available sources.IBM has not tested those products and cannot confirm the accuracy ofperformance, compatibility or any other claims related to non-IBM products.Questions on the capabilities of non-IBM products should be addressed to thesuppliers of those products.

This information contains examples of data and reports used in daily businessoperations. To illustrate them as completely as possible, the examples may includethe names of individuals, companies, brands, and products. All of these names arefictitious and any similarity to the names and addresses used by an actual businessenterprise is entirely coincidental.

COPYRIGHT LICENSE:This information contains sample application programs in source language, whichillustrates programming techniques on various operating platforms. You may copy,modify, and distribute these sample programs in any form without payment toIBM, for the purposes of developing, using, marketing or distributing applicationprograms conforming to the application programming interface for the operatingplatform for which the sample programs are written. These examples have notbeen thoroughly tested under all conditions. IBM, therefore, cannot guarantee orimply reliability, serviceability, or function of these programs. You may copy,modify, and distribute these sample programs in any form without payment toIBM for the purposes of developing, using, marketing, or distributing applicationprograms conforming to IBM’s application programming interfaces.

Each copy or any portion of these sample programs or any derivative work, mustinclude a copyright notice as follows:© (your company name) (year). Portions of this code are derived from IBM Corp.Sample Programs. © Copyright IBM Corp. 1997, 2000. All rights reserved.

30 Domino AgentRunner

Page 35: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

Programming interface information

Programming interface information is intended to help you create applicationsoftware using this program.

General-use programming interfaces allow the customer to write applicationsoftware that obtain the services of this program’s tools.

However, this information may also contain diagnosis, modification, and tuninginformation. Diagnosis, modification and tuning information is provided to helpyou debug your application software.

Warning: Do not use this diagnosis, modification, and tuning information as aprogramming interface because it is subject to change.

© Copyright IBM Corp. 1998, 2000 31

Page 36: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

32 Domino AgentRunner

Page 37: Domino AgentRunner - · PDF fileTo set up your VisualAge for Java IDE to use the Domino AgentRunner, you must add the Domino Java ... under “Domino 5 Designer ... Open Lotus Domino

Trademarks and service marks

The following terms are trademarks of International Business MachinesCorporation in the United States, or other countries, or both:v AIXv AS/400v DB2v CICSv CICS/ESAv IBMv IMSv Language Environmentv MQSeriesv Network Stationv OS/2v OS/390v OS/400v RS/6000v S/390v VisualAgev VTAMv WebSphere

Lotus, Lotus Notes and Domino are trademarks or registered trademarks of LotusDevelopment Corporation in the United States, or other countries, or both.

Tivoli Enterprise Console and Tivoli Module Designer are trademarks of TivoliSystems Inc. in the United States, or other countries, or both.

Encina and DCE Encina Lightweight Client are trademarks of Transarc Corporationin the United States, or other countries, or both.

Java and all Java-based trademarks and logos are trademarks or registeredtrademarks of Sun Microsystems, Inc. in the United States and other countries.

ActiveX, Microsoft, SourceSafe, Visual C++, Visual SourceSafe, Windows, WindowsNT, Win32, Win32s and the Windows logo are trademarks or registered trademarksof Microsoft Corporation in the United States, or other countries, or both.

UNIX is a registered trademark in the United States and other countries licensedexclusively through X/Open Company Limited.

Intel and Pentium are trademarks of Intel Corporation in the United States, orother countries, or both.

Other company, product, and service names, which may be denoted by a doubleasterisk(**), may be trademarks or service marks of others.

© Copyright IBM Corp. 1998, 2000 33