1 23 package com.sun.appserv.management.ext.logging; 24 25 import java.util.Map ; 26 import java.util.HashMap ; 27 import java.util.Date ; 28 import java.util.logging.Level ; 29 30 import com.sun.appserv.management.util.misc.ArrayUtil; 31 import com.sun.appserv.management.util.misc.ObjectUtil; 32 33 import static com.sun.appserv.management.ext.logging.LogRecordFields.*; 34 35 37 42 public final class LogQueryEntryImpl 43 implements LogQueryEntry 44 { 45 private transient Map <String ,String > mNameValuePairsMap; 46 47 final long mRecordNumber; 48 final Date mDate; 49 final String mLevel; 50 final String mProductName; 51 final String mMessage; 52 final String mMessageID; 53 final String mModule; 54 final String mNameValuePairs; 55 56 public 57 LogQueryEntryImpl( 58 final long recordNumber, 59 final Date date, 60 final String level, 61 final String productName, 62 final String message, 63 final String messageID, 64 final String module, 65 final String nameValuePairs) 66 { 67 if ( date == null || level == null || message == null || 68 module == null || nameValuePairs == null ) 69 { 70 throw new IllegalArgumentException (); 71 } 72 73 mRecordNumber = recordNumber; 74 mDate = date; 75 mLevel = Level.parse( level ).toString(); 76 mProductName = productName; 77 mModule = module; 78 mMessage = message; 79 mMessageID = messageID; 80 mNameValuePairs = nameValuePairs; 81 } 82 83 public 84 LogQueryEntryImpl( final Object [] values ) 85 { 86 if ( values.length != NUM_FIELDS ) 87 { 88 throw new IllegalArgumentException ( "wrong number of fields: " + values.length); 89 } 90 91 mRecordNumber = (Long )values[ RECORD_NUMBER_INDEX ]; 92 mDate = (Date )values[ DATE_INDEX ]; 93 mLevel = Level.parse( (String )values[ LEVEL_INDEX ] ).toString(); 94 mProductName = (String )values[ PRODUCT_NAME_INDEX ]; 95 mMessageID = (String )values[ MESSAGE_ID_INDEX ]; 96 mModule = (String )values[ MODULE_INDEX ]; 97 mMessage = (String )values[ MESSAGE_INDEX ]; 98 mNameValuePairs = (String )values[ NAME_VALUE_PAIRS_INDEX ]; 99 } 100 101 public Object [] 102 getFields() 103 { 104 final Object [] fields = new Object [ NUM_FIELDS ]; 105 106 fields[ RECORD_NUMBER_INDEX ] = mRecordNumber; 107 fields[ DATE_INDEX ] = mDate; 108 fields[ LEVEL_INDEX ] = mLevel; 109 fields[ PRODUCT_NAME_INDEX ] = mProductName; 110 fields[ MESSAGE_ID_INDEX ] = mMessageID; 111 fields[ MODULE_INDEX ] = mModule; 112 fields[ MESSAGE_INDEX ] = mMessage; 113 fields[ NAME_VALUE_PAIRS_INDEX ]= mNameValuePairs; 114 115 return fields; 116 } 117 118 140 141 142 public long 143 getRecordNumber() 144 { 145 return mRecordNumber; 146 } 147 148 public Date 149 getDate() 150 { 151 return mDate; 152 } 153 154 public String 155 getModule() 156 { 157 return mModule; 158 } 159 160 public String 161 getLevel() 162 { 163 return mLevel; 164 } 165 166 public String 167 getProductName() 168 { 169 return mProductName; 170 } 171 172 public String 173 getMessage() 174 { 175 return mMessage; 176 } 177 178 public String 179 getMessageID() 180 { 181 return mMessageID; 182 } 183 184 public String 185 getNameValuePairs() 186 { 187 return mNameValuePairs; 188 } 189 190 191 private static final String NVP_PAIRS_DELIM = ";"; 192 193 private static final String PAIR_DELIM = "="; 194 195 private Map <String ,String > 196 parseNameValuePairs() 197 { 198 final String src = getNameValuePairs(); 199 final Map <String ,String > m = new HashMap <String ,String >(); 200 201 final String [] pairs = src.split( NVP_PAIRS_DELIM ); 202 203 for( String pair : pairs ) 204 { 205 final int idx = pair.indexOf( PAIR_DELIM ); 206 if ( idx < 0 ) 207 { 208 throw new IllegalArgumentException ( src ); 209 } 210 final String name = pair.substring( 0, idx ).trim(); 211 final String value = pair.substring( idx + 1, pair.length() ).trim(); 212 213 m.put( name, value ); 214 } 215 216 return m; 217 } 218 219 public Map <String ,String > 220 getNameValuePairsMap() 221 { 222 if ( mNameValuePairsMap == null ) 223 { 224 mNameValuePairsMap = parseNameValuePairs(); 225 } 226 227 return mNameValuePairsMap; 228 } 229 230 public String 231 getThreadID() 232 { 233 return getNameValuePairsMap().get( THREAD_ID_KEY ); 234 } 235 236 public String 237 getObjectName() 238 { 239 return getNameValuePairsMap().get( OBJECTNAME_KEY ); 240 } 241 242 public String 243 toString() 244 { 245 final String D = "|"; 246 247 return "[#" + 249 getRecordNumber() + D + 250 getDate() + D + 251 getLevel() + D + 252 getProductName() + D + 253 getModule() + D + 254 getNameValuePairs() + D + 255 getMessage() + D + 256 getMessageID() + D + 257 "]"; 258 } 259 260 public int 261 hashCode() 262 { 263 return ObjectUtil.hashCode( mDate, mLevel, 264 mProductName, mMessage, mMessageID, mModule, mNameValuePairs) ^ 265 ObjectUtil.hashCode( mRecordNumber ); 266 } 267 268 public boolean 269 equals( final Object rhs ) 270 { 271 boolean equal = false; 272 273 if ( this == rhs ) 274 { 275 equal = true; 276 } 277 else if ( rhs instanceof LogQueryEntry ) 278 { 279 final LogQueryEntry e = (LogQueryEntry)rhs; 280 281 equal = ArrayUtil.arraysEqual( getFields(), e.getFields() ); 282 } 283 284 return equal; 285 } 286 } 287 288 289 290 291 292 293 | Popular Tags |