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

📄 cb3.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 2 页
字号:
&nbsp;&nbsp;ResourceBundle.getBundle(&quot;com.sun.cb.CoffeeRegistry&quot;);// Create organization name and description Organization org =&nbsp;&nbsp;blcm.createOrganization(bundle.getString(&quot;org.name&quot;));InternationalString s = &nbsp;&nbsp;blcm.createInternationalString&nbsp;&nbsp;(bundle.getString(&quot;org.description&quot;));org.setDescription(s);// Create primary contact, set name User primaryContact = blcm.createUser();PersonName pName =&nbsp;&nbsp;blcm.createPersonName(bundle.getString(&quot;person.name&quot;));primaryContact.setPersonName(pName);<a name="wp67402"> </a></pre></div><a name="wp67403"> </a><p class="pBody">It adds a telephone number and email address for the user, then makes the user the primary contact:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">org.setPrimaryContact(primaryContact);<a name="wp67404"> </a></pre></div><a name="wp67405"> </a><p class="pBody">It gives JAXRPCCoffeeDistributor a classification using the North American Industry Classification System (NAICS). In this case it uses the classification &quot;Other Grocery and Related Products Wholesalers&quot;.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">Classification classification = (Classification)&nbsp;&nbsp;blcm.createClassification(cScheme,&nbsp;&nbsp;&nbsp;&nbsp;bundle.getString(&quot;classification.name&quot;), &nbsp;&nbsp;&nbsp;&nbsp;bundle.getString(&quot;classification.value&quot;));Collection classifications = new ArrayList();classifications.add(classification);org.addClassifications(classifications);<a name="wp67406"> </a></pre></div><a name="wp67407"> </a><p class="pBody">Next, it adds the JAX-RPC service, called &quot;JAXRPCCoffee Service,&quot; and its service binding. The access URI for the service binding contains the endpoint URL that remote clients will use to contact our service:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">http://localhost:8080/jaxrpc-coffee-supplier/jaxrpc<a name="wp67408"> </a>Collection services = new ArrayList();Service service =&nbsp;&nbsp;blcm.createService(bundle.getString(&quot;service.name&quot;));InternationalString is = &nbsp;&nbsp;blcm.createInternationalString&nbsp;&nbsp;(bundle.getString(&quot;service.description&quot;));service.setDescription(is);// Create service bindingsCollection serviceBindings = new ArrayList();ServiceBinding binding = blcm.createServiceBinding();is = blcm.createInternationalString&nbsp;&nbsp;(bundle.getString(&quot;service.binding&quot;));binding.setDescription(is);binding.setValidateURI(false);binding.setAccessURI(endpoint);serviceBindings.add(binding);// Add service bindings to serviceservice.addServiceBindings(serviceBindings);// Add service to services, then add services to organizationservices.add(service);org.addServices(services);<a name="wp90109"> </a></pre></div><a name="wp67422"> </a><p class="pBody">Then it saves the organization to the registry:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">Collection orgs = new ArrayList();orgs.add(org);BulkResponse response = blcm.saveOrganizations(orgs);<a name="wp67423"> </a></pre></div><a name="wp67382"> </a><p class="pBody">The <code class="cCode">BulkResponse</code> object returned by <code class="cCode">saveOrganizations</code> includes the <code class="cCode">Key</code> object containing the unique key value for the organization. The <code class="cCode">executePublish</code> method first checks to make sure the <code class="cCode">saveOrganizations</code> call succeeded. </p><a name="wp67429"> </a><p class="pBody">If the call succeeded, the method extracts the value from the <code class="cCode">Key</code> object and displays it:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">Collection keys = response.getCollection();Iterator keyIter = keys.iterator();if (keyIter.hasNext()) {&nbsp;&nbsp;javax.xml.registry.infomodel.Key orgKey =&nbsp;&nbsp;&nbsp;&nbsp;(javax.xml.registry.infomodel.Key) keyIter.next();&nbsp;&nbsp;id = orgKey.getId();&nbsp;&nbsp;System.out.println(&quot;Organization key is &quot; + id);}<a name="wp67430"> </a></pre></div><a name="wp67431"> </a><p class="pBody">Finally, the method returns the string <code class="cCode">id</code> so that the <code class="cCode">OrgPublisher</code> program can save it in a file for use by the <code class="cCode">OrgRemover</code> program.</p><a name="wp65013"> </a><h3 class="pHeading2">Deleting the Service From the Registry</h3><a name="wp65014"> </a><p class="pBody">The <code class="cCode"><a  href="../examples/cb/jaxrpc/src/registry/com/sun/cb/OrgRemover.java" target="_blank">contextDestroyed</a></code> <code class="cCode">method</code> deletes the service from the Registry Server. Like the <code class="cCode">contextInitialized</code> <code class="cCode">method</code>, the <code class="cCode">contextDestroyed</code> <code class="cCode">method</code> starts by fetching URLs from <code class="cCode">URLHelper</code> and other values from the <code class="cCode">CoffeeRegistry.properties</code> file. One these values, <code class="cCode">keyFile</code>, is the name of the file that contains the key that uniquely identifies the service. <code class="cCode">The</code> <code class="cCode">contextDestroyed</code> <code class="cCode">method</code> reads the key from the file, connects to the Registry Server by invoking <code class="cCode">makeConnection</code>, and then deletes the service from the registry by calling <code class="cCode">executeRemove</code>. Here is the source code for the <code class="cCode">contextDestroyed</code> <code class="cCode">method</code>:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">public void contextDestroyed(ServletContextEvent event) {&nbsp;&nbsp;String keyStr = null;&nbsp;&nbsp;String queryURL = URLHelper.getQueryURL();&nbsp;&nbsp;String publishURL = URLHelper.getPublishURL();&nbsp;&nbsp;ResourceBundle registryBundle =            ResourceBundle.getBundle(&nbsp;&nbsp;&nbsp;&nbsp;&quot;com.sun.cb.CoffeeRegistry&quot;);&nbsp;&nbsp;String username = &nbsp;&nbsp;registryBundle.getString(&quot;registry.username&quot;);&nbsp;&nbsp;String password = &nbsp;&nbsp;&nbsp;&nbsp;registryBundle.getString(&quot;registry.password&quot;);&nbsp;&nbsp;String keyFile = registryBundle.getString(&quot;key.file&quot;);&nbsp;&nbsp;try {&nbsp;&nbsp;&nbsp;&nbsp;FileReader in = new FileReader(keyFile);&nbsp;&nbsp;&nbsp;&nbsp;char[] buf = new char[512];&nbsp;&nbsp;&nbsp;&nbsp;while (in.read(buf, 0, 512) &gt;= 0) { }&nbsp;&nbsp;&nbsp;&nbsp;in.close();&nbsp;&nbsp;&nbsp;&nbsp;keyStr = new String(buf).trim();&nbsp;&nbsp;} catch (IOException ex) {&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(ex.getMessage());&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;JAXRRemover remover = new JAXRRemover();&nbsp;&nbsp;&nbsp;&nbsp;remover.makeConnection(queryURL, publishURL);&nbsp;&nbsp;&nbsp;&nbsp;javax.xml.registry.infomodel.Key modelKey = null;&nbsp;&nbsp;&nbsp;&nbsp;modelKey = remover.createOrgKey(keyStr);&nbsp;&nbsp;&nbsp;&nbsp;remover.executeRemove(modelKey, username, password);}<a name="wp90723"> </a></pre></div><a name="wp90803"> </a><p class="pBody">Instantiated by the <code class="cCode">contextDestroyed</code> <code class="cCode">method</code>, the <code class="cCode"><a  href="../examples/cb/jaxrpc/src/registry/com/sun/cb/JAXRRemover.java" target="_blank">JAXRRemover</a></code> class contains the <code class="cCode">makeConnection</code>, <code class="cCode">createOrgKey</code>, and <code class="cCode">executeRemove</code> methods. It is almost identical to the sample program <code class="cCode"><a  href="../examples/jaxr/simple/src/JAXRDelete.java" target="_blank">JAXRDelete.java</a></code>, which is described in <a  href="JAXR3.html#wp64166">Removing Data from the Registry</a>.</p><a name="wp90804"> </a><p class="pBody">The <code class="cCode">makeConnection</code> method is identical to the <code class="cCode">JAXRPublisher</code> method of the same name.</p><a name="wp90805"> </a><p class="pBody">The <code class="cCode">createOrgKey</code> method is a utility method that takes one argument, the string value extracted from the key file. It obtains the <code class="cCode">RegistryService</code> object and the <code class="cCode">BusinessLifeCycleManager</code> object, then creates a <code class="cCode">Key</code> object from the string value.</p><a name="wp90806"> </a><p class="pBody">The <code class="cCode">executeRemove</code> method takes three arguments: a username, a password, and the <code class="cCode">Key</code> object returned by the <code class="cCode">createOrgKey</code> method. It uses the username and password arguments to establish its security credentials with the Registry Server, just as the <code class="cCode">executePublish</code> method does.</p><a name="wp90807"> </a><p class="pBody">The method then wraps the <code class="cCode">Key</code> object in a <code class="cCode">Collection</code> and uses the <code class="cCode">BusinessLifeCycleManager</code> object's <code class="cCode">deleteOrganizations</code> method to delete the organization. </p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">Collection keys = new ArrayList();keys.add(key);BulkResponse response = blcm.deleteOrganizations(keys);<a name="wp90808"> </a></pre></div><a name="wp67455"> </a><p class="pBody">The <code class="cCode">deleteOrganizations</code> method returns the keys of the organizations it deleted, so the <code class="cCode">executeRemove</code> method then verifies that the correct operation was performed and displays the key for the deleted organization.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">Collection retKeys = response.getCollection();Iterator keyIter = retKeys.iterator();javax.xml.registry.infomodel.Key orgKey = null; if (keyIter.hasNext()) { &nbsp;&nbsp;orgKey = (javax.xml.registry.infomodel.Key) keyIter.next();&nbsp;&nbsp;id = orgKey.getId();&nbsp;&nbsp;System.out.println(&quot;Organization key was &quot; + id);}<a name="wp67456"> </a></pre></div>    </blockquote>   <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <table width="550" summary="layout" id="SummaryNotReq1">      <tr>	<td align="left" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>	</td>        <td align="center" valign="center"><a accesskey="p" href="CB2.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="CB4.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a>        </td>	<td align="right" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font>	</font>	</td>      </tr>    </table>    <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"><p><font size="-1">All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other workswithout express written permission from Sun Microsystems.</font>  </body></html>

⌨️ 快捷键说明

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