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

📄 pubquerybean.java

📁 j2ee API 开发重要工具 免费下载 欢迎使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2003 Sun Microsystems, Inc.  All rights reserved.  U.S.  * Government Rights - Commercial software.  Government users are subject  * to the Sun Microsystems, Inc. standard license agreement and  * applicable provisions of the FAR and its supplements.  Use is subject  * to license terms.   *  * This distribution may include materials developed by third parties.  * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks  * or registered trademarks of Sun Microsystems, Inc. in the U.S. and  * other countries.   *  * Copyright (c) 2003 Sun Microsystems, Inc. Tous droits reserves. *  * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de  * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions  * en vigueur de la FAR (Federal Acquisition Regulations) et des  * supplements a celles-ci.  Distribue par des licences qui en  * restreignent l'utilisation. *  * Cette distribution peut comprendre des composants developpes par des  * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE  * sont des marques de fabrique ou des marques deposees de Sun  * Microsystems, Inc. aux Etats-Unis et dans d'autres pays. */import java.rmi.RemoteException; import java.util.*;import java.net.*;import javax.ejb.*;import javax.naming.*;import javax.xml.registry.*;import javax.xml.registry.infomodel.*; /** * Bean class for PubQuery enterprise bean. Defines findOrganization * business method as well as required methods for a stateless * session bean. */public class PubQueryBean implements SessionBean {    SessionContext  sc = null;    Connection      connection = null;    ResourceBundle  registryBundle =       ResourceBundle.getBundle("PubQueryBeanExample");    public PubQueryBean() {        System.out.println("In PubQueryBean() (constructor)");    }    /**     * Sets the associated session context. The container calls      * this method after the instance creation.     */    public void setSessionContext(SessionContext sc) {        this.sc = sc;    }    /**     * Instantiates the enterprise bean.  Creates the      * connection and looks up the topic.     */    public void ejbCreate() {        Context           context = null;        ConnectionFactory factory = null;        System.out.println("In PubQueryBean.ejbCreate()");        try {            String queryUrl = registryBundle.getString("query.url");            String publishUrl = registryBundle.getString("publish.url");            String httpProxyHost = registryBundle.getString("http.proxyHost");            String httpProxyPort = registryBundle.getString("http.proxyPort");            String httpsProxyHost = registryBundle.getString("https.proxyHost");            String httpsProxyPort = registryBundle.getString("https.proxyPort");            /*              * Define connection configuration properties.              * For simple queries, you need the query URL.             */            Properties props = new Properties();            props.setProperty("javax.xml.registry.queryManagerURL",                queryUrl);            props.setProperty("javax.xml.registry.lifeCycleManagerURL",                 publishUrl);            props.setProperty("com.sun.xml.registry.http.proxyHost",                 httpProxyHost);            props.setProperty("com.sun.xml.registry.http.proxyPort",                 httpProxyPort);            // Create a connection            context = new InitialContext();            factory = (ConnectionFactory)                 context.lookup("java:comp/env/eis/JAXR");            factory.setProperties(props);            connection = factory.createConnection();            System.out.println("Created connection to registry");        } catch (Throwable t) {            // JAXRException or NamingException could be thrown            System.err.println("PubQueryBean.ejbCreate:" +                "Exception: " + t.toString());        }    }/** * Creates an organization and publishes it to a registry. */    public void executePublish() throws EJBException {        RegistryService rs = null;        BusinessLifeCycleManager blcm = null;        BusinessQueryManager bqm = null;        try {            System.out.println("\nPublishing an organization:");            rs = connection.getRegistryService();            blcm = rs.getBusinessLifeCycleManager();            bqm = rs.getBusinessQueryManager();            System.out.println("Got registry service, query " +                "manager, and life cycle manager");            // Get authorization from the registry            String username = registryBundle.getString("registry.username");            String password = registryBundle.getString("registry.password");            PasswordAuthentication passwdAuth =                new PasswordAuthentication(username,                     password.toCharArray());            Set creds = new HashSet();            creds.add(passwdAuth);            connection.setCredentials(creds);            System.out.println("Established security credentials");            // Create organization name and description            Organization org =                 blcm.createOrganization(registryBundle.getString("org.name"));            InternationalString s =                 blcm.createInternationalString(registryBundle.getString("org.description"));            org.setDescription(s);            // Create primary contact, set name            User primaryContact = blcm.createUser();            PersonName pName =                 blcm.createPersonName(registryBundle.getString("person.name"));            primaryContact.setPersonName(pName);            // Set primary contact phone number            TelephoneNumber tNum = blcm.createTelephoneNumber();            tNum.setNumber(registryBundle.getString("phone.number"));            Collection phoneNums = new ArrayList();            phoneNums.add(tNum);            primaryContact.setTelephoneNumbers(phoneNums);            // Set primary contact email address            EmailAddress emailAddress =                 blcm.createEmailAddress(registryBundle.getString("email.address"));            Collection emailAddresses = new ArrayList();            emailAddresses.add(emailAddress);            primaryContact.setEmailAddresses(emailAddresses);            // Set primary contact for organization            org.setPrimaryContact(primaryContact);            // Set classification scheme to NAICS            ClassificationScheme cScheme =                 bqm.findClassificationSchemeByName(null,                     registryBundle.getString("classification.scheme"));            // Create and add classification            Classification classification =                 blcm.createClassification(cScheme,                     registryBundle.getString("classification.name"), 	                    registryBundle.getString("classification.value"));            Collection classifications = new ArrayList();            classifications.add(classification);            org.addClassifications(classifications);            // Create services and service            Collection services = new ArrayList();            Service service =                 blcm.createService(registryBundle.getString("service.name"));            InternationalString is =                 blcm.createInternationalString(registryBundle.getString("service.description"));            service.setDescription(is);            // Create service bindings            Collection serviceBindings = new ArrayList();            ServiceBinding binding = blcm.createServiceBinding();            is =                 blcm.createInternationalString(registryBundle.getString("svcbinding.description"));            binding.setDescription(is);            // allow us to publish a fictitious URL without an error            binding.setValidateURI(false);            binding.setAccessURI(registryBundle.getString("svcbinding.accessURI"));            serviceBindings.add(binding);            // Add service bindings to service            service.addServiceBindings(serviceBindings);            // Add service to services, then add services to organization            services.add(service);            org.addServices(services);

⌨️ 快捷键说明

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