View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.log4j.or.jms;
19  
20  import org.apache.log4j.helpers.LogLog;
21  import org.apache.log4j.or.ObjectRenderer;
22  
23  import javax.jms.Message;
24  import javax.jms.JMSException;
25  import javax.jms.DeliveryMode;
26  
27  /**
28     Render <code>javax.jms.Message</code> objects.
29  
30     @author Ceki G&uuml;lc&uuml;
31     @since 1.0 */
32  public class MessageRenderer implements ObjectRenderer {
33  
34    public
35    MessageRenderer() {
36    }
37  
38  
39    /**
40       Render a {@link javax.jms.Message}.
41    */
42    public
43    String  doRender(Object o) {
44      if(o instanceof Message) {
45        StringBuffer sbuf = new StringBuffer();
46        Message m = (Message) o;
47        try {
48  	sbuf.append("DeliveryMode=");
49  	switch(m.getJMSDeliveryMode()) {
50  	case DeliveryMode.NON_PERSISTENT :
51  	  sbuf.append("NON_PERSISTENT");
52  	  break;
53  	case DeliveryMode.PERSISTENT :
54  	  sbuf.append("PERSISTENT");
55  	  break;
56  	default: sbuf.append("UNKNOWN");
57  	}
58  	sbuf.append(", CorrelationID=");
59  	sbuf.append(m.getJMSCorrelationID());
60  
61  	sbuf.append(", Destination=");
62  	sbuf.append(m.getJMSDestination());
63  
64  	sbuf.append(", Expiration=");
65  	sbuf.append(m.getJMSExpiration());
66  
67  	sbuf.append(", MessageID=");
68  	sbuf.append(m.getJMSMessageID());
69  
70  	sbuf.append(", Priority=");
71  	sbuf.append(m.getJMSPriority());
72  
73  	sbuf.append(", Redelivered=");
74  	sbuf.append(m.getJMSRedelivered());
75  
76  	sbuf.append(", ReplyTo=");
77  	sbuf.append(m.getJMSReplyTo());
78  
79  	sbuf.append(", Timestamp=");
80  	sbuf.append(m.getJMSTimestamp());
81  
82  	sbuf.append(", Type=");
83  	sbuf.append(m.getJMSType());
84  
85  	//Enumeration enum = m.getPropertyNames();
86  	//while(enum.hasMoreElements()) {
87  	//  String key = (String) enum.nextElement();
88  	//  sbuf.append("; "+key+"=");
89  	//  sbuf.append(m.getStringProperty(key));
90  	//}
91  
92        } catch(JMSException e) {
93  	LogLog.error("Could not parse Message.", e);
94        }
95        return sbuf.toString();
96      } else {
97        return o.toString();
98      }
99    }
100 }