[Contents] [Previous] [Next] [Index]

## Chapter 4
Using CORBA Components

This document describes how to use CORBA objects as Netscape ONE components using Visual JavaScript (VJS). You import CORBA objects into the VJS palette as components, and use the components to build applications. It describes how data types are mapped between CORBA, Java, and JavaScript, and it also provides reminders about configuring a user's system to run an application that uses CORBA-based components.

Sections in this document include the following topics:

- What are CORBA Components?
- Installing a CORBA Component
- Mapping Data Types
- Connecting to a CORBA Object
- Accessing a CORBA Object at Run Time

## What are CORBA Components?

Netscape ONE supports the Common Object Request Broker Architecture (CORBA) in its tools and products through the use of CORBA components. CORBA specifies how software objects distributed over a network can work together without regard to client and server operating systems and without regard to the programming languages originally used to build those objects.

A CORBA-based component defines an interface that specifies the services the component can request, the services the component can provide, and the kinds of data it can receive and send. Ordinarily, the native interface for a CORBA object is described in an interface definition language (IDL) file. The IDL file does not implement a CORBA object, but instead describes its entry points: the names of its operations, their return types, and arguments. The IDL file is compiled to produce stub code in a native language, such as C++ or Java, and this stub code is subsequently filled out by developers to implement the object.

You can install CORBA objects into the VJS palette as components for use in building applications. VJS uses an IDL file to construct a JavaScript Bean (JSB) file for the component. The JSB file is a stub for the CORBA object, that describes its interface to VJS, and enables the display of its methods in the VJS inspector at design time. For a complete description of the JSB file structure, see JSB File Structure Reference.

At run time, VJS applications can use CORBA-based components to request services from an object request broker (ORB), or to process service requests received from an ORB. The ORB is responsible for marshalling and processing requests for service, which frees applications from locating those services and translating between disparate operating systems and data structures.

For a more complete introduction to CORBA, see CORBA: Catching the Next Wave.

## Installing a CORBA Component

To import a CORBA component into VJS:

> 1. Choose Install CORBA Object from the VJS menu.

> 2. Specify the IDL file to import in the dialog box. Note that the import process takes a short time.

> NOTE: The following restrictions and workarounds apply to IDL files:

- #include statements are not handled in PR3. Manually copy the included file into the IDL file before installing.

- #directives cause an error during install. Remove #directives from the IDL file before installing.

- typedefs in IDL files do not work correctly in CORBA components. A typedef that should map to an integer is be mapped to an object. Manually replace the typedef name with the underlying type prior to install.

VJS retrieves the specified interface information, converts it to a JSB file that is stored in the palette archive, and displays a corresponding "CORBA" icon on the palette.VJS creates one JSB file for each interface definition in the IDL file. Default names and icons are generated automatically, but can be edited by the user in VJS.

The following sections describes the Component Methods, Component Properties, and Component Attributes associated with imported components.

### Component Methods

An imported component has one JavaScript method declaration for each interface operation defined in the IDL file for the original CORBA object. These declarations map the data types of parameters and return type of the original object to corresponding Java data types, or to the java.lang.Object type when an exact match is not available. For more information, see Mapping Data Types.

Because the JS component is a stub for the server object, it must be connected to the server object before it is useful. Once connected, the component will have a member called "corbaObject" which is the ORB's local Java representation of the object. The JS methods formulate calls through the Dynamic Invocation Interface (DII) on this object, and return the results.

An imported component's methods are essentially wrappers for the actual operations associated with the CORBA object.

#### Working with Parameters

IDL files can specify three different kinds of parameters for its operations: IN, OUT, and IN/OUT. These parameters can be of any recognized IDL data type, and may involve mapping data types. CORBA uses IN and IN/OUT parameters to receive information from the calling application. You must pass an initial value to IN and IN/OUT parameters. CORBA uses OUT and IN/OUT parameters to pass values back to the calling application. These parameter values may be in addition to an operation's return value. You do not need to set an initial value for OUT parameters.

IN parameters exactly like standard Java and JavaScript parameters. OUT and IN/OUT parameters work a little differently. For these cases, you must create a JS object (e.g. myParam = new Object()). The actual value for the parameter is passed in and out through the object's value member (e.g., myParam.value. If it is an IN/OUT parameter, you need to set the value member to the value you want to pass to the object. In either OUT and IN/OUT cases, after the call is complete, you can get the value that the operation passed back to you from the value member of the object.

> NOTE: The JSB method wrappers created for a CORBA object interface maps the CORBA operation's parameter data types to corresponding Java data types where they exist, but the JSB wrapper does not indicate whether a parameter is an IN, OUT, or IN/OUT type. You should examine the IDL file to determine the kinds of parameter, whether you must supply a value to them when you call the operations, and whether you should examine parameters for values on return from the call.

### Component Properties

