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