1 45 package org.openejb.util; 46 47 import java.io.File ; 48 import java.io.FileInputStream ; 49 import java.io.IOException ; 50 import java.io.FileNotFoundException ; 51 import java.io.InputStream ; 52 import java.io.FileOutputStream ; 53 import java.util.HashMap ; 54 import java.util.Properties ; 55 import java.net.URL ; 56 57 import org.apache.log4j.Category; 58 import org.apache.log4j.Level; 59 import org.apache.log4j.PropertyConfigurator; 60 import org.openejb.loader.SystemInstance; 61 import org.openejb.OpenEJBException; 62 63 64 80 public class Logger { 81 protected static final HashMap _loggers = new HashMap (); 83 protected Category _logger = null; 84 public I18N i18n = null; 85 86 public static void initialize(Properties props) 87 { 88 Log4jConfigUtils log4j = new Logger.Log4jConfigUtils(props); 89 90 log4j.configure(); 91 } 92 93 101 static public Logger getInstance( String category, String resourceName ) { 102 HashMap bundles = (HashMap )_loggers.get( category ); 103 Logger logger = null; 104 105 if ( bundles == null ) { 106 synchronized (Logger.class) { 107 bundles = (HashMap )_loggers.get( category ); 108 if ( bundles == null ) { 109 bundles = new HashMap (); 110 _loggers.put( category, bundles ); 111 } 112 } 113 } 114 115 logger = (Logger)bundles.get( resourceName ); 116 if ( logger == null ) { 117 synchronized (Logger.class) { 118 logger = (Logger)bundles.get( resourceName ); 119 if ( logger == null ) { 120 logger = new Logger( resourceName ); 121 logger._logger = Category.getInstance( category ); 122 123 bundles.put( resourceName, logger ); 124 } 125 } 126 } 127 128 return logger; 129 } 130 131 139 protected Logger( String resourceName ) { 140 i18n = new I18N( resourceName ); 141 } 142 143 148 public boolean isDebugEnabled() { 149 return _logger.isDebugEnabled(); 150 } 151 152 157 public boolean isErrorEnabled() { 158 return _logger.isEnabledFor( Level.ERROR ); 159 } 160 161 166 public boolean isFatalEnabled() { 167 return _logger.isEnabledFor( Level.FATAL ); 168 } 169 170 175 public boolean isInfoEnabled() { 176 return _logger.isInfoEnabled(); 177 } 178 179 180 185 public boolean isWarningEnabled() { 186 return _logger.isEnabledFor( Level.WARN ); 187 } 188 189 190 195 public void debug( String message ) { 196 if ( isDebugEnabled() ) _logger.debug( message ); 197 } 198 199 207 public void debug( String message, Throwable t ) { 208 if ( isDebugEnabled() ) _logger.debug( message, t ); 209 } 210 211 216 public void error( String message ) { 217 if ( isErrorEnabled() ) _logger.error( message ); 218 } 219 220 228 public void error( String message, Throwable t ) { 229 if ( isErrorEnabled() ) _logger.error( message, t ); 230 } 231 232 237 public void fatal( String message ) { 238 if ( isFatalEnabled() ) _logger.fatal( message ); 239 } 240 241 249 public void fatal( String message, Throwable t ) { 250 if ( isFatalEnabled() ) _logger.fatal( message, t ); 251 } 252 253 258 public void info( String message ) { 259 if ( isInfoEnabled() ) _logger.info( message ); 260 } 261 262 270 public void info( String message, Throwable t ) { 271 if ( isInfoEnabled() ) _logger.info( message, t ); 272 } 273 274 279 public void warning( String message ) { 280 if ( isWarningEnabled() ) _logger.warn( message ); 281 } 282 283 291 public void warning( String message, Throwable t ) { 292 if ( isWarningEnabled() ) _logger.warn( message, t ); 293 } 294 295 296 public class I18N { 297 298 protected Messages _messages = null; 299 300 protected I18N( String resourceName ) { 301 _messages = new Messages( resourceName ); 302 } 303 304 311 public void info( String code ) { 312 if ( isInfoEnabled() ) _logger.info( _messages.message( code ) ); 313 } 314 315 323 public void info( String code, Throwable t ) { 324 if ( isInfoEnabled() ) _logger.info( _messages.message( code ), t ); 325 } 326 327 328 336 public void info( String code, Object arg0 ) { 337 if ( isInfoEnabled() ) { 338 Object [] args = { arg0 }; 339 info( code, args ); 340 } 341 } 342 343 352 public void info( String code, Throwable t, Object arg0 ) { 353 if ( isInfoEnabled() ) { 354 Object [] args = { arg0 }; 355 info( code, t, args ); 356 } 357 } 358 359 368 public void info( String code, Object arg0, Object arg1 ) { 369 if ( isInfoEnabled() ) { 370 Object [] args = { arg0, arg1 }; 371 info( code, args ); 372 } 373 } 374 375 385 public void info( String code, Throwable t, Object arg0, Object arg1 ) { 386 if ( isInfoEnabled() ) { 387 Object [] args = { arg0, arg1 }; 388 info( code, t, args ); 389 } 390 } 391 392 402 public void info( String code, Object arg0, Object arg1, Object arg2 ) { 403 if ( isInfoEnabled() ) { 404 Object [] args = { arg0, arg1, arg2 }; 405 info( code, args ); 406 } 407 } 408 409 420 public void info( String code, Throwable t, Object arg0, Object arg1, Object arg2 ) { 421 if ( isInfoEnabled() ) { 422 Object [] args = { arg0, arg1, arg2 }; 423 info( code, t, args ); 424 } 425 } 426 427 438 public void info( String code, Object arg0, Object arg1, Object arg2, Object arg3 ) { 439 if ( isInfoEnabled() ) { 440 Object [] args = { arg0, arg1, arg2, arg3 }; 441 info( code, args ); 442 } 443 } 444 445 457 public void info( String code, Throwable t, Object arg0, Object arg1, Object arg2, Object arg3 ) { 458 if ( isInfoEnabled() ) { 459 Object [] args = { arg0, arg1, arg2, arg3 }; 460 info( code, t, args ); 461 } 462 } 463 464 476 public void info( String code, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4 ) { 477 if ( isInfoEnabled() ) { 478 Object [] args = { arg0, arg1, arg2, arg3, arg4 }; 479 info( code, args ); 480 } 481 } 482 483 496 public void info( String code, Throwable t, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4 ) { 497 if ( isInfoEnabled() ) { 498 Object [] args = { arg0, arg1, arg2, arg3, arg4 }; 499 info( code, t, args ); 500 } 501 } 502 503 516 public void info( String code, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5 ) { 517 if ( isInfoEnabled() ) { 518 Object [] args = { arg0, arg1, arg2, arg3, arg4, arg5 }; 519 info( code, args ); 520 } 521 } 522 523 537 public void info( String code, Throwable t, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5 ) { 538 if ( isInfoEnabled() ) { 539 Object [] args = { arg0, arg1, arg2, arg3, arg4, arg5 }; 540 info( code, t, args ); 541 } 542 } 543 544 552 public void info( String code, Object [] args ) { 553 _logger.info( _messages.format( code, args ) ); 554 } 555 556 565 public void info( String code, Throwable t, Object [] args ) { 566 _logger.info( _messages.format( code, args ), t ); 567 } 568 569 576 public void warning( String code ) { 577 if ( isWarningEnabled() ) _logger.warn( _messages.message( code ) ); 578 } 579 580 588 public void warning( String code, Throwable t ) { 589 if ( isWarningEnabled() ) _logger.warn( _messages.message( code ), t ); 590 } 591 592 600 public void warning( String code, Object arg0 ) { 601 if ( isWarningEnabled() ) { 602 Object [] args = { arg0 }; 603 warning( code, args ); 604 } 605 } 606 607 616 public void warning( String code, Throwable t, Object arg0 ) { 617 if ( isWarningEnabled() ) { 618 Object [] args = { arg0 }; 619 warning( code, t, args ); 620 } 621 } 622 623 632 public void warning( String code, Object arg0, Object arg1 ) { 633 if ( isWarningEnabled() ) { 634 Object [] args = { arg0, arg1 }; 635 warning( code, args ); 636 } 637 } 638 639 649 public void warning( String code, Throwable t, Object arg0, Object arg1 ) { 650 if ( isWarningEnabled() ) { 651 Object [] args = { arg0, arg1 }; 652 warning( code, t, args ); 653 } 654 } 655 656 666 public void warning( String code, Object arg0, Object arg1, Object arg2 ) { 667 if ( isWarningEnabled() ) { 668 Object [] args = { arg0, arg1, arg2 }; 669 warning( code, args ); 670 } 671 } 672 673 684 public void warning( String code, Throwable t, Object arg0, Object arg1, Object arg2 ) { 685 if ( isWarningEnabled() ) { 686 Object [] args = { arg0, arg1, arg2 }; 687 warning( code, t, args ); 688 } 689 } 690 691 702 public void warning( String code, Object arg0, Object arg1, Object arg2, Object arg3 ) { 703 if ( isWarningEnabled() ) { 704 Object [] args = { arg0, arg1, arg2, arg3 }; 705 warning( code, args ); 706 } 707 } 708 709 721 public void warning( String code, Throwable t, Object arg0, Object arg1, Object arg2, Object arg3 ) { 722 if ( isWarningEnabled() ) { 723 Object [] args = { arg0, arg1, arg2, arg3 }; 724 warning( code, t, args ); 725 } 726 } 727 728 740 public void warning( String code, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4 ) { 741 if ( isWarningEnabled() ) { 742 Object [] args = { arg0, arg1, arg2, arg3, arg4 }; 743 warning( code, args ); 744 } 745 } 746 747 760 public void warning( String code, Throwable t, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4 ) { 761 if ( isWarningEnabled() ) { 762 Object [] args = { arg0, arg1, arg2, arg3, arg4 }; 763 warning( code, t, args ); 764 } 765 } 766 767 780 public void warning( String code, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5 ) { 781 if ( isWarningEnabled() ) { 782 Object [] args = { arg0, arg1, arg2, arg3, arg4, arg5 }; 783 warning( code, args ); 784 } 785 } 786 787 801 public void warning( String code, Throwable t, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5 ) { 802 if ( isWarningEnabled() ) { 803 Object [] args = { arg0, arg1, arg2, arg3, arg4, arg5 }; 804 warning( code, t, args ); 805 } 806 } 807 808 816 public void warning( String code, Object [] args ) { 817 _logger.warn( _messages.format( code, args ) ); 818 } 819 820 829 public void warning( String code, Throwable t, Object [] args ) { 830 _logger.warn( _messages.format( code, args ), t ); 831 } 832 833 834 841 public void error( String code ) { 842 if ( isErrorEnabled() ) _logger.error( _messages.message( code ) ); 843 } 844 845 853 public void error( String code, Throwable t ) { 854 if ( isErrorEnabled() ) _logger.error( _messages.message( code ), t ); 855 } 856 857 865 public void error( String code, Object arg0 ) { 866 if ( isErrorEnabled() ) { 867 Object [] args = { arg0 }; 868 error( code, args ); 869 } 870 } 871 872 881 public void error( String code, Throwable t, Object arg0 ) { 882 if ( isErrorEnabled() ) { 883 Object [] args = { arg0 }; 884 error( code, t, args ); 885 } 886 } 887 888 897 public void error( String code, Object arg0, Object arg1 ) { 898 if ( isErrorEnabled() ) { 899 Object [] args = { arg0, arg1 }; 900 error( code, args ); 901 } 902 } 903 904 914 public void error( String code, Throwable t, Object arg0, Object arg1 ) { 915 if ( isErrorEnabled() ) { 916 Object [] args = { arg0, arg1 }; 917 error( code, t, args ); 918 } 919 } 920 921 931 public void error( String code, Object arg0, Object arg1, Object arg2 ) { 932 if ( isErrorEnabled() ) { 933 Object [] args = { arg0, arg1, arg2 }; 934 error( code, args ); 935 } 936 } 937 938 949 public void error( String code, Throwable t, Object arg0, Object arg1, Object arg2 ) { 950 if ( isErrorEnabled() ) { 951 Object [] args = { arg0, arg1, arg2 }; 952 error( code, t, args ); 953 } 954 } 955 956 967 public void error( String code, Object arg0, Object arg1, Object arg2, Object arg3 ) { 968 if ( isErrorEnabled() ) { 969 Object [] args = { arg0, arg1, arg2, arg3 }; 970 error( code, args ); 971 } 972 } 973 974 986 public void error( String code, Throwable t, Object arg0, Object arg1, Object arg2, Object arg3 ) { 987 if ( isErrorEnabled() ) { 988 Object [] args = { arg0, arg1, arg2, arg3 }; 989 error( code, t, args ); 990 } 991 } 992 993 1005 public void error( String code, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4 ) { 1006 if ( isErrorEnabled() ) { 1007 Object [] args = { arg0, arg1, arg2, arg3, arg4 }; 1008 error( code, args ); 1009 } 1010 } 1011 1012 1025 public void error( String code, Throwable t, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4 ) { 1026 if ( isErrorEnabled() ) { 1027 Object [] args = { arg0, arg1, arg2, arg3, arg4 }; 1028 error( code, t, args ); 1029 } 1030 } 1031 1032 1045 public void error( String code, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5 ) { 1046 if ( isErrorEnabled() ) { 1047 Object [] args = { arg0, arg1, arg2, arg3, arg4, arg5 }; 1048 error( code, args ); 1049 } 1050 } 1051 1052 1066 public void error( String code, Throwable t, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5 ) { 1067 if ( isErrorEnabled() ) { 1068 Object [] args = { arg0, arg1, arg2, arg3, arg4, arg5 }; 1069 error( code, t, args ); 1070 } 1071 } 1072 1073 1081 public void error( String code, Object [] args ) { 1082 _logger.error( _messages.format( code, args ) ); 1083 } 1084 1085 1094 public void error( String code, Throwable t, Object [] args ) { 1095 _logger.error( _messages.format( code, args ), t ); 1096 } 1097 1098 1105 public void fatal( String code ) { 1106 _logger.fatal( _messages.message( code ) ); 1107 } 1108 1109 1117 public void fatal( String code, Throwable t ) { 1118 _logger.fatal( _messages.message( code ), t ); 1119 } 1120 1121 1129 public void fatal( String code, Object arg0 ) { 1130 Object [] args = { arg0 }; 1131 fatal( code, args ); 1132 } 1133 1134 1143 public void fatal( String code, Throwable t, Object arg0 ) { 1144 Object [] args = { arg0 }; 1145 fatal( code, t, args ); 1146 } 1147 1148 1157 public void fatal( String code, Object arg0, Object arg1 ) { 1158 Object [] args = { arg0, arg1 }; 1159 fatal( code, args ); 1160 } 1161 1162 1172 public void fatal( String code, Throwable t, Object arg0, Object arg1 ) { 1173 Object [] args = { arg0, arg1 }; 1174 fatal( code, t, args ); 1175 } 1176 1177 1187 public void fatal( String code, Object arg0, Object arg1, Object arg2 ) { 1188 Object [] args = { arg0, arg1, arg2 }; 1189 fatal( code, args ); 1190 } 1191 1192 1203 public void fatal( String code, Throwable t, Object arg0, Object arg1, Object arg2 ) { 1204 Object [] args = { arg0, arg1, arg2 }; 1205 fatal( code, t, args ); 1206 } 1207 1208 1219 public void fatal( String code, Object arg0, Object arg1, Object arg2, Object arg3 ) { 1220 Object [] args = { arg0, arg1, arg2, arg3 }; 1221 fatal( code, args ); 1222 } 1223 1224 1236 public void fatal( String code, Throwable t, Object arg0, Object arg1, Object arg2, Object arg3 ) { 1237 Object [] args = { arg0, arg1, arg2, arg3 }; 1238 fatal( code, t, args ); 1239 } 1240 1241 1253 public void fatal( String code, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4 ) { 1254 Object [] args = { arg0, arg1, arg2, arg3, arg4 }; 1255 fatal( code, args ); 1256 } 1257 1258 1271 public void fatal( String code, Throwable t, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4 ) { 1272 Object [] args = { arg0, arg1, arg2, arg3, arg4 }; 1273 fatal( code, t, args ); 1274 } 1275 1276 1289 public void fatal( String code, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5 ) { 1290 Object [] args = { arg0, arg1, arg2, arg3, arg4, arg5 }; 1291 fatal( code, args ); 1292 } 1293 1294 1308 public void fatal( String code, Throwable t, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5 ) { 1309 Object [] args = { arg0, arg1, arg2, arg3, arg4, arg5 }; 1310 fatal( code, t, args ); 1311 } 1312 1313 1321 public void fatal( String code, Object [] args ) { 1322 _logger.fatal( _messages.format( code, args ) ); 1323 } 1324 1325 1334 public void fatal( String code, Throwable t, Object [] args ) { 1335 _logger.fatal( _messages.format( code, args ), t ); 1336 } 1337 1338 1339 1346 public void debug( String code ) { 1347 if ( isDebugEnabled() ) _logger.debug( _messages.message( code ) ); 1348 } 1349 1350 1358 public void debug( String code, Throwable t ) { 1359 if ( isDebugEnabled() ) _logger.debug( _messages.message( code ), t ); 1360 } 1361 1362 1370 public void debug( String code, Object arg0 ) { 1371 if ( isDebugEnabled() ) { 1372 Object [] args = { arg0 }; 1373 debug( code, args ); 1374 } 1375 } 1376 1377 1386 public void debug( String code, Throwable t, Object arg0 ) { 1387 if ( isDebugEnabled() ) { 1388 Object [] args = { arg0 }; 1389 debug( code, t, args ); 1390 } 1391 } 1392 1393 1402 public void debug( String code, Object arg0, Object arg1 ) { 1403 if ( isDebugEnabled() ) { 1404 Object [] args = { arg0, arg1 }; 1405 debug( code, args ); 1406 } 1407 } 1408 1409 1419 public void debug( String code, Throwable t, Object arg0, Object arg1 ) { 1420 if ( isDebugEnabled() ) { 1421 Object [] args = { arg0, arg1 }; 1422 debug( code, t, args ); 1423 } 1424 } 1425 1426 1436 public void debug( String code, Object arg0, Object arg1, Object arg2 ) { 1437 if ( isDebugEnabled() ) { 1438 Object [] args = { arg0, arg1, arg2 }; 1439 debug( code, args ); 1440 } 1441 } 1442 1443 1454 public void debug( String code, Throwable t, Object arg0, Object arg1, Object arg2 ) { 1455 if ( isDebugEnabled() ) { 1456 Object [] args = { arg0, arg1, arg2 }; 1457 debug( code, t, args ); 1458 } 1459 } 1460 1461 1472 public void debug( String code, Object arg0, Object arg1, Object arg2, Object arg3 ) { 1473 if ( isDebugEnabled() ) { 1474 Object [] args = { arg0, arg1, arg2, arg3 }; 1475 debug( code, args ); 1476 } 1477 } 1478 1479 1491 public void debug( String code, Throwable t, Object arg0, Object arg1, Object arg2, Object arg3 ) { 1492 if ( isDebugEnabled() ) { 1493 Object [] args = { arg0, arg1, arg2, arg3 }; 1494 debug( code, t, args ); 1495 } 1496 } 1497 1498 1510 public void debug( String code, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4 ) { 1511 if ( isDebugEnabled() ) { 1512 Object [] args = { arg0, arg1, arg2, arg3, arg4 }; 1513 debug( code, args ); 1514 } 1515 } 1516 1517 1530 public void debug( String code, Throwable t, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4 ) { 1531 if ( isDebugEnabled() ) { 1532 Object [] args = { arg0, arg1, arg2, arg3, arg4 }; 1533 debug( code, t, args ); 1534 } 1535 } 1536 1537 1550 public void debug( String code, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5 ) { 1551 if ( isDebugEnabled() ) { 1552 Object [] args = { arg0, arg1, arg2, arg3, arg4, arg5 }; 1553 debug( code, args ); 1554 } 1555 } 1556 1557 1571 public void debug( String code, Throwable t, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5 ) { 1572 if ( isDebugEnabled() ) { 1573 Object [] args = { arg0, arg1, arg2, arg3, arg4, arg5 }; 1574 debug( code, t, args ); 1575 } 1576 } 1577 1578 1586 public void debug( String code, Object [] args ) { 1587 _logger.debug( _messages.format( code, args ) ); 1588 } 1589 1590 1599 public void debug( String code, Throwable t, Object [] args ) { 1600 _logger.debug( _messages.format( code, args ), t ); 1601 } 1602 } 1603 1604 static class Log4jConfigUtils { 1605 1606 Properties props; 1607 1608 public Log4jConfigUtils(Properties props) 1609 { 1610 this.props = props; 1611 } 1612 1613 public void configure(){ 1614 String config = props.getProperty( "log4j.configuration" ); 1615 if (config == null) { 1616 config = "conf/logging.conf"; 1617 } 1618 try{ 1619 config = getAbsolutePath(config, "conf/default.logging.conf", false); 1621 1622 Properties log4jProps = loadProperties(config); 1624 1625 PropertyConfigurator.configure(filterProperties(log4jProps)); 1626 } catch (Exception e){ 1627 System.err.println("Failed to configure log4j. "+e.getMessage()); 1628 } 1629 } 1630 1631 public Properties loadProperties(String file) throws Exception { 1632 Properties props = new Properties (); 1633 FileInputStream fin = null; 1634 1635 try{ 1636 fin = new FileInputStream (file); 1637 props.load(fin); 1638 } finally { 1639 if (fin != null) fin.close(); 1640 } 1641 return props; 1642 } 1643 1644 1651 public Properties filterProperties(Properties log4jProps) { 1652 Object [] names = log4jProps.keySet().toArray(); 1653 for (int i=0; i < names.length; i++){ 1654 String name = (String )names[i]; 1655 if (name.endsWith(".File")) { 1656 String path = log4jProps.getProperty(name); 1657 try { 1658 File file = SystemInstance.get().getBase().getFile(path, false); 1659 if (!file.getParentFile().exists()) { 1660 file = SystemInstance.get().getHome().getFile(path, false); 1661 } 1662 path = file.getPath(); 1663 } catch (IOException ignored) { 1664 } 1667 log4jProps.setProperty(name, path); 1668 } 1669 } 1670 return log4jProps; 1671 } 1672 1673 public String getAbsolutePath(String path, String secondaryPath, boolean create) 1674 throws OpenEJBException { 1675 File file = null; 1676 1677 if (path != null) { 1678 1682 file = new File (path); 1683 if (file != null && file.exists() && file.isFile()) { 1684 return file.getAbsolutePath(); 1685 } 1686 1687 1690 try { 1691 file = SystemInstance.get().getBase().getFile(path); 1692 if (file != null && file.exists() && file.isFile()) { 1693 return file.getAbsolutePath(); 1694 } 1695 } catch (FileNotFoundException ignored) { 1696 } catch (IOException ignored) { 1697 } 1698 1699 1702 try { 1703 file = SystemInstance.get().getHome().getFile(path); 1704 if (file != null && file.exists() && file.isFile()) { 1705 return file.getAbsolutePath(); 1706 } 1707 } catch (FileNotFoundException ignored) { 1708 } catch (IOException ignored) { 1709 } 1710 1711 } 1712 1713 try { 1714 1718 try { 1719 file = SystemInstance.get().getBase().getFile(secondaryPath); 1720 if (file != null && file.exists() && file.isFile()) { 1721 return file.getAbsolutePath(); 1722 } 1723 } catch (java.io.FileNotFoundException ignored) { 1724 } 1725 1726 1730 try { 1731 file = SystemInstance.get().getHome().getFile(secondaryPath); 1732 if (file != null && file.exists() && file.isFile()) { 1733 return file.getAbsolutePath(); 1734 } 1735 } catch (java.io.FileNotFoundException ignored) { 1736 } 1737 1738 if (create) 1744 { 1745 File confDir = SystemInstance.get().getBase().getDirectory("conf", true); 1746 1747 file = createConfig(new File (confDir, secondaryPath)); 1748 } 1749 } catch (java.io.IOException e) { 1750 e.printStackTrace(); 1751 throw new OpenEJBException("Could not locate config file: ", e); 1752 } 1753 1754 return (file == null) ? null : file.getAbsolutePath(); 1755 } 1756 1757 private static File createConfig(File file) throws java.io.IOException { 1758 try{ 1759 URL defaultConfig = new URL ("resource:/" + file.getName()); 1760 InputStream in = defaultConfig.openStream(); 1761 FileOutputStream out = new FileOutputStream (file); 1762 1763 int b = in.read(); 1764 1765 while (b != -1) { 1766 out.write(b); 1767 b = in.read(); 1768 } 1769 1770 in.close(); 1771 out.close(); 1772 1773 } catch (Exception e){ 1774 e.printStackTrace(); 1775 } 1776 1777 return file; 1778 } 1779 1780 } 1781} | Popular Tags |