Source Code Cross Referenced for PojoSupport.java in  » ESB » servicemix » org » apache » servicemix » components » util » 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 » servicemix » org.apache.servicemix.components.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.servicemix.components.util;
018:
019:        import javax.jbi.JBIException;
020:        import javax.jbi.component.ComponentContext;
021:        import javax.jbi.component.ComponentLifeCycle;
022:        import javax.jbi.messaging.DeliveryChannel;
023:        import javax.jbi.messaging.ExchangeStatus;
024:        import javax.jbi.messaging.Fault;
025:        import javax.jbi.messaging.InOnly;
026:        import javax.jbi.messaging.InOptionalOut;
027:        import javax.jbi.messaging.InOut;
028:        import javax.jbi.messaging.MessageExchange;
029:        import javax.jbi.messaging.MessageExchangeFactory;
030:        import javax.jbi.messaging.MessagingException;
031:        import javax.jbi.messaging.NormalizedMessage;
032:        import javax.jbi.servicedesc.ServiceEndpoint;
033:        import javax.management.ObjectName;
034:        import javax.xml.namespace.QName;
035:
036:        import org.apache.commons.logging.Log;
037:        import org.apache.commons.logging.LogFactory;
038:        import org.apache.servicemix.jbi.FaultException;
039:        import org.apache.servicemix.jbi.NotInitialisedYetException;
040:        import org.apache.servicemix.jbi.management.BaseLifeCycle;
041:
042:        /**
043:         * A useful base class for a POJO based JBI component which contains most of the basic plumbing
044:         *
045:         * @version $Revision: 564900 $
046:         */
047:        public abstract class PojoSupport extends BaseLifeCycle implements 
048:                ComponentLifeCycle {
049:
050:            protected Log logger = LogFactory.getLog(getClass());
051:
052:            private ComponentContext context;
053:            private ObjectName extensionMBeanName;
054:            private QName service;
055:            private String endpoint;
056:            private MessageExchangeFactory exchangeFactory;
057:            private String description = "POJO Component";
058:            private ServiceEndpoint serviceEndpoint;
059:            private DeliveryChannel channel;
060:
061:            protected PojoSupport() {
062:            }
063:
064:            protected PojoSupport(QName service, String endpoint) {
065:                this .service = service;
066:                this .endpoint = endpoint;
067:            }
068:
069:            /**
070:             * Get the description
071:             * @return the description
072:             */
073:            public String getDescription() {
074:                return description;
075:            }
076:
077:            /**
078:             * Called when the Component is initialized
079:             *
080:             * @param cc
081:             * @throws JBIException
082:             */
083:            public void init(ComponentContext cc) throws JBIException {
084:                this .context = cc;
085:                this .channel = this .context.getDeliveryChannel();
086:                init();
087:                if (service != null && endpoint != null) {
088:                    serviceEndpoint = context.activateEndpoint(service,
089:                            endpoint);
090:                }
091:            }
092:
093:            /**
094:             * Shut down the item. The releases resources, preparing to uninstall
095:             * 
096:             * @exception javax.jbi.JBIException if the item fails to shut down.
097:             */
098:            public void shutDown() throws javax.jbi.JBIException {
099:                if (serviceEndpoint != null) {
100:                    context.deactivateEndpoint(serviceEndpoint);
101:                }
102:                exchangeFactory = null;
103:                super .shutDown();
104:            }
105:
106:            // Helper methods
107:            //-------------------------------------------------------------------------
108:
109:            /**
110:             * A helper method to return the body of the message as a POJO which could be a
111:             * bean or some DOMish model of the body.
112:             *
113:             * @param message the message on which to extract the body
114:             * @return the body of the message as a POJO or DOM object
115:             * @throws MessagingException
116:             */
117:            public Object getBody(NormalizedMessage message)
118:                    throws MessagingException {
119:                return MessageHelper.getBody(message);
120:            }
121:
122:            /**
123:             * Sets the body of the message as a POJO
124:             *
125:             * @param message the message on which to set the body
126:             * @param body    the POJO or DOMish model to set
127:             * @throws MessagingException
128:             */
129:            public void setBody(NormalizedMessage message, Object body)
130:                    throws MessagingException {
131:                MessageHelper.setBody(message, body);
132:            }
133:
134:            // Properties
135:            //-------------------------------------------------------------------------
136:            public ObjectName getExtensionMBeanName() {
137:                return extensionMBeanName;
138:            }
139:
140:            public void setExtensionMBeanName(ObjectName extensionMBeanName) {
141:                this .extensionMBeanName = extensionMBeanName;
142:            }
143:
144:            public ComponentContext getContext() {
145:                return context;
146:            }
147:
148:            public QName getService() {
149:                return service;
150:            }
151:
152:            public void setService(QName service) {
153:                this .service = service;
154:            }
155:
156:            public String getEndpoint() {
157:                return endpoint;
158:            }
159:
160:            public void setEndpoint(String endpoint) {
161:                this .endpoint = endpoint;
162:            }
163:
164:            /**
165:             * Provide access to the default message exchange exchangeFactory, lazily creating one.
166:             */
167:            public MessageExchangeFactory getExchangeFactory()
168:                    throws MessagingException {
169:                if (exchangeFactory == null && context != null) {
170:                    exchangeFactory = getDeliveryChannel()
171:                            .createExchangeFactory();
172:                }
173:                return exchangeFactory;
174:            }
175:
176:            public DeliveryChannel getDeliveryChannel()
177:                    throws MessagingException {
178:                if (channel == null) {
179:                    throw new NotInitialisedYetException();
180:                }
181:                return channel;
182:            }
183:
184:            /**
185:             * A helper method to allow a component to initialise prior to the endpoint being activated
186:             * but after the component context has been configured.
187:             *
188:             * @throws JBIException
189:             */
190:            protected void init() throws JBIException {
191:                super .init();
192:            }
193:
194:            /**
195:             * A helper method to indicate that the message exchange is complete
196:             * which will set the status to {@link ExchangeStatus#DONE} and send the message
197:             * on the delivery channel.
198:             *
199:             * @param exchange
200:             * @throws MessagingException
201:             */
202:            public void done(MessageExchange exchange)
203:                    throws MessagingException {
204:                exchange.setStatus(ExchangeStatus.DONE);
205:                getDeliveryChannel().send(exchange);
206:            }
207:
208:            public void send(MessageExchange exchange)
209:                    throws MessagingException {
210:                getDeliveryChannel().send(exchange);
211:            }
212:
213:            public boolean sendSync(MessageExchange exchange)
214:                    throws MessagingException {
215:                return getDeliveryChannel().sendSync(exchange);
216:            }
217:
218:            public boolean sendSync(MessageExchange exchange, long timeMillis)
219:                    throws MessagingException {
220:                return getDeliveryChannel().sendSync(exchange, timeMillis);
221:            }
222:
223:            /**
224:             * A helper method to indicate that the message exchange should be
225:             * continued with the given response and send the message
226:             * on the delivery channel.
227:             *
228:             * @param exchange
229:             * @throws MessagingException
230:             */
231:            public void answer(MessageExchange exchange,
232:                    NormalizedMessage answer) throws MessagingException {
233:                exchange.setMessage(answer, "out");
234:                getDeliveryChannel().send(exchange);
235:            }
236:
237:            /**
238:             * A helper method which fails and completes the given exchange with the specified fault
239:             */
240:            public void fail(MessageExchange exchange, Fault fault)
241:                    throws MessagingException {
242:                if (exchange instanceof  InOnly || fault == null) {
243:                    exchange.setError(new FaultException(
244:                            "Fault occured for in-only exchange", exchange,
245:                            fault));
246:                } else {
247:                    exchange.setFault(fault);
248:                }
249:                getDeliveryChannel().send(exchange);
250:            }
251:
252:            /**
253:             * A helper method which fails and completes the given exchange with the specified error
254:             * @throws MessagingException 
255:             */
256:            public void fail(MessageExchange exchange, Exception error)
257:                    throws MessagingException {
258:                if (exchange instanceof  InOnly
259:                        || !(error instanceof  FaultException)) {
260:                    exchange.setError(error);
261:                } else {
262:                    FaultException faultException = (FaultException) error;
263:                    exchange.setFault(faultException.getFault());
264:                }
265:                getDeliveryChannel().send(exchange);
266:            }
267:
268:            /**
269:             * A helper method which will return true if the exchange is capable of both In and Out such as InOut,
270:             * InOptionalOut etc.
271:             *
272:             * @param exchange
273:             * @return true if the exchange can handle both input and output
274:             */
275:            protected boolean isInAndOut(MessageExchange exchange) {
276:                return exchange instanceof  InOut
277:                        || exchange instanceof  InOptionalOut;
278:            }
279:
280:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.