Source Code Cross Referenced for MessageAdaptorImpl.java in  » ESB » open-esb » com » sun » jbi » binding » jms » handler » 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.binding.jms.handler 
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:         * @(#)MessageAdaptorImpl.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.binding.jms.handler;
030:
031:        import com.sun.jbi.StringTranslator;
032:
033:        import com.sun.jbi.binding.jms.JMSBindingContext;
034:        import com.sun.jbi.binding.jms.JMSBindingResources;
035:
036:        import com.sun.jbi.binding.jms.util.UtilBase;
037:
038:        import java.util.HashMap;
039:
040:        import java.util.logging.Logger;
041:
042:        import javax.jbi.messaging.MessageExchange;
043:
044:        import javax.jms.Destination;
045:        import javax.jms.JMSException;
046:        import javax.jms.Message;
047:        import javax.jms.DeliveryMode;
048:
049:        /**
050:         * Implements a Message Adaptor Interface.
051:         *
052:         * @author Sun Microsystems Inc.
053:         */
054:        class MessageAdaptorImpl extends UtilBase implements  MessageAdaptor,
055:                JMSBindingResources {
056:            /**
057:             * Logger object.
058:             */
059:            protected Logger mLogger;
060:            /**
061:             * Translator.
062:             */
063:            protected StringTranslator mStringTranslator;
064:            /**
065:             * Reply to.
066:             */
067:            private Destination mReplyTo;
068:            /**
069:             *  Exception.
070:             */
071:            private Exception mException;
072:            /**
073:             * Properties.
074:             */
075:            private HashMap mJMSProperties;
076:            /**
077:             * Correlation ID.
078:             */
079:            private String mCorrelationId;
080:            /**
081:             * Endpoint  name.
082:             */
083:            private String mEndpointName;
084:            /**
085:             * Type.
086:             */
087:            private String mJMSType;
088:            /**
089:             * Message Id.
090:             */
091:            private String mMessageId;
092:            /**
093:             * Operation.
094:             */
095:            private String mOperation;
096:            /**
097:             * Operation namespace.
098:             */
099:            private String mOperationNamespace;
100:            /**
101:             *  Service name.
102:             */
103:            private String mServiceName;
104:            /**
105:             * Error.
106:             */
107:            private StringBuffer mError;
108:            /**
109:             * Delivery mode.
110:             */
111:            private int mDeliveryMode;
112:            /**
113:             * Priority.
114:             */
115:            private int mJMSPriority;
116:
117:            /**
118:             * Epilogue processor
119:             */
120:            private Object mEpilogueProcessor;
121:
122:            /**
123:             * Creates a new MessageAdaptorImpl object.
124:             */
125:            public MessageAdaptorImpl() {
126:                mJMSProperties = new HashMap();
127:                mError = new StringBuffer();
128:                mLogger = JMSBindingContext.getInstance().getLogger();
129:                mStringTranslator = JMSBindingContext.getInstance()
130:                        .getStringTranslator();
131:            }
132:
133:            /**
134:             * Sets error.
135:             *
136:             * @param err error.
137:             */
138:            public void setError(String err) {
139:                super .setError(err);
140:            }
141:
142:            /**
143:             * Returns the error.
144:             *
145:             * @return error.
146:             */
147:            public String getError() {
148:                return super .getError();
149:            }
150:
151:            /**
152:             * Sets exception.
153:             *
154:             * @param ex exception.
155:             */
156:            public void setException(Exception ex) {
157:                super .setException(ex);
158:            }
159:
160:            /**
161:             * Returns exception.
162:             *
163:             * @return exception.
164:             */
165:            public Exception getException() {
166:                return super .getException();
167:            }
168:
169:            /**
170:             * Setter for property mCorrelationId.
171:             *
172:             * @param msg New value of property mCorrelationId.
173:             */
174:            public void setJMSCorrelationId(javax.jms.Message msg) {
175:                try {
176:                    mCorrelationId = msg.getJMSCorrelationID();
177:                } catch (JMSException je) {
178:                    ;
179:                }
180:            }
181:
182:            /**
183:             * Getter for property mCorrelationId.
184:             *
185:             * @return Value of property mCorrelationId.
186:             */
187:            public java.lang.String getJMSCorrelationId() {
188:                return mCorrelationId;
189:            }
190:
191:            /**
192:             * Setter for property mDeliveryMode.
193:             *
194:             * @param msg New value of property mDeliveryMode.
195:             */
196:            public void setJMSDeliveryMode(javax.jms.Message msg) {
197:                try {
198:                    mDeliveryMode = msg.getJMSDeliveryMode();
199:                } catch (JMSException je) {
200:                    ;
201:                }
202:            }
203:
204:            /**
205:             * Getter for property mDeliveryMode.
206:             *
207:             * @return Value of property mDeliveryMode.
208:             */
209:            public int getJMSDeliveryMode() {
210:                return mDeliveryMode;
211:            }
212:
213:            /**
214:             * Sets the JMS headers.
215:             *
216:             * @param msg JMS message.
217:             */
218:            public void setJMSHeaders(Message msg) {
219:                try {
220:                    msg.setJMSCorrelationID(getJMSCorrelationId());
221:                    msg.setJMSMessageID(getJMSMessageId());
222:                    msg.setJMSReplyTo(getJMSReplyTo());
223:                } catch (JMSException je) {
224:                    ;
225:                }
226:            }
227:
228:            /**
229:             * Setter for property mMessageId.
230:             *
231:             * @param msg New value of property mMessageId.
232:             */
233:            public void setJMSMessageId(javax.jms.Message msg) {
234:                try {
235:                    mMessageId = msg.getJMSMessageID();
236:                } catch (JMSException je) {
237:                    ;
238:                }
239:            }
240:
241:            /**
242:             * Getter for property mMessageId.
243:             *
244:             * @return Value of property mMessageId.
245:             */
246:            public java.lang.String getJMSMessageId() {
247:                return mMessageId;
248:            }
249:
250:            /**
251:             * Setter for property mJMSPriority.
252:             *
253:             * @param msg New value of property mJMSPriority.
254:             */
255:            public void setJMSPriority(javax.jms.Message msg) {
256:                try {
257:                    mJMSPriority = msg.getJMSPriority();
258:                } catch (JMSException je) {
259:                    ;
260:                }
261:            }
262:
263:            /**
264:             * Getter for property mJMSPriority.
265:             *
266:             * @return Value of property mJMSPriority.
267:             */
268:            public int getJMSPriority() {
269:                return mJMSPriority;
270:            }
271:
272:            /**
273:             * Sets the JMS properties.
274:             *
275:             * @param msg JMS message.
276:             */
277:            public void setJMSProperties(Message msg) {
278:                try {
279:                    msg.setStringProperty(MessageProperties.JBI_SERVICE_NAME,
280:                            getNMSServiceName());
281:
282:                    msg.setStringProperty(MessageProperties.JBI_ENDPOINT_NAME,
283:                            getNMSEndpointName());
284:
285:                    msg.setStringProperty(MessageProperties.JBI_OPERATION_NAME,
286:                            getNMSOperation());
287:
288:                    msg.setStringProperty(
289:                            MessageProperties.JBI_OPERATION_NAMESPACE,
290:                            getNMSOperationNamespace());
291:                } catch (JMSException je) {
292:                    ;
293:                }
294:            }
295:
296:            /**
297:             * Setter for property mReplyTo.
298:             *
299:             * @param msg New value of property mReplyTo.
300:             */
301:            public void setJMSReplyTo(javax.jms.Message msg) {
302:                try {
303:                    mReplyTo = msg.getJMSReplyTo();
304:                } catch (JMSException je) {
305:                    ;
306:                }
307:            }
308:
309:            /**
310:             * Set JMS reply to.
311:             *
312:             * @param reply reply to destination.
313:             */
314:            public void setJMSReplyTo(javax.jms.Destination reply) {
315:                mReplyTo = reply;
316:            }
317:
318:            /**
319:             * Getter for property mReplyTo.
320:             *
321:             * @return Value of property mReplyTo.
322:             */
323:            public javax.jms.Destination getJMSReplyTo() {
324:                return mReplyTo;
325:            }
326:
327:            /**
328:             * Returns JMS status.
329:             *
330:             * @param msg JMS message.
331:             *
332:             * @return satatus string.
333:             */
334:            public String getJMSStatus(Message msg) {
335:                String status = null;
336:
337:                try {
338:                    status = msg
339:                            .getStringProperty(MessageProperties.JBI_STATUS);
340:                } catch (JMSException je) {
341:                    status = new String(MessageProperties.SUCCESS);
342:                }
343:
344:                if ((status == null) || (status.trim().equals(""))) {
345:                    status = new String(MessageProperties.SUCCESS);
346:                }
347:
348:                return status;
349:            }
350:
351:            /**
352:             * Setter for property mJMSType.
353:             *
354:             * @param msg New value of property mJMSType.
355:             */
356:            public void setJMSType(javax.jms.Message msg) {
357:                try {
358:                    mJMSType = msg.getJMSType();
359:                } catch (JMSException je) {
360:                    ;
361:                }
362:            }
363:
364:            /**
365:             * Getter for property mJMSType.
366:             *
367:             * @return Value of property mJMSType.
368:             */
369:            public java.lang.String getJMSType() {
370:                return mJMSType;
371:            }
372:
373:            /**
374:             * Returns name.
375:             *
376:             * @return name string.
377:             */
378:            public String getName() {
379:                return "";
380:            }
381:
382:            /**
383:             * Gets the reply to destination.
384:             *
385:             * @return reply destination.
386:             */
387:            public String getReplyToDestinationName() {
388:                if (mReplyTo == null) {
389:                    return null;
390:                }
391:
392:                String name = null;
393:
394:                try {
395:                    if (mReplyTo instanceof  javax.jms.Queue) {
396:                        name = ((javax.jms.Queue) (mReplyTo)).getQueueName();
397:                    } else if (mReplyTo instanceof  javax.jms.Topic) {
398:                        name = ((javax.jms.Topic) (mReplyTo)).getTopicName();
399:                    }
400:                } catch (Exception e) {
401:                    name = null;
402:                }
403:
404:                return name;
405:            }
406:
407:            /**
408:             * Sets the status.
409:             *
410:             * @param msg JMS message.
411:             * @param status status string.
412:             */
413:            public void setStatus(Message msg, String status) {
414:                try {
415:                    if (status != null) {
416:                        msg.setStringProperty(MessageProperties.JBI_STATUS,
417:                                status);
418:                    }
419:                } catch (JMSException je) {
420:                    mLogger.severe(mStringTranslator
421:                            .getString(JMS_CANNOT_SET_JMS_STATUS));
422:                }
423:            }
424:
425:            /**
426:             * Check validity.
427:             *
428:             * @return true if valid.
429:             */
430:            public boolean isValid() {
431:                return super .isValid();
432:            }
433:
434:            /**
435:             * Clears all error strings.
436:             */
437:            public void clear() {
438:                super .clear();
439:            }
440:
441:            /**
442:             * Converts a JMS message to NMR message.
443:             *
444:             * @param msg JMS message.
445:             * @param exch NMR message.
446:             */
447:            public void convertJMStoNMSMessage(Message msg, MessageExchange exch) {
448:                if (msg != null) {
449:                    processJMSHeaders(msg);
450:                    processJMSProperties(msg);
451:                }
452:
453:                if (exch != null) {
454:                    setNMSProperties(exch);
455:                }
456:            }
457:
458:            /**
459:             * Convert NMR to JMS messages.
460:             *
461:             * @param exch NMR message.
462:             * @param msg JMS message.
463:             */
464:            public void convertNMStoJMSMessage(MessageExchange exch, Message msg) {
465:                if (exch != null) {
466:                    processNMSHeaders(exch);
467:                    processNMSProperties(exch);
468:                }
469:
470:                if (msg != null) {
471:                    setJMSHeaders(msg);
472:                    setJMSProperties(msg);
473:                }
474:            }
475:
476:            /**
477:             * Process JMS headers.
478:             *
479:             * @param msg JMS message.
480:             */
481:            public void processJMSHeaders(Message msg) {
482:                if (msg != null) {
483:                    setJMSCorrelationId(msg);
484:                    setJMSDeliveryMode(msg);
485:                    setJMSMessageId(msg);
486:                    setJMSReplyTo(msg);
487:                    setJMSType(msg);
488:                    setJMSPriority(msg);
489:                }
490:            }
491:
492:            /**
493:             * Process NMR message.
494:             *
495:             * @param ex NMR message.
496:             */
497:            public void processNMSHeaders(MessageExchange ex) {
498:                if (ex != null) {
499:                    setNMSServiceName(ex);
500:                    setNMSEndpointName(ex);
501:                    setNMSOperation(ex);
502:                }
503:            }
504:
505:            /**
506:             * Process NMR properties.
507:             *
508:             * @param ex NMR exchange.
509:             */
510:            public void processNMSProperties(MessageExchange ex) {
511:                if (ex != null) {
512:                    String cor = (String) ex
513:                            .getProperty(MessageProperties.JMS_CORRELATION_ID);
514:
515:                    if (cor != null) {
516:                        setNMSCorrelationId((String) ex
517:                                .getProperty(MessageProperties.JMS_CORRELATION_ID));
518:                    } else {
519:                        setNMSCorrelationId(ex.getExchangeId());
520:                    }
521:
522:                    setNMSDeliveryMode((String) ex
523:                            .getProperty(MessageProperties.DELIVERY_MODE));
524:                    setNMSMessageId(ex.getExchangeId());
525:                }
526:            }
527:
528:            /**
529:             * Updates the error message.
530:             *
531:             * @param msg JMS message.
532:             * @param obj object.
533:             */
534:            public void updateJMSErrorMessage(Message msg, Object obj) {
535:                ;
536:            }
537:
538:            /**
539:             * Updates the NMR out message.
540:             *
541:             * @param msg JMS message.
542:             * @param exch NMR message.
543:             */
544:            public void updateNMSOutMessage(Message msg, MessageExchange exch) {
545:                ;
546:            }
547:
548:            /**
549:             * Gets the JMS properties.
550:             *
551:             * @param msg JMS message.
552:             * @param property properties.
553:             *
554:             * @return string representing properties.
555:             */
556:            private String getJMSProperty(Message msg, String property) {
557:                String value = null;
558:
559:                try {
560:                    value = msg.getStringProperty(property);
561:                } catch (JMSException je) {
562:                    ;
563:                }
564:
565:                return value;
566:            }
567:
568:            /**
569:             * Sets the NMR correlation Id.
570:             *
571:             * @param s correlation id string.
572:             */
573:            private void setNMSCorrelationId(String s) {
574:                mCorrelationId = s;
575:            }
576:
577:            /**
578:             * Sets the NMR delivery mode.
579:             *
580:             * @param mode delivery mode.
581:             */
582:            private void setNMSDeliveryMode(String mode) {
583:                if ((mode != null)
584:                        && (mode.trim()
585:                                .equals(MessageProperties.PERSISTENT_MODE))) {
586:                    mDeliveryMode = DeliveryMode.PERSISTENT;
587:                } else {
588:                    mDeliveryMode = DeliveryMode.NON_PERSISTENT;
589:                }
590:            }
591:
592:            /**
593:             * Sets the endpoint name.
594:             *
595:             * @param ex NMR message.
596:             */
597:            private void setNMSEndpointName(MessageExchange ex) {
598:                mEndpointName = ex.getEndpoint().getEndpointName();
599:            }
600:
601:            /**
602:             * Gets the endpoint name.
603:             *
604:             * @return endpoint name.
605:             */
606:            private String getNMSEndpointName() {
607:                return mEndpointName;
608:            }
609:
610:            /**
611:             * Sets the NMR message Id.
612:             *
613:             * @param id message id.
614:             */
615:            private void setNMSMessageId(String id) {
616:                mMessageId = id;
617:            }
618:
619:            /**
620:             * Sets the NMR operation.
621:             *
622:             * @param ex NMR exchange.
623:             */
624:            private void setNMSOperation(MessageExchange ex) {
625:                mOperation = ex.getOperation().getLocalPart();
626:                mOperationNamespace = ex.getOperation().getNamespaceURI();
627:            }
628:
629:            /**
630:             * Gets the NMR operation.
631:             *
632:             * @return operation name.
633:             */
634:            private String getNMSOperation() {
635:                return mOperation;
636:            }
637:
638:            /**
639:             * Gets NMR operation namespace.
640:             *
641:             * @return namespace.
642:             */
643:            private String getNMSOperationNamespace() {
644:                return mOperationNamespace;
645:            }
646:
647:            /**
648:             * Sets the NMR properties.
649:             *
650:             * @param exch NMR message.
651:             */
652:            private void setNMSProperties(MessageExchange exch) {
653:                if (getJMSCorrelationId() != null) {
654:                    exch.setProperty(MessageProperties.JMS_CORRELATION_ID,
655:                            getJMSCorrelationId());
656:                }
657:
658:                if (getJMSDeliveryMode() == DeliveryMode.PERSISTENT) {
659:                    exch.setProperty(MessageProperties.DELIVERY_MODE,
660:                            MessageProperties.PERSISTENT_MODE);
661:                } else {
662:                    exch.setProperty(MessageProperties.DELIVERY_MODE,
663:                            MessageProperties.NON_PERSISTENT_MODE);
664:                }
665:
666:                if (getJMSMessageId() != null) {
667:                    exch.setProperty(MessageProperties.JMS_MESSAGE_ID,
668:                            getJMSMessageId());
669:                }
670:
671:                if (getReplyToDestinationName() != null) {
672:                    exch.setProperty(MessageProperties.REPLY_TO,
673:                            getReplyToDestinationName());
674:                }
675:            }
676:
677:            /**
678:             * Sets the NMR service name.
679:             *
680:             * @param ex NMR message.
681:             */
682:            private void setNMSServiceName(MessageExchange ex) {
683:                mServiceName = ex.getEndpoint().getServiceName().toString();
684:            }
685:
686:            /**
687:             * Gets the NMR service name.
688:             *
689:             * @return service name.
690:             */
691:            private String getNMSServiceName() {
692:                return mServiceName;
693:            }
694:
695:            /**
696:             * Process JMS properties.
697:             *
698:             * @param msg JMS message.
699:             */
700:            private void processJMSProperties(Message msg) {
701:                mJMSProperties.put(MessageProperties.JMS_OPERATION,
702:                        getJMSProperty(msg, MessageProperties.JMS_OPERATION));
703:
704:                mJMSProperties.put(MessageProperties.JBI_STATUS,
705:                        getJMSProperty(msg, MessageProperties.JBI_STATUS));
706:            }
707:
708:            /**
709:             * Getter for property mEpilogueProcessor.
710:             * @return Value of property mEpilogueProcessor.
711:             */
712:            public java.lang.Object getEpilogueProcessor() {
713:                return mEpilogueProcessor;
714:            }
715:
716:            /**
717:             * Setter for property mEpilogueProcessor.
718:             * @param mEpilogueProcessor New value of property mEpilogueProcessor.
719:             */
720:            public void setEpilogueProcessor(java.lang.Object mEpilogueProcessor) {
721:                this.mEpilogueProcessor = mEpilogueProcessor;
722:            }
723:
724:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.