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

📄 pubquerybean.java

📁 《j2ee经典实例详解》的源代码。原书无附带光盘。介绍的是一个在线银行系统的例子。绝对难得
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            // Add service bindings to service            service.addServiceBindings(serviceBindings);            // Add service to services, then add services to organization            services.add(service);            org.addServices(services);            // 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) {                logger.info("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();                    logger.info("Organization key is " + id);                }            } else {                Iterator excIter = exceptions.iterator();                Exception exception = null;                while (excIter.hasNext()) {                    exception = (Exception) excIter.next();                    logger.severe("Exception on save: " + exception.toString());                }            }        } catch (Throwable t) {            // JAXRException could be thrown            logger.severe("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 {            logger.info("\nQuerying for an organization:");            // Get registry service and query manager            rs = connection.getRegistryService();            bqm = rs.getBusinessQueryManager();            logger.info("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())) {                logger.info("No organizations found");            } else {                while (orgIter.hasNext()) {                    Organization org = (Organization) orgIter.next();                    logger.info("Org name: " + getName(org));                    logger.info("Org description: " + getDescription(org));                    logger.info("Org key id: " + getKey(org));                    // Display primary contact information                    User pc = org.getPrimaryContact();                    if (pc != null) {                        PersonName pcName = pc.getPersonName();                        logger.info("Contact name: " + pcName.getFullName());                        Collection phNums = pc.getTelephoneNumbers(null);                        Iterator phIter = phNums.iterator();                        while (phIter.hasNext()) {                            TelephoneNumber num =                                (TelephoneNumber) phIter.next();                            logger.info("Contact phone number: " +                                num.getNumber());                        }                        Collection eAddrs = pc.getEmailAddresses();                        Iterator eaIter = eAddrs.iterator();                        while (eaIter.hasNext()) {                            EmailAddress eAd = (EmailAddress) eaIter.next();                            logger.info("Contact 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();                        logger.info("Service name: " + getName(svc));                        logger.info("Service description: " +                            getDescription(svc));                        Collection serviceBindings = svc.getServiceBindings();                        Iterator sbIter = serviceBindings.iterator();                        while (sbIter.hasNext()) {                            ServiceBinding sb = (ServiceBinding) sbIter.next();                            logger.info("Service binding description: " +                                getDescription(sb));                            logger.info("Service binding access URI: " +                                sb.getAccessURI());                        }                    }                    // Print spacer between organizations                    logger.info(" --- ");                }            }        } catch (Throwable t) {            // JAXRException could be thrown            logger.severe("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 {        logger.info("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 + -