KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > or > jms > MessageRenderer


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.log4j.or.jms;
18
19 import org.apache.log4j.helpers.LogLog;
20 import org.apache.log4j.or.ObjectRenderer;
21
22 import javax.jms.Message JavaDoc;
23 import javax.jms.JMSException JavaDoc;
24 import javax.jms.DeliveryMode JavaDoc;
25
26 /**
27    Render <code>javax.jms.Message</code> objects.
28
29    @author Ceki G&uuml;lc&uuml;
30    @since 1.0 */

31 public class MessageRenderer implements ObjectRenderer {
32
33   public
34   MessageRenderer() {
35   }
36
37
38   /**
39      Render a {@link javax.jms.Message}.
40   */

41   public
42   String JavaDoc doRender(Object JavaDoc o) {
43     if(o instanceof Message JavaDoc) {
44       StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc();
45       Message JavaDoc m = (Message JavaDoc) o;
46       try {
47     sbuf.append("DeliveryMode=");
48     switch(m.getJMSDeliveryMode()) {
49     case DeliveryMode.NON_PERSISTENT :
50       sbuf.append("NON_PERSISTENT");
51       break;
52     case DeliveryMode.PERSISTENT :
53       sbuf.append("PERSISTENT");
54       break;
55     default: sbuf.append("UNKNOWN");
56     }
57     sbuf.append(", CorrelationID=");
58     sbuf.append(m.getJMSCorrelationID());
59
60     sbuf.append(", Destination=");
61     sbuf.append(m.getJMSDestination());
62
63     sbuf.append(", Expiration=");
64     sbuf.append(m.getJMSExpiration());
65
66     sbuf.append(", MessageID=");
67     sbuf.append(m.getJMSMessageID());
68
69     sbuf.append(", Priority=");
70     sbuf.append(m.getJMSPriority());
71
72     sbuf.append(", Redelivered=");
73     sbuf.append(m.getJMSRedelivered());
74
75     sbuf.append(", ReplyTo=");
76     sbuf.append(m.getJMSReplyTo());
77
78     sbuf.append(", Timestamp=");
79     sbuf.append(m.getJMSTimestamp());
80
81     sbuf.append(", Type=");
82     sbuf.append(m.getJMSType());
83
84     //Enumeration enum = m.getPropertyNames();
85
//while(enum.hasMoreElements()) {
86
// String key = (String) enum.nextElement();
87
// sbuf.append("; "+key+"=");
88
// sbuf.append(m.getStringProperty(key));
89
//}
90

91       } catch(JMSException JavaDoc e) {
92     LogLog.error("Could not parse Message.", e);
93       }
94       return sbuf.toString();
95     } else {
96       return o.toString();
97     }
98   }
99 }
100
Popular Tags