When you install a CORBA object into VJS, the resulting JavaScript component is automatically assigned properties. These properties come from three sources:

- Attributes specified in the IDL interface

- SCRIPT or APPLET tag attributes (for example, PURPOSE, CLASS, and sometimes SRC, WIDTH, HEIGHT)

- VJS (ObjectURL, which specifies the URL to the actual instance of the CORBA object)

The ObjectURL property is especially important because it establishes the connection between the actual CORBA object and the component that represents it in VJS. For more information see Connecting to a CORBA Object.

> NOTE: Because CORBA objects do not implement events, you cannot use the VJS events and you cannot use bound properties as you can for JavaScript components and Java objects.

### Component Attributes

CORBA objects may have attributes. Attributes are mapped to JavaScript Component Properties in VJS, and you can use the inspector to examine them.

### Component Events

There are no events on CORBA components.

## Mapping Data Types

CORBA data types specified in an IDL file are automatically mapped to corresponding Java data types as much as possible when you import the IDL file into VJS as a component. Because CORBA objects can be implemented in C++ or Java, CORBA recognizes a wider variety of data types than Java, so some data type translation occurs. The following table summarizes IDL-to-Java mappings used by VJS. It also notes any additional translation that must occur between Java and JavaScript when you work with certain Java data types, such as java.lang.Char.

IDL Data Type | Java Data Type | JavaScript Data Type
--- | --- | ---
null | java.lang.Object | object
void | java.lang.Void |
short | java.lang.Short | number
long | java.lang.Long | number
ushort | java.lang.Short | number
ulong | java.lang.Integer | number
float | java.lang.Float | number
double | java.lang.Double | number
boolean | java.lang.Boolean | boolean
char | java.lang.Char | number (integer)
octet | java.lang.Byte | number
any | java.lang.Object | object
TypeCode | java.lang.Object | object
Principal | java.lang.Object | object
objref | java.lang.Object | object
struct | java.lang.Object | object
union | java.lang.Object | object
enum | java.lang.Object | object
string | java.lang.String | string
sequence | java.lang.Object | object
array | java.lang.Object | object
alias | java.lang.Object | object
except | java.lang.Object | object
longlong | java.lang.Long | number
ulonglong | java.lang.Long | number
longdouble | java.lang.Double | number
wchar | java.lang.Char | number (integer)
wstring | java.lang.String | string
fixed | java.lang.Object | object
estruct | java.lang.Object | object

> NOTE: This table is preliminary, and subject to change. See the "Netscape ISB for Java Programmer's Guide" for the latest information about IDL-to-Java data type mappings.

In general, note that:

- Java does not recognize unsigned data types. Unsigned IDL data types, such as ulong, ulonglong, and ushort, are translated into their corresponding signed types in Java. As a result, some values that are reported in Java as negative numbers may actually represent very large positive values.

- CORBA data types for which there is not a corresponding Java data type are always translated to the java.lang.Object type.

- JavaScript does not recognize the Java.lang.Char data type. The java.lang.Char data type must be translated to an integer value for processing in JavaScript. Do not translate the java.lang.Char data type to a one character string. Similarly, on translation from JavaScript to Java, numeric values that represent characters must be converted to the correct Java.lang.Char value. Your application must handle these conversions.

## Connecting to a CORBA Object

An application that uses a CORBA component can connect to a CORBA object using:

- The ObjectURL property of the component. This is the preferred method of connection, which depends on having the Netscape Enterprise Server 3.0 installed and running.

- Through the use of a custom Java function that specifies corbaObject. This method, setCorbaObject, requires that you have a custom Java library of routines for handling CORBA connections.

The ObjectURL property is unique to JavaScript components that result from importing a CORBA object IDL into VJS. ObjectURL specifies the URL to the actual instance of the CORBA object. When you first import a CORBA object into VJS, you should give ObjectURL an initial value.

You can change the value of ObjectURL at design-time through the inspector, and you can change the value of ObjectURL programmatically at run time, through the setObjectURL method. When ObjectURL is changed, the JavaScript component is bound to the newly-specified CORBA object on the fly. Object binding is actually managed by the platform's name service; in order for binding to occur, the CORBA objects you specify in the ObjectURL property must be listed in the name service.

For more information about using CORBA with Enterprise Server 3.0, see "Writing Web Applications with WAI". For more information about building Java applications that can use the Netscape Internet Service Broker API to create CORBA applications, see the "Netscape ISB for Java Programmer's Guide".

## Accessing a CORBA Object at Run Time

After you import a CORBA object into VJS, use the resulting JavaScript component to build applications just as you use the built-in components already on the VJS palette. At run time, the application automatically accesses the CORBA object using the CORBA support built into Communicator.

[Contents] [Previous] [Next] [Index]

Last Updated: 09/03/97 11:33:50

Copyright © 1997 Netscape Communications Corporation