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

📄 lib0025.html

📁 This handbook is a concise guide to architecting, designing, and building J2EE applications. It guid
💻 HTML
字号:
<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Determining a Data Structure</title>
<link rel="STYLESHEET" type="text/css" href="images/xpolecat.css">
<link rel="STYLESHEET" type="text/css" href="images/ie.content.css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/teamlib.gif" width="62" height="15" border="0" align="absmiddle"  alt="Team LiB"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href="LiB0024.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0026.html"><img src="images/next.gif" width="41" height="15" border="0" align="absmiddle" alt="Next Section"></a>
</div></td></tr></table>
<br>
<div class="chapter">
<a name="ch04"></a>
<div class="section">
<h2 class="first-section-title"><a name="112"></a><a name="ch04lev1sec2"></a>Determining a Data Structure</h2><p class="first-para">
<b class="bold">Document all data passed to an external application.</b> The communication structure or format, along with the conditions that dictate transmission, is part of your contract with the external system developers. The data structure should be documented and agreed to in writing.</p>
<p class="para">If the communication method chosen is Web services, RMI, CORBA, or enterprise beans, documenting the data structure is an object-modeling exercise. You'll need to fully define the services or beans along any method, as well as the objects used in their arguments. Object-modeling concepts are more fully covered in <a href="LiB0038.html#184" target="_parent" class="chapterjump">chapter 6</a>.</p>
<p class="para">The parts you need to identify and document for the external interface are the name and type of the service, the name and return type (typically a <a name="113"></a><a name="IDX-40"></a>value object) of the method, and any required arguments. Since the return type and arguments might be value objects (VOs), the fields on those VOs will have to be documented as well. Sometimes VOs are referred to as <i class="emphasis">data</i> <i class="emphasis">transfer objects</i>.</p>
<p class="para">For example, consider a Web service, CustomerService, with a method called <span class="fixed">getCustomerInfo()</span> passing a userId string and returning an object of type <span class="fixed">CustomerVO</span>. For the external interface, all parties need to know legal argument rules, what the fields in <span class="fixed">CustomerVO</span> will contain, and what exceptions, if any, might be thrown. <a class="internaljump" href="#ch04fig01">Figure 4.1</a> shows an example.</p>
<div class="miscfigure">
<table class="BlueLine" border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td bgcolor="000080" class="bluecell"><font size="2" face="Arial" color="010100"><b><img src="_.gif" width="1" height="2" alt="Start Figure" border="0"></b></font></td>
</tr>
</table>
<a name="114"></a><a name="ch04fig01"></a>
<div class="miscfigure-informaltable">
<table border="0">
<tbody>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">
<b class="bold">Service Name:</b>
</p>
</td><td class="td" align="left">
<p class="table-para">CustomerService</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">
<b class="bold">Service Type:</b>
</p>
</td><td class="td" align="left">
<p class="table-para">WebService</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">
<b class="bold">Client class:</b>
</p>
</td><td class="td" align="left">
<p class="table-para">com.jmu.client.CustomerServiceClient</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">
<b class="bold">Client jar:</b>
</p>
</td><td class="td" align="left">
<p class="table-para">JmuClient.jar</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="miscfigure-informaltable">
<table border="0">
<thead>
<tr valign="top">
<th class="th" scope="col" align="left" valign="top" colspan="2">
<p class="table-para">
<b class="bold">Customer Information Retrieval</b>
</p>
</th>
</tr>
</thead>
<tbody>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">
<b class="bold">Method Name:</b>
</p>
</td><td class="td" align="left">
<p class="table-para">getCustomerInfo</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">
<b class="bold">Arguments:</b>
</p>
</td><td class="td" align="left">
<p class="table-para">CustomerID&#8212;(String)</p>
<ul class="itemizedlist">
<li class="first-listitem">
<p class="table-para">CustomerID cannot be null</p>
</li>
<li class="listitem">
<p class="table-para">CustomerID cannot be blank</p>
</li>
</ul>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">
<b class="bold">Returns:</b>
</p>
</td><td class="td" align="left">
<p class="table-para">com.jmu.vo.CustomerVO</p>
<ul class="itemizedlist">
<li class="first-listitem">
<p class="table-para">firstName (String)</p>
</li>
<li class="listitem">
<p class="table-para">lastName (String)</p>
</li>
<li class="listitem">
<p class="table-para">id (String)</p>
</li>
<li class="listitem">
<p class="table-para">streetAddress (String)</p>
</li>
<li class="listitem">
<p class="table-para">city (String)</p>
</li>
<li class="listitem">
<p class="table-para">state (String)&#8212;two letter abbreviation, capitalized.</p>
</li>
<li class="listitem">
<p class="table-para">telephone (String)</p>
</li>
</ul>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">
<b class="bold">Exceptions:</b>
</p>
</td><td class="td" align="left">
<ul class="itemizedlist">
<li class="first-listitem">
<p class="table-para">java.lang.IllegalArgumentException if customer ID is null or blank</p>
</li>
<li class="listitem">
<p class="table-para">com.jmu.common.CustomerNotFound if no customer exists</p>
</li>
<li class="listitem">
<p class="table-para">java.rmi.RemoteException if technical issue with the call</p>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</div>
<table class="BlueLine" border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td bgcolor="000080" class="bluecell"><font size="2" face="Arial" color="010100"><b><img src="_.gif" width="1" height="2" alt="End Figure" border="0"></b></font></td>
</tr>
</table>
<br style="line-height: 1">
<span class="miscfigure-title"><span class="figure-titlelabel">Figure 4.1: </span>Example Interface Specification</span>
</div>
<p class="para">If you choose messaging as the communication method, you need to fully define the format of the message transmission. By far the most popular format employed these days is XML.</p>
<a name="115"></a><a name="IDX-41"></a>
<p class="para">XML is a common protocol for interapplication communication and message formats. XML is preferred in the Java world because many open source tools are available.</p>
<p class="para">
<b class="bold">Use simple XML formats for interfaces to legacy platforms.</b> XML can be a headache for developers using legacy platforms if your company won't buy an XML parser. Open source parsers and other tools are not available for COBOL or PL/I, at the time of this writing. This would be a valuable open source project.</p>
<p class="para">When the external application is a legacy system and the client doesn't buy XML tools to assist, custom formats are common out of practical necessity. Custom formats can have a keyword-type organization (like XML) or some type of positional organization. COBOL lends itself to fixed-length strings using a positional format.</p>
<p class="para">You need to develop a DTD or schema, or otherwise document the XML document formats and tags with allowed values. Leaving this communication verbal is a recipe for disappointment and countless project delays. <a href="LiB0047.html#216" target="_parent" class="chapterjump">Chapter 7</a> includes material to help you design XML documents.</p>
<p class="para">
<b class="bold">You don't necessarily have to validate XML documents for external interfaces.</b> Developing a DTD to describe a document format does not mean that you have to "validate" the document when it's parsed. Validation works well for documents that were directly written by people, and thus more likely to contain errors. Application interfaces are mechanical. Aside from initial development, the probability of receiving a malformed XML document that was programmatically generated from another application is low. Given this, the benefits of validation don't usually outweigh its performance costs.</p>
<p class="last-para">
<b class="bold">Avoid sending serialized Java objects as message content.</b> This effectively negates the benefits of loose coupling by making both applications dependent on the same classes. If a change is made to one of the objects referenced by the serialized class, the change would have to be deployed to both applications simultaneously. Further, serialization problems can occur if one of the applications upgrades its Java Virtual Machine (JVM). Serialized objects cannot be visually inspected to determine content; they must be programmatically processed. They also limit communication to Java applications.</p>
</div>
</div><br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/teamlib.gif" width="62" height="15" border="0" align="absmiddle"  alt="Team LiB"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href="LiB0024.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0026.html"><img src="images/next.gif" width="41" height="15" border="0" align="absmiddle" alt="Next Section"></a>
</div></td></tr></table>
</body></html>

⌨️ 快捷键说明

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