Source Code Cross Referenced for MessageExchangeHelper.java in  » Workflow-Engines » Dalma » com » sun » jbi » engine » sequencing » 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 » Workflow Engines » Dalma » com.sun.jbi.engine.sequencing.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright (c) 2004-2005 Sun Microsystems Inc., All Rights Reserved.
002:
003:        /*
004:         * MessageExchangeHelper.java
005:         *
006:         * SUN PROPRIETARY/CONFIDENTIAL
007:         * This software is the proprietary information of Sun Microsystems, Inc.
008:         * Use is subject to license term
009:         */
010:        package com.sun.jbi.engine.sequencing.util;
011:
012:        import com.sun.jbi.engine.sequencing.PatternRegistry;
013:        import com.sun.jbi.engine.sequencing.SequencingEngineContext;
014:
015:        import java.util.logging.Logger;
016:
017:        import javax.jbi.messaging.DeliveryChannel;
018:        import javax.jbi.messaging.ExchangeStatus;
019:        import javax.jbi.messaging.Fault;
020:        import javax.jbi.messaging.InOnly;
021:        import javax.jbi.messaging.InOut;
022:        import javax.jbi.messaging.MessageExchange;
023:        import javax.jbi.messaging.MessageExchangeFactory;
024:        import javax.jbi.messaging.NormalizedMessage;
025:        import javax.jbi.messaging.RobustInOnly;
026:
027:        /**
028:         * Helper class to process message exchanges.
029:         *
030:         * @author Sun Microsystems, Inc.
031:         */
032:        public class MessageExchangeHelper {
033:            /**
034:             * Logger.
035:             */
036:            private static Logger sLog = Logger
037:                    .getLogger("com.sun.jbi.engine.seqeuncing");
038:
039:            /**
040:             * Creates a new instance of MessageExchangeHelper.
041:             */
042:            public MessageExchangeHelper() {
043:            }
044:
045:            /**
046:             * Returns error.
047:             *
048:             * @param msg ME
049:             *
050:             * @return exception exception
051:             */
052:            public static Exception getError(MessageExchange msg) {
053:                if (msg == null) {
054:                    return null;
055:                }
056:
057:                if (msg.getPattern().toString().trim().equals(
058:                        PatternRegistry.IN_OUT)) {
059:                    return (((InOut) (msg)).getError());
060:                } else if (msg.getPattern().toString().trim().equals(
061:                        PatternRegistry.IN_ONLY)) {
062:                    return null;
063:                } else if (msg.getPattern().toString().trim().equals(
064:                        PatternRegistry.ROBUST_IN_ONLY)) {
065:                    return (((RobustInOnly) (msg)).getError());
066:                } else {
067:                    return null;
068:                }
069:            }
070:
071:            /**
072:             * Returns fault.
073:             *
074:             * @param msg message exchange from which fault has to be extracted.
075:             *
076:             * @return Fault fault
077:             */
078:            public static Fault getFault(MessageExchange msg) {
079:                if (msg == null) {
080:                    return null;
081:                }
082:
083:                if (msg.getPattern().toString().trim().equals(
084:                        PatternRegistry.IN_OUT)) {
085:                    return (((InOut) (msg)).getFault());
086:                } else if (msg.getPattern().toString().trim().equals(
087:                        PatternRegistry.IN_ONLY)) {
088:                    return null;
089:                } else if (msg.getPattern().toString().trim().equals(
090:                        PatternRegistry.ROBUST_IN_ONLY)) {
091:                    return (((RobustInOnly) (msg)).getFault());
092:                } else {
093:                    return null;
094:                }
095:            }
096:
097:            /**
098:             * Returns the in message.
099:             *
100:             * @param msg message exchange
101:             *
102:             * @return normalized message
103:             */
104:            public static NormalizedMessage getInMessage(MessageExchange msg) {
105:                if (msg == null) {
106:                    sLog.severe("Returnign nulll in getInMessage()");
107:
108:                    return null;
109:                }
110:
111:                if (msg.getPattern().toString().trim().equals(
112:                        PatternRegistry.IN_OUT)) {
113:                    return (((InOut) (msg)).getInMessage());
114:                } else if (msg.getPattern().toString().trim().equals(
115:                        PatternRegistry.IN_ONLY)) {
116:                    return (((InOnly) (msg)).getInMessage());
117:                } else if (msg.getPattern().toString().trim().equals(
118:                        PatternRegistry.ROBUST_IN_ONLY)) {
119:                    return (((RobustInOnly) (msg)).getInMessage());
120:                } else {
121:                    return null;
122:                }
123:            }
124:
125:            /**
126:             * Returns the out message.
127:             *
128:             * @param msg message exchange
129:             *
130:             * @return normalized message
131:             */
132:            public static NormalizedMessage getOutMessage(MessageExchange msg) {
133:                if (msg == null) {
134:                    return null;
135:                }
136:
137:                if (msg.getPattern().toString().trim().equals(
138:                        PatternRegistry.IN_OUT)) {
139:                    return (((InOut) (msg)).getOutMessage());
140:                } else if (msg.getPattern().toString().trim().equals(
141:                        PatternRegistry.IN_ONLY)) {
142:                    return null;
143:                } else if (msg.getPattern().toString().trim().equals(
144:                        PatternRegistry.ROBUST_IN_ONLY)) {
145:                    return null;
146:                } else {
147:                    return null;
148:                }
149:            }
150:
151:            /**
152:             * Creates an exchange corresponding to pattern.
153:             *
154:             * @param pattern pattern
155:             *
156:             * @return message exchange
157:             */
158:            public static MessageExchange createExchange(String pattern) {
159:                sLog.fine("Creating exchange for pattern " + pattern);
160:
161:                MessageExchange tmpExchng = null;
162:
163:                try {
164:                    DeliveryChannel chnl = SequencingEngineContext
165:                            .getInstance().getChannel();
166:
167:                    MessageExchangeFactory factory = chnl
168:                            .createExchangeFactory();
169:
170:                    if (pattern.trim().equals(PatternRegistry.IN_OUT)) {
171:                        tmpExchng = factory.createInOutExchange();
172:                    } else if (pattern.trim().equals(PatternRegistry.IN_ONLY)) {
173:                        tmpExchng = factory.createInOnlyExchange();
174:                    } else if (pattern.trim().equals(
175:                            PatternRegistry.ROBUST_IN_ONLY)) {
176:                        tmpExchng = factory.createRobustInOnlyExchange();
177:                    }
178:
179:                    return tmpExchng;
180:                } catch (Exception e) {
181:                    e.printStackTrace();
182:
183:                    return null;
184:                }
185:            }
186:
187:            /**
188:             * Updates the message exchange.
189:             *
190:             * @param msg message exchange.
191:             * @param in in message
192:             *
193:             * @return true / false depending if update was successful or not
194:             */
195:            public static boolean updateInMessage(MessageExchange msg,
196:                    NormalizedMessage in) {
197:                if (msg == null) {
198:                    return false;
199:                }
200:
201:                if (in != null) {
202:                    return createIn(msg, in);
203:                }
204:
205:                return true;
206:            }
207:
208:            /**
209:             * Updates the message accding to the arguments provided.
210:             *
211:             * @param msg ME
212:             * @param out Out message
213:             * @param error errror message
214:             * @param fault fault
215:             *
216:             * @return true if update is successfull.
217:             */
218:            public static boolean updateMessage(MessageExchange msg,
219:                    NormalizedMessage out, Exception error, Fault fault) {
220:                if (msg == null) {
221:                    return false;
222:                }
223:
224:                if (out != null) {
225:                    return createOut(msg, out);
226:                }
227:
228:                if (fault != null) {
229:                    return createFault(msg, fault);
230:                }
231:
232:                if (error != null) {
233:                    return createError(msg, error);
234:                }
235:
236:                try {
237:                    msg.setStatus(ExchangeStatus.DONE);
238:
239:                    if (msg.getProperty(ConfigData.RESPONSE_SEQ_ID) == null) {
240:                        String id = SequencingEngineUtil.getTrackingId();
241:                        msg.setProperty(ConfigData.RESPONSE_SEQ_ID, id);
242:                    }
243:                } catch (Exception e) {
244:                    e.printStackTrace();
245:
246:                    return false;
247:                }
248:
249:                return true;
250:            }
251:
252:            /**
253:             * Creates an error message.
254:             *
255:             * @param msg ME
256:             * @param error exception
257:             *
258:             * @return true/ false.
259:             */
260:            private static boolean createError(MessageExchange msg,
261:                    Exception error) {
262:                try {
263:                    if (error == null) {
264:                        msg.setError(new Exception("Unknown Exception"));
265:
266:                        return true;
267:                    }
268:
269:                    msg.setError(error);
270:
271:                    if (msg.getProperty(ConfigData.RESPONSE_SEQ_ID) == null) {
272:                        String id = SequencingEngineUtil.getTrackingId();
273:                        msg.setProperty(ConfigData.RESPONSE_SEQ_ID, id);
274:                    }
275:                } catch (Exception me) {
276:                    me.printStackTrace();
277:
278:                    return false;
279:                }
280:
281:                return true;
282:            }
283:
284:            /**
285:             * Creates a fault message.
286:             *
287:             * @param msg ME
288:             * @param flt fault
289:             *
290:             * @return true / false
291:             */
292:            private static boolean createFault(MessageExchange msg, Fault flt) {
293:                if (flt == null) {
294:                    return false;
295:                }
296:
297:                try {
298:                    if (msg.getPattern().toString().trim().equals(
299:                            PatternRegistry.IN_ONLY)) {
300:                        msg.setStatus(ExchangeStatus.ERROR);
301:                    }
302:
303:                    msg.setFault(flt);
304:                } catch (Exception e) {
305:                    e.printStackTrace();
306:
307:                    return false;
308:                }
309:
310:                return true;
311:            }
312:
313:            /**
314:             * Creates an In Message.
315:             *
316:             * @param msg ME
317:             * @param in in message
318:             *
319:             * @return true / false.
320:             */
321:            private static boolean createIn(MessageExchange msg,
322:                    NormalizedMessage in) {
323:                String id = SequencingEngineUtil.getTrackingId();
324:
325:                try {
326:                    if (msg.getPattern().toString().trim().equals(
327:                            PatternRegistry.IN_OUT)) {
328:                        ((InOut) (msg)).setInMessage(in);
329:                        msg.setProperty(ConfigData.REQUEST_SEQ_ID, id);
330:                    } else if (msg.getPattern().toString().trim().equals(
331:                            PatternRegistry.IN_ONLY)) {
332:                        ((InOnly) (msg)).setInMessage(in);
333:                        msg.setProperty(ConfigData.REQUEST_SEQ_ID, id);
334:                    } else if (msg.getPattern().toString().trim().equals(
335:                            PatternRegistry.ROBUST_IN_ONLY)) {
336:                        ((RobustInOnly) (msg)).setInMessage(in);
337:                        msg.setProperty(ConfigData.REQUEST_SEQ_ID, id);
338:                    } else {
339:                        return false;
340:                    }
341:                } catch (Exception e) {
342:                    e.printStackTrace();
343:
344:                    return false;
345:                }
346:
347:                return true;
348:            }
349:
350:            /**
351:             * Creates the out message.
352:             *
353:             * @param msg ME
354:             * @param out out message
355:             *
356:             * @return true /false.
357:             */
358:            private static boolean createOut(MessageExchange msg,
359:                    NormalizedMessage out) {
360:                String id = SequencingEngineUtil.getTrackingId();
361:
362:                try {
363:                    if (msg.getPattern().toString().trim().equals(
364:                            PatternRegistry.IN_OUT)) {
365:                        ((InOut) (msg)).setOutMessage(out);
366:                        msg.setProperty(ConfigData.RESPONSE_SEQ_ID, id);
367:                    } else if (msg.getPattern().toString().trim().equals(
368:                            PatternRegistry.IN_ONLY)) {
369:                        msg.setStatus(ExchangeStatus.DONE);
370:                        msg.setProperty(ConfigData.RESPONSE_SEQ_ID, id);
371:                    } else if (msg.getPattern().toString().trim().equals(
372:                            PatternRegistry.ROBUST_IN_ONLY)) {
373:                        msg.setStatus(ExchangeStatus.DONE);
374:                        msg.setProperty(ConfigData.RESPONSE_SEQ_ID, id);
375:                    } else {
376:                        return false;
377:                    }
378:                } catch (Exception e) {
379:                    e.printStackTrace();
380:
381:                    return false;
382:                }
383:
384:                return true;
385:            }
386:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.