📄 pubquerybean.java
字号:
// Add organization and submit to registry // Retrieve key if successful Collection orgs = new ArrayList(); orgs.add(org); BulkResponse response = blcm.saveOrganizations(orgs); Collection exceptions = response.getExceptions(); if (exceptions == null) { System.out.println("Organization saved"); Collection keys = response.getCollection(); Iterator keyIter = keys.iterator(); if (keyIter.hasNext()) { javax.xml.registry.infomodel.Key orgKey = (javax.xml.registry.infomodel.Key) keyIter.next(); String id = orgKey.getId(); System.out.println("Organization key is " + id); } } else { Iterator excIter = exceptions.iterator(); Exception exception = null; while (excIter.hasNext()) { exception = (Exception) excIter.next(); System.err.println("Exception on save: " + exception.toString()); } } } catch (Throwable t) { // JAXRException could be thrown System.err.println("PubQueryBean.executePublish: " + "Exception: " + t.toString()); sc.setRollbackOnly(); } } /** * Searches for organizations containing a string and * displays data about them. * * @param qString the string argument */ public void executeQuery(String qString) throws EJBException { RegistryService rs = null; BusinessQueryManager bqm = null; try { System.out.println("\nQuerying for an organization:"); // Get registry service and query manager rs = connection.getRegistryService(); bqm = rs.getBusinessQueryManager(); System.out.println("Got registry service and " + "query manager"); // Define find qualifiers and name patterns Collection findQualifiers = new ArrayList(); findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC); Collection namePatterns = new ArrayList(); namePatterns.add("%" + qString + "%"); // Find using the name BulkResponse response = bqm.findOrganizations(findQualifiers, namePatterns, null, null, null, null); Collection orgs = response.getCollection(); // Display information about the organizations found Iterator orgIter = orgs.iterator(); if (!(orgIter.hasNext())) { System.out.println("No organizations found"); } else while (orgIter.hasNext()) { Organization org = (Organization) orgIter.next(); System.out.println("Org name: " + getName(org)); System.out.println("Org description: " + getDescription(org)); System.out.println("Org key id: " + getKey(org)); // Display primary contact information User pc = org.getPrimaryContact(); if (pc != null) { PersonName pcName = pc.getPersonName(); System.out.println(" Contact name: " + pcName.getFullName()); Collection phNums = pc.getTelephoneNumbers(null); Iterator phIter = phNums.iterator(); while (phIter.hasNext()) { TelephoneNumber num = (TelephoneNumber) phIter.next(); System.out.println(" Phone number: " + num.getNumber()); } Collection eAddrs = pc.getEmailAddresses(); Iterator eaIter = eAddrs.iterator(); while (eaIter.hasNext()) { EmailAddress eAd = (EmailAddress) eaIter.next(); System.out.println(" Email Address: " + eAd.getAddress()); } } // Display service and binding information Collection services = org.getServices(); Iterator svcIter = services.iterator(); while (svcIter.hasNext()) { Service svc = (Service) svcIter.next(); System.out.println(" Service name: " + getName(svc)); System.out.println(" Service description: " + getDescription(svc)); Collection serviceBindings = svc.getServiceBindings(); Iterator sbIter = serviceBindings.iterator(); while (sbIter.hasNext()) { ServiceBinding sb = (ServiceBinding) sbIter.next(); System.out.println(" Binding " + "Description: " + getDescription(sb)); System.out.println(" Access URI: " + sb.getAccessURI()); } } // Print spacer between organizations System.out.println(" --- "); } } catch (Throwable t) { // JAXRException could be thrown System.err.println("PubQueryBean.executeQuery: " + "Exception: " + t.toString()); sc.setRollbackOnly(); } } /** * Helper method. * Returns the name value for a registry object. * * @param ro a RegistryObject * @return the String value */ private String getName(RegistryObject ro) throws JAXRException { try { return ro.getName().getValue(); } catch (NullPointerException npe) { return "No Name"; } } /** * Helper method. * Returns the description value for a registry object. * * @param ro a RegistryObject * @return the String value */ private String getDescription(RegistryObject ro) throws JAXRException { try { return ro.getDescription().getValue(); } catch (NullPointerException npe) { return "No Description"; } } /** * Helper method. * Returns the key id value for a registry object. * * @param ro a RegistryObject * @return the String value */ private String getKey(RegistryObject ro) throws JAXRException { try { return ro.getKey().getId(); } catch (NullPointerException npe) { return "No Key"; } } /** * Closes the connection. */ public void ejbRemove() throws RemoteException { System.out.println("In PubQueryBean.ejbRemove()"); if (connection != null) { try { connection.close(); } catch (Exception e) { e.printStackTrace(); } } } public void ejbActivate() {} public void ejbPassivate() {}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -