BEA Logo BEA BEA eLink JAM Release

  Corporate Info  |  News  |  Solutions  |  Products  |  Partners  |  Services  |  Events  |  Download  |  How To Buy

 

   BEA eLink JAM Doc Home   |   BEA eLink Java Adapter for Mainframe WLS Edition User Guide   |   Previous Topic   |   Next Topic   |   Contents   |   Index

Developing Java Applications

 

The BEA eLink Java Adapter for Mainframe WLS Edition (JAM) code generation tool produces Java code from COBOL copybook source files. This generated Java code consists of both data mapping code and framework code for any application that will invoke the mainframe application through the gateway.

The following sections describe how the base Java application is generated, what role the COBOL copybook plays in the generation, and how to determine the type of application you want to generate.

This topic consists of the following sub-topics.

 


Building the Base Java Application

The JAM code generation tool allows you to produce working Java code that functions within a Java Server execution model. The Java code produced is centered around typed data buffers.

In COBOL/CICS terms, a typed data buffer represents a group data item, or record, defined by a COBOL copybook that specifies the COMMAREA data area used by a CICS DPL program.

In Java terms, a typed data buffer is an object (instantiation) of a class type. The fields of the class correspond to the data fields within a record. Field values are retrieved and modified through the use of accessor functions (i.e., get and set functions).

Data View Concepts

Typed data buffers are handled by the Java DataView class, which performs all of the necessary conversions and translations of the data fields within each record. The result is the ability to send and receive data buffers between Java clients and COBOL/CICS DPL programs. All of the underlying data conversions are performed transparently to each side of the application; the Java side of the application manipulates the data buffers as Java objects, and the COBOL/CICS side manipulates them as COMMAREA linkage section data items.

These Java files are then used by application programmers to write other Java source files that extend the classes defined in the generated source files. The user-defined classes typically add methods and variables that embody the business logic of the application.

The generated source files provide a simple framework centered around the typed data buffers (i.e., the COMMAREAs) of the CICS application. It is up to the Java application programmer to extend this framework of classes.

The heart of a JAM application is the sending and receiving of data records between the Java application system and the remote (mainframe) system. This is accomplished by employing a DataView that corresponds to a mainframe data record. On the mainframe side, the DataView represents the CICS COMMAREA data that is sent between DPL programs. On the Java side, the DataView represents a class object containing the COMMAREA data fields. The JAM application framework provides all of the data conversions necessary to send and receive data records between Java systems and the mainframe.

The following figure provides an illustration of how the underlying JAM generation tools work together.

Figure 3-1 Understanding the Underlying JAM Tools

The following figure provides an illustration of the JAM general application transport method.

Figure 3-2 JAM General Application Transport Method

 


Obtaining the COBOL Copybook

A mainframe COBOL/CICS, IMS, or mainframe application typically uses a copybook source file to define its COMMAREA. This file is specified in a COPY directive within the LINKAGE SECTION of the source program.

If the CICS application does not use a copybook file (but simply defines the COMMAREA directly in the program source), you will have to create one from the definition contained in the program source.

The JAM code generation tools support most of the COBOL data types and data clauses, however, some obsolete constructs along with floating point data types are not supported. Also, a few COBOL features are not supported. For unsupported constructs, you will have to determine if the copybook can be used without modification. In most cases, unsupported items are treated as alphanumeric data types or are simply ignored.

Each copybook's contents (which define a COMMAREA record) are parsed by the EgenCobol application generator tool, producing DataView sub-classes that provide facilities to:

Creating a New Copybook

If you are producing a new application on the mainframe or modifying one that did not previously support DPL, then one or more new copybooks are required. You should keep in mind the COBOL features and data types that are supported by JAM as you create these copybooks.

Using an Existing Copybook

When a mainframe application has an existing DPL interface, it most likely has the data for that interface described in a COBOL copybook. The first thing that must be done is to verify that no COBOL features or data types that JAM does not support are used in the interface. The easiest way to check a copybook is to attempt to process it.

An example COBOL copybook source file is shown in the following listing. It is assumed that the copybook is identical to the copybook used by the mainframe COBOL application programs.

Listing 3-1 Sample emprec.cpy COBOL Copybook


1	*------------------------------------------------------
2 * emprec.cpy
3 * An employee record.
4 *------------------------------------------------------
5
6 02 emp-record. (Comment 1)
7
8 04 emp-ssn pic 9(9) comp-3.
9
10 04 emp-name.
11 06 emp-name-last pic x(15). (Comment 2)
12 06 emp-name-first pic x(15).
13 06 emp-name-mi pic x.
14
15 04 emp-addr. (Comment 3)
16 06 emp-addr-street pic x(30).
17 06 emp-addr-st pic x(2).
18 06 emp-addr-zip pic x(9).
19
20 * End


Script Comments

The following numbered comments refer to the numbered comments in the prior listing.

Table 3-1 Script Comments

Comment 1

Declaration of a record (group) data item.

Comment 2

An elementary item.

Comment 3

An aggregate item.

