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