Source Code Cross Referenced for ExchangeFactory.java in  » ESB » open-esb » com » sun » jbi » messaging » 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 » ESB » open esb » com.sun.jbi.messaging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)ExchangeFactory.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.messaging;
030:
031:        import com.sun.jbi.messaging.util.Translator;
032:        import com.sun.jbi.messaging.util.WSDLHelper;
033:
034:        import java.net.URI;
035:        import java.util.HashMap;
036:        import java.util.logging.Logger;
037:        import javax.xml.namespace.QName;
038:
039:        import javax.jbi.messaging.MessageExchange;
040:        import javax.jbi.messaging.InOnly;
041:        import javax.jbi.messaging.InOptionalOut;
042:        import javax.jbi.messaging.InOut;
043:        import javax.jbi.messaging.RobustInOnly;
044:        import javax.jbi.servicedesc.ServiceEndpoint;
045:
046:        import org.w3c.dom.Document;
047:
048:        /** A message exchange factory is used used to create new instances of 
049:         *  MessageExchange. Service consumers use these factories to create message 
050:         *  exchanges when initiating a new service request. Message exchange factories
051:         *  are created using the javax.jbi.component.ComponentContext given to the
052:         *  component during its initialization (see javax.jbi.component.ComponentLifeCycle ). 
053:         *  There are a variety of ways to creating such factories, each of which creates
054:         *  a context that is used to provide some of the default properties of 
055:         *  MessageExchange instances created by the factory instances. For example, 
056:         *  a factory can be created for a particular endpoint, ensuring that all 
057:         *  exchanges created by the factory have that endpoint set as the default 
058:         *  endpoint property of the exchange. This allows components to retain 
059:         *  factories as a way of aligning internal processing context with the context 
060:         *  contained in the factory, ensuring that the exchanges created consistently 
061:         *  reflect that context.
062:         * @author Sun Microsystems, Inc.
063:         */
064:        public class ExchangeFactory implements 
065:                javax.jbi.messaging.MessageExchangeFactory {
066:            private MessageService mMsgSvc;
067:            private QName mInterface;
068:            private QName mService;
069:            private ServiceEndpoint mEndpoint;
070:            private EndpointRegistry mRegistry;
071:
072:            ExchangeFactory(MessageService msgSvc) {
073:                mMsgSvc = msgSvc;
074:                mRegistry = EndpointRegistry.getInstance();
075:            }
076:
077:            static ExchangeFactory newInterfaceFactory(MessageService msgSvc,
078:                    QName interfaceName) {
079:                ExchangeFactory ef;
080:
081:                ef = new ExchangeFactory(msgSvc);
082:                ef.setInterface(interfaceName);
083:
084:                return ef;
085:            }
086:
087:            static ExchangeFactory newServiceFactory(MessageService msgSvc,
088:                    QName serviceName) {
089:                ExchangeFactory ef;
090:
091:                ef = new ExchangeFactory(msgSvc);
092:                ef.setService(serviceName);
093:
094:                return ef;
095:            }
096:
097:            static ExchangeFactory newEndpointFactory(MessageService msgSvc,
098:                    ServiceEndpoint endpoint) {
099:                ExchangeFactory ef;
100:
101:                ef = new ExchangeFactory(msgSvc);
102:                ef.setEndpoint(endpoint);
103:
104:                return ef;
105:            }
106:
107:            public MessageExchange createExchange(URI pattern)
108:                    throws javax.jbi.messaging.MessagingException {
109:                MessageExchangeProxy proxy;
110:                MessageExchangeImpl impl;
111:                String uriStr;
112:
113:                // Decide which pattern to create
114:                switch (ExchangePattern.valueOf(pattern)) {
115:                case IN_ONLY:
116:                    proxy = new InOnlyImpl();
117:                    break;
118:
119:                case IN_OUT:
120:                    proxy = new InOutImpl();
121:                    break;
122:
123:                case IN_OPTIONAL_OUT:
124:                    proxy = new InOptionalOutImpl();
125:                    break;
126:
127:                case ROBUST_IN_ONLY:
128:                    proxy = new RobustInOnlyImpl();
129:                    break;
130:
131:                default:
132:                    throw new javax.jbi.messaging.MessagingException(Translator
133:                            .translate(LocalStringKeys.INVALID_MEP_URI,
134:                                    new Object[] { pattern }));
135:
136:                }
137:
138:                // Associate proxy with exchange impl
139:                impl = new MessageExchangeImpl(proxy, mMsgSvc);
140:
141:                // Apply any defaults from the factory
142:                proxy.setInterfaceName(mInterface);
143:                proxy.setService(mService);
144:                proxy.setEndpoint(mEndpoint);
145:
146:                return proxy;
147:            }
148:
149:            public MessageExchange createExchange(QName serviceName,
150:                    QName operationName)
151:                    throws javax.jbi.messaging.MessagingException {
152:                MessageExchange exchange;
153:                RegisteredEndpoint[] endpoints;
154:                Document desc;
155:                HashMap operations;
156:                URI opURI;
157:
158:                // try and find an endpoint for this service
159:                endpoints = mRegistry.getInternalEndpointsForService(
160:                        serviceName, true);
161:
162:                if (endpoints.length == 0) {
163:                    throw new javax.jbi.messaging.MessagingException(
164:                            Translator
165:                                    .translate(
166:                                            LocalStringKeys.CANT_FIND_ENDPOINT_FOR_SERVICE,
167:                                            new Object[] { serviceName }));
168:                }
169:
170:                operations = WSDLHelper.getOperationsForService(mMsgSvc
171:                        .queryDescriptor(endpoints[0]), serviceName);
172:
173:                if (operations == null) {
174:                    throw new javax.jbi.messaging.MessagingException(Translator
175:                            .translate(LocalStringKeys.ENDPOINT_NO_DESCRIPTOR,
176:                                    new Object[] { endpoints[0]
177:                                            .getEndpointName() }));
178:                }
179:
180:                if (!operations.containsKey(operationName.toString())) {
181:                    throw new javax.jbi.messaging.MessagingException(Translator
182:                            .translate(LocalStringKeys.NONEXISTENT_OPERATION,
183:                                    new Object[] { operationName.toString() }));
184:                }
185:
186:                opURI = createURI((String) operations.get(operationName
187:                        .toString()));
188:                exchange = createExchange(opURI);
189:
190:                exchange.setService(serviceName);
191:                exchange.setOperation(operationName);
192:
193:                return exchange;
194:            }
195:
196:            public InOnly createInOnlyExchange()
197:                    throws javax.jbi.messaging.MessagingException {
198:                return (InOnly) createExchange(ExchangePattern.IN_ONLY.getURI());
199:            }
200:
201:            public InOptionalOut createInOptionalOutExchange()
202:                    throws javax.jbi.messaging.MessagingException {
203:                return (InOptionalOut) createExchange(ExchangePattern.IN_OPTIONAL_OUT
204:                        .getURI());
205:            }
206:
207:            public InOut createInOutExchange()
208:                    throws javax.jbi.messaging.MessagingException {
209:                return (InOut) createExchange(ExchangePattern.IN_OUT.getURI());
210:            }
211:
212:            public RobustInOnly createRobustInOnlyExchange()
213:                    throws javax.jbi.messaging.MessagingException {
214:                return (RobustInOnly) createExchange(ExchangePattern.ROBUST_IN_ONLY
215:                        .getURI());
216:            }
217:
218:            private void setInterface(QName interfaceName) {
219:                mInterface = interfaceName;
220:            }
221:
222:            private void setService(QName serviceName) {
223:                mService = serviceName;
224:            }
225:
226:            private void setEndpoint(ServiceEndpoint endpoint) {
227:                mEndpoint = endpoint;
228:            }
229:
230:            /** Used to construct the URI flavor of the pattern constants.
231:             */
232:            private static URI createURI(String uri) {
233:                try {
234:                    return (new URI(uri));
235:                } catch (java.net.URISyntaxException uriEx) {
236:                    throw new java.lang.IllegalArgumentException();
237:                }
238:            }
239:
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.