The jCOM bi-directional software comes with tools that developers can use to generate the intermediate software components the jCOM bridge requires to communicate and perform the translation. Take a look at these tools, which will help you understand how the software pieces enable the jCOM bridge to perform bi-directional communication with COM components. com2javaThe com2java tool, shown in Figure 20.1, reads information from a type library of COM classes or interfaces. After interpreting the information from the type library, the com2java utility generates Java classes that contain the necessary functionality to enable Java applications and components deployed in WebLogic Server to access the COM components as if they were Java classes. The generated Java classes actually act as a proxy for COM components. The type libraries used by the com2java tool are typically generated using either Visual C++ or Visual Basic, the two language tools used to develop COM components. Figure 20.1. Screen shot of the com2java tool.The translation functionality provided by the com2java tool is not restricted to server-side COM components. Visual components such as ActiveX controls can also be accessed using the com2java tool. The com2java tool generates two kinds of files for a COM interface, defined in the type library file:
The com2java tool supports the processing of the following types in the type library:
The com2java tool is located in the WebLogic Server's bin directory. There is a non-GUI command-line version also available named com2javacmd. java2comCOM clients, such as Visual Basic clients, may want to access Java objects or EJB components deployed in WebLogic Server. The java2com tool helps in generating an IDL file that can be used by the COM component to generate the client-side classes needed to access Java objects and components deployed in WebLogic Server. The java2com tool works on the Java classes to analyze their structure using reflection technique and generates an IDL file and Java wrapper classes, as you'll learn next. IDL File for the COM ComponentThe java2com tool generates a COM interface for each Java interface that it encounters during processing. For example, for an interface named com.sams.learnweblogic7.MySAMSHomeInterface, the tool generates a COM interface named ComSamsLearnweblogic7MySAMSHomeInterface (the name can be overridden with any name that you specify in the generation process). For public Java classes, as well, the tool generates COM interfaces that correspond to the definition of each public Java class. As an example, for the public bean implementation class of an EJB named com.sams.learnweblogic7.MySAMSBeanImpl, the COM interface generated will be IComSamsLearnweblogic7MyBeanImpl (the name can be similarly changed). All these interfaces are consolidated and written in the final generated file, for example, mysams.idl. The structure of the IDL file is for use only by COM components. The mysams.idl file should then be compiled using the tools provided with Visual C++ to generate the required type library file. Finally, you would need to register this type library file along with the COM client application by using the regtlb tool. You will learn about using regtlb later in this section. Java Wrapper ClassesThe Java wrapper classes are specific to the Java object that will be accessed by a COM component. These wrapper classes are required by the jCOM bridge software to perform the actual marshalling, that is, translation from a COM component request to an RMI IIOP request used internally by Java objects and EJB components deployed in WebLogic Server. The java2com batch file is located in the WebLogic Server's bin directory. The command used to invoke the tool is java com.bea.jcom.Main regjvmThe regjvm tool that is provided as part of the jCOM bridge software is used to register the information of the Java Virtual Machine (JVM) of the WebLogic Server when you need to establish communication between a COM client and Java objects deployed on WebLogic Server. The regjvm GUI tool is used to define the mode of communication. Normally, you would select the DCOM Pure Java mode of communication and supply the WebLogic Server host name and port number. This information should be saved after providing a logical name for the JVM id. This logical name, or JVM id, will be used by the regtlb utility to register a type library in the Windows registry, along with the JVM id. A command-line version called regjvmcmd is also available. The regjvm (or regjvmcmd) file is located in the WebLogic Server's bin directory. The command used to invoke the tool is regjvm or regjvmcmd regtlbThe final utility that you will be looking at is the regtlb utility. The regtlb utility is the final step involved when establishing a static, or early binding, communication between a COM client and Java objects deployed on WebLogic Server. The regtlb utility is used to register the type library generated after compiling a COM-compliant IDL file. The regtlb takes the type library and the JVM id (generated using the regjvm or regjvmcmd utilities) and registers it with the COM client. The regtlb batch file is located in the WebLogic Server's bin directory. The command used to invoke the tool is regtlb Now you will look at how the communication between WebLogic Server and COM takes place using jCOM bridge software and the tools that you learned about earlier. |