Using Java Beans

Two types of Java beans are generated by Task Builder:

The workflow

Assuming you have generated your task or service bean, published them to MCS, and created your session pools, then using Java beans typically follows a specific workflow:

  1. Instantiate the bean
  2. Set the bean's input properties
  3. Execute the task
  4. Get the bean's output properties
  5. Terminate the bean
Note Since each service bean can contain more than one task, you would repeat steps 2 through 4 until each task has been executed.

Generated Java beans can be used to add host access tasks to applications created in any Java application development environment. Each bean includes additional read-write and read-only methods representing the inputs and outputs built into the task.

Using Task Beans

When you generate service beans the following files are created and copied to Attachmate/EAI/recordings/<projectname>:

NavMapClientBeans.jar
NavMapJavadoc.jar*
readme.txt

The Javadoc.jar is created only if you selected the Generate Javadocs option when you configured options for generating task beans.

In these examples, the generated task bean is named myBean.

Setting Inputs Example
Execute your task by setting your inputs and calling executeSync(). Name your input fields, inputField1 and inputField2 and set the inputs as follows:
myBean.inputField1("my input");
myBean.inputField2("more input");
myBean.executeSync();
Getting Outputs Example
If your output is not in a table and your output field is named outputField1 The following method call retrieves your output:
String output1 = myBean.getoutputField1();
If the output is in a table with multiple fields in each record, the output is represented as indexed properties. If the fields are named filename and filetype, in a table, the following methods are available:

//gets the record count
int rowCount = myBean.get_RecordCount();

//get the first filename. The argument is the record index
String filename = myBean.getTableName$Filename(0);

//gets an array of filenames
String[]filenameArray = myBean.getTableName$Filename();

//gets the first filetype. The argument is the record index
String filetype = myBean.getTableName$FileType(0);

//gets an array of filetypes
String[]filetypeArray = myBean.getTableName$Filetype();

where TableName is the name of your table.

Maintaining session allocation

Typically, sessions are allocated just prior to task execution and then freed up immediately after task completion. There may be situations when it is necessary to maintain an allocated session from one task bean to another. This is called preserving context.

Context refers to the host connection or session that has been allocated to a bean. Pools of host connections (session pools) are created using MCS, and each task bean, when executed, is allocated a session. When you "preserve context," the session will not be disconnected after executing the task bean, making it available for future executions. It is possible to transfer or copy context from one task bean to another.

Set the bean method, setPreserveContext() with the following values:

Use this value To
PRESERVE_ALWAYS always preserve context after task execution.
PRESERVE_NEVER never preserve context after execution.
PRESERVE_ON_ERROR only preserve context if an error occurs during execution.

Transferring, Copying, and Clearing Context

Let's assume we have two beans; myBean1 and myBean2. You can transfer, copy, and clear context as follows:

Action Example
Transfer context from myBean1 to myBean2
(this removes the context from myBean1)
myBean1.executeSync();
myBean2.transferContext(myBean1);
Copy context from myBean1 to myBean2
(this does not remove the context from myBean1)
myBean1.executeSync();
myBean2.copyContext(myBean1);
Clear the context (the session will be freed) myBean1.clearContext();

Using Service Beans

When you generate service beans the following files are created and copied to Attachmate/EAI/recordings/<projectname>.:

tasknameservicebean.class, Java bean class file for the generated task, contains: tasknameservicebean.java
and a data bean for each set of task inputs or outputs

Service beans with Apache Axis Web Services

When you generate Web services for Apache Axis, a bean is generated, which is essentially identical to a service bean, but includes a Web Service Deployment Descriptor (WSDD) for deployment to the Apache Axis serer. A WSDD is an XML document for configuring Apache Axis Web services.

Code sample using a service bean

//Instantiate the service bean
            TestServiceBean bean = new TestServiceBean();

            //Set the task inputs
            ScreenInputs inputs = new ScreenInputs();
            inputs.setInput("data");

            //Execute the task
            ScreenOutputs outputs = bean.Task(inputs);

            //Display the output
            System.out.println(outputs.getOutput());     
Related Topics
Bullet Using Tasks in Your Applications, Overview
Bullet ITask Sample Code
Bullet Service Bean Sample Code
Bullet Javadocs
  Attachmate