The emprec.cpy copybook shown in the example declares a group item named emp-record. (This copybook is available in the examples/samples.jar file in JAM installation directory.

The JAM EgenCobol utility parses a COBOL copybook and generates a Java class that encapsulates the data record declared in the copybook. It does this by parsing an Egen script file containing a DataView definition similar to the following example.

Listing 3-2 Sample emprec.egen Script


view Sample.EmployeeRecord from emprec.cpy


The prior example specifies that the COBOL copybook file named emprec.cpy is to be parsed, and that a Java source file named EmployeeRecord.java, containing the definition of class EmployeeRecord in package sample, is to be generated from it.

Assuming this script was saved into a file named emprec.egen, the following shell command parses the copybook file named emprec.cpy and attempts to generate a Java source file named EmployeeRecord.java in the current directory:

Listing 3-3 Sample Copybook Parse Command


java bea.jam.egen.EgenCobol emprec.egen


If no error or warning messages are issued, the copybook is compatible with JAM and the source is created.

Note: You must establish a Java class path that refers to the JAM distribution jar file for this command to work properly. Please refer to the "Error Messages" section of this document for suggestions on resolving other problems.

The following example illustrates the resulting generated Java source file, EmployeeRecord.java with unimportant comments and implementation details removed for clarity.

Listing 3-4 Generated EmployeeRecord.java Source File


//EmployeeRecord.java
//Data view class generated by egencobol emprec.cpy

package Sample;(Comment 1)

//Imports

import bea.dmd.DataView.DataView;
...

/**DataView class for EmployeeRecord buffers*/

public final class EmployeeRecord (Comment 2)
extends DataView
{
...

	// Code for field "emp-ssn"
private BigDecimal m_empSsn;(Comment 3)

	public BigDecimal getEmpSsn() {...}(Comment 4)

	/** DataView subclass for emp-name Group */
public final class EmpNameV
(Comment 5)
extends DataView
{
...

	     	// Code for field "emp-name-last"
private String m_empNamelast;

	     	public void setEmpNameLast(String value) {...}
public String getEmpNameLast() {...}(Comment 6)

		// Code for field "emp-name-first"
private String m_empNameFirsrt;

		public void setEmpnameFisrt (String value) {...}
public String getEmpNameFirst() {...}

		// Code for field "emp-name-mi"
private String m_empNameMi;

		public void setEmpNameMi (String value) {...}
public String getEmpnameMi() {...}
}

	// Code for field "emp-name"
private EmpNameV m_empname" (Comment 7)

	public EmpnameV getEmpname() {...}

	/**DataView subclass for emp-addr Group */
public final class EmpAddrV
extends DataView
{
...

		// Code for field "emp-addr-street"
private String m_empAddrStreet;

		public void setEmpAddrStreet(Street value) {...}
public String getEmpAddrStreet() {...}

		// Code for field "emp-addr-st"
private String m_empAddrSt;

		public void setEmpAddrSt(String value) {...}
public String getEmpAddrSt() {...}

		// Code for field "emp-addr-zip"
private String m_empAddrZip;

		public void setEmpAddrZip(String value) {...}
public String getEmpAddrZip() {...}
}

	// Code for field "emp-addr"
private EmpAddrV m_empAddr;

	public EmpAddrV getEmpAddr() {...}
}

//End EmployeeRecord.java


Script Comments

The following numbered comments refer to the numbered comments in the prior listing.

Table 3-2 Script Comments

Comment 1

The package name is defined in the Egen script.

Comment 2

The data record is encapsulated in a class that extends the DataView class.

Comment 3

Each class member variable corresponds to a field in the data record.

Comment 4

Each data field has accessor functions.

Comment 5

Each aggregate data field has a corresponding nested inner class that extends the DataView class.

Comment 6

Each data field within an aggregate data field has accessor functions.

Comment 7

Each COBOL data field name is converted into a Java identifier.

 


Generating the Java Application Source

In addition to the COBOL copybook requirement, you must also determine which of the following application models you want to generate.

The one you choose depends on the type of application you are building.

For all of the following applications you can generate, you must provide a script file containing definitions for the application, including the COBOL copybook file name, the DataView class names, and so forth.

Generating a Servlet-Only JAM Application

This type of application produces a Java servlet application that executes within a Java server environment (such as WebLogic Server). It is started from a web browser when the user enters a URL that is configured to invoke the servlet. The servlet presents an HTML form containing data fields and buttons. The buttons can be configured to invoke:

In general, servlets generated by EgenCobol are intended for testing purposes and are not easily customized to provide a more aesthetically pleasing interface.

Generating a Servlet-only JAM application consists of the following steps;

  1. Creating a script.

  2. Processing a script.

  3. Working with the generated files.

  4. Customizing the application.

The following topics discuss these steps and offer examples of each.

Creating a Script

In order to produce a servlet-only application, the script file that describes your DataViews must be enhanced to describe the mainframe services accessed, the browser pages produced, and the servlets that produce them. Service definitions look like the following listing.

Listing 3-5 Sample Service Definition


service getSalary
accepts EmployeeRecord [cp037]
returns EmployeeRecord [cp037]


This listing defines a service named getSalary that accepts an input buffer of type EmployeeRecord and returns an output buffer of type EmployeeRecord. Additional, the EmployeeRecord is transferred to and from the mainframe using character translation code page cp037 (which is a U.S. EBCDIC character set). It is this service name which also requires an entry in the jcrmgw.cfg file.

A browser page that uses this service might be defined as the following.

Listing 3-6 Sample Page Definition


page EmployeeQuery "Employee Salary Query"
{
view EmployeeRecord [cp037]

buttons
{
Query service (getSalary)
shows EmployeeQuery
}
}


This listing defines an HTML page named EmployeeQuery, with a text title of "Employee Salary Query", that displays an EmployeeRecord record object as an HTML form. It also specifies that the form has a button labeled "Query." When the button is pressed, the service getSalary is invoked and is passed the contents of the browser page as an EmployeeRecord object (the fields of which may have been modified by the user). Afterwards, the EmployeeQuery page is used to display the results.

The servlet that serves this page might be defined like the following listing.

Listing 3-7 Sample servlet Definition


servlet EmployeeQueryServlet shows EmployeeQuery


This listing defines an application servlet class named EmployeeQueryServlet, and specifies that it displays the HTML page named EmployeeQuery as its initial display page.

The following listing shows a complete script for defining a servlet application.

Listing 3-8 Sample Servlet-Only Script


1  #---------------------------------------------------------
2 # empservlet.egen
3 # JAM script for a servlet-only application.
4 #
5 # $Id: empservlet.egen,v 1.2 2000/01/25 18:34:14 david Exp$
6 #--------------------------------------------------------------
7
8 # DataViews (typed data records)
9
10 view sample.EmployeeRecord (Comment 1)
11 from emprec.cpy
12
13 # Services
14
15 service sampleCreate (Comment 2)
16 accepts EmployeeRecord
17 returns EmployeeRecord
18
19 service sampleRead (Comment 2)
20 accepts EmployeeRecord
21 returns EmployeeRecord
22
23 service sampleUpdate (Comment 2)
24 accepts EmployeeRecord
25 returns EmployeeRecords
26
27 service sampleDelete (Comment 2)
28 accepts EmployeeRecord
29 returns EmployeeRecord
30
31 # Servlet HTML pages
32
33 page initial "Initial page" (Comment 3)
34 {
35 view EmployeeRecord [CP037] (Comment 4)
36
37 buttons
38 {
39 "Create" (Comment 5)
40 service ("sampleCreate")
41 shows fullPage
42
43 "Read" (Comment 5)
44 service ("sampleRead")
45 shows fullPage
46 }
47 }
48
49 page fullPage "Complete page"
50 {
51 view EmployeeRecord
52
53 buttons
54 {
55 "Create"
56 service ("sampleCreate")
57 shows fullPage
58
59 "Read"
60 service ("sampleread")
61 shows fullpage
62
63 "Update"
64 service ("sampleDelete")
65 shows fullpage
66
67 "Delete"
68 service ("sampleDelete")
69 shows fullpage
70 }
71 }
72
73 # Servlets
74
75 servlet sample.SampleServlet (Comment 6)
76 shows initial
77
78 # End


Script Comments

The following numbered comments refer to the numbered comments in the prior listing.

Table 3-3 Script Comments

Comment 1

Defines a DataView class, specifying its corresponding copybook source file and its package file.

Comment 2

Defines a service function and its input and output parameter types.

Comment 3

Defines an HTML page to be displayed by the servlet.

Comment 4

Specifies the DataView class to display on the page and the character code page.

Comment 5

Defines a button and its associated class method.

Comment 6

Defines a servlet class and its initial HTML display page.

Processing a Script

Issuing the following command will process the script:

Listing 3-9 Sample Script Process Command


%java bea.jam.egen.EgenCobol empservlet.egen
emprec.cpy, Lines: 21 Errors: 0, Warnings:0
Generating sample.EmployeeRecord...
Generating group emp-name
Generating group emp-addr
Generating sample.SampleServlet...


Generated Files

This script command generates the following files.

Table 3-4 Sample Script Generated Files

Files

Content

SampleServlet.java

Servlet source code.

EmployeeRecord.java

Source for the DataView object.

SampleServlet.java Source File

The following listing illustrates the contents of the generated SampleServlet.java source file (with some parts omitted).

Listing 3-10 Sample SampleServlet.java Contents


//  SampleServlet.java
//
// Servlet class generated by egencobol on 25-Jan-2000.

package sample;

//  Imports

import javax.servlet.http.HttpServlet;
import weblogic.html.ServletPage;
import bea.dmd.DataView.DataView;
import bea.jam.egen.EgenServlet;
...

/** servlet class for EmployeeRecord buffers. */

public class SampleServlet
extends EgenServlet
{
/** Create a new servlet. */
public SampleServlet() (Comment 1)
}
...
}

	/** Get an instance of the initial DataView for this
Servlet.*/
protected DataView initialDataView()
{
...
}

	...
}

