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

📄 lib0108.html

📁 java外企软件工程师就业班 J2EE方向 《J2EE架构师手册》 电子书
💻 HTML
字号:
<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Making Components Easy to Configure and Control</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="LiB0107.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0109.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="ch16"></a>
<div class="section">
<h2 class="first-section-title"><a name="523"></a><a name="ch16lev1sec3"></a>Making Components Easy to Configure and Control</h2><p class="first-para">
<b class="bold">Minimize the number of properties a user must configure.</b> Some components use a properties file, which is a file of key and value pairs, to manage configuration settings. These files are often used in conjunction with the <span class="fixed">java.util.Properties</span> object. <a class="internaljump" href="#ch16list03">Listing 16.3</a> is a short extract from a past release of the WebLogic <span class="unicode">&#8482;</span> application server software. It illustrates what a properties file looks like.</p>
<div class="example">
<span class="example-title"><span class="example-titlelabel">Listing 16.3: </span>Sample Properties File</span><a name="524"></a><a name="ch16list03"></a>
<div class="formalbody">
<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 example" border="0"></b></font></td>
</tr>
</table>
<pre class="literallayout">
###############################################
# Server configuration
###############################################
# If the DTD location is changed from the default this property
# needs to changed to point to the new location.
commerce.xml.entity.basePath=H:\bea\weblogic700\portal/lib/dtd

##############################################
# Logger class
##############################################
commerce.log.class=com.beasys.commerce.util.NonCatalogLog
commerce.log.display.deprecated=true
commerce.log.display.debug=false
</pre>
<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 example" border="0"></b></font></td>
</tr>
</table>
<table class="BlankSpace" border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td height="16"></td>
</tr>
</table>
</div>
</div>
<p class="para">The more properties users need in order to choose values for running your component, the longer and harder your component is to configure. You can alleviate this problem by choosing sensible defaults for as many configuration properties as possible. In addition, clear error messages for incorrect configurations can make your components easy to use. The method BEA used for WebLogic<span class="unicode">&#8482;</span> was to write an installation program that configured required properties on install.</p>
<a name="525"></a><a name="IDX-217"></a>
<p class="para">
<b class="bold">Minimize the required complexity of any needed XML documents.</b> The more complex the document structure, the harder the component is to configure and control. Jakarta's Ant project is an excellent example of using XML files effectively. Ant is an XML scripting utility commonly used for application builds. Its scripting language is XML based, and its structure is simple and intuitive. Although Ant has an extensive array of options, it also has sensible defaults and good documentation. This open source project is available at <a target="_top" class="url" href="http://ant.apache.org/">http://ant.apache.org/</a>.</p>
<p class="para">
<b class="bold">Produce clear error messages on invalid configurations.</b> Components must have clear error messages. Nothing is more aggravating than trying to figure out why code you didn't write is degenerating into a <span class="fixed">NullPointer-Exception</span>. Clear error messages can make the difference in a developer's perception of your component.</p>
<p class="para">
<b class="bold">Provide numerous configuration file examples that are easy to copy.</b> This is especially important if the component is capable of complex configurations. I suggest providing basic examples as well as complex ones. Although it isn't a Java-based component, the best example of this concept I can think of is the command directive file used for the SqlLoader utility that comes with Oracle's database software. In the book <I>Oracle Database Utilities 10g Release</I>, <a href="LiB0081.html#373" target="_parent" class="chapterjump">chapter 12</a> gives examples of several database loads. It's easy to find a load directive file to start from that's relatively close to the one you need. This book is available online at <a target="_top" class="url" href="http://technet.oracle.com/">http://technet.oracle.com/</a>.</p>
<p class="last-para">
<b class="bold">Limit installation and configuration instructions to a one-page cheat sheet. </b>If the instructions are too long and complex, it reduces the benefit of using the component in the first place. Having an expanded document for complete functionality is fine, but users doing basic tasks shouldn't have to read more than a page or two.</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="LiB0107.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0109.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 + -