001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.log4j.or.jms; 019 020import org.apache.log4j.helpers.LogLog; 021import org.apache.log4j.or.ObjectRenderer; 022 023import javax.jms.Message; 024import javax.jms.JMSException; 025import javax.jms.DeliveryMode; 026 027/** 028 Render <code>javax.jms.Message</code> objects. 029 030 @author Ceki Gülcü 031 @since 1.0 */ 032public class MessageRenderer implements ObjectRenderer { 033 034 public 035 MessageRenderer() { 036 } 037 038 039 /** 040 Render a {@link javax.jms.Message}. 041 */ 042 public 043 String doRender(Object o) { 044 if(o instanceof Message) { 045 StringBuffer sbuf = new StringBuffer(); 046 Message m = (Message) o; 047 try { 048 sbuf.append("DeliveryMode="); 049 switch(m.getJMSDeliveryMode()) { 050 case DeliveryMode.NON_PERSISTENT : 051 sbuf.append("NON_PERSISTENT"); 052 break; 053 case DeliveryMode.PERSISTENT : 054 sbuf.append("PERSISTENT"); 055 break; 056 default: sbuf.append("UNKNOWN"); 057 } 058 sbuf.append(", CorrelationID="); 059 sbuf.append(m.getJMSCorrelationID()); 060 061 sbuf.append(", Destination="); 062 sbuf.append(m.getJMSDestination()); 063 064 sbuf.append(", Expiration="); 065 sbuf.append(m.getJMSExpiration()); 066 067 sbuf.append(", MessageID="); 068 sbuf.append(m.getJMSMessageID()); 069 070 sbuf.append(", Priority="); 071 sbuf.append(m.getJMSPriority()); 072 073 sbuf.append(", Redelivered="); 074 sbuf.append(m.getJMSRedelivered()); 075 076 sbuf.append(", ReplyTo="); 077 sbuf.append(m.getJMSReplyTo()); 078 079 sbuf.append(", Timestamp="); 080 sbuf.append(m.getJMSTimestamp()); 081 082 sbuf.append(", Type="); 083 sbuf.append(m.getJMSType()); 084 085 //Enumeration enum = m.getPropertyNames(); 086 //while(enum.hasMoreElements()) { 087 // String key = (String) enum.nextElement(); 088 // sbuf.append("; "+key+"="); 089 // sbuf.append(m.getStringProperty(key)); 090 //} 091 092 } catch(JMSException e) { 093 LogLog.error("Could not parse Message.", e); 094 } 095 return sbuf.toString(); 096 } else { 097 return o.toString(); 098 } 099 } 100}