//End SampleServlet.java


Script Comments

The following numbered comments refer to the numbered comments in the prior listing.

Table 3-5 Script Comments

Comment 1

Defines a servlet class.

Customizing a Servlet-Only JAM Application

The generated Java classes produced for servlet applications are intended for proof of concept and prototypes, and can be customized in limited ways. It is presumed that some other development tool will be used to develop a servlet or other user interface on top of the generated EJB's or client classes.

This section describes the way that generated servlet code can be customized.

The following figure illustrates the relationships and inheritance hierarchy between the JAM classes comprising the application.

Figure 3-3 The JAM Servlet Class Hierarchy

The generated Java code for a servlet application is a class that inherits class EgenServlet. Class EgenServlet is provided in the JAM distribution jar file.

The base class illustrated in the following listing provides the basic framework for a servlet.

Listing 3-11 EgenServlet.java Base Class


//==========================================================
// EgenServlet.java
// The base class for generated servlets.
//===============================================================

package bea.jam.egen;

//Imports

...

/****************************************************************
* The base class for generated servlets
*/

abstract public class EgenServlet
extends HttpServlet
{
/** Perform an HTTP Get operation. */
public void doGet(HttpServletRequest req,HttpServletResponse
resp)
throws ServletException, IOException
{
DataView dv;
HttpSession session=reqgetSession(true);

    ...

    // Get the initial DataView data record
dv = initialDataView();

    // Invoke the user-defined callback
dv = doGetSetup(dv,session);

    // Convert the DataView into an HTML form
...
}

   /** Perform a HTTP Post operation. */
public void doPost(HttpServletRequest req,HttpServletResponse
resp)
throws ServletException, IOException
{
DataView dv;
HttpSession session=reqgetSession(true);

    // Move the HTML form data into a DataView
...

    // Invoke the user-defined callback
dv = doPostSetup(dv, session);

    // Execute the form button
...

    //Invoke the user-defined callback
dv = doPostFinal(dv, session);

    // Convert the DataView into an HTML form
...
}

   /** User exit for pre-presentation processing for a GET request.
*/
public DataView doGetSetup (DataView in, HttpSession session)
{
// Default behavior may be overridden
return in;
}

   /**User exit for before business logic processing for a POST
request. */
public DataView doPostSetup (DataView in, HttpSession session)
{
// Default behavior, may be overridden
return in;
}

   /** User exit for after business logic processing for a POST
request. */
public DataView doPostFinal (DataView in, HttpSession session)
{
// Default behavior, may be overridden
return in;
}

   /** Get an instance of the initial DataView for this servlet. */
protected abstract DataView initialDataView();

   /**
* The title for the initial page.
* This should be initialized in the subclass constructor.
*/
protected String m_initialTitle;

   /** 
* The buttons for the initial page.
* This should be initialized in the subclass constructor.
*/
protected Button[] m_initialButtons;
}

// End EgenServlet.java


The EgenServlet base class provides functions for the GET and POST operations for the servlet's HTML page.

Both of these operations invoke the following default callback functions:

Your class, which (indirectly) extends the EgenServlet base class, overrides these functions and provides additional business logic to modify the contents of the DataView. Each of these functions is passed to the DataView object containing the current record data. Each is expected to return a (potentially modified) DataView object.

Note: The overriding functions must have exactly the same signature as the functions in the base class.

The following illustration shows the sequence of operations that occur during the course of a user's browser session. For example, the series of events that occur within the EgenServlet class.

Figure 3-4 User Browser-Session Flowchart

Example ExtSampleServlet.java Class

The following listing shows an sample ExtSampleServlet class that extends the generated SampleServlet class, and adds a validation function (isSsnValid()) for the emp-ssn (m_empSsn) field of the DataView EmployeeRecord class. The three callback functions are overridden by the functions in the extended class. If the emp-ssn field is determined to be invalid, an exception is thrown.

Exceptions are caught by the Java server (WLS) and cause a simple informational text page to be presented to the user's browser. Any string text associated with the exception is displayed along with an execution stack trace that was in effect at the time that the exception was thrown.

Listing 3-12 Sample ExtSampleServlet.java Contents


//==========================================================
// ExtSampleServlet.java
// Example class that extends a generated JAM servlet application.
//===============================================================

package sample;

// System imports

import java.math.Bigdecimal;

import javax.servlet.http.HttpSession;
import bea.dmd.DataView.DataView;
import bea.jam.egen.EgenServlet;

// Local Imports

import sample.EmployeeRecord;
import sample.SampleServlet;

/***************************************************************
*/ Extends the SampleServlet class, adding additional business logic

*/

