1 23 package com.sun.appserv.management.util.jmx.stringifier; 24 25 import java.util.Date ; 26 import javax.management.Notification ; 27 import javax.management.MBeanServerNotification ; 28 29 import com.sun.appserv.management.util.stringifier.Stringifier; 30 import com.sun.appserv.management.util.stringifier.SmartStringifier; 31 import com.sun.appserv.management.util.misc.StringUtil; 32 33 public class NotificationStringifier implements Stringifier 34 { 35 public static final NotificationStringifier DEFAULT = new NotificationStringifier(); 36 37 protected Options mOptions; 38 39 public final static class Options 40 { 41 public boolean mIncludeObjectName; 43 public boolean mIncludeTimeStamp; 44 public boolean mIncludeType; 45 public boolean mIncludeSequenceNumber; 46 public boolean mIncludeUserData; 47 public String mDelim; 48 49 public 50 Options() 51 { 52 mIncludeObjectName = true; 53 mIncludeTimeStamp = true; 54 mIncludeType = true; 55 mIncludeSequenceNumber = true; 56 mIncludeUserData = false; 57 mDelim = ", "; 58 } 59 60 } 61 62 63 public 64 NotificationStringifier( ) 65 { 66 mOptions = new Options(); 67 } 68 69 public 70 NotificationStringifier( Options options ) 71 { 72 mOptions = options; 73 } 74 75 protected void 76 append( StringBuffer b, Object o) 77 { 78 if ( b.length() != 0 ) 79 { 80 b.append( mOptions.mDelim ); 81 } 82 83 b.append( SmartStringifier.toString( o ) ); 84 } 85 86 public String 87 stringify( Object o ) 88 { 89 final Notification notif = (Notification )o; 90 91 return( _stringify( notif ).toString() ); 92 } 93 94 public static String 95 toString( Object o ) 96 { 97 return( DEFAULT.stringify( o ) ); 98 } 99 100 protected StringBuffer 101 _stringify( Notification notif ) 102 { 103 final StringBuffer b = new StringBuffer (); 104 105 if ( mOptions.mIncludeSequenceNumber ) 106 { 107 append( b, "#" + notif.getSequenceNumber() ); 108 } 109 110 if ( mOptions.mIncludeTimeStamp ) 111 { 112 append( b, new Date ( notif.getTimeStamp() ) ); 113 } 114 115 if ( mOptions.mIncludeObjectName ) 116 { 117 append( b, StringUtil.quote( notif.getSource() ) ); 118 } 119 120 if ( mOptions.mIncludeType ) 121 { 122 append( b, notif.getType() ); 123 } 124 125 if ( mOptions.mIncludeUserData ) 126 { 127 append( b, StringUtil.quote( notif.getUserData() ) ); 128 } 129 130 if ( notif instanceof MBeanServerNotification ) 131 { 132 final MBeanServerNotification n = (MBeanServerNotification )notif; 134 135 append( b, StringUtil.quote( n.getMBeanName() ) ); 136 } 137 138 return( b ); 139 } 140 } 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | Popular Tags |