1 23 24 package com.sun.enterprise.util.diagnostics; 25 26 import java.io.*; 27 import java.util.*; 28 import com.sun.enterprise.util.Assertion; 29 import java.util.logging.Logger ; 31 import java.util.logging.Level ; 32 import com.sun.logging.LogDomains; 33 35 43 44 public class ReporterImpl implements IReporterEnum 45 { 46 47 static Logger _logger=LogDomains.getLogger(LogDomains.UTIL_LOGGER); 49 public ReporterImpl() 51 { 52 ctor(null, -1); 53 } 54 55 57 ReporterImpl(int theSeverityLevel) 58 { 59 ctor(null, theSeverityLevel); 60 } 61 62 64 public ReporterImpl(String sid) 65 { 66 ctor(sid, -1); 67 } 68 69 71 ReporterImpl(String sid, int theSeverityLevel) 72 { 73 ctor(sid, theSeverityLevel); 74 } 75 76 82 public void setSeverityLevel(int level) 83 { 84 debug("setSeverityLevel(" + level + ")"); 86 if(level < 0) 87 level = 0; 88 89 severityLevel = level; 90 } 91 92 94 public void setSeverityLevel(String level) 95 { 96 debug("setSeverityLevel(" + level + ")"); 98 severityLevel = calcSeverityLevel(level); 99 } 100 101 103 public int getSeverityLevel() 104 { 105 return severityLevel; 106 } 107 108 110 public String getSeverityLevelString() 111 { 112 if(severityLevel <= OFF) 113 return severityNames[severityLevel]; 114 115 return severityNames[OFF]; 116 } 117 118 120 public void setName(String theName) 121 { 122 Assertion.check(theName); 123 name = theName; 124 } 125 126 128 public String getName() 129 { 130 return name; 131 } 132 133 139 public void verbose(Object o) 140 { 141 if(checkSeverity(VERBOSE)) 142 pr(VERBOSE, o); 143 } 144 145 147 public void info(Object o) 148 { 149 if(checkSeverity(INFO)) 150 pr(INFO, o); 151 } 152 153 155 public void warn(Object o) 156 { 157 if(checkSeverity(WARN)) 159 pr(WARNING, o); 160 } 161 162 164 public void warning(Object o) 165 { 166 if(checkSeverity(WARN)) 167 pr(WARNING, o); 168 } 169 170 172 public void error(Object o) 173 { 174 if(checkSeverity(ERROR)) 175 pr(ERROR, o); 176 } 177 178 180 public void critical(Object o) 181 { 182 if(checkSeverity(CRIT)) 183 pr(CRITICAL, o); 184 } 185 187 public void crit(Object o) 188 { 189 if(checkSeverity(CRIT)) 190 pr(CRITICAL, o); 191 } 192 193 195 public void dump(Object o, String s) 196 { 197 if(checkSeverity(DUMP) && o != null) 198 { 199 if(s == null) 200 s = ""; 201 202 String s2 = s + "\n********** Object Dump Start ***********\n" + ObjectAnalyzer.toStringWithSuper(o) + "\n********** Object Dump End ***********"; pr(OBJECT_DUMP, s2); 205 } 206 } 207 208 210 public void dump(String s) 211 { 212 if(checkSeverity(DUMP)) 213 { 214 pr(OBJECT_DUMP, s); 215 } 216 } 217 218 219 221 public void dump(Object o) 222 { 223 dump(o, null); 224 } 225 226 232 235 public void insist(String s) 236 { 237 if(checkSeverity(ASSERT)) 238 { 239 try 240 { 241 Assertion.check(s); 242 } 243 catch(Assertion.Failure f) 244 { 245 pr(ASSERT, new StackTrace().toString() + f); 246 throw f; 247 } 248 } 249 } 250 251 253 public void insist(String checkme, String s) 254 { 255 if(checkSeverity(ASSERT)) 256 { 257 try 258 { 259 Assertion.check(checkme, s); 260 } 261 catch(Assertion.Failure f) 262 { 263 pr(ASSERT, new StackTrace().toString() + f); 264 throw f; 265 } 266 } 267 } 268 269 271 public void insist(boolean b) 272 { 273 if(checkSeverity(ASSERT)) 274 { 275 try 276 { 277 Assertion.check(b); 278 } 279 catch(Assertion.Failure f) 280 { 281 pr(ASSERT, new StackTrace().toString() + f); 282 throw f; 283 } 284 } 285 } 286 287 289 public void insist(boolean b, String s) 290 { 291 if(checkSeverity(ASSERT)) 292 { 293 try 294 { 295 Assertion.check(b, s); 296 } 297 catch(Assertion.Failure f) 298 { 299 pr(ASSERT, new StackTrace().toString() + f); 300 throw f; 301 } 302 } 303 } 304 305 307 public void insist(Object o) 308 { 309 if(checkSeverity(ASSERT)) 310 { 311 try 312 { 313 Assertion.check(o); 314 } 315 catch(Assertion.Failure f) 316 { 317 pr(ASSERT, new StackTrace().toString() + f); 318 throw f; 319 } 320 } 321 } 322 323 325 public void insist(Object o, String s) 326 { 327 if(checkSeverity(ASSERT)) 328 { 329 try 330 { 331 Assertion.check(o, s); 332 } 333 catch(Assertion.Failure f) 334 { 335 pr(ASSERT, new StackTrace().toString() + f); 336 throw f; 337 } 338 } 339 } 340 341 343 public void insist(double z) 344 { 345 if(checkSeverity(ASSERT)) 346 { 347 try 348 { 349 Assertion.check(z); 350 } 351 catch(Assertion.Failure f) 352 { 353 pr(ASSERT, new StackTrace().toString() + f); 354 throw f; 355 } 356 } 357 } 358 359 361 public void insist(double z, String s) 362 { 363 if(checkSeverity(ASSERT)) 364 { 365 try 366 { 367 Assertion.check(z, s); 368 } 369 catch(Assertion.Failure f) 370 { 371 pr(ASSERT, new StackTrace().toString() + f); 372 throw f; 373 } 374 } 375 } 376 377 379 public void insist(long l) 380 { 381 if(checkSeverity(ASSERT)) 382 { 383 try 384 { 385 Assertion.check(l); 386 } 387 catch(Assertion.Failure f) 388 { 389 pr(ASSERT, new StackTrace().toString() + f); 390 throw f; 391 } 392 } 393 } 394 395 397 public void insist(long l, String s) 398 { 399 if(checkSeverity(ASSERT)) 400 { 401 try 402 { 403 Assertion.check(l, s); 404 } 405 catch(Assertion.Failure f) 406 { 407 pr(ASSERT, new StackTrace().toString() + f); 408 throw f; 409 } 410 } 411 } 412 413 417 public ReporterWriter setWriter(ReporterWriter lwriter) { 418 ReporterWriter retVal = null; 419 if (null != lwriter) { 420 retVal = this.writer; 421 this.writer = lwriter; 422 } 423 return retVal; 424 } 425 426 432 private void ctor(String theName, int theSeverityLevel) 433 { 434 if(theName != null && theName.length() > 0) 435 setName(theName); 436 437 if(theSeverityLevel >= 0) 438 setSeverityLevel(theSeverityLevel); 439 else 440 { 441 String sl = System.getProperty("ForteReporterDebugLevel"); if(sl != null && sl.length() > 0) 443 { 444 setSeverityLevel(sl); 447 } 448 449 sl = System.getProperty("com.iplanet.util.diagnostic.Reporter.severityLevel"); if(sl != null && sl.length() > 0) 451 { 452 setSeverityLevel(sl); 455 } 456 457 sl = System.getProperty("com.sun.enterprise.util.diagnostic.Reporter.severityLevel"); if(sl != null && sl.length() > 0) 459 { 460 setSeverityLevel(sl); 463 } 464 465 sl = System.getProperty("Reporter"); if(sl != null && sl.length() > 0) 467 { 468 setSeverityLevel(sl); 471 } 472 } 473 474 className = getClass().getName(); 475 writer = new ReporterWriter(getName()); 476 477 debug("Ctor called"); debug("ReporterImpl Severity Level: " + getSeverityLevel()); } 480 481 483 private boolean checkSeverity(int severity) 484 { 485 if(severity >= severityLevel) 486 return true; 487 488 return false; 489 } 490 491 493 private CallerInfo getCallerInfo() 494 { 495 try 496 { 497 return new CallerInfo(new Object [] { this }); 498 } 499 catch(CallerInfoException e) 500 { 501 debug(e.toString()); 502 return null; 503 } 504 } 505 506 508 private void pr(int severity, Object o) 509 { 510 try 511 { 512 CallerInfo ci = getCallerInfo(); 513 514 String s; 515 516 if(o == null) 517 { 518 s = "null Object argument"; } 520 else 521 { 522 s = o.toString(); 523 524 if(s == null) s = "null toString result from Object"; } 527 528 529 if(ci != null) 530 s = ci.toString() + ": " + s; 532 writer.println(severity, s); 533 } 534 catch(Throwable e) 535 { 536 537 _logger.log(Level.WARNING,"iplanet_util.pr_exception",e); 540 } 542 } 543 544 546 private String getClassName() 547 { 548 Assertion.check(className); 549 return className; 550 } 551 552 554 private int calcSeverityLevel(String original) 555 { 556 if(original == null || original.length() <= 0) 557 return DISABLED; 558 559 String s = original.toUpperCase(); 560 561 563 try 564 { 565 int ret = Integer.parseInt(s); 566 567 if(ret < 0) 568 ret = 0; 569 570 return ret; 571 } 572 catch(NumberFormatException e) 573 { 574 } 575 576 578 if(s.equals("ALL") || s.equals("NOISY") || s.equals("EVERYTHING") || s.equals("ON") || s.equals("MONDO") || s.equals("YES") || s.equals("TRUE") || s.equals("DUMP") || s.startsWith("MAX")) return 0; 581 if(s.startsWith("NO") || s.equals("OFF") || s.equals("FALSE") || s.equals("QUIET") || s.startsWith("MIN")) return DISABLED; 583 584 char first = s.charAt(0); 589 for(int i = 0; i < severityNames.length; i++) 590 { 591 if(severityNames[i].toUpperCase().charAt(0) == first) 592 return i; 593 } 594 595 debug("Unknown value for commandline argument \"-DIABDebug=" + original + "\""); return DISABLED; 598 } 599 600 private void debug(String s) 601 { 602 if(doDebug) 603 _logger.log(Level.FINE,"ReporterImpl Report --> " +s); 606 } 608 609 611 private int severityLevel = OFF; 612 private String name = "Main"; private ReporterWriter writer; 614 private String className; 615 private static final boolean doDebug = false; 616 } 617 618 | Popular Tags |