public class ExtSampleServlet
extends SampleServlet
{
// Public functions

	/********************************************************
* User exit for pre-presentation processing for a GET

	* request. This is called prior to the presentation of the
* first HTML page to the user's browser.
*/

	public DataView doGetSetup (DataView in HttpSession session)
{
EmployeeRecord erec;

	  // Overrides the default behavior

	  // Load default data into the empty DataView
erec = (EmployeeRecord) in;
erec.getEmprecord().setEmpSsn(BigDecimal.valueOf(99999));

	  return (erec);
}

	/********************************************************
* User exit for before business logic processing for a POST
* request. This is called after the user activates a button
* on the HTMl form, but before the action associated with the
* button is performed.
*/

        public DataView doPostSetup (DataView in HttpSession session)
{
EmployeeRecord erec;

	  // Overrides the default behavior

	  // validate the Social Security Number field
erec = (Employeerecord) in;

	  if (!isSsnValid(erec.getEmpRecord().getEmpSsn()))
{
// The SSN is not valid
throw new Error ("Invalid Social Security Number:"
= erec.getEmprecord().getEmpSsn());
}

	  return (erec;
}

	/*********************************************************
* User exit for after business logic processing for a POST
* request. This is called after the action is performed for
* the button on the HTML form is activated by the user.
*/

	public DataView doPostFinal(DataView in HttpSession session)
}
// Overrides the default behavior

		// Nothing to do here

		return (in);
}

 // Private functions

	/********************************************************
* Validates an SSN field.
*
* @return
* True if the SSN is valid, otherwise false.
*/

	private boolean isSsnValid(final BigDecimal ssn)
{
if (ssn.longValue() < 100000000)
{
// Oops, the SSN should not have a leading zero
return (false);
}
else
return (true);
}
}

 //End ExtSampleServlet.java


Once the ExtSampleServlet class has been written, it and the other servlet Java source files must be compiled and deployed in the same manner as other servlets.

Generating a Client Enterprise Java Bean-Based Application

This type of application produces Java classes that comprise an EJB application. The class methods are invoked from requests originating from other EJB classes, and transfer data records to and from the mainframe (remote system). From the viewpoint of the mainframe, the Java classes act as a remote DTP or IMS client. From the viewpoint of the EJB classes, they act as regular EJB classes.

Generating a Client Enterprise Java Bean-based application consists of the following steps;

  1. Creating a script.

  2. Processing a script.

  3. Working with the generated files.

  4. Customizing the application.

The following topics discuss these steps and offer examples of each.

Creating a Script

In order to produce an EJB-based application, the script file that defines your DataViews must be enhanced to describe both the mainframe services accessed and the EJB that will access them. A service description might look like the following listing example.

Listing 3-13 Sample service Description


service getSalary

	accepts EmployeeRecord
returns EmployeeRecord


This sample listing defines a service named getSalary that accepts an input buffer of type EmployeeRecord and returns an output buffer of type EmpDataView. It is this service name which also requires an entry in the jcrmgw.cfg file.

An EJB that uses this service might be defined like the following listing.

Listing 3-14 Sample getSalary Service Definition


client ejb MyEJBName	MyEJBHome
{
method getPay is service getSalary
}


This listing defines a Java bean class named MyEJBName with a method named getPay. The method corresponds to service name getSalary. The EJB home will be registered in JNDI under the name MyEJBHome.

The following listing shows the contents of a complete script file for defining a client EJB application.

Listing 3-15 Sample Client EJB Script


1  #---------------------------------------------------------
2 # empclient.egen
3 # JAM script for an employee record.
4 #
5 # $Id: empclient.egen,v 1.1 2000/01/25 18:34:14 david Exp$
6 #--------------------------------------------------------------
7
8 # DataViews (typed data records)
9
10 view sample.EmployeeRecord (Comment 1)
11 from emprec.cpy
12
13 # Services
14
15 service sampleCreate (Comment 2)
16 accepts EmployeeRecord
17 returns EmployeeRecord
18
19 service sampleRead (Comment 2)
20 accepts EmployeeRecord
21 returns EmployeeRecord
22
23 service sampleUpdate (Comment 2)
24 accepts EmployeeRecord
25 returns EmployeeRecord
26
27 service sampleDelete (Comment 2)
28 accepts EmployeeRecord
29 returns EmployeeRecord
30
31 # Clients and servers
32
33 client ejb sample.SampleEBean my.sampleBean (Comment 3)
34 {
35 method newEmployee (Comment 4)
36 is service sampleCreate
37
38 method readEmployee (Comment 4)
39 is service sampleReads
40 }
41
42 # End


Script Comments

The following numbered comments refer to the numbered comments in the prior listing.

Table 3-6 Script Comments

Comment 1

Defines a DataView class, specifying its corresponding copybook source file and its package name.

Comment 2

Defines a service function and its input and output parameter types.

Comment 3

Defines a client EJB class and its home name.

Comment 4

Defines a client class method and its service name.

Processing the Script

Issuing the following command will process the script.

Listing 3-16 Sample Script Process Command


% CLASSPATH=jam.jar java bea.jam.egen.EgenCobol empclient.egen
emprec.cpy, Lines: 21, Errors: 0, Warnings: 0
Generating sample.EmployeeRecord...
Generating group emp-name
Generating group emp-addr
Generating SampleEBean...


Generated Files

This script command generates the following files.

Table 3-7 Sample Script Generated Files

File

Content

SampleEBean.java

Source for the EJB remote interface.

SampleEBeanBean.java

Source for the EJB implementation.

SampleEBeanHome.java

Source for the EJB home interface.

SampleEBeanDD.txt

Sample deployment descriptor.

EmployeeRecord.java

Source for the DataView object.

SampleEBean.java Source File

The following listing shows the contents of the generated SampleEBean.java source file.

Listing 3-17 Sample SampleEBean.java Contents


// SampleEBean.java
//
// EJB Remote Interface generated by EgenCobol on 24-Jan-2000.

package sample;

// Imports

import javax.ejb.EJBObject;
...

/** Remote Interface for SampleEBean EJB. */

public interface SampleEBean (Comment 1)
extends EJBObject
{
// newEmployee (Comment 2)
EmployeeRecord newEmployee (EmployeeRecord commarea)
throws RemoteException, UnexpectedException;

	readEmployee (Comment 2)
EmployeeRecord readEmployee (EmploymentRecord commarea)
throws RemoteException, UnexpectedException;
}

// End SampleEBean.java


Script Comments

The following numbered comments refer to the numbered comments in the prior listing.

Table 3-8 Script Comments

Comment 1

Defines an EJB interface.

Comment 2

Methods to convert a raw COMMAREA into a Java DataView object.

SampleEBeanBean.java Source File

The following listing shows the contents of the generated SampleEBeanBean.java source file.

