📄 corba.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Writing Advanced Applications, Chapter 4: Distributed Computing</TITLE>
<META NAME="AUTHOR" CONTENT="Monica Pawlan and Calvin Austin">
<META NAME="KEYWORDS" CONTENT="programming, advanced, Java 2">
<META NAME="OWNER" CONTENT="Editorial/JDC">
<META NAME="revision" CONTENT="@(#)corba.src 1.5 07/16/99 JDC">
</HEAD>
<!-- Start Body Insert-->
<BODY BGCOLOR="#ffffff">
<!-- End Body Insert-->
<!-- Start PageTop Insert -->
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR ALIGN="CENTER" VALIGN="TOP">
<TD WIDTH="157" ALIGN="LEFT">
<IMG SRC="/images/pixel.gif" HEIGHT="40" WIDTH="40" ALT="">
<A HREF="http://java.sun.com/index.html"><IMG SRC="/images/javalogo52x88.gif" WIDTH="52" HEIGHT="88" ALT="Java Technology Home Page" BORDER="0"></A>
<BR>
<IMG SRC="/images/pixel.gif" WIDTH="157" HEIGHT="1" ALT=""></TD>
<TD>
<FORM NAME="seek1" METHOD="GET" ACTION="http://search.java.sun.com/query.html">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">
<TR>
<TD ALIGN="RIGHT">
<IMG SRC="/images/stripelt.gif" WIDTH="6" HEIGHT="14" ALT=""></TD>
<TD WIDTH="100%">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">
<TR>
<TD BGCOLOR="#CC9966" WIDTH="100%">
<IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
</TR>
<TR>
<TD>
<IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
</TR>
<TR>
<TD BGCOLOR="#CC9966">
<IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
</TR>
<TR>
<TD>
<IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
</TR>
<TR>
<TD BGCOLOR="#CC9966">
<IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
</TR>
<TR>
<TD>
<IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
</TR>
<TR>
<TD BGCOLOR="#CC9966">
<IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="LEFT">
<IMG SRC="/images/stripert.gif" WIDTH="6" HEIGHT="14" ALT=""></TD>
<TD>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
<TR>
<TD VALIGN="CENTER">
<A HREF="http://java.sun.com/a-z/index.html"><IMG SRC="/images/azindex.gif" BORDER="0" WIDTH="72" HEIGHT="11" ALT="A-Z Index"></A></TD>
<TD VALIGN="CENTER">
<FONT FACE="Helvetica" SIZE="1">
<INPUT TYPE="text" SIZE="15" MAXLENGTH="128" NAME=qt></FONT></TD>
<TD VALIGN="CENTER">
<INPUT TYPE="image" SRC="/images/search.button.gif"
value="search" BORDER="0" WIDTH="55" HEIGHT="14" ALT="Search"></TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</FORM>
<P>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="0" CELLSPACING="0">
<TR VALIGN="TOP">
<TD WIDTH="100%"><IMG SRC="/images/chiclet.row.gif" WIDTH="55"
HEIGHT="18" ALT=""></TD>
<TD ROWSPAN="4" ALIGN="RIGHT" WIDTH="152">
<A HREF="/developer/index.html"><IMG SRC="/images/developer.connection.header.gif" BORDER="0" HEIGHT="42" WIDTH="319" ALT="Java Developer Connection(SM)"></A></TD>
</TR>
<TR VALIGN="TOP">
<TD BGCOLOR="#FFFFFF" HEIGHT="1" WIDTH="100%">
<IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
</TR>
<TR VALIGN="TOP">
<TD BGCOLOR="#CC9966" HEIGHT="1" WIDTH="100%">
<IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
</TR>
<TR VALIGN="TOP">
<TD><A HREF="/developer/onlineTraining/"><IMG SRC="/images/online-training.gif" ALT="Online Training" BORDER=0></A></TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<!-- End PageTop Insert -->
<!-- Start NavBar Insert -->
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="3" BGCOLOR="#FFFFFF" WIDTH="157" ALIGN="LEFT">
<!-- tab categories -->
<TR>
<TD><A HREF="http://java.sun.com/products/"><IMG SRC="/images/side.tab.products.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Downloads, APIs, Documentation"></A></TD>
</TR>
<TR>
<TD><A HREF="/developer/index.html"><IMG SRC="/images/side.tab.developer.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Java Developer Connection"></A></TD>
</TR>
<TR>
<TD><A HREF="/developer/infodocs/index.shtml"><IMG SRC="/images/side.tab.docs.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Tutorials, Tech Articles, Training"></A></TD>
</TR>
<TR>
<TD><A HREF="/developer/support/index.html"><IMG SRC="/images/side.tab.support.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Online Support"></A></TD>
</TR>
<TR>
<TD><A HREF="/developer/community/index.html"><IMG SRC="/images/side.tab.community.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Community Discussion"></A></TD>
</TR>
<TR>
<TD><A HREF="http://java.sun.com/industry/"><IMG SRC="/images/side.tab.news.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="News & Events from Everywhere"></A></TD>
</TR>
<TR>
<TD><A HREF="http://java.sun.com/solutions"><IMG SRC="/images/side.tab.solutions.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Products from Everywhere"></A></TD>
</TR>
<TR>
<TD><A HREF="http://java.sun.com/casestudies"><IMG SRC="/images/side.tab.case.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="How Java Technology is Used Worldwide"></A></TD>
</TR>
<TR><TD> </TD></TR>
<!-- End NavBar Insert -->
<!-- START SUB-NAV -->
<TR>
<TD><!-- INSERT SUB-NAV INFO -->
</TD>
</TR>
<!-- END SUB-NAV -->
</TABLE>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
<TR>
<TD>
<!-- Template Version 2.0 -->
<!-- ================== -->
<!-- Start Main Content -->
<!-- ================== -->
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
<TR>
<TD VALIGN="TOP">
<FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A NAME="top"></A>
<DIV ALIGN="RIGHT">
<H2>Writing Advanced Applications<BR>
<FONT SIZE="3">Chapter 4: Common Object Request Broker Architecture (CORBA)</FONT></H2>
<FONT SIZE="-1">[<A HREF="rmi.html"><<BACK</A>] [<A HREF="index.html#contents">CONTENTS</A>] [<A HREF="jdbc.html">NEXT>></A>]</FONT></DIV>
<P>
Both the Remote Method Invocation (RMI) and Enterprise JavaBeans<FONT SIZE="-2"><SUP>TM</SUP></FONT>
auction application implementations use the Java<FONT SIZE="-2"><SUP>TM</SUP></FONT> language to
implement the different auction service tiers. However, you might need
to integrate with applications written in C, C++ or other languages and
running on a myriad of operating systems and machines.
<P>
One way to integrate with other applications is to transmit data in a
common format such as 8 bit characters over a TCP/IP socket. The
disadvantage is you have to spend a fair amount of time deriving
a messaging protocol and mapping the various data structures to and
from the common transmission format so the data can be sent and received
over the TCP/IP connection.
<P>
This is exactly where Common Object Request Broker Architecture (CORBA)
and its Interface Definition Language (IDL) can help. IDL provides
a common format to represent an object that can be distributed
to other applications. The other applications might not even understand
objects, but as long as they can provide a mapping between the common IDL format
and their own data representations, the applications can share data.
<P>
This chapter describes the Java language to IDL mapping scheme, and
how to replace the original container-managed <CODE>RegistrationBean</CODE>
with its CORBA server equivalent. The <CODE>SellerBean.java</CODE> and
<CODE>AuctionServlet.java</CODE> programs are changed to interoperate
with the CORBA <CODE>RegistrationServer</CODE> program.
<UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#scheme">IDL Mapping Scheme</A></FONT>
<UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#ref">Quick Reference</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#map">Setting up IDL Mappings </A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#other">Other IDL Types</A></FONT>
</UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#auction">CORBA in the Auction Application</A></FONT>
<UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#server">CORBA RegistrationServer</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#idl">IDL Mappings File</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#comp">Compiling the IDL Mappings File</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#stub">Stub and Skeleton Files</A></FONT>
</UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#orb">Object Request Broker (ORB)</A></FONT>
<UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#make">Making the CORBA Server Accessible</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#plug">Plugging in a New ORB</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#name">Naming Service Access by CORBA Clients</A></FONT>
</UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#help">Helper and Holder Classes</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#gar">Garbage Collection</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#call">CORBA Callbacks</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#any">Using the Any Type</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#conclude">Conclusion</A></FONT>
</UL>
<A NAME="scheme"></A>
<H3>IDL Mapping Scheme</H3>
Many programming languages provide a mapping between
their data types to the common denominator IDL
format, and the Java language is no exception. The Java language can send
objects defined by IDL to other CORBA distributed applications, and
receive objects defined by IDL from other CORBA distributed applications.
<P>
This section describes the Java language to IDL mapping scheme and,
where needed, presents issues you need to take into consideration.
<A NAME="ref"></A>
<H4>Quick Reference</H4>
Here is a quick reference table of the Java language to CORBA IDL
data types, and the runtime exceptions thrown when conversions fail.
Data types in this table that need explanation are covered below.
<P>
<TABLE BORDER=1 CELLPADDING=1 CELLSPACING=1>
<TR><TH><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Java Data Type</FONT></TH><TH><FONT FACE="Verdana, Arial, Helvetica, sans-serif">IDL Format</FONT></TH><TH><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Runtime Exception</FONT></TH></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">byte</FONT></TD><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">octet</FONT></TD><TD></TD></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">boolean</FONT></TD><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">boolean</FONT></TD><TD></TD></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">char</FONT></TD><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">char</FONT></TD><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">DATA_CONVERSION</FONT></TD><TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">char</FONT></TD><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">wchar</FONT></TD><TD></TD></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">double</FONT></TD><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">double</FONT></TD><TD></TD></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">float</FONT></TD><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">float</FONT></TD><TD></TD></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">int</FONT></TD><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">long</FONT></TD><TD></TD></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">int</FONT></TD><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">unsigned long</FONT></TD><TD></TD></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">long</FONT></TD><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">long long</FONT></TD><TD></TD></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">long</FONT></TD><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">unsigned long long</FONT></TD><TD></TD></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">short</FONT></TD><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">short</FONT></TD><TD></TD></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">short</FONT></TD><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">unsigned short</FONT></TD><TD></TD></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">java.lang.String</FONT></TD><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">string</FONT></TD><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">DATA_CONVERSION</FONT></TD></TR>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">java.lang.String</FONT></TD><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">wstring</FONT></TD><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">MARSHAL</FONT></TD></TR>
</TABLE>
<P>
<STRONG>Unsigned Values:</STRONG>
The Java data types <CODE>byte</CODE>, <CODE>short</CODE>, <CODE>int</CODE>,
and <CODE>long</CODE> are represented by 8 bit, 16 bit, 32 bit and 64 bit
two's-complement integers. This means a Java <CODE>short</CODE> value represents
the range -2<SUP>15</SUP> to 2<SUP>15</SUP> - 1 or -32768 to 32767 inclusive.
The equivalent signed IDL type for a short, <CODE>short</CODE>,
matches that range, but the unsigned IDL <CODE>short</CODE> type uses
the range 0 to 2<SUP>15</SUP> or 0 to 65535.
<P>
This means that in the case of a <CODE>short</CODE>, if an unsigned
short value greater than 32767 is passed to a program written in the Java
language, the <CODE>short</CODE> value is represented in the Java language
as a negative number. This can cause confusion in boundary tests for a value
greater than 32767 or less than 0.
<P>
<STRONG>IDL char Types:</STRONG>
The Java language uses 16-bit unicode, but the IDL <CODE>char</CODE> and
<CODE>string</CODE> types are 8-bit characters. You can map a Java
<CODE>char</CODE> to an 8-bit IDL <CODE>char</CODE>
to transmit multi-byte characters if you use an array to do it.
However, the IDL wide char type <CODE>wchar</CODE> is specifically designed
for languages with multi-byte characters and allocates a fixed number of
bytes as needed to contain that language set for each and every letter.
<P>
When mapping between the Java language <CODE>char</CODE> type and the
IDL <CODE>char</CODE> type, the <CODE>DATA_CONVERSION</CODE> exception
is thrown if the character does not fit into 8 bits.
<P>
<STRONG>IDL string Types:</STRONG>
The IDL <CODE>string</CODE> type can be thought of as a sequence of IDL
<CODE>char</CODE> types, and also raises the <CODE>DATA_CONVERSION</CODE> exception.
The IDL <CODE>wstring</CODE> type is equivalent to a sequence of <CODE>wchars</CODE>
terminated by a <CODE>wchar NULL</CODE>.
<P>
An IDL <CODE>string</CODE> and <CODE>wstring</CODE> type can either have a
fixed size or no maximum defined sized. If you try to map
a <CODE>java.lang.String</CODE> to a fixed size or bounded IDL <CODE>string</CODE>
and the <CODE>java.lang.String</CODE> is too large, a <CODE>MARSHAL</CODE>
exception is raised.
<A NAME="map"></A>
<H4>Setting up IDL Mappings</H4>
Java language to IDL mappings are placed in a file with a <CODE>.idl</CODE>
extension. The file is compiled so it can be accessed by CORBA programs
that need to send and receive data.
This section explains how to construct the mappings for
package statements and the Java data types. The section below on
<A HREF="#server">CORBA RegistrationServer Implementation</A> describes how
to use this information to
set up an IDL mapping file for the CORBA <CODE>Registration</CODE>
server.
<P>
<STRONG>Java packages and interfaces</STRONG>:
Java package statements are equivalent to the <CODE>module</CODE>
type in IDL. The <CODE>module</CODE> types can be nested, which results in
generated Java classes being created in nested sub-directories.
<P>
For example, if a CORBA program contains this package statement:
<PRE>
package registration;
</PRE>
the mappings file would have this IDL module mapping for it:
<PRE>
module registration {
};
</PRE>
<P>
If a CORBA program contains a package hierarchy like this
<PRE>
package registration.corba;
</PRE>
the equivalent IDL module mapping is this:
<PRE>
module registration {
module corba {
};
};
</PRE>
Distributed classes are defined as Java interfaces and map to the
IDL interface type. IDL does not define access such as <CODE>public</CODE>
or <CODE>private</CODE> like you find
in the Java language, but does allow inheritance from other interfaces.
<P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -