1 2 17 18 19 package org.apache.poi.util; 20 21 import java.util.*; 22 23 33 34 public abstract class POILogger 35 { 36 37 public static final int DEBUG = 1; 38 public static final int INFO = 3; 39 public static final int WARN = 5; 40 public static final int ERROR = 7; 41 public static final int FATAL = 9; 42 43 48 POILogger() 49 {} 50 51 abstract public void initialize(final String cat); 52 53 abstract public void log(final int level, final Object obj1); 54 55 60 abstract public boolean check(final int level); 61 62 69 70 77 78 public void log(final int level, final Object obj1, final Object obj2) 79 { 80 if (check(level)) 81 { 82 log(level, new StringBuffer (32).append(obj1).append(obj2)); 83 } 84 } 85 86 94 95 public void log(final int level, final Object obj1, final Object obj2, 96 final Object obj3) 97 { 98 99 100 if (check(level)) 101 { 102 log(level, 103 new StringBuffer (48).append(obj1).append(obj2) 104 .append(obj3)); 105 } 106 } 107 108 117 118 public void log(final int level, final Object obj1, final Object obj2, 119 final Object obj3, final Object obj4) 120 { 121 122 123 if (check(level)) 124 { 125 log(level, 126 new StringBuffer (64).append(obj1).append(obj2) 127 .append(obj3).append(obj4)); 128 } 129 } 130 131 141 142 public void log(final int level, final Object obj1, final Object obj2, 143 final Object obj3, final Object obj4, final Object obj5) 144 { 145 146 147 if (check(level)) 148 { 149 log(level, 150 new StringBuffer (80).append(obj1).append(obj2) 151 .append(obj3).append(obj4).append(obj5)); 152 } 153 } 154 155 166 167 public void log(final int level, final Object obj1, final Object obj2, 168 final Object obj3, final Object obj4, final Object obj5, 169 final Object obj6) 170 { 171 172 173 if (check(level)) 174 { 175 log(level , 176 new StringBuffer (96).append(obj1).append(obj2) 177 .append(obj3).append(obj4).append(obj5).append(obj6)); 178 } 179 } 180 181 193 194 public void log(final int level, final Object obj1, final Object obj2, 195 final Object obj3, final Object obj4, final Object obj5, 196 final Object obj6, final Object obj7) 197 { 198 199 200 if (check(level)) 201 { 202 log(level, 203 new StringBuffer (112).append(obj1).append(obj2) 204 .append(obj3).append(obj4).append(obj5).append(obj6) 205 .append(obj7)); 206 } 207 } 208 209 222 223 public void log(final int level, final Object obj1, final Object obj2, 224 final Object obj3, final Object obj4, final Object obj5, 225 final Object obj6, final Object obj7, final Object obj8) 226 { 227 228 229 if (check(level)) 230 { 231 log(level, 232 new StringBuffer (128).append(obj1).append(obj2) 233 .append(obj3).append(obj4).append(obj5).append(obj6) 234 .append(obj7).append(obj8)); 235 } 236 } 237 238 245 246 public void log(final int level, final Object obj1, 247 final Throwable exception) 248 { 249 log(level , obj1, exception); 250 } 251 252 260 261 public void log(final int level, final Object obj1, final Object obj2, 262 final Throwable exception) 263 { 264 265 266 if (check(level)) 267 { 268 log(level, new StringBuffer (32).append(obj1).append(obj2), 269 exception); 270 } 271 } 272 273 282 283 public void log(final int level, final Object obj1, final Object obj2, 284 final Object obj3, final Throwable exception) 285 { 286 287 288 if (check(level)) 289 { 290 log(level, new StringBuffer (48).append(obj1).append(obj2) 291 .append(obj3), exception); 292 } 293 } 294 295 305 306 public void log(final int level, final Object obj1, final Object obj2, 307 final Object obj3, final Object obj4, 308 final Throwable exception) 309 { 310 311 312 if (check(level)) 313 { 314 log(level, new StringBuffer (64).append(obj1).append(obj2) 315 .append(obj3).append(obj4), exception); 316 } 317 } 318 319 330 331 public void log(final int level, final Object obj1, final Object obj2, 332 final Object obj3, final Object obj4, final Object obj5, 333 final Throwable exception) 334 { 335 336 337 if (check(level)) 338 { 339 log(level, new StringBuffer (80).append(obj1).append(obj2) 340 .append(obj3).append(obj4).append(obj5), exception); 341 } 342 } 343 344 356 357 public void log(final int level, final Object obj1, final Object obj2, 358 final Object obj3, final Object obj4, final Object obj5, 359 final Object obj6, final Throwable exception) 360 { 361 362 363 if (check(level)) 364 { 365 log(level , new StringBuffer (96).append(obj1) 366 .append(obj2).append(obj3).append(obj4).append(obj5) 367 .append(obj6), exception); 368 } 369 } 370 371 384 385 public void log(final int level, final Object obj1, final Object obj2, 386 final Object obj3, final Object obj4, final Object obj5, 387 final Object obj6, final Object obj7, 388 final Throwable exception) 389 { 390 391 392 if (check(level)) 393 { 394 log(level, new StringBuffer (112).append(obj1).append(obj2) 395 .append(obj3).append(obj4).append(obj5).append(obj6) 396 .append(obj7), exception); 397 } 398 } 399 400 414 415 public void log(final int level, final Object obj1, final Object obj2, 416 final Object obj3, final Object obj4, final Object obj5, 417 final Object obj6, final Object obj7, final Object obj8, 418 final Throwable exception) 419 { 420 421 422 if (check(level)) 423 { 424 log(level, new StringBuffer (128).append(obj1).append(obj2) 425 .append(obj3).append(obj4).append(obj5).append(obj6) 426 .append(obj7).append(obj8), exception); 427 } 428 } 429 430 454 455 public void logFormatted(final int level, final String message, 456 final Object obj1) 457 { 458 commonLogFormatted(level, message, new Object [] 459 { 460 obj1 461 }); 462 } 463 464 489 490 public void logFormatted(final int level, final String message, 491 final Object obj1, final Object obj2) 492 { 493 commonLogFormatted(level, message, new Object [] 494 { 495 obj1, obj2 496 }); 497 } 498 499 525 526 public void logFormatted(final int level, final String message, 527 final Object obj1, final Object obj2, 528 final Object obj3) 529 { 530 commonLogFormatted(level, message, new Object [] 531 { 532 obj1, obj2, obj3 533 }); 534 } 535 536 563 564 public void logFormatted(final int level, final String message, 565 final Object obj1, final Object obj2, 566 final Object obj3, final Object obj4) 567 { 568 commonLogFormatted(level, message, new Object [] 569 { 570 obj1, obj2, obj3, obj4 571 }); 572 } 573 574 private void commonLogFormatted(final int level, final String message, 575 final Object [] unflatParams) 576 { 577 578 579 if (check(level)) 580 { 581 Object [] params = flattenArrays(unflatParams); 582 583 if (params[ params.length - 1 ] instanceof Throwable ) 584 { 585 log(level, StringUtil.format(message, params), 586 ( Throwable ) params[ params.length - 1 ]); 587 } 588 else 589 { 590 log(level, StringUtil.format(message, params)); 591 } 592 } 593 } 594 595 598 599 private Object [] flattenArrays(final Object [] objects) 600 { 601 List results = new ArrayList(); 602 603 for (int i = 0; i < objects.length; i++) 604 { 605 results.addAll(objectToObjectArray(objects[ i ])); 606 } 607 return ( Object [] ) results.toArray(new Object [ results.size() ]); 608 } 609 610 private List objectToObjectArray(Object object) 611 { 612 List results = new ArrayList(); 613 614 if (object instanceof byte []) 615 { 616 byte[] array = ( byte [] ) object; 617 618 for (int j = 0; j < array.length; j++) 619 { 620 results.add(new Byte (array[ j ])); 621 } 622 } 623 if (object instanceof char []) 624 { 625 char[] array = ( char [] ) object; 626 627 for (int j = 0; j < array.length; j++) 628 { 629 results.add(new Character (array[ j ])); 630 } 631 } 632 else if (object instanceof short []) 633 { 634 short[] array = ( short [] ) object; 635 636 for (int j = 0; j < array.length; j++) 637 { 638 results.add(new Short (array[ j ])); 639 } 640 } 641 else if (object instanceof int []) 642 { 643 int[] array = ( int [] ) object; 644 645 for (int j = 0; j < array.length; j++) 646 { 647 results.add(new Integer (array[ j ])); 648 } 649 } 650 else if (object instanceof long []) 651 { 652 long[] array = ( long [] ) object; 653 654 for (int j = 0; j < array.length; j++) 655 { 656 results.add(new Long (array[ j ])); 657 } 658 } 659 else if (object instanceof float []) 660 { 661 float[] array = ( float [] ) object; 662 663 for (int j = 0; j < array.length; j++) 664 { 665 results.add(new Float (array[ j ])); 666 } 667 } 668 else if (object instanceof double []) 669 { 670 double[] array = ( double [] ) object; 671 672 for (int j = 0; j < array.length; j++) 673 { 674 results.add(new Double (array[ j ])); 675 } 676 } 677 else if (object instanceof Object []) 678 { 679 Object [] array = ( Object [] ) object; 680 681 for (int j = 0; j < array.length; j++) 682 { 683 results.add(array[ j ]); 684 } 685 } 686 else 687 { 688 results.add(object); 689 } 690 return results; 691 } 692 693 } 695 | Popular Tags |