⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch03.htm

📁 corba比较入门级的介绍详细间接了corba访问发布各种细节。
💻 HTM
📖 第 1 页 / 共 5 页
字号:
	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TRANSIENT</TD>		<TD ALIGN="LEFT">Transient failure--re-issue request.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">FREE_MEM</TD>		<TD ALIGN="LEFT">Cannot free memory.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">INV_IDENT</TD>		<TD ALIGN="LEFT">Invalid identifier syntax.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">INV_FLAG</TD>		<TD ALIGN="LEFT">Invalid flag was specified.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">INTF_REPOS</TD>		<TD ALIGN="LEFT">Error accessing interface repository.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">BAD_CONTEXT</TD>		<TD ALIGN="LEFT">Error processing context object.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">OBJ_ADAPTER</TD>		<TD ALIGN="LEFT">Failure detected by object adapter.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">DATA_CONVERSION</TD>		<TD ALIGN="LEFT">Data conversion error.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">OBJECT_NOT_EXIST</TD>		<TD ALIGN="LEFT">Nonexistent object--delete reference.</TD>	</TR></TABLE><H2><A NAME="Heading32"></A><FONT COLOR="#000077">The any Type</FONT></H2><P>For those occasional methods that need to accept any sort of CORBA object as aparameter or take a parameter that could potentially be one of several unrelateddata types (in other words, none of the data types are inherited from any of theothers), IDL provides the any type. When any is used as the type of a parameter orreturn value, that value can literally be any IDL type. A method that accepts anany as an input parameter will usually need to determine precisely what type of objectis being passed before it can manipulate the object; you will see how this is donewhen you begin implementing CORBA clients and servers.<BLOCKQUOTE>	<P><HR><B>Note:</B>For a method that must accept one of various types of CORBA objects as	a parameter, the any is not always the only choice. If the type of the parameter	can be one of only a few types, and the type of the parameter is known, then the	union type might be a better choice. However, with the union type, all of the types	must be known in advance; this is not true for an any type. An any parameter can	literally hold any type of object, even one that is unknown to the server receiving	the any parameter. <HR></BLOCKQUOTE><P>For an example of the any type, see Listing 3.12. In this example, the browseObject()method accepts a single parameter, called object, of type any. A client calling thismethod can use an object of any IDL type to fill this parameter. Internally to browseObject(),the method will attempt to determine what the actual type of object is. If it determinesthat object is a type of object it can interact with, it will do so. Otherwise, itwill raise the UnknownObjectType exception, which is returned to the caller.<H4><FONT COLOR="#000077">Listing 3.12. any example.</FONT></H4><PRE><FONT COLOR="#0066FF">1: interface ObjectBrowser {2:     exception UnknownObjectType {3:         string message;4:     };5:     void browseObject(in any object) raises (UnknownObjectType);6: };</FONT></PRE><H2><A NAME="Heading33"></A><FONT COLOR="#000077">The TypeCode Pseudotype</FONT></H2><P>Along with the any type comes the TypeCode pseudotype. TypeCode is not actuallyan IDL type; instead, it provides type information to a CORBA application. In mostmethod calls, the types of the parameters passed to the method are known becausethey are specified by the IDL method signatures. However, when a method accepts anany type as an argument, the actual type of that object is unknown. This is whereTypeCode comes in. Because every CORBA type--both standard types such as long andstring and user-defined types such as Television--has a unique TypeCode associatedwith it, a method implementation can determine which type of object was sent throughits any parameter. When the object's type is determined, the method can act on thatobject. Think of TypeCodes as a sort of runtime-type information for CORBA applications.<H2><A NAME="Heading34"></A><FONT COLOR="#000077">Summary</FONT></H2><P>This chapter presented the basic data types provided by CORBA's Interface DefinitionLanguage (IDL), including integer and floating point numeric types, Boolean values,and characters and character strings. Because many of these data types closely resembledata types of programming languages like C, C++, or Java, readers who are alreadyfamiliar with one of these languages will have little difficulty assimilating theIDL types.</P><P>You have expanded your knowledge of IDL to now include higher-level data types--particularlythe user-defined types--and their uses. Most importantly, you are familiar with theinterface construct and how it defines the behavior of CORBA objects. Because theinterface is one of the fundamental IDL data types, a clear understanding of thisconstruct is essential to the design of CORBA applications. Indeed, you cannot designor implement a CORBA application without interfaces.</P><P>Today you have seen some very useful IDL data types and constructs, in particular,the sequence and array types for storing multiple values of similar types. You learnedabout the exceptions in IDL, including the predefined CORBA standard exceptions.Finally, you looked at the any type, which can contain a value of any IDL type, andits counterpart, the TypeCode pseudotype, for determining unknown data types passedto a method. These constructs--particularly the sequences and exceptions--are essentialfor building robust CORBA applications.</P><P>You've covered just about everything there is to know about IDL; now it's timeto apply it. In the next chapter--Day 4, &quot;Building a CORBA Application&quot;--you'lldo just that, translating IDL definitions into working CORBA server and client applications.<H2><A NAME="Heading35"></A><FONT COLOR="#000077">Q&amp;A</FONT></H2><DL>	<DD><B>Q What's the point of having both</B> sequence <B>and array types?</B><BR>	<B><BR>	A</B> Array types are useful when the number of elements in an array is fixed and	known in advance. In many instances, though, this is not the case; arrays often vary	in size as members are dynamically added and removed. Consequently, a dynamically	sizable array, such as the IDL sequence, is often much more convenient. For maximum	flexibility, IDL offers both.<BR>	<B><BR>	Q What are all those</B> exception<B>s</B> <B>and when (or how) are they raised?</B><BR>	<B><BR>	A</B> First of all, nondistributed methods have little need for many of the CORBA	standard exceptions, but they make a lot more sense in a distributed environment.	As mentioned previously, the standard exceptions are generally not raised by any	code that you will write; rather, the exceptions in this set are raised automatically	by the ORB when an error condition occurs. Remember that all IDL methods implicitly	raise these exceptions, even the accessor/mutator methods generated by the IDL compiler	for each attribute.<BR>	<B><BR>	Q Why isn't (insert your favorite primitive data type here) supported?</B><BR>	<B><BR>	A </B>Because one primary goal of IDL is to be language-neutral, it isn't practical	to support all primitive data types contained in all languages. Rather than attempt	to provide this level of support (nearly impossible to achieve), IDL provides the	most common and useful primitive data types.<BR>	<B><BR>	Q How does an object modify one of its </B>attribute<B>s when that </B>attribute<B>	is declared to be </B>readonly<B>?</B><BR>	<B><BR>	A</B> If you're asking questions like this, you're definitely thinking ahead. When	you learn about implementation of IDL interfaces on Day 4, it will become clear how	this is accomplished. For the time being, though, remember that the object implementing	an interface has full access to its own state. A readonly attribute is mapped to	a method of that object, and that method can return any value the object wants. Typically,	the implementing object will define actual attributes of its own that correspond	to attributes in the IDL interface, although this isn't strictly necessary.<BR>	<B><BR>	Q Because Java does not support multiple inheritance, how is multiple inheritance	of IDL interfaces achieved in Java?<BR>	<BR>	A</B> You'll see when you begin implementing IDL interfaces in Java that the IDL	language mapping for Java maps IDL interfaces to Java interfaces. Although multiple	inheritance of classes is not supported in Java, multiple inheritance of interfaces	is.</DL><H2><A NAME="Heading36"></A><FONT COLOR="#000077">Workshop</FONT></H2><P>The following section will help you test your comprehension of the material presentedin this chapter and put what you've learned into practice. You'll find the answersto the quiz in Appendix A.<H3><A NAME="Heading37"></A><FONT COLOR="#000077">Quiz</FONT></H3><DL>	<DD><B>1</B>. Define a type (using typedef) called temperatureSequence that is a	sequence of sequences of floats (yes, this is legal).<BR>	<B><BR>	2</B>. Why might a type as described in the preceding question be useful?<BR>	<B><BR>	3</B>. Why are exceptions useful?<BR>	<B><BR>	4</B>. Why is the module construct useful?<BR>	<B><BR>	5</B>. Name some practical uses for the octet data type.<BR>	<B><BR>	6</B>. Define an enumerated type containing the months of the year.<BR>	<B><BR>	7</B>. Why might a nonblocking remote method call be advantageous, compared to a	blocking method call?<BR>	<B><BR>	8</B>. Imagine a compound data type with a large number of data members. This data	type will frequently be used by a client application, which will generally need to	access each of the data members. Would it be more efficient to encapsulate this data	type into a struct or an interface? Why?<BR>	<B><BR>	9</B>. Because an IDL method can return a value, what is the purpose of out and inout	parameter types?<BR>	<B><BR>	10</B>. Why is a oneway method unable to return any value to the caller? Can you	think of a mechanism, using oneway calls, to return a result to the caller?</DL><H3><A NAME="Heading38"></A><FONT COLOR="#000077">Exercises</FONT></H3><DL>	<DD><B>1</B>. Consider the following classes: Conduit, Faucet, FuseBox, Outlet, Pipe,	WaterHeater, WaterPump, and Wire. How would you partition these classes? What relationships,	if any, are there between the partitions you have created?<BR>	<B><BR>	2</B>. Create an interface that describes a clock/radio (which can set the hours,	set the minutes, set the alarm time, and so on).<FONT COLOR="#000077"></FONT></DL><CENTER><P><HR><A HREF="../ch02/ch02.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch04/ch04.htm"><IMGSRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <BR><BR><BR><IMG SRC="../button/corp.gif" WIDTH="284" HEIGHT="45" ALIGN="BOTTOM" ALT="Macmillan Computer Publishing USA"BORDER="0"></P><P>&#169; <A HREF="../copy.htm">Copyright</A>, Macmillan Computer Publishing. Allrights reserved.</CENTER></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -