KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > component > common > util > ManagementMessageUtil


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: InstallationService.java 154 2006-03-27 15:30:10Z ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.component.common.util;
23
24 /**
25  * This class gathers the dtd used for the management message
26  *
27  * @author ddesjardins - eBMWebsourcing
28  */

29 public class ManagementMessageUtil {
30
31     public static final String JavaDoc TASK_RESULT_FAILED = "FAILED";
32
33     public static final String JavaDoc TASK_RESULT_SUCCESS = "SUCCESS";
34
35     public static final String JavaDoc MESSAGE_TYPE_ERROR = "ERROR";
36
37     public static final String JavaDoc MESSAGE_TYPE_WARNING = "WARNING";
38
39     public static final String JavaDoc MESSAGE_TYPE_INFO = "INFO";
40
41     private static final String JavaDoc XMLNS = "http://java.sun.com/xml/ns/jbi/management-message";
42
43     private static final String JavaDoc TASK_RESULT_DETAILS = "task-result-details";
44
45     private static final String JavaDoc TASK_ID = "task-id";
46
47     private static final String JavaDoc TASK_RESULT = "task-result";
48
49     private static final String JavaDoc MESSAGE_TYPE = "message-type";
50
51     private static final String JavaDoc EXCEPTION_INFO = "exception-info";
52
53     private static final String JavaDoc NESTING_LEVEL = "nesting-level";
54
55     private static final String JavaDoc MSG_LOC_INFO = "msg-loc-info";
56
57     private static final String JavaDoc LOC_TOKEN = "loc-token";
58
59     private static final String JavaDoc LOC_MESSAGE = "loc-message";
60
61     private static final String JavaDoc LOC_PARAM = "loc-param";
62
63     private static final String JavaDoc STACK_TRACE = "stack-trace";
64
65     private static final String JavaDoc COMPONENT_TASK_RESULT = "component-task-result";
66
67     private static final String JavaDoc COMPONENT_TASK_RESULT_DETAILS = "component-task-result-details";
68
69     private static final String JavaDoc COMPONENT_NAME = "component-name";
70
71     /**
72      * Return a component task result xml
73      *
74      * @param componentName
75      * component name
76      * @param taskId
77      * id of the task
78      * @param taskResult
79      * result of the task
80      * @return xml string
81      */

82     public static String JavaDoc getComponentTaskResult(String JavaDoc componentName,
83             String JavaDoc taskId, String JavaDoc taskResult) {
84         return ManagementMessageUtil.getComponentTaskResult(componentName,
85                 taskId, taskResult, null, null, null, null, null, null, null);
86     }
87
88     /**
89      * Return a component task result xml
90      *
91      * @param componentName
92      * component name
93      * @param taskId
94      * id of the task
95      * @param taskResult
96      * result of the task
97      * @param messageType
98      * type of message
99      * @param nestingLevel
100      * nesting level of the exception
101      * @param exceptionMessage
102      * message of the exception
103      * @param exceptionMessageParams
104      * list of the param for the exception message
105      * @param stackStrace
106      * stacktrace
107      * @return xml string
108      */

109     public static String JavaDoc getComponentTaskResult(String JavaDoc componentName,
110             String JavaDoc taskId, String JavaDoc taskResult, String JavaDoc messageType,
111             String JavaDoc nestingLevel, String JavaDoc exceptionMessage,
112             String JavaDoc[] exceptionMessageParams, String JavaDoc stackStrace) {
113         return getComponentTaskResult(componentName, taskId, taskResult,
114                 messageType, null, null, nestingLevel, exceptionMessage,
115                 exceptionMessageParams, stackStrace);
116     }
117
118     /**
119      * Return a component task result xml
120      *
121      * @param componentName
122      * component name
123      * @param taskId
124      * id of the task
125      * @param taskResult
126      * result of the task
127      * @param messageType
128      * type of message
129      * @param message
130      * message
131      * @param messageParams
132      * list of param for the message
133      * @return xml string
134      */

135     public static String JavaDoc getComponentTaskResult(String JavaDoc componentName,
136             String JavaDoc taskId, String JavaDoc taskResult, String JavaDoc messageType,
137             String JavaDoc message, String JavaDoc[] messageParams) {
138         return getComponentTaskResult(componentName, taskId, taskResult,
139                 messageType, message, messageParams, null, null, null, null);
140     }
141
142     /**
143      * Return a component task result xml
144      *
145      * @param componentName
146      * component name
147      * @param taskId
148      * id of the task
149      * @param taskResult
150      * result of the task
151      * @param messageType
152      * type of message
153      * @param message
154      * message
155      * @param messageParams
156      * list of param for the message
157      * @param nestingLevel
158      * nesting level of the exception
159      * @param exceptionMessage
160      * message of the exception
161      * @param exceptionMessageParams
162      * list of the param for the exception message
163      * @param stackStrace
164      * stacktrace
165      * @return xml string
166      */

167     public static String JavaDoc getComponentTaskResult(String JavaDoc componentName,
168             String JavaDoc taskId, String JavaDoc taskResult, String JavaDoc messageType,
169             String JavaDoc message, String JavaDoc[] messageParams, String JavaDoc nestingLevel,
170             String JavaDoc exceptionMessage, String JavaDoc[] exceptionMessageParams,
171             String JavaDoc stackStrace) {
172         StringBuffer JavaDoc xmlInput = new StringBuffer JavaDoc();
173         xmlInput.append("\t\t<" + ManagementMessageUtil.COMPONENT_TASK_RESULT
174                 + ">\n");
175         xmlInput.append("\t\t\t<" + ManagementMessageUtil.COMPONENT_NAME + ">"
176                 + componentName + "</" + ManagementMessageUtil.COMPONENT_NAME
177                 + ">\n");
178         xmlInput.append("\t\t\t<"
179                 + ManagementMessageUtil.COMPONENT_TASK_RESULT_DETAILS
180                 + " xmlns='" + ManagementMessageUtil.XMLNS + "'>\n");
181         xmlInput.append("\t\t\t\t<" + ManagementMessageUtil.TASK_RESULT_DETAILS
182                 + ">\n");
183         xmlInput.append("\t\t\t\t\t<" + ManagementMessageUtil.TASK_ID + ">"
184                 + taskId + "</" + ManagementMessageUtil.TASK_ID + ">\n");
185         xmlInput
186                 .append("\t\t\t\t\t<" + ManagementMessageUtil.TASK_RESULT + ">"
187                         + taskResult + "</" + ManagementMessageUtil.TASK_RESULT
188                         + ">\n");
189         if (messageType != null) {
190             xmlInput.append("\t\t\t\t\t<" + ManagementMessageUtil.MESSAGE_TYPE
191                     + ">" + messageType + "</"
192                     + ManagementMessageUtil.MESSAGE_TYPE + ">\n");
193             if (message != null) {
194                 xmlInput.append("\t\t\t\t\t<"
195                         + ManagementMessageUtil.MSG_LOC_INFO + ">\n");
196                 // TODO change token with a key message for looking up localized
197
// text
198
// for the message
199
xmlInput.append("\t\t\t\t\t\t<"
200                         + ManagementMessageUtil.LOC_TOKEN + ">jbimsg</"
201                         + ManagementMessageUtil.LOC_TOKEN + ">\n");
202                 xmlInput.append("\t\t\t\t\t\t<"
203                         + ManagementMessageUtil.LOC_MESSAGE + ">" + message
204                         + "</" + ManagementMessageUtil.LOC_MESSAGE + ">\n");
205                 for (String JavaDoc string : messageParams) {
206                     xmlInput.append("\t\t\t\t\t\t<"
207                             + ManagementMessageUtil.LOC_PARAM + ">" + string
208                             + "</" + ManagementMessageUtil.LOC_PARAM + ">\n");
209                 }
210                 xmlInput.append("\t\t\t\t\t</"
211                         + ManagementMessageUtil.MSG_LOC_INFO + ">\n");
212             }
213             if (exceptionMessage != null) {
214                 xmlInput.append("\t\t\t\t\t<"
215                         + ManagementMessageUtil.EXCEPTION_INFO + ">\n");
216                 xmlInput.append("\t\t\t\t\t\t<"
217                         + ManagementMessageUtil.NESTING_LEVEL + ">"
218                         + nestingLevel + "</"
219                         + ManagementMessageUtil.NESTING_LEVEL + ">\n");
220                 xmlInput.append("\t\t\t\t\t\t<"
221                         + ManagementMessageUtil.MSG_LOC_INFO + ">\n");
222                 // TODO change token with a key message for looking up localized
223
// text
224
// for the message
225
xmlInput.append("\t\t\t\t\t\t\t<"
226                         + ManagementMessageUtil.LOC_TOKEN + ">jbimsg</"
227                         + ManagementMessageUtil.LOC_TOKEN + ">\n");
228                 xmlInput.append("\t\t\t\t\t\t\t<"
229                         + ManagementMessageUtil.LOC_MESSAGE + ">"
230                         + exceptionMessage + "</"
231                         + ManagementMessageUtil.LOC_MESSAGE + ">\n");
232                 for (String JavaDoc string : exceptionMessageParams) {
233                     xmlInput.append("\t\t\t\t\t\t\t<"
234                             + ManagementMessageUtil.LOC_PARAM + ">" + string
235                             + "</" + ManagementMessageUtil.LOC_PARAM + ">\n");
236                 }
237                 xmlInput.append("\t\t\t\t\t\t</"
238                         + ManagementMessageUtil.MSG_LOC_INFO + ">\n");
239                 if (stackStrace != null) {
240                     xmlInput.append("\t\t\t\t\t\t<"
241                             + ManagementMessageUtil.STACK_TRACE + ">"
242                             + stackStrace + "</"
243                             + ManagementMessageUtil.STACK_TRACE + ">\n");
244                 }
245                 xmlInput.append("\t\t\t\t</"
246                         + ManagementMessageUtil.EXCEPTION_INFO + ">\n");
247             }
248         }
249         xmlInput.append("\t\t\t\t</"
250                 + ManagementMessageUtil.TASK_RESULT_DETAILS + ">\n");
251         xmlInput.append("\t\t\t</"
252                 + ManagementMessageUtil.COMPONENT_TASK_RESULT_DETAILS + ">\n");
253         xmlInput.append("\t\t</" + ManagementMessageUtil.COMPONENT_TASK_RESULT
254                 + ">\n");
255         return xmlInput.toString();
256     }
257
258 }
259
Popular Tags