Chapter 12 Creating CORBA-Java Components
When you code the parameters for each method, make sure you use the Java datatype that corresponds to the datatype you defined in the Jaguar Manager.
If you have an IDL interface If you are starting with an IDL interface rather than an existing class file, you can use Jaguar Manager to create a class that contains the necessary method declarations. See "Generate stub, skeleton, and implementation files" for more information.
To implement a Java source file for a Java component that runs on a Jaguar server, follow these steps:
Use Jaguar Manager to generates stubs and skeletons for the component. Jaguar Manager will also create a sample implementation template for the class that implements the component methods.
Internally, Jaguar's IDL-to-Java compiler is invoked by Jaguar Manager to generate Java stubs and skeletons. The direct compiler interface is not intended for customer use.
What the skeleton does The skeleton class interprets component invocation requests and calls the corresponding method in your component with the parameter values supplied by the client. When a client sends an invocation request, the skeleton reads the parameter data and calls the Java method. When the method returns, the skeleton sends output parameter values, return values, and exception status to the client.
You must generate a new skeleton class if:
Using the sample implementation Jaguar Manager creates a sample source for the implementation class that is specified in the Component Properties window. The generated template file name is:
componentImpl.java.new
where component is the name of the component. The .new extension avoids conflicts with existing source files.
The sample implementation provides a starting point for your own implementation, as it contains all the required method definitions to match the IDL interfaces that the component implements. Each method has the same name as the IDL operation it implements, and uses return and parameter datatypes that are mapped according to the type mappings that you have chosen (see "Choose implementation datatypes").
In the Java component, component interface methods must be public and cannot be declared static. If the IDL definition of the method has a non-empty raises clause, the Java method must throw equivalent Java exceptions for the IDL exceptions listed in the raises clause.
All methods in the implementation throw the exception org.omg.CORBA.NO_IMPLEMENT. Replace this code with your own method implementation.
If you've added methods to an existing component, you can copy the additional method signatures from the .new file to your original source file.
Stubs may be required to compile the component If the component's definition uses user-defined types for parameters, return values, or exceptions, Java stubs are required for these types. These stubs are generated when you generate stubs for your component, as described in "Generating Java stubs".
Compiled Java stubs for user-defined IDL types must be available when you compile your component's implementation file.
You can generate Java source files for skeleton classes from Jaguar Manager as follows:
Jaguar Manager generates the skeleton source file into the same Java package as the component's implementation class. Skeletons are named as _sk_Package_Comp.java, where Package represents the Jaguar package name and Comp represents the component name.
You must compile the Java class that implements the component before you compile the skeleton class.
Compile the skeleton classes with a compiler that is compatible with JDK 1.1. Make sure that the CLASSPATH setting contains the code base directory and the Jaguar html/classes subdirectory. For example, if code base is c:\classes, these commands compile _sk_calc.java:
cd c:\classes\Calculator
set CLASSPATH=c:\classes;%JAGUAR%\html\classes;%CLASSPATH%
javac _sk_calc.java
In addition to any Java packages that you might need, you might also need to import several Java packages. Classes coded with IDL datatypes and classes coded with SQL datatypes require different import statements.
Chapter 1, "Java Classes and Interfaces" in the Jaguar CTS API Reference provides reference pages for these packages.
The packages below are useful if your component is implemented using SQL datatypes:
Package(s) |
Description |
---|---|
com.sybase.jaguar.beans.enterprise |
Contains Jaguar's implementation of the Enterprise JavaBeans (EJB) support classes (including the ServerBean interface and the shared data classes). These classes are based on an early draft of the JavaSoft EJB specification and are subject to change. |
com.sybase.jaguar.server |
Contains utility classes for use in server-side Java code. |
com.sybase.jaguar.sql |
Defines interfaces for defining and sending result sets. See "Sending result sets with Java" for details on using these classes. |
com.sybase.jaguar.jcm |
Provides the Java Connection Management (JCM) classes. See Chapter 28, "Using Connection Management" for a description of this feature. |
com.sybase.jaguar.util com.sybase.jaguar.util.jdbc11 |
Contain the JException class and the holder classes that are used to pass inout and out parameter values. |
The fragment below shows the import statements for all of these classes:
import com.sybase.jaguar.server.*;
import com.sybase.jaguar.util.*;
import com.sybase.jaguar.util.jdbc11.*;
import com.sybase.jaguar.sql.*;
import com.sybase.jaguar.jcm.*;
import com.sybase.jaguar.beans.enterprise.*;
You can also import com.sybase.jaguar.*, but you must remember to include the rest of the package name when you specify methods.
The packages below are useful if your component is implemented using the standard CORBA IDL-to-Java datatype mappings:
Package(s) |
Description |
---|---|
org.omg.CORBA |
Contains Java holder and helper classes for each of the core CORBA datatypes. Also defines the interfaces for a standard Java client-side Object Request Broker. |
com.sybase.CORBA.jdbc11.* |
Contains utility classes for converting between Jaguar IDL datatypes and core Java datatypes. |
com.sybase.jaguar.server |
Contains utility classes for use in server-side Java code. |
com.sybase.jaguar.sql |
Defines interfaces for defining and sending result sets. See "Sending result sets with Java" for details on using these classes. |
com.sybase.jaguar.jcm |
Provides the Java Connection Management (JCM) classes. See Chapter 28, "Using Connection Management" for a description of this feature. |
com.sybase.jaguar.util.JException |
Many of the methods in the Jaguar Java classes throw JException. Note that the packages com.sybase.jaguar.util and org.omg.CORBA contain identically named classes, so you can not import all classes from both packages. To avoid compilation problems, import JException explicitly or always refer to this class by its full name. |
The fragment below shows the import statements for all of these classes:
import org.omg.CORBA.*;
import com.sybase.CORBA.jdbc11.*;
import com.sybase.jaguar.util.JException;
import com.sybase.jaguar.server.*;
import com.sybase.jaguar.sql.*;
import com.sybase.jaguar.jcm.*;
A class constructor is normally used to initialize instance-specific data. However, if your component implements the ServerBean interface, then you should use the activate(InstanceContext, String) and deactivate() methods to manage instance-specific data.
If the component does not implement the ServerBean interface, then instance-specific initialization must be done in the constructor.
Any uncaught exception that is thrown within the constructor aborts the creation of the new component instance.
The ServerBean interface provides methods that the Jaguar server invokes in response to transitions in the component's lifecycle. Chapter 3, "Understanding Transactions and Component Lifecycles" describes how component instances are created, bound to clients, and destroyed.
Implement the ServerBean interface if any of the following requirements apply:
If you are adapting an existing class that does not implement ServerBean to run as a Jaguar component, you may need to modify the source to add the ServerBean methods and required activation and deactivation code. If you do not have access to the source, create an adaptor class that implements ServerBean and calls the existing class methods. Install the adaptor class as the implementation class for the component.
If a class does not implement ServerBean, you can set component properties in Jaguar Manager to control instance reuse (pooling) and how the component participates in transactions. See "Configuring component properties" for more information.
To support the ServerBean interface, your class must implement the ServerBean interface and these methods:
For more information on these methods, see the reference page for jaguar.beans.enterprise.ServerBean in the Jaguar CTS API Reference.
Errors occuring during component execution should be handled gracefully as follows:
Java components can record errors or status messages to the server's log file. Writing to the log creates a permanent record of the error, and log messages can be automatically stamped with the date and time that the message was written. Call any of the System.out.print methods to write to the log.
You can also throw an uncaught exception. Ideally, any exception thrown by your component should be a standard CORBA IDL exception or a user-defined IDL exception (the latter must be listed in the raises clause of the IDL method definition and the throws clause of the equivalent Java method declaration). All exceptions are forwarded to the client, but only exceptions that are defined in IDL can be rethrown by the client stub as a duplicate of the server-side exception. CORBA ORB and Jaguar EJB clients receive forwarded exceptions differently:
Copyright © 2000 Sybase, Inc. All rights reserved. |