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