Source Code Cross Referenced for RegistryConnector.java in  » J2EE » JOnAS-4.8.6 » olstore » client » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » olstore.client 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (c) 2005 Red Hat, Inc. All rights reserved.
003:         *
004:         * This library is free software; you can redistribute it and/or modify it under
005:         * the terms of the GNU Lesser General Public License as published by the Free
006:         * Software Foundation; either version 2.1 of the License, or any later version.
007:         *
008:         * This library is distributed in the hope that it will be useful, but WITHOUT
009:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
010:         * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
011:         * details.
012:         *
013:         * You should have received a copy of the GNU Lesser General Public License
014:         * along with this library; if not, write to the Free Software Foundation, Inc.,
015:         * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
016:         *
017:         * Component of: Red Hat Application Server
018:         *
019:         * Initial Developers: Gregory Lapouchnian
020:         *                     Patrick Smith
021:         * --------------------------------------------------------------------------
022:         * $Id: RegistryConnector.java 7027 2005-07-08 14:00:45Z glapouch $
023:         * --------------------------------------------------------------------------
024:         */package olstore.client;
025:
026:        import java.net.PasswordAuthentication;
027:        import java.util.ArrayList;
028:        import java.util.Collection;
029:        import java.util.HashSet;
030:        import java.util.Iterator;
031:        import java.util.List;
032:        import java.util.Properties;
033:        import java.util.Set;
034:
035:        import javax.xml.registry.BulkResponse;
036:        import javax.xml.registry.BusinessQueryManager;
037:        import javax.xml.registry.Connection;
038:        import javax.xml.registry.ConnectionFactory;
039:        import javax.xml.registry.JAXRException;
040:        import javax.xml.registry.RegistryService;
041:        import javax.xml.registry.infomodel.ExternalLink;
042:        import javax.xml.registry.infomodel.Organization;
043:        import javax.xml.registry.infomodel.Service;
044:        import javax.xml.registry.infomodel.ServiceBinding;
045:        import javax.xml.registry.infomodel.SpecificationLink;
046:
047:        /**
048:         * Connect to the UDDI registry and retrieve WSDL URLs for the OLstore client.
049:         */
050:        public class RegistryConnector {
051:
052:            /** A connection to the UDDI registry. */
053:            private Connection connection;
054:
055:            /** Used to send queries to the registry. */
056:            private BusinessQueryManager bqm;
057:
058:            /** The list of URLs found for the OLStore specials endpoint. */
059:            private List specialsWSDLLocations;
060:
061:            /** The list of URLs found for the OLStore shopping cart endpoint. */
062:            private List cartWSDLLocations;
063:
064:            /**
065:             * Prepare a registry connector to query the UDDI registry for WSDL
066:             * information.
067:             */
068:            public RegistryConnector() {
069:                specialsWSDLLocations = new ArrayList();
070:                cartWSDLLocations = new ArrayList();
071:            }
072:
073:            /**
074:             * Create a connection and retrieve the endpoint locations.
075:             * @throws Exception if an error occurs while connecting and querying the
076:             * registry
077:             */
078:            public void retrieveWSDLLocations() throws Exception {
079:                // only connect to the registry if the WSDL location lists are empty
080:                if (cartWSDLLocations.isEmpty()
081:                        || specialsWSDLLocations.isEmpty()) {
082:                    try {
083:                        makeConnection();
084:                        findWSDLLocations();
085:                        closeConnection();
086:                    } catch (JAXRException e) {
087:                        throw new Exception(
088:                                "Could not retrieve WSDL locations from the UDDI registry.\n"
089:                                        + e.getMessage());
090:                    }
091:                }
092:            }
093:
094:            /**
095:             * Close the connection to the UDDI registry.
096:             * @throws JAXRException if the connection could not be closed
097:             */
098:            public void closeConnection() throws JAXRException {
099:                connection.close();
100:            }
101:
102:            /**
103:             * Create a connection to the UDDI registry.
104:             * @throws Exception if there is a problem creating a connection.
105:             */
106:            public void makeConnection() throws Exception {
107:
108:                Configure config = new Configure();
109:
110:                Properties props = new Properties();
111:                props.setProperty("javax.xml.registry.queryManagerURL", config
112:                        .getProperty("queryURL"));
113:                props.setProperty("javax.xml.registry.lifeCycleManagerURL",
114:                        config.getProperty("publishURL"));
115:
116:                try {
117:                    // Create the connection, passing it the configuration properties
118:                    ConnectionFactory factory = ConnectionFactory.newInstance();
119:                    factory.setProperties(props);
120:                    connection = factory.createConnection();
121:
122:                    // Get registry service and managers
123:                    RegistryService rs = connection.getRegistryService();
124:
125:                    // Get manager capabilities from registry service
126:                    bqm = rs.getBusinessQueryManager();
127:
128:                    // Set client authorization information for privileged registry
129:                    // operations
130:                    PasswordAuthentication passwdAuth = new PasswordAuthentication(
131:                            config.getProperty("user"), config.getProperty(
132:                                    "pass").toCharArray());
133:                    Set creds = new HashSet();
134:                    creds.add(passwdAuth);
135:
136:                    // Set credentials on the JAXR provider
137:                    connection.setCredentials(creds);
138:
139:                    // Set communication preference
140:                    connection.setSynchronous(true);
141:
142:                } catch (Exception e) {
143:                    // try to close the connection if it was created
144:                    if (connection != null) {
145:                        try {
146:                            connection.close();
147:                        } catch (JAXRException je) {
148:                            throw je;
149:                        }
150:                    }
151:                    throw e;
152:                }
153:            }
154:
155:            /**
156:             * Find all the endpoint URLs in the registry for OLStore.
157:             * @throws JAXRException if there is a problem with querying the registry
158:             */
159:            public void findWSDLLocations() throws JAXRException {
160:
161:                Collection names = new ArrayList();
162:                String orgName = "Red Hat Olstore";
163:                names.add(orgName);
164:
165:                BulkResponse br = bqm.findOrganizations(null, names, null,
166:                        null, null, null);
167:                Iterator iter = br.getCollection().iterator();
168:
169:                while (iter.hasNext()) {
170:                    Organization org = (Organization) iter.next();
171:                    Iterator serviceIter = org.getServices().iterator();
172:
173:                    while (serviceIter.hasNext()) {
174:                        Service service = (Service) serviceIter.next();
175:
176:                        // get the service bindings
177:                        Collection serviceBindings = service
178:                                .getServiceBindings();
179:
180:                        Iterator sbIter = serviceBindings.iterator();
181:                        while (sbIter.hasNext()) {
182:                            ServiceBinding serviceBinding = (ServiceBinding) sbIter
183:                                    .next();
184:
185:                            // Get a collection of SpecificationLinks
186:                            Collection specificationLinks = serviceBinding
187:                                    .getSpecificationLinks();
188:
189:                            Iterator linkIter = specificationLinks.iterator();
190:                            while (linkIter.hasNext()) {
191:                                SpecificationLink specificationLink = (SpecificationLink) linkIter
192:                                        .next();
193:
194:                                // Get a collection of ExternalLinks 
195:                                Collection externalLinks = specificationLink
196:                                        .getExternalLinks();
197:
198:                                Iterator elinkIter = externalLinks.iterator();
199:                                while (elinkIter.hasNext()) {
200:                                    ExternalLink externalLink = (ExternalLink) elinkIter
201:                                            .next();
202:                                    String externalURI = externalLink
203:                                            .getExternalURI();
204:
205:                                    // put this WSDL URL into the appropriate list
206:                                    if (service.getName().getValue().equals(
207:                                            "Red Hat Olstore - Shopping cart")) {
208:                                        cartWSDLLocations.add(externalURI);
209:                                    } else {
210:                                        specialsWSDLLocations.add(externalURI);
211:                                    }
212:
213:                                }
214:                            }
215:                        }
216:                    }
217:                }
218:
219:            }
220:
221:            /**
222:             * Get the list of shopping cart endpoint locations.
223:             *
224:             * @return Returns the cartWSDLLocations.
225:             */
226:            public List getCartWSDLLocations() {
227:                return cartWSDLLocations;
228:            }
229:
230:            /**
231:             * Get the list of OLStore endpoint locations.
232:             *
233:             * @return Returns the specialsWSDLLocations.
234:             */
235:            public List getSpecialsWSDLLocations() {
236:                return specialsWSDLLocations;
237:            }
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.