Source Code Cross Referenced for BuildManagementMessageImpl.java in  » ESB » open-esb » com » sun » jbi » management » system » 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.management.system 
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:         * @(#)BuildManagementMessageImpl.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.management.system;
030:
031:        import java.util.HashMap;
032:        import org.w3c.dom.Element;
033:        import java.io.StringWriter;
034:        import org.w3c.dom.Document;
035:        import java.util.logging.Logger;
036:        import javax.xml.parsers.DocumentBuilder;
037:        import javax.xml.parsers.DocumentBuilderFactory;
038:        import com.sun.jbi.management.ComponentMessageHolder;
039:        import com.sun.jbi.management.ManagementMessageBuilder;
040:        import com.sun.jbi.management.internal.support.DOMUtil;
041:        import com.sun.jbi.management.internal.support.XmlReader;
042:        import com.sun.jbi.management.message.MessageBuilder;
043:
044:        /**
045:         *  BuildManagementMessageImpl provides utility methods to build messages
046:         *  (as XML string) that are returned to the clients by the JBI Framework.
047:         */
048:        public class BuildManagementMessageImpl implements 
049:                ManagementMessageBuilder {
050:
051:            /** String to represent UNKNOWN elements */
052:            String missingDataStr = "UNKNOWN";
053:
054:            /** String to represent INVALID input */
055:            String cannotBuildMsgStr = "CANNOT_BUILD_MESSAGE_INVALID_DATA";
056:
057:            /** Max. nesting level */
058:            int MAX_NESTING_LEVEL = 32;
059:
060:            /* ManagmentContext
061:             *
062:             */
063:            private ManagementContext mContext = null;
064:
065:            /* Logger 
066:             *
067:             */
068:            private Logger mLogger = null;
069:
070:            /** Constructs a <CODE>BuildManagementMessageImpl</CODE>.  */
071:            public BuildManagementMessageImpl() {
072:
073:                mLogger = Logger
074:                        .getLogger("javax.jbi.management.ManagementMessageBuilder");
075:
076:            }
077:
078:            /**
079:             * Return an XML string of the task result(either status of exception). 
080:             * This is the task executed by the component
081:             * @param params Status details of the component
082:             * @return XML string with task status
083:             * @throws Exception If fails to build XML string
084:             *
085:             */
086:            public String buildComponentMessage(ComponentMessageHolder cmObj)
087:                    throws Exception {
088:                String mMsgTypeToBuild = null;
089:                String compTaskMsg = null;
090:
091:                try {
092:                    mMsgTypeToBuild = cmObj.getComponentMessageType();
093:
094:                    if (mMsgTypeToBuild.equalsIgnoreCase("STATUS_MSG"))
095:                        compTaskMsg = buildComponentTaskStatusMessage(cmObj);
096:
097:                    if (mMsgTypeToBuild.equalsIgnoreCase("EXCEPTION_MSG"))
098:                        compTaskMsg = buildComponentTaskExceptionMessage(cmObj);
099:
100:                    if (compTaskMsg == null)
101:                        compTaskMsg = cannotBuildMsgStr;
102:                } catch (Exception e) {
103:                    throw e;
104:                }
105:
106:                return compTaskMsg;
107:
108:            }
109:
110:            /**
111:             * Return an XML string of the task status. This is the task executed
112:             * by the component
113:             * @param params Status details of the component
114:             * @return XML string with task status
115:             * @throws Exception If fails to build XML string
116:             *
117:             */
118:            public String buildComponentTaskStatusMessage(
119:                    ComponentMessageHolder mmObj) throws Exception {
120:
121:                String cmpStatMsg = null;
122:                Document doc = null;
123:                String locToken = null;
124:                String locMessage = null;
125:                String locParam = null;
126:
127:                try {
128:                    String componentName = mmObj.getComponentName();
129:                    if (componentName == null)
130:                        componentName = missingDataStr;
131:
132:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
133:                            .newInstance();
134:                    DocumentBuilder db = dbf.newDocumentBuilder();
135:                    doc = db.newDocument();
136:                    Element elem = doc.createElement("component-task-result");
137:                    Element compNameElem = doc.createElement("component-name");
138:                    Element compTaskRsltDtlsElem = doc
139:                            .createElement("component-task-result-details");
140:
141:                    DOMUtil.UTIL.setTextData(compNameElem, componentName);
142:
143:                    Element taskRsltDtlsElem = buildStatusXMLFragment(doc,
144:                            mmObj);
145:                    compTaskRsltDtlsElem.appendChild(taskRsltDtlsElem);
146:                    elem.appendChild(compNameElem);
147:                    elem.appendChild(compTaskRsltDtlsElem);
148:                    doc.appendChild(elem);
149:                    StringWriter sw = new StringWriter();
150:                    cmpStatMsg = DOMUtil.UTIL.DOM2String(doc, sw);
151:
152:                } catch (Exception e) {
153:                    e.printStackTrace();
154:                    throw e;
155:                }
156:
157:                return cmpStatMsg;
158:
159:            }
160:
161:            /**
162:             * Return an XML string of the task status. This is the task executed
163:             * by the framework
164:             * @param doc XML document which needs to be built
165:             * @param taskName name of the task
166:             * @param taskResult Status of the task 
167:             * @param frameworkLocale Locale in which the framework is running 
168:             * @return Element with framework task status
169:             * @throws Exception If fails to build framework task status
170:             *
171:             */
172:            public Element buildFrameworkTaskStatusMessage(Document doc,
173:                    ManagementMessageHolder mmObj) throws Exception {
174:
175:                Element elem = null;
176:
177:                try {
178:                    String frmwkLocale = mmObj.getFrameworkLocale();
179:                    if (frmwkLocale == null) {
180:                        /* Note : Since this is a helper class which can
181:                         * be instantiated by the component, JBI resource
182:                         * bundle cannot be used. Hence strings are hard coded.
183:                         */
184:                        String errMsg = "JBIMA0450: BuildManagementMessage : Framework Locale cannot be null ";
185:                        mLogger.warning(errMsg);
186:                        throw new Exception(errMsg);
187:                    }
188:
189:                    elem = doc.createElement("jbi-task-result");
190:                    Element frmwkTaskRsltElem = doc
191:                            .createElement("frmwk-task-result");
192:                    Element frmwkTaskRsltDtlsElem = doc
193:                            .createElement("frmwk-task-result-details");
194:                    Element frmwkLocaleElem = doc.createElement("locale");
195:
196:                    DOMUtil.UTIL.setTextData(frmwkLocaleElem, frmwkLocale);
197:
198:                    Element taskRsltDtlsElem = buildStatusXMLFragment(doc,
199:                            mmObj);
200:                    frmwkTaskRsltDtlsElem.appendChild(taskRsltDtlsElem);
201:                    frmwkTaskRsltDtlsElem.appendChild(frmwkLocaleElem);
202:                    frmwkTaskRsltElem.appendChild(frmwkTaskRsltDtlsElem);
203:                    elem.appendChild(frmwkTaskRsltElem);
204:
205:                } catch (Exception e) {
206:                    e.printStackTrace();
207:                    throw e;
208:                }
209:
210:                return elem;
211:            }
212:
213:            private Element buildStatusXMLFragment(Document doc,
214:                    ComponentMessageHolder mmObj) throws Exception {
215:
216:                String cmpStatMsg = null;
217:                String locToken = null;
218:                String locMessage = null;
219:                String[] locParam = null;
220:                Element taskRsltDtlsElem = null;
221:
222:                try {
223:                    String taskName = mmObj.getTaskName();
224:                    if (taskName == null) {
225:                        /* Note : Since this is a helper class which can
226:                         * be instantiated by the component, JBI resource
227:                         * bundle cannot be used. Hence strings are hard coded.
228:                         */
229:                        String errMsg = "JBIMA0451: BuildManagementMessage : Task name cannot be null ";
230:                        mLogger.warning(errMsg);
231:                        throw new Exception(errMsg);
232:                    }
233:
234:                    String taskResult = mmObj.getTaskResult();
235:                    if (taskResult == null) {
236:                        /* Note : Since this is a helper class which can
237:                         * be instantiated by the component, JBI resource
238:                         * bundle cannot be used. Hence strings are hard coded.
239:                         */
240:                        String errMsg = "JBIMA0456: BuildManagementMessage : Task result cannot be null ";
241:                        mLogger.warning(errMsg);
242:                        throw new Exception(errMsg);
243:                    }
244:
245:                    String messageType = mmObj.getStatusMessageType();
246:                    if (messageType != null) {
247:                        locToken = mmObj.getLocToken(1);
248:                        if (locToken == null)
249:                            locToken = missingDataStr;
250:                        locMessage = mmObj.getLocMessage(1);
251:                        if (locMessage == null)
252:                            locMessage = missingDataStr;
253:                        locParam = (String[]) mmObj.getLocParam(1);
254:
255:                    }
256:
257:                    Element[] msgLocInfoElem = new Element[32];
258:                    Element[] locTokenElem = new Element[32];
259:                    Element[] locMessageElem = new Element[32];
260:                    Element[] taskStatMsgElem = new Element[32];
261:                    taskRsltDtlsElem = doc.createElement("task-result-details");
262:                    Element taskIdElem = doc.createElement("task-id");
263:                    Element taskRsltStatElem = doc.createElement("task-result");
264:                    Element msgTypeElem = doc.createElement("message-type");
265:                    taskStatMsgElem[0] = doc.createElement("task-status-msg");
266:                    msgLocInfoElem[0] = doc.createElement("msg-loc-info");
267:                    locTokenElem[0] = doc.createElement("loc-token");
268:                    locMessageElem[0] = doc.createElement("loc-message");
269:
270:                    DOMUtil.UTIL.setTextData(taskIdElem, taskName);
271:                    DOMUtil.UTIL.setTextData(taskRsltStatElem, taskResult);
272:
273:                    taskRsltDtlsElem.appendChild(taskIdElem);
274:                    taskRsltDtlsElem.appendChild(taskRsltStatElem);
275:
276:                    int j = 0;
277:                    if (messageType != null) {
278:                        DOMUtil.UTIL.setTextData(msgTypeElem, messageType);
279:                        taskRsltDtlsElem.appendChild(msgTypeElem);
280:
281:                        while (locToken != null && locMessage != null) {
282:                            DOMUtil.UTIL.setTextData(locTokenElem[j], locToken);
283:                            DOMUtil.UTIL.setTextData(locMessageElem[j],
284:                                    locMessage);
285:
286:                            msgLocInfoElem[j].appendChild(locTokenElem[j]);
287:                            msgLocInfoElem[j].appendChild(locMessageElem[j]);
288:                            if (locParam != null) {
289:                                Element[] locParamElem = new Element[32];
290:                                for (int k = 0; k < locParam.length; k++) {
291:                                    locParamElem[k] = doc
292:                                            .createElement("loc-param");
293:                                    DOMUtil.UTIL.setTextData(locParamElem[k],
294:                                            locParam[k]);
295:                                    msgLocInfoElem[j]
296:                                            .appendChild(locParamElem[k]);
297:                                }
298:
299:                            }
300:                            taskStatMsgElem[j].appendChild(msgLocInfoElem[j]);
301:                            taskRsltDtlsElem.appendChild(taskStatMsgElem[j]);
302:
303:                            j++;
304:                            locToken = mmObj.getLocToken(j + 1);
305:                            locMessage = mmObj.getLocMessage(j + 1);
306:                            locParam = mmObj.getLocParam(j + 1);
307:                            taskStatMsgElem[j] = doc
308:                                    .createElement("task-status-msg");
309:                            msgLocInfoElem[j] = doc
310:                                    .createElement("msg-loc-info");
311:                            locTokenElem[j] = doc.createElement("loc-token");
312:                            locMessageElem[j] = doc
313:                                    .createElement("loc-message");
314:
315:                        }
316:
317:                    }
318:
319:                } catch (Exception e) {
320:                    e.printStackTrace();
321:                    throw e;
322:                }
323:
324:                return taskRsltDtlsElem;
325:
326:            }
327:
328:            public Element buildExceptionXMLFragment(Document doc,
329:                    ComponentMessageHolder mmObj) throws Exception {
330:
331:                String cmpStatMsg = null;
332:                String locToken = null;
333:                String locMessage = null;
334:                String[] locParam = null;
335:                Throwable exObj = null;
336:                Element taskRsltDtlsElem = null;
337:
338:                try {
339:                    String taskName = mmObj.getTaskName();
340:                    if (taskName == null) {
341:                        /* Note : Since this is a helper class which can
342:                         * be instantiated by the component, JBI resource
343:                         * bundle cannot be used. Hence strings are hard coded.
344:                         */
345:                        String errMsg = "JBIMA0452: BuildManagementMessage : Task name cannot be null ";
346:                        mLogger.warning(errMsg);
347:                        throw new Exception(errMsg);
348:                    }
349:                    String taskResult = mmObj.getTaskResult();
350:                    if (taskResult == null) {
351:                        /* Note : Since this is a helper class which can
352:                         * be instantiated by the component, JBI resource
353:                         * bundle cannot be used. Hence strings are hard coded. 
354:                         * 
355:                         */
356:                        String errMsg = "JBIMA0453: BuildManagementMessage : Task result cannot be null ";
357:                        mLogger.warning(errMsg);
358:                        throw new Exception(errMsg);
359:                    }
360:                    String messageType = mmObj.getExceptionMessageType();
361:
362:                    locToken = mmObj.getLocToken(1);
363:                    if (locToken == null)
364:                        locToken = missingDataStr;
365:                    locMessage = mmObj.getLocMessage(1);
366:
367:                    locParam = mmObj.getLocParam(1);
368:
369:                    exObj = mmObj.getExceptionObject();
370:
371:                    taskRsltDtlsElem = doc.createElement("task-result-details");
372:                    Element taskIdElem = doc.createElement("task-id");
373:                    Element taskRsltStatElem = doc.createElement("task-result");
374:                    Element msgTypeElem = doc.createElement("message-type");
375:                    DOMUtil.UTIL.setTextData(taskIdElem, taskName);
376:                    DOMUtil.UTIL.setTextData(taskRsltStatElem, taskResult);
377:                    if (messageType != null) {
378:                        DOMUtil.UTIL.setTextData(msgTypeElem, messageType);
379:                        taskRsltDtlsElem.appendChild(msgTypeElem);
380:                    }
381:
382:                    taskRsltDtlsElem.appendChild(taskIdElem);
383:                    taskRsltDtlsElem.appendChild(taskRsltStatElem);
384:                    if (messageType != null) {
385:                        DOMUtil.UTIL.setTextData(msgTypeElem, messageType);
386:                        taskRsltDtlsElem.appendChild(msgTypeElem);
387:                    }
388:
389:                    if (exObj == null) {
390:                        Element exInfoElem = doc
391:                                .createElement("exception-info");
392:                        Element msgLocInfoElem = doc
393:                                .createElement("msg-loc-info");
394:                        Element locTokenElem = doc.createElement("loc-token");
395:                        Element locMessageElem = doc
396:                                .createElement("loc-message");
397:                        Element nestingLevelElem = doc
398:                                .createElement("nesting-level");
399:                        Element stckTraceElem = doc
400:                                .createElement("stack-trace");
401:
402:                        DOMUtil.UTIL.setTextData(locTokenElem, locToken);
403:
404:                        if (locMessage != null)
405:                            DOMUtil.UTIL
406:                                    .setTextData(locMessageElem, locMessage);
407:                        else
408:                            DOMUtil.UTIL.setTextData(locMessageElem,
409:                                    missingDataStr);
410:
411:                        DOMUtil.UTIL.setTextData(nestingLevelElem,
412:                                missingDataStr);
413:                        DOMUtil.UTIL.setTextData(stckTraceElem, missingDataStr);
414:
415:                        msgLocInfoElem.appendChild(locTokenElem);
416:                        msgLocInfoElem.appendChild(locMessageElem);
417:
418:                        if (locParam != null) {
419:                            Element[] locParamElem = new Element[32];
420:                            for (int i = 0; i < locParam.length; i++) {
421:                                locParamElem[i] = doc
422:                                        .createElement("loc-param");
423:                                DOMUtil.UTIL.setTextData(locParamElem[i],
424:                                        locParam[i]);
425:                                msgLocInfoElem.appendChild(locParamElem[i]);
426:                            }
427:
428:                        }
429:
430:                        exInfoElem.appendChild(nestingLevelElem);
431:                        exInfoElem.appendChild(msgLocInfoElem);
432:                        exInfoElem.appendChild(stckTraceElem);
433:                        taskRsltDtlsElem.appendChild(exInfoElem);
434:
435:                    } else {
436:                        int nestingLevel = 1;
437:                        Element[] exInfoElem = new Element[MAX_NESTING_LEVEL];
438:                        Element[] msgLocInfoElem = new Element[MAX_NESTING_LEVEL];
439:                        Element[] locTokenElem = new Element[MAX_NESTING_LEVEL];
440:                        Element[] locMessageElem = new Element[MAX_NESTING_LEVEL];
441:                        Element[] nestingLevelElem = new Element[MAX_NESTING_LEVEL];
442:                        Element[] stckTraceElem = new Element[MAX_NESTING_LEVEL];
443:
444:                        while (exObj != null) {
445:                            exInfoElem[nestingLevel] = doc
446:                                    .createElement("exception-info");
447:                            msgLocInfoElem[nestingLevel] = doc
448:                                    .createElement("msg-loc-info");
449:                            locTokenElem[nestingLevel] = doc
450:                                    .createElement("loc-token");
451:                            locMessageElem[nestingLevel] = doc
452:                                    .createElement("loc-message");
453:                            nestingLevelElem[nestingLevel] = doc
454:                                    .createElement("nesting-level");
455:                            stckTraceElem[nestingLevel] = doc
456:                                    .createElement("stack-trace");
457:
458:                            StackTraceElement[] stckTrElem = exObj
459:                                    .getStackTrace();
460:                            StringBuffer sb = new StringBuffer("");
461:                            if (stckTrElem != null) {
462:                                for (int i = 0; i < stckTrElem.length; i++) {
463:                                    String stckTrace = stckTrElem[i].toString();
464:                                    sb.append(stckTrace);
465:                                    sb.append("\n");
466:                                }
467:                            }
468:
469:                            if (nestingLevel == 1) {
470:                                DOMUtil.UTIL.setTextData(
471:                                        locTokenElem[nestingLevel], locToken);
472:                                if (locMessage == null)
473:                                    DOMUtil.UTIL.setTextData(
474:                                            locMessageElem[nestingLevel], exObj
475:                                                    .getMessage());
476:                                else {
477:                                    if (exObj.getMessage().endsWith(locMessage)) {
478:                                        DOMUtil.UTIL.setTextData(
479:                                                locMessageElem[nestingLevel],
480:                                                locMessage);
481:                                    } else {
482:                                        DOMUtil.UTIL.setTextData(
483:                                                locMessageElem[nestingLevel],
484:                                                locMessage + " "
485:                                                        + exObj.getMessage());
486:                                    }
487:                                }
488:                            } else {
489:                                String errMsgWithToken = exObj.getMessage();
490:                                String token;
491:                                String errMsg = null;
492:                                if (MessageBuilder
493:                                        .isLocalizedMessage(errMsgWithToken)) {
494:                                    token = MessageBuilder
495:                                            .getMessageToken(errMsgWithToken);
496:                                    errMsg = MessageBuilder
497:                                            .getMessageString(errMsgWithToken);
498:                                } else {
499:                                    token = missingDataStr;
500:                                    errMsg = errMsgWithToken;
501:                                }
502:
503:                                DOMUtil.UTIL.setTextData(
504:                                        locTokenElem[nestingLevel], token);
505:                                DOMUtil.UTIL.setTextData(
506:                                        locMessageElem[nestingLevel], errMsg);
507:
508:                            }
509:
510:                            DOMUtil.UTIL.setTextData(
511:                                    nestingLevelElem[nestingLevel], Integer
512:                                            .toString(nestingLevel));
513:                            DOMUtil.UTIL.setTextData(
514:                                    stckTraceElem[nestingLevel], sb.toString());
515:
516:                            msgLocInfoElem[nestingLevel]
517:                                    .appendChild(locTokenElem[nestingLevel]);
518:                            msgLocInfoElem[nestingLevel]
519:                                    .appendChild(locMessageElem[nestingLevel]);
520:
521:                            if (nestingLevel == 1) {
522:                                if (locParam != null) {
523:                                    Element[] locParamElem = new Element[32];
524:                                    for (int i = 0; i < locParam.length; i++) {
525:                                        locParamElem[i] = doc
526:                                                .createElement("loc-param");
527:                                        DOMUtil.UTIL.setTextData(
528:                                                locParamElem[i], locParam[i]);
529:                                        msgLocInfoElem[nestingLevel]
530:                                                .appendChild(locParamElem[i]);
531:                                    }
532:
533:                                }
534:                            } else {
535:                                Element locParamElement = doc
536:                                        .createElement("loc-param");
537:                                DOMUtil.UTIL.setTextData(locParamElement,
538:                                        missingDataStr);
539:                                msgLocInfoElem[nestingLevel]
540:                                        .appendChild(locParamElement);
541:
542:                            }
543:
544:                            exInfoElem[nestingLevel]
545:                                    .appendChild(nestingLevelElem[nestingLevel]);
546:                            exInfoElem[nestingLevel]
547:                                    .appendChild(msgLocInfoElem[nestingLevel]);
548:                            exInfoElem[nestingLevel]
549:                                    .appendChild(stckTraceElem[nestingLevel]);
550:                            taskRsltDtlsElem
551:                                    .appendChild(exInfoElem[nestingLevel]);
552:
553:                            nestingLevel++;
554:                            exObj = exObj.getCause();
555:                        }
556:                    }
557:
558:                } catch (Exception e) {
559:                    e.printStackTrace();
560:                    throw e;
561:                }
562:
563:                return taskRsltDtlsElem;
564:
565:            }
566:
567:            /**
568:             * Constructs an XML string of the component exception.
569:             * @param params HashMap containing component exception information 
570:             * @return XML string representing component exception
571:             * @throws Exception If fails to build component exception message
572:             *
573:             */
574:            public String buildComponentTaskExceptionMessage(
575:                    ComponentMessageHolder mmObj) throws Exception {
576:
577:                String cmpStatMsg = null;
578:                Document doc = null;
579:
580:                try {
581:
582:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
583:                            .newInstance();
584:                    DocumentBuilder db = dbf.newDocumentBuilder();
585:                    doc = db.newDocument();
586:                    Element elem = doc.createElement("component-task-result");
587:                    Element compNameElem = doc.createElement("component-name");
588:                    Element compTaskRsltDtlsElem = doc
589:                            .createElement("component-task-result-details");
590:
591:                    String componentName = mmObj.getComponentName();
592:                    if (componentName == null) {
593:                        /* Note : Since this is a helper class which can
594:                         * be instantiated by the component, JBI resource
595:                         * bundle cannot be used. Hence strings are hard coded.
596:                         */
597:                        String errMsg = "JBIMA0457: BuildManagementMessage : Component name cannot be null ";
598:                        mLogger.warning(errMsg);
599:                        throw new Exception(errMsg);
600:                    }
601:                    DOMUtil.UTIL.setTextData(compNameElem, componentName);
602:
603:                    Element taskRsltDtlsElem = buildExceptionXMLFragment(doc,
604:                            mmObj);
605:
606:                    compTaskRsltDtlsElem.appendChild(taskRsltDtlsElem);
607:                    elem.appendChild(compNameElem);
608:                    elem.appendChild(compTaskRsltDtlsElem);
609:                    doc.appendChild(elem);
610:                    StringWriter sw = new StringWriter();
611:                    cmpStatMsg = DOMUtil.UTIL.DOM2String(doc, sw);
612:
613:                } catch (Exception e) {
614:                    throw e;
615:                }
616:
617:                return cmpStatMsg;
618:            }
619:
620:            /**
621:             * Constructs an XML string of the framework exception.
622:             * @param doc Document that needs to be built
623:             * @param params HashMap containing component exception information 
624:             * @return XML string representing framework exception
625:             * @throws Exception If fails to build framework exception message
626:             *
627:             */
628:            public Element buildFrameworkExceptionMessage(Document doc,
629:                    ManagementMessageHolder mmObj) throws Exception {
630:
631:                Element elem = null;
632:
633:                try {
634:                    String isCauseFrmwk = mmObj.isCauseFramework();
635:                    if (isCauseFrmwk == null)
636:                        isCauseFrmwk = missingDataStr;
637:
638:                    String frmwkLocale = mmObj.getFrameworkLocale();
639:                    if (frmwkLocale == null) {
640:                        /* Note : Since this is a helper class which can
641:                         * be instantiated by the component, JBI resource
642:                         * bundle cannot be used. Hence strings are hard coded. 
643:                         */
644:                        String errMsg = "JBIMA0454: BuildManagementMessage : Framework Locale cannot be null ";
645:                        mLogger.warning(errMsg);
646:                        throw new Exception(errMsg);
647:                        /*
648:                        throw new Exception(
649:                            "Cannot build Framework Exception Message. Framework Locale not set. ");
650:                         */
651:                    }
652:
653:                    elem = doc.createElement("frmwk-task-result");
654:                    Element frmwkTaskRsltDtlsElem = doc
655:                            .createElement("frmwk-task-result-details");
656:                    Element frmwkLocaleElem = doc.createElement("locale");
657:                    Element isCauseFrmwkElem = doc
658:                            .createElement("is-cause-framework");
659:                    DOMUtil.UTIL.setTextData(isCauseFrmwkElem, isCauseFrmwk);
660:                    DOMUtil.UTIL.setTextData(frmwkLocaleElem, frmwkLocale);
661:
662:                    Element taskRsltDtlsElem = buildExceptionXMLFragment(doc,
663:                            mmObj);
664:
665:                    frmwkTaskRsltDtlsElem.appendChild(taskRsltDtlsElem);
666:                    frmwkTaskRsltDtlsElem.appendChild(frmwkLocaleElem);
667:                    elem.appendChild(frmwkTaskRsltDtlsElem);
668:                    elem.appendChild(isCauseFrmwkElem);
669:
670:                } catch (Exception e) {
671:                    e.printStackTrace();
672:                    throw e;
673:                }
674:
675:                return elem;
676:
677:            }
678:
679:            /**
680:             * Returns a org.w3c.dom.Element.
681:             * @return org.w3c.dom.Document 
682:             * @throws Exception If fails to build Document
683:             *
684:             */
685:            public Document createDocument() throws Exception {
686:
687:                Document doc = null;
688:
689:                try {
690:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
691:                            .newInstance();
692:                    DocumentBuilder db = dbf.newDocumentBuilder();
693:                    doc = db.newDocument();
694:                } catch (Exception e) {
695:                    e.printStackTrace();
696:                    throw e;
697:                }
698:
699:                return doc;
700:            }
701:
702:            /**
703:             * Constructs an XML string of the framework exception.
704:             * @param taskName name of the task
705:             * @param stckTrElem Array of StackTraceElements 
706:             * @param jbiExLocToken Error message token
707:             * @param jbiExLocMessage Framework error message
708:             * @return XML string representing framework exception message
709:             *
710:             */
711:            public String buildCompleteExceptionMessage(
712:                    ManagementMessageHolder mmObj) {
713:                String jbiTaskStr = null;
714:
715:                /*
716:                HashMap params = new HashMap ();
717:                params.put ("ISCAUSEFRAMEWORK", mmObj.isCauseFramework());
718:                params.put ("FRMWKLOCALE", mmObj.getFrameworkLocale());
719:                params.put ("TASKID", mmObj.getTaskName());
720:                params.put ("TASKRESULT", mmObj.getTaskResult());
721:                params.put ("LOCTOKEN", mmObj.getLocToken(1));
722:                params.put ("LOCPARAM", mmObj.getLocParam(1));
723:                params.put ("LOCMESSAGE", mmObj.getLocMessage(1));
724:                params.put ("EXCEPTIONOBJECT", mmObj.getExceptionObject());
725:                 */
726:
727:                jbiTaskStr = buildJbiTask(mmObj);
728:
729:                return jbiTaskStr;
730:
731:            }
732:
733:            /**
734:             * Constructs an XML string of the framework exception.
735:             * @param params HashMap containing framework exception information 
736:             * @return XML string representing framework exception
737:             *
738:             */
739:            public String buildJbiTask(ManagementMessageHolder mmObj) {
740:                String jbiTask = null;
741:
742:                try {
743:
744:                    Document doc = createDocument();
745:                    Element elem = doc.createElement("jbi-task");
746:                    elem.setAttribute("version", "1.0");
747:                    elem
748:                            .setAttribute("xmlns",
749:                                    "http://java.sun.com/xml/ns/jbi/management-message");
750:                    elem.setAttribute("xmlns:xsi",
751:                            "http://www.w3.org/2001/XMLSchema-instance");
752:                    elem
753:                            .setAttribute("xsi:schemaLocation",
754:                                    "http://java.sun.com/xml/ns/jbi/management-message ./managementMessage.xsd");
755:                    Element jbiTaskRsltElem = doc
756:                            .createElement("jbi-task-result");
757:                    mmObj.setCauseFramework(true);
758:                    Element frmwkExElem = buildFrameworkExceptionMessage(doc,
759:                            mmObj);
760:                    elem.appendChild(jbiTaskRsltElem);
761:                    jbiTaskRsltElem.appendChild(frmwkExElem);
762:                    doc.appendChild(elem);
763:                    StringWriter sw = new StringWriter();
764:                    jbiTask = DOMUtil.UTIL.DOM2String(doc, sw);
765:
766:                    // Validate management message
767:                    XmlReader xmlRdr = new XmlReader();
768:                    boolean isValidJbiXml = xmlRdr
769:                            .validateManagementMessage(jbiTask);
770:                    if (!isValidJbiXml) {
771:                        String errMsg = "JBIMA0591: BuildManagementMessage : Validation of management message failed ";
772:                        mLogger.warning(errMsg);
773:                        throw new Exception(errMsg);
774:                    }
775:
776:                } catch (Exception e) {
777:                    e.printStackTrace();
778:                }
779:
780:                return jbiTask;
781:
782:            }
783:
784:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.