Listing 3-18 Sample SampleEBeanBean.java Contents


// SampleEBeanBean.java
//
// EJB generated by EgenCobol on 24-Jan-2000.

package sample;

//Imports

import bea.jam.egen.EgenClientBean;
...

/** EJB implementation. */

public class SampleEBeanBean (Comment 1)
extends EgenClientBean
{
// newEmployee

	public EmployeeRecord newEmployee (EmployeeRecord commarea)
throws IOException, snaException (Comment 2)
{
...
}

	//readEmployee

	public EmployeeRecord readEmployee (EmployeeRecord commarea)
throws IOException, snaException (Comment 2)
{
...
}

}

// End SampleEBeanBean.java


Script Comments

The following numbered comments refer to the numbered comments in the prior listing.

Table 3-9 Script Comments

Comment 1

Defines an EJB client bean.

Comment 2

The methods convert a raw COMMAREA into a Java DataView object.

SampleEBeanHome.java Source File

The following listing shows the contents of the generated SampleEBeanHome.java source file.

Listing 3-19 Sample SampleEBeanHome.java Contents


// SampleEBeanHome.java
//
// EJB Home interface generated by EgenCobol on 24-Jan-2000.

package sample;

// Imports

import javax.ejb.EJBHome;
...

/** Home interface for SampleEBean EJB. */

public interface SampleEBeanHome (Comment 1)
extends EJBHome
{
// create

	SampleEBean create()
throws CreateException, remoteException;
}

// End SampleEBeanHome.java


Script Comments

The following numbered comments refer to the numbered comments in the prior listing.

Table 3-10 Script Comments

Comment 1

Defines an EJB home interface.

SampleEBeanDD.txt Source File

The following listing shows the contents of the generated SampleEBeanDD.txt source file

Listing 3-20 Sample SampleEBeanDD.txt Contents


(SessionDescriptor
beanHomename my.sampleBean (Comment 1)
enterprisebeanClassName SampleEBeanBean
homeInterfaceclassName SampleEBeanHome
remoteinterfaceclassName SampleEBean
isReentrant false
; session EJBean-specific properties
stateManagementType STATELESS_SESSION
sessionTimeout 5; seconds
; end session EJBean-specific properties

	(accessControlEntries
; DEFAULT
); end accessControlEntries

	(control Descriptors
(DEFAULT
isolationLevel TRANSACTION_SERIALIZABLE
transactionAttribute TX_NOT_SUPPORTED
runAsMode CLIENT_IDENTITY
; runAsIdentity traderAdmin
); end DEFAULT
); end controlDescriptors

	(environmentProperties

	maxbeansInFreePool					100
maxBeansInCache 100
idleTimeoutSeconds 5
); end environmentProperties
); end SessionDescriptor


Script Comments

The following numbered comments refer to the numbered comments in the prior listing.

Table 3-11 Script Comments

Comment 1

Defines an EJB session descriptor.

Customizing an Enterprise Java Bean-Based Application

Unlike the servlet applications, the generated Java classes produced for EJB applications are intended for customizing.

This section describes the way that generated client EJB code can be customized.

The following figure illustrates the relationships and inheritance hierarchy between the JAM classes comprising the application.

Figure 3-5 The JAM Client EJB Class Hierarchy

The generated Java code for a client EJB application is a class that inherits class EgenClientBean. The EgenClientBean class is provided in the JAM distribution jar file.

This base class, illustrated in the following listing, provides the basic framework for an EJB. It provides the required methods for a Stateless Session EJB.

Listing 3-21 EgenClientBean.java Base Class


//=========================================================
// EgenClientBean.java
// The base class for generated client EJB's.
//
//---------------------------------------------------------------

package bea.jam.egen;

abstract public class EgenClientBean
implements SessionBean
{
//Implementation of ejbActivate(), ejbRemove(),
// ejbPassiveate(), ejbCreate() and setSessionContext()
...

	/**
* Call a service by name through the jcrmgw.
*
* @exception bea.sna.jcrmgw.snaException For Gateway errors
* @exception java.io.IOException For data translation
errors.
*/
protected byte[] callService(String service, byte[] in)
throws snaException, IOException
}
// Low level gateway access code
...
}

	// Variables

	  protected transient SessionContext m_context;
protected transient Properties m_properties;
}

// End EgenClientBean.java


The generated class, illustrated in the following Listing, adds the methods specific to this EJB.

Listing 3-22 Generated SampleClientBean.java Class


// SampleClientBean.java
//
// EJB generated by EgenCobol on Feb 2, 2000.
//

package sample;

...

/**
* EJB implementation.
*/
public class SampleClientBean extends EgenClientBean
{
// deleteEmployee
//
public EmployeeRecord deleteEmployee(EmployeeRecord
commarea)
throws IOException, snaException
{
// Make the remote call.
//
...
}

	//updateEmployee
//
public EmployeeRecord updateEmployee (EmployeeRecord
commarea)
throws IOException, snaException
{
// Make the remote call.
//
...
}

	// readEmployee
//
public Employeerecord readEmployee (EmployeeRecord commarea)
throws IOException, snaException
{
// Make the remote call.
//
...
}

	// newEmployee
//
public EmployeeRecord newEmployee (EmployeeRecord commarea)
throws IOException, snaException
{
// Make the remote call.
//
...
}
}

// END SampleClientBean.java


The following listing illustrates an example ExtSampleClientBean class that extends the generated SampleClientBean class, adding a validation function (isSsnValid()) for the emp-ssn (m_empSsn) field of the DataView EmployeeRecord class. The four methods are overridden by the methods in the extended class. If the emp-ssn field is determined to be invalid, an exception is thrown. Otherwise, the original function is called to perform the mainframe operation.

Listing 3-23 Example ExtSampleClientBean.java Class


// ExtSampleClientBean.java
//

package sample;

// Imports
//
import java.io.IOException;
import bea.jam.egen.EgenClientBean;
import bea.sna.jcrmgw.snaException;
import bea.base.io.MainframeWriter;
import bea.base.io.MainframeReader;

/**
* EJB implementation.
*/
public class ExtSampleClientBean extends SampleClientBean
{
// deleteEmployee
//
public EmployeeRecord deleteEmployee (EmployeeRecord
commarea)
throws IOEXception, snaException
{
EmployeeRecord erec = (EmployeeRecord) in;
if (!isSsnValid (erec.getEmprecord().getEmpSsn()))
{
// The SSN is not valid
throw new Error ("Invalid Social Security Number:" +
erec.getEmpRecord().getEmpSsn());
}

	  // Make the remote call.
//
return super.deleteEmployee (commarea);
}

	// updateEmployee
//
public EmployeeRecord updateEmployee (EmployeeRecord
commarea)
throws IOException, snaException
{
EmployeeRecord erec = (EmployeeRecord) in;
if (!isSsnValid (erec.getEmpRecord().getEmpSsn()))
{
// The SSN is not valid.
throw new Error("Invalid Social Security Number: "+
erec.getEmprecord().getEmpSsn());
}

	// Make the remote call.
//
return super.updateEmployee (commarea);
}

	// readEmployee
//
public EmployeeRecord readEmployee (EmployeeRecord commarea)
throws IOException, snaException
{
EmployeeRecord erec = (EmployeeRecord) in;
if (!isSsnValid(erec.getEmpRecord().getEmpSsn()))
{
// The SSN is not valid.
throw new Error ("Invalid Social Security Number: "+
erec.getEmpRecord().getEmpSsn());
}

	// Make the remote call.
//
return super.readEmployee (commarea);
}

	//newEmployee
//
return super.readEmployee (commarea);
}

	// new Employee
//
public EmployeeRecord newEmployee(EmployeeRecord commarea)
throws IOException, snaException
{
EmployeeRecord erec = (EmployeeRecord) in;
if (!isSsnValid(erec.getEmpRecord().getEmpSsn()))
{

		// The SSN is not valid.
throw new Error("Invalid Social Security Number:"+
erec.getEmprecord().getEmpSsn());
}

	// Make the remote call.
//
return super.newEmployee(commarea);
}

// Private Functions

	/*********************************************************
* Validates an SSn field.
*/

	private boolean isSsnValid(Big Decimal ssn)
{
if (ssn.longValue() < 100000000)
{
// Oops, should not have a leading zero.
return false;
}
return true;
}
}

// END ExtSampleClientBean.java


Once the ExtSampleClientBean class has been written, it and the other EJB Java source files must be compiled and deployed in the same manner as other EJB's. Prior to deploying, the deployment descriptor must be modified; the enterpriseBeanClassName property must be set to the name of your extended EJB implementation class.

Generating a Server Enterprise Java Bean-Based Application

This type of application produces Java classes that comprise an EJB application, similar to a Client EJB application, but acting as a remote server from the viewpoint of the mainframe. The classes process service requests originating from the mainframe (remote) system, known as "inbound" requests, and transfer data records to and from the mainframe. From the viewpoint of the Java classes, they receive EJB method requests. From the viewpoint of the mainframe application, it invokes remote DPL or IMS programs.

Generating a Server Enterprise Java Bean-based application consists of the following steps:

  1. Creating a script.

  2. Processing the script.

  3. Working with the generated files.

  4. Customizing the application.

The following topics discuss these steps and offer examples of each.

Creating a Script

The following listing shows the contents of a complete script for defining a server EJB application.

Listing 3-24 Sample Server EJB Script


1  #--------------------------------------------------------
2 # empserver.egen
3 # JAM script for an employee record.
4 #
5 # $Id: empserver.egen, v 1.1 2000/01/21 23:20:40
6 #-------------------------------------------------------------
7
8 # DataViews (typed data records)
9
10 view sample.EmployeeRecord (Comment 1)
11 from emprec.cpy
12
13 # Clients and servers (Comment 2)
14
15 server ejb sample.SampleEServer my.sampleServer (Comment 3)
16 {
17 method newEmployee (EmployeeRecord)(Comment 4)
18 returns EmployeeRecord
19 }
20
21 # End


Script Comments

The following numbered comments refer to the numbered comments in the prior listing.

Table 3-12

Comment 1

Defines a DataView class, specifying its corresponding copybook source file and its package name.

Comment 2

Defines a server EJB class.

Comment 3

my.sampleServer is the home interface identifier for this bean. This value must be included in an entry in the local Services section of the jcrmgw.cfg file for the Java gateway.

Comment $

Defines a server class method and its parameter.

Processing the Script

Issuing the following command will process the script.

Listing 3-25 Sample Script Process Command


% CLASSPATH=jam.jar java bea.jam.egen.EgenCobol empserver.egen
emprec.cpy, Lines: 21, Errors: 0, Warnings: 0
Generating sample.EmployeeRecord...
Generating group emp-name
Generating group emp-addr
Generating SampleEServer...


Generated Files

This script command generates the following files.

Table 3-13 Sample Script Generated Files

File

Content

SampleEServer.java

Source for the EJB remote interface.

SampleEServerBean.java

Source for the EJB implementation.

SampleEServerHome.java

Source for the EJB jhome interface.

SampleEServerDD.txt

Sample deployment descriptor.

EmployeeRecord.java

Source for the DataView object.

SampleEServer.java Source File

The following listing shows the content of the generated SampleEServer.java source file.

Listing 3-26 Sample SampleEServer.java Contents


// SampleEServer.java
//
// EJB Remote Interface generated by EgenCobol on 24-Jan-2000.

package sample;

// Imports

import javax.ejb.EJBObject;
...

/** Remote Interface for SampleEServer EJB. */

public interface SampleEServer
extends gwObject
{
//dispatch
byte[] dispatch(byte[] commarea, Object future)
throws RemoteException, UnexpectedException;
}

// End SampleEServer.java


SampleEServerBean.java Source File

The following listing shows the contents of the generated SampleEServerBean.java source file.

Listing 3-27 Sample SampleEServerBean.java Contents


// SampleEServerBean.java
//
EJB generated by EgenCobol on 24-Jan-2000.

package sample;

// Imports

import bea.jam.egen.EgenServerBean;
...

/** EJB implementation. */

public class SampleEServerBean
extends EgenServerBean
{
// dispatch
public byte[] dispatch (bute[] commarea, Object future)
throws IOException
{
...
}

	/**
* Do the actual work for a newEmployee operation.
* NOTE: This routine should be overridden to do actual work
*/
EmployeeRecord newEmployee (EmployeeRecord commarea)
{
return new EmployeeRecord();
}
}

//End SampleEServerBean.java


SampleEServerHome.java Source File

The following listing shows the contents of the generated SampleEServerHome.java source file.

Listing 3-28 Sample SampleEServerHome.java Contents


// SampleEServerHome.java
//
// EJB Home interface generated by EgenCobol on 24-Jan-2000.

package sample;

//Imports

import javax.ejb.EJBHome;
...

/** Home interface for SampleEServer EJB. */

public interface SampleEServerHome
extends EJBHome
{
//create
SampleEServer create()
throws CreateException, RemoteException;
}

// End SampleEServerHome.java


SampleEServerDD.txt Source File

The following listing shows the contents of the generated SampleEServerDD.txt source file.

Listing 3-29 Sample SampleEServerDD.txt Contents


(SessionDescriptor
beanHomeName StatelessSession.my.sampleServer
enterprisebeanClassName SampleEServerBean
homeInterfaceClassName SampleEServerHome
remoteInterfaceClassName SampleEServer (Comment 1)
isReentrant false
; session EJBean-specific properties
stateManagementType STATELESS_SESSION
sessionTimeout 5; seconds
; end session EJBean-specific properties

  (accessControlEntries
; DEFAULT
); end accessControlEntries

  (controlDescriptors
DEFAULT
isolationLevel TRANSACTION_SERIALIZABLE
transactionAttribute TX_NOT_SUPPORTED
runAsMode CLIENT_IDENTITY
; runAsIdentity traderAdmin
); end DEFAULT
); end controlDescriptors

 (environmentProperites

	maxBeansInFreePool				100
maxBeansInCache 100
idleTimeoutSeconds 5
); end environmentProperties
); end SessionDescriptor


Script Comments

The following numbered comments refer to the numbered comments in the prior listing.

Table 3-14 Script Comments

Comment 1

Defines an EJB session descriptor.

Customizing a Server Enterprise Java Bean-Based Application

The generated server enterprise Java bean-based applications are only intended for customizing, since they perform no real work without customizing.

This section describes the way that generated server EJB code can be customized.

The following figure illustrates the relationships and inheritance hierarchy between the JAM classes comprising the application.

Figure 3-6 The JAM Server EJB Class Hierarchy

The generated Java code for a client EJB application is a class that inherits class EgenServerBean. The EgenServerBean class is provided in the JAM distribution jar file. This base class, illustrated in the following listing, provides the basic framework for an EJB. It provides the required methods for a Stateless Session EJB.

Listing 3-30 EgenServerBean.java Base Class


//==========================================================
// EgenServerBean.java
// The base class for generated server EJB's.
//
//===============================================================

package bea.jam.egen;

abstract public class EgenServerBean
implements SessionBean
{
// Implementation of ejbActivate(), ejbRemove(),
// ejbPassivate(),
// setSessionContext() and ejbCreate().
...

// Variables

	protected transient SessionContext m_context;
protected transient Properties m_properties;
}

// End EgenServerBean.java


The generated class, illustrated in the following listing, adds the methods specific to this EJB.

Listing 3-31 Generated SampleServerBean.java Class


// SampleServerBean.java
//
// EJB generated by EgenCobol on 03-Feb-00.
//

package sample;

//Imports
//
import java.io.IOException;
import java.util.Hashtable;
import bea.sna.jcrmgw.snaException;
import bea.base.io.MainframeWriter
import bea.base.io.MainframeReader;
import bea.jam.egen.EgenServerBean;
import bea.jam.egen.InboundDispatcher;

/**
* EJB implementation
*/
public class SampleServerBean extends EgenServerBean
{
// dispatch
//
public byte[] dispatch(byte[] commarea, Object future)
throws IOException
{
EmployeeRecord inputBuffer
= new EmployeeRecord (new
MainframeReader (commarea));
EmployeeRecord result = newEmployee (inputBuffer);;
return result.toByteArray (new MainframeWriter());
}

   /**
* Do the actual work for a newEmployee operation.
* NOTE: This routine should be overridden to do actual work
*/
EmployeeRecord newEmployee(EmployeeRecord commarea)
{
return new EmployeeRecord();
}
}

// END SampleServerBean.java


The following listing shows an example ExtSampleServerBean class that extends the generated SampleServerBean class, providing an implementation of the newEmployee() method. The example method merely prints a message indicating that a newEmployee request has been received.

Listing 3-32 Sample ExtSampleServerBean.java Contents


// ExtSampleServerBean.java
//

package sample;

/**
* EJB implementation
*/
public class ExtSampleServerBean extends SampleServerBean
{
public EmployeeRecord newEmployee (EmployeeRecord in)
{
System.out.println("New Employee: " +
in.getEmpName().getEmpNameFirsr()
+ " " + in.getEmpname().getEmpNameLast());
return in;
}
}

// END ExtSampleServerBean.java


Once the ExtSampleServerBean class has been written, it and the other EJB Java source files must be compiled and deployed in the same manner as other EJB's. Before deploying, the deployment descriptor must be modified; the enterpriseBeanClassName must be set to the name of your extended EJB implementation class.

Generating a Stand-Alone Client Application

This type of application produces simple Java classes that perform the appropriate conversions of data records sent between Java and the mainframe, but without all of the EJB support methods. These classes are intended to be lower-level components upon which more complicated applications are built.

Generating a stand-alone application consists of the following steps;

  1. Generating a script.

  2. Processing a script.

  3. Working with the generated files.

  4. Customizing the application.

The following listing shows the contents of a complete script for defining a stand-alone client class with multiple services.

Listing 3-33 Sample Stand-Alone Client Class Script


1  #--------------------------------------------------------
2 # empclass.egen
3 # JAM script for an employee record.
4 #
5 # $Id: empclass.egen, v 1.1 2000/01/21 23:20:40
6 #-------------------------------------------------------------
7
8 # DataViews (typed data records)
9
10 view sample.EmployeeRecord (Comment 1)
11 from emprec.cpy
12
13 # Services
14
15 service sampleCreate (Comment 2)
16 accepts EmployeeRecord
17 returns EmployeeRecord
18
19 service sampleRead (Comment 2)
20 accepts EmployeeRecord
21 returns EmployeeRecord
22
23 service sampleUpdate (Comment 2)
24 accepts EmployeeRecord
25 returns EmployeeRecord
26
27 service sampleDelete (Comment 2)
28 accepts EmployeeRecord
29 returns EmployeeRecord
30
31 # Clients and servers
32
33 client class sample.SampleClass (Comment 3)
34 {
35 method newEmployee (Comment 4)
36 is service sampleCreate
37
38 method readEmployee (Comment 4)
39 is service sampleRead
40 }
41
42 # End


Script Comments

The following numbered comments refer to the numbered comments in the prior listing.

Table 3-15 Script Comments

Comment 1

Defines a DataView class, specifying its corresponding copybook source file and its package name.

Comment 2

Defines a service function and its input and output parameter types.

Comment 3

Defines a simple client class.

Comment 4

Defines a client class method and its parameter types.

Processing a Script

Issuing the following command will process the script.

Listing 3-34 Sample Script Process Command


% CLASSPATH=jam.jar jave bea.jam.egen.EgenCobol empclass.egen
emprec.cpy, Lines: 21, Errors: 0, warnings: 0
Generating sample.EmployeeRecord...
Generating group emp-name
Generating group emp-addr
Generating SampleClass...


Generated Files

This script command generates the following files.

Table 3-16 Sample Script Generated Files

File

Content

SampleClass.java

Source for the sample class.

EmployeeRecord.java

Source for the DataView class.

SampleClass.java Source File

The following listing contains the generated SampleClass.java source file.

Listing 3-35 Sample SampleClass.java Source File


// SampleClass.java
//
// Client class generated by EgenCobol on 24-Jan-2000.

package sample;(Comment 1)

// Imports

import bea.jam.egen.EgenClient;
...

/* Mainframe client class. */

public class SampleClass (Comment 2)
extends EgenClient
{
// newEmployee
public EmployeeRecord newEmployee (EmployeeRecord commarea)
throws IOException, snaException (Comment 3)
{
...
}

	// readEmployee
public EmployeeRecord readEmployee (EmployeeRecord commarea)
throws IOException, snaException (Comment 3)
{
...
}
}

// End SampleClass.java


Script Comments

The following numbered comments refer to the numbered comments in the prior listing.

Table 3-17 Script Comments

Comment 1

The package name is defined in the Egen script.

Comment 2

The data record is encapsulated in a class that extends the EgenClient class.

Comment 3

The methods convert a raw COMMAREA into a Java DataView object.

Customizing a Stand-Alone Java Application

The stand-alone client class model is the simplest JAM code generation model both in terms of the code generated and customizing the generated code.

The following figure illustrates the relationships and inheritance hierarchy between the JAM classes comprising the application.

Figure 3-7 The JAM Client EJB Class Hierarchy

The generated Java code for a client class application is a class that inherits class EgenClient. The EgenClient class is provided in the JAM distribution jar file. This base class, illustrated in the following listing provides the basic framework for a client to the jcrmgw. It provides the required methods for accessing the gateway.

Listing 3-36 Generated EgenClient.java Class


//==========================================================
// EgenClient.java
// Basic functionality for clients of the jcrmgw
//
//---------------------------------------------------------------

package bea.jam.egen;

public class EgenClient
{

	public byte[] callService(String service, byte[] in)
throws snaException, IOException
{
// make a mainframe request through the gateway.
...
}
}

// End EgenClientBean.java


The generated class, illustrated in the following listing, adds the methods specific to the users application

Listing 3-37 Sample SampleClient.java Class


// SampleClass.java
//
// Client class generated by EgenCobol on 02-Feb-00.
//

package sample;

// Imports
//
import java.io.IOException;
import bea.jam.egen.EgenClient;
import bea.sna.jcrmgw.snaException;
import bea.base.io.MainframeWriter;
import bea.base.io.MainframeReader;

/**
* Mainframe client class.
*/
public class SampleClass extends EgenClient
{
// newEmployee
//
public EmployeeRecord newEmployee(EmployeeRecord commarea)
throws IOException, snaException
{
// Make the remote call.
//
byte[] inputBuffer = commarea.toByteArray(new
MainframeWriter());
byte[] rawResult = callService("sampleCreate",
inputBuffer);
EmployeeRecord result =
new EmployeeRecord(new
MainframeReader(rawResult));
return result;
}
// readEmployee
//
public EmployeeRecord readEmployee(EmployeeRecord commarea)
throws IOException, snaException
{
// Make the remote call.
//
byte[] inputBuffer = commarea.toButeArray(new
MainframeWriter());
byte[] rawResult = callService("sampleRead", inputBuffer);
EmployeeRecord result =
new EmployeeRecord(new MainframeReader(rawResult)):
return result
}
]

// End SampleClass.java


Your class, which extends or uses the SampleClient class, simply overrides or calls these methods to provide additional business logic, modifying the contents of the DataView. It may also add additional methods, if desired.

The following listing shows an example ExtSampleClass class that extends the generated SampleClient class.

Listing 3-38 Sample ExtSampleClient.java Contents


// ExtSampleClient.java
//

package sample;

// Imports
//
import java.io.IOException;
import bea.jam.egen.EgenClientBean;
import bea.sna.jcrmgw.snaException;
import bea.base.io.MainframeWriter;
import bea.base.io.MainframeReader;

/**
* Extended Sample Class
*/
public class ExtSampleClient extends SampleClass
{
// deleteEmployee
//
public EmployeeRecord deleteEmployee(EmployeeRecord
commarea)
throws IOException, snaException
{
EmployeeRecord erec=(EmployeeRecord) in;
if (!isSsnValid(erec.getEmpRecord().getEmpSsn()))
{
// The SSN is not valid.
throw new Error )"Invalid Social Security Number:"+
erec.getEmpRecord().getEmpSsm());
}

	// Make the remote call.
//
return super.deleteEmployee(commarea);
}

	//updateEmployee
//
public EmployeeRecord updateEmployee(EmployeeRecord
commarea)
throws IOException, snaException
{
EmployeeRecord erec = (EmployeeRecord) in;
if (!isSsnValid(erec.getEmpRecord().getEmpSsn()))
{
The SSN is not valid.
throw new Error ("Invalid Social Security Number:"+
erec.getEmpRecord().getEmpSsn());
}

	// Make the remote call.
//
return super.updateEmployee(commarea);
}

	// readEmployee
//
public EmployeeRecord readEmployee(EmployeeRecord commarea)
throws IOException, snaException
{
EmployeeRecord erec = )EmployeeRecord)in;
if (!isSsnValid(erec.getEmpRecord().getEmpSsn()))
{
// The SSN is not valid.
throw new Error("Invalid Social Security Number:"+
erec.getEmpRecord().getEmpSsn());
}

	// Make the remote call.
//
return super.readEmployee(commarea);
}

	//newEmployee
//
public EmployeeRecord newEmployee(EmployeeRecord commarea)
throws IOException, snaException
{
EmployeeRecord erec = (EmployeeRecord) in;
if (!isSsnValid(erec.getEmpRecord().getEmpSsn()))
{
// The SSN is not valid.
throw new Error("Invalid Social Security Number:"+
erec.getEmpRecord().getEmpSsn());
}

	// Make the remote call.
//
return super.newEmployee(commarea);
}

// Private functions

	/******************************************************
* Validates an SSN field.
*/

	private boolean isSsnValid(BigDecimal ssn)
{
if (ssn.longValue() < 100000000)
{
// Ops, should not have a leading zero.
return false;
}

	return (true);
}
]

// END ExtSampleClient.java


Once the ExtSampleClient class has been written, it and the other Java source files must be compiled and placed on to your WEBLOGICCLASSPATH.