1 24 25 package org.objectweb.cjdbc.controller.core; 26 27 import java.io.BufferedOutputStream ; 28 import java.io.BufferedReader ; 29 import java.io.BufferedWriter ; 30 import java.io.DataOutputStream ; 31 import java.io.File ; 32 import java.io.FileNotFoundException ; 33 import java.io.FileOutputStream ; 34 import java.io.FileReader ; 35 import java.io.FileWriter ; 36 import java.io.IOException ; 37 import java.io.InputStream ; 38 import java.net.URL ; 39 import java.net.URLDecoder ; 40 import java.text.SimpleDateFormat ; 41 import java.util.ArrayList ; 42 import java.util.Date ; 43 import java.util.Enumeration ; 44 import java.util.Hashtable ; 45 import java.util.Iterator ; 46 import java.util.Locale ; 47 import java.util.zip.ZipEntry ; 48 import java.util.zip.ZipFile ; 49 50 import javax.management.NotCompliantMBeanException ; 51 import javax.management.ObjectName ; 52 53 import org.objectweb.cjdbc.common.exceptions.ControllerException; 54 import org.objectweb.cjdbc.common.exceptions.VirtualDatabaseException; 55 import org.objectweb.cjdbc.common.i18n.Translate; 56 import org.objectweb.cjdbc.common.jmx.JmxConstants; 57 import org.objectweb.cjdbc.common.jmx.JmxException; 58 import org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean; 59 import org.objectweb.cjdbc.common.jmx.notifications.CjdbcNotificationList; 60 import org.objectweb.cjdbc.common.log.LogManager; 61 import org.objectweb.cjdbc.common.log.Trace; 62 import org.objectweb.cjdbc.common.util.Constants; 63 import org.objectweb.cjdbc.common.xml.ControllerXmlTags; 64 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags; 65 import org.objectweb.cjdbc.common.xml.XmlComponent; 66 import org.objectweb.cjdbc.common.xml.XmlTools; 67 import org.objectweb.cjdbc.controller.core.security.ControllerSecurityManager; 68 import org.objectweb.cjdbc.controller.core.shutdown.ControllerForceShutdownThread; 69 import org.objectweb.cjdbc.controller.core.shutdown.ControllerSafeShutdownThread; 70 import org.objectweb.cjdbc.controller.core.shutdown.ControllerShutdownThread; 71 import org.objectweb.cjdbc.controller.core.shutdown.ControllerWaitShutdownThread; 72 import org.objectweb.cjdbc.controller.jmx.AbstractStandardMBean; 73 import org.objectweb.cjdbc.controller.jmx.MBeanServerManager; 74 import org.objectweb.cjdbc.controller.jmx.RmiConnector; 75 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase; 76 import org.objectweb.cjdbc.controller.xml.DatabasesParser; 77 78 88 public final class Controller extends AbstractStandardMBean 89 implements 90 ControllerMBean, 91 XmlComponent 92 { 93 94 95 private int portNumber; 96 private int backlogSize; 97 98 103 private String ipAddress; 104 105 106 private ControllerServerThread connectionThread; 107 108 109 static Trace logger = Trace 110 .getLogger("org.objectweb.cjdbc.controller.core.Controller"); 111 112 113 private Hashtable virtualDatabases; 114 115 116 private Hashtable configuration; 117 118 119 private ControllerSecurityManager security; 120 121 122 private ReportManager report; 123 124 private boolean isShuttingDown; 125 126 127 128 138 public Controller(String ipAddress, int port, int backlog) 139 throws NotCompliantMBeanException , JmxException 140 { 141 super(ControllerMBean.class); 142 virtualDatabases = new Hashtable (); 143 this.ipAddress = ipAddress; 144 this.portNumber = port; 145 this.backlogSize = backlog; 146 ObjectName name = JmxConstants.getControllerObjectName(); 147 MBeanServerManager.registerMBean(this, name); 148 } 149 150 154 165 public void addVirtualDatabases(String xml, String vdbName, int autoEnable, 166 String checkpoint) throws ControllerException 167 { 168 if (logger.isDebugEnabled()) 169 logger.debug(Translate.get("controller.add.virtualdatabase", vdbName)); 170 if (vdbName != null && this.hasVirtualDatabase(vdbName)) 171 { 172 throw new ControllerException(Translate 173 .get("controller.add.virtualdatabase.already.used")); 174 } 175 try 176 { 177 DatabasesParser parser = new DatabasesParser(this, vdbName, autoEnable, 178 checkpoint); 179 parser.readXML(xml, true); 180 } 181 catch (Exception e) 182 { 183 String msg = Translate.get("controller.add.virtualdatabase.failed", e); 184 logger.warn(msg, e); 185 throw new ControllerException(msg); 186 } 187 } 188 189 194 public void addVirtualDatabases(String xml) throws ControllerException 195 { 196 if (logger.isDebugEnabled()) 197 { 198 logger.debug(Translate.get("controller.loading.virtualdatabase")); 199 } 200 this.addVirtualDatabases(xml, null, 201 ControllerConstants.AUTO_ENABLE_BACKEND, 202 ControllerConstants.DATABASE_DEFAULT_CHECKPOINT); 203 } 204 205 211 public void addVirtualDatabase(VirtualDatabase vdb) 212 throws ControllerException 213 { 214 this.addVirtualDatabase(vdb, ControllerConstants.AUTO_ENABLE_BACKEND, 215 ControllerConstants.DATABASE_DEFAULT_CHECKPOINT); 216 } 217 218 228 public synchronized void addVirtualDatabase(VirtualDatabase vdb, 229 int autoLoad, String checkPoint) throws ControllerException 230 { 231 if (hasVirtualDatabase(vdb.getDatabaseName())) 233 { 234 String msg = Translate.get("controller.database.already.exists", vdb 235 .getDatabaseName()); 236 logger.warn(msg); 237 throw new ControllerException(msg); 238 } 239 else 240 { 241 virtualDatabases.put(vdb.getDatabaseName(), vdb); 242 243 if (MBeanServerManager.isJmxEnabled()) 245 { 246 Hashtable databases = new Hashtable (); 247 try 248 { 249 databases.put("backends", vdb.getAllBackendNames()); 250 } 251 catch (VirtualDatabaseException e) 252 { 253 } 255 RmiConnector.broadcastNotification(this, 256 CjdbcNotificationList.CONTROLLER_VIRTUALDATABASE_ADDED, 257 CjdbcNotificationList.NOTIFICATION_LEVEL_INFO, Translate.get( 258 "notification.virtualdatabase.added", vdb 259 .getVirtualDatabaseName()), databases); 260 } 261 } 262 263 try 265 { 266 if (logger.isDebugEnabled()) 267 logger.debug(Translate.get("controller.database.autoenable", autoLoad)); 268 269 switch (autoLoad) 270 { 271 case ControllerConstants.AUTO_ENABLE_TRUE : 272 vdb.enableAllBackendsFromCheckpoint(); 273 break; 274 case ControllerConstants.AUTO_ENABLE_FALSE : 275 break; 276 case ControllerConstants.AUTO_ENABLE_FORCE : 277 logger.warn("Backends enabled in force mode from checkpoint " 278 + checkPoint); 279 vdb.forceEnableAllBackendsFromCheckpoint(checkPoint); 280 break; 281 default : 282 logger 283 .error("Unsupported autoEnabledBackends mode in controller configuration"); 284 break; 285 } 286 } 287 catch (VirtualDatabaseException e) 288 { 289 throw new ControllerException(e); 290 } 291 292 logger.info(Translate.get("controller.add.virtualdatabase", vdb 293 .getDatabaseName())); 294 } 295 296 303 public VirtualDatabase getVirtualDatabase(String virtualDatabaseName) 304 { 305 return (VirtualDatabase) virtualDatabases.get(virtualDatabaseName); 306 } 307 308 311 public ArrayList getVirtualDatabaseNames() 312 { 313 ArrayList result = new ArrayList (); 314 for (Iterator iter = virtualDatabases.values().iterator(); iter.hasNext();) 315 result.add(((VirtualDatabase) iter.next()).getVirtualDatabaseName()); 316 return result; 317 } 318 319 324 public ArrayList getVirtualDatabases() 325 { 326 ArrayList result = new ArrayList (); 327 for (Iterator iter = virtualDatabases.values().iterator(); iter.hasNext();) 328 result.add(iter.next()); 329 return result; 330 } 331 332 339 public boolean hasVirtualDatabase(String name) 340 { 341 return virtualDatabases.containsKey(name); 342 } 343 344 347 public String removeVirtualDatabase(String virtualname) 348 throws ControllerException 349 { 350 if (hasVirtualDatabase(virtualname)) 351 { 352 VirtualDatabase vdb = (VirtualDatabase) virtualDatabases.get(virtualname); 353 try 354 { 355 vdb.disableAllBackends(); 356 } 357 catch (VirtualDatabaseException e) 358 { 359 throw new ControllerException(e); 360 } 361 this.virtualDatabases.remove(virtualname); 362 363 if (MBeanServerManager.isJmxEnabled()) 365 { 366 Hashtable databases = new Hashtable (); 367 try 368 { 369 databases.put("backends", vdb.getAllBackendNames()); 370 } 371 catch (VirtualDatabaseException e) 372 { 373 } 375 RmiConnector.broadcastNotification(this, 376 CjdbcNotificationList.CONTROLLER_VIRTUALDATABASE_REMOVED, 377 CjdbcNotificationList.NOTIFICATION_LEVEL_INFO, Translate.get( 378 "notification.virtualdatabase.removed", vdb 379 .getVirtualDatabaseName()), databases); 380 } 381 } 382 return Translate.get("controller.removeVirtualDatabase.success", 383 virtualname); 384 } 385 386 390 393 public void addDriver(byte[] bytes) throws Exception 394 { 395 File driversDirectory = null; 397 URL url = Controller.class 398 .getResource(ControllerConstants.C_JDBC_DRIVER_JAR_FILE); 399 boolean error = false; 400 if (url != null) 401 { 402 driversDirectory = (new File (URLDecoder.decode(url.getFile()))) 403 .getParentFile(); 404 error = (driversDirectory == null) || !driversDirectory.exists(); 405 } 406 407 if (error) 408 { 409 String msg = Translate.get("controller.driver.dir.not.found"); 410 logger.error(msg); 411 throw new ControllerException(msg); 412 } 413 414 File temp = null; 416 try 417 { 418 temp = File.createTempFile("driver", "zip", driversDirectory); 419 FileOutputStream output = new FileOutputStream (temp); 420 output.write(bytes); 421 output.close(); 422 } 423 catch (IOException e) 424 { 425 String msg = Translate.get("controller.add.jar.read.failed", e); 426 logger.error(msg); 427 throw new ControllerException(msg); 428 } 429 430 try 432 { 433 Enumeration entries; 434 ZipFile zipFile = new ZipFile (temp); 435 436 int lenght; 438 InputStream in; 439 BufferedOutputStream out; 440 byte[] buffer = new byte[1024]; 441 442 entries = zipFile.entries(); 443 while (entries.hasMoreElements()) 444 { 445 ZipEntry entry = (ZipEntry ) entries.nextElement(); 446 447 if (entry.isDirectory()) 448 { 449 if (logger.isDebugEnabled()) 451 logger.debug(Translate.get("controller.add.jar.extract.dir", entry 452 .getName())); 453 454 (new File (driversDirectory, entry.getName())).mkdir(); 455 continue; 456 } 457 458 if (logger.isDebugEnabled()) 460 logger.debug(Translate.get("controller.add.jar.extract.file", entry 461 .getName())); 462 463 in = zipFile.getInputStream(entry); 464 out = new BufferedOutputStream (new FileOutputStream (driversDirectory 465 + System.getProperty("file.separator") + entry.getName())); 466 while ((lenght = in.read(buffer)) >= 0) 467 out.write(buffer, 0, lenght); 468 469 in.close(); 470 out.close(); 471 } 472 473 zipFile.close(); 474 temp.delete(); 475 logger.info(Translate.get("controller.add.jar.to.directory", 476 driversDirectory.toString())); 477 } 478 catch (IOException e) 479 { 480 String msg = Translate.get("controller.driver.extract.failed", e); 481 logger.error(msg); 482 throw new ControllerException(msg); 483 } 484 } 485 486 500 public String loadXmlConfiguration(String filename, String virtualName, 501 int autoLoad, String checkPoint) throws Exception 502 { 503 FileReader fileReader = null; 504 try 505 { 506 filename = filename.trim(); 507 try 508 { 509 fileReader = new FileReader (filename); 510 } 511 catch (FileNotFoundException fnf) 512 { 513 return Translate.get("controller.file.not.found", filename); 514 } 515 516 BufferedReader in = new BufferedReader (fileReader); 518 StringBuffer xml = new StringBuffer (); 519 String line; 520 do 521 { 522 line = in.readLine(); 523 if (line != null) 524 xml.append(line); 525 } 526 while (line != null); 527 528 addVirtualDatabases(xml.toString(), virtualName, autoLoad, checkPoint); 530 return Translate.get("controller.file.send", filename); 531 } 532 catch (Exception e) 533 { 534 logger.error(Translate.get("controller.loadXml.failed", e), e); 535 throw new ControllerException(Translate.get("controller.loadXml.failed", 536 e)); 537 } 538 finally 539 { 540 if (fileReader != null) 541 fileReader.close(); 542 } 543 } 544 545 552 public String saveConfiguration() throws VirtualDatabaseException 553 { 554 String msg = Translate.get("controller.save.configuration.failed"); 555 try 556 { 557 String configurationFile = ControllerConstants 558 .getSaveFile(new SimpleDateFormat ("yyyy-MM-dd-HH-mm") 559 .format(new Date ())); 560 DataOutputStream dos = new DataOutputStream (new BufferedOutputStream ( 561 new FileOutputStream (configurationFile))); 562 StringBuffer xml = new StringBuffer (); 563 xml.append(XmlTools.prettyXml(getXmlVirtualDatabases())); 564 String prettyXml = xml.toString(); 565 prettyXml = XmlTools.insertCjdbcDoctype(prettyXml); 568 dos.write(prettyXml.getBytes()); 569 dos.close(); 570 msg = Translate.get("controller.save.configuration", configurationFile); 571 } 572 catch (Exception e) 573 { 574 msg = Translate.get("controller.save.configuration.failed", e); 575 logger.error(msg); 576 } 577 return msg; 578 } 579 580 588 public void endOfController(Exception fatal) 589 { 590 logger.fatal(Translate.get("fatal.error")); 591 if (report.isGenerateOnFatal()) 592 { 593 new ReportManager(this, fatal).generate(); 594 logger.info(Translate.get("fatal.report.generated", report 595 .getReportLocation() 596 + File.separator + ControllerConstants.REPORT_FILE)); 597 } 598 Runtime.getRuntime().exit(1); 599 } 600 601 606 public ControllerServerThread getConnectionThread() 607 { 608 return connectionThread; 609 } 610 611 614 public boolean isShuttingDown() 615 { 616 return isShuttingDown; 617 } 618 619 622 public void shutdown(int level) throws ControllerException 623 { 624 ControllerShutdownThread shutdownThread = null; 625 synchronized (this) 626 { 627 if (isShuttingDown()) 628 { 629 logger.info(Translate.get("controller.already.shutting.down", this 630 .getControllerName())); 631 return; 632 } 633 634 if (isSecurityEnabled() && !security.getAllowConsoleShutdown()) 635 throw new ControllerException(Translate 636 .get("controller.shutdown.refused")); 637 638 switch (level) 639 { 640 case Constants.SHUTDOWN_WAIT : 641 shutdownThread = new ControllerWaitShutdownThread(this); 642 logger.info(Translate.get("controller.shutdown.type.wait", this 643 .getControllerName())); 644 break; 645 case Constants.SHUTDOWN_SAFE : 646 isShuttingDown = true; 647 shutdownThread = new ControllerSafeShutdownThread(this); 648 logger.info(Translate.get("controller.shutdown.type.safe", this 649 .getControllerName())); 650 break; 651 case Constants.SHUTDOWN_FORCE : 652 isShuttingDown = true; 653 shutdownThread = new ControllerForceShutdownThread(this); 654 logger.warn(Translate.get("controller.shutdown.type.force", this 655 .getControllerName())); 656 break; 657 default : 658 String msg = Translate 659 .get("controller.shutdown.unknown.level", level); 660 logger.error(msg); 661 throw new RuntimeException (msg); 662 } 663 } 664 665 Thread thread = new Thread (shutdownThread.getShutdownGroup(), 666 shutdownThread, "Controller Shutdown Thread"); 667 thread.start(); 668 669 try 670 { 671 logger.info("Waiting for shutdown"); 672 thread.join(); 673 logger.info("Shutdown over"); 674 } 675 catch (InterruptedException e) 676 { 677 e.printStackTrace(); 678 } 679 } 680 681 708 public static void main(String [] args) throws Exception 709 { 710 logger.info(getVersion()); 711 712 System.setProperty("javax.management.builder.initial", 713 org.objectweb.cjdbc.controller.jmx.MBeanServerBuilder.class.getName()); 714 715 ControllerFactory conf = new ControllerFactory(args); 716 Controller controller = conf.getController(); 717 if (controller != null) 718 controller.launch(); 719 else 720 throw new Exception (Translate.get("controller.configure.failed")); 721 } 722 723 727 public void launch() 728 { 729 connectionThread = new ControllerServerThread(this); 730 connectionThread.start(); 731 732 SimpleDateFormat formatter = new SimpleDateFormat ( 733 "yyyy.MM.dd ww 'at' hh:mm:ss a zzz"); 734 Date day = new Date (); 735 String date = formatter.format(day); 736 logger.info(Translate.get("controller.date", date)); 737 logger.info(Translate.get("controller.ready", getControllerName())); 738 } 739 740 744 749 public String getControllerName() 750 { 751 return ipAddress + ":" + portNumber; 752 } 753 754 759 public String getIPAddress() 760 { 761 return ipAddress; 762 } 763 764 769 public void setIPAddress(String ipAddress) 770 { 771 this.ipAddress = ipAddress; 772 } 773 774 779 public int getPortNumber() 780 { 781 return portNumber; 782 } 783 784 789 public void setPortNumber(int port) 790 { 791 portNumber = port; 792 } 793 794 797 public int getBacklogSize() 798 { 799 return backlogSize; 800 } 801 802 805 public void setBacklogSize(int size) 806 { 807 backlogSize = size; 808 } 809 810 815 public boolean getJmxEnable() 816 { 817 return MBeanServerManager.isJmxEnabled(); 818 } 819 820 825 public String getJmxName() 826 { 827 if (getJmxEnable()) 828 { 829 RmiConnector connector = ((RmiConnector) RmiConnector.getRmiConnectors() 830 .get(0)); 831 return connector.getHostName() + ":" + connector.getPort(); 832 } 833 else 834 return getControllerName(); 835 } 836 837 842 public void setJmxEnable(boolean enable) 843 { 844 configuration.put(ControllerFactory.JMX_ENABLE, "" + enable); 845 } 846 847 852 public static String getVersion() 853 { 854 return Translate.get("controller.info", Constants.VERSION); 855 } 856 857 862 public Hashtable getConfiguration() 863 { 864 return configuration; 865 } 866 867 872 public boolean isSecurityEnabled() 873 { 874 return security != null; 875 } 876 877 880 public ControllerSecurityManager getSecurity() 881 { 882 return security; 883 } 884 885 888 public void setSecurity(ControllerSecurityManager security) 889 { 890 this.security = security; 891 } 892 893 896 public String generateReport() throws Exception 897 { 898 report.startReport(); 899 return report.generate(); 900 } 901 902 905 public String getLoggingConfiguration() throws Exception 906 { 907 return report.generate(); 908 } 909 910 915 public void setConfiguration(Hashtable configuration) 916 { 917 this.configuration = configuration; 918 } 919 920 923 public String getVersionNumber() 924 { 925 return Constants.VERSION; 926 } 927 928 931 public String getAssociatedString() 932 { 933 return "controller"; 934 } 935 936 939 public String getXml() 940 { 941 try 942 { 943 String prettyXml = XmlTools.prettyXml(getXmlController()); 944 return XmlTools.insertCjdbcControllerDoctype(prettyXml); 945 } 946 catch (Exception e) 947 { 948 logger.error(Translate.get("controller.xml.transformation.failed", e)); 949 return e.getMessage(); 950 } 951 } 952 953 959 public String getXmlController() 960 { 961 StringBuffer info = new StringBuffer (); 962 info.append("<C-JDBC-CONTROLLER>"); 963 info.append("<" + ControllerXmlTags.ELT_CONTROLLER + " " 964 + ControllerXmlTags.ATT_CONTROLLER_IP + "=\"" + this.getIPAddress() 965 + "\" " + ControllerXmlTags.ATT_CONTROLLER_PORT + "=\"" 966 + this.getPortNumber() + "\" " + ">"); 967 968 info.append("<" + ControllerXmlTags.ELT_INTERNATIONALIZATION + " " 969 + ControllerXmlTags.ATT_LANGUAGE + "=\"" 970 + Locale.getDefault().getLanguage() + "\"/>"); 971 972 if (report.isReportEnabled()) 973 { 974 info.append("<" + ControllerXmlTags.ELT_REPORT + " " 975 + ControllerXmlTags.ATT_REPORT_ENABLE_FILE_LOGGING + "=\"" 976 + report.isEnableFileLogging() + "\" " 977 + ControllerXmlTags.ATT_REPORT_HIDE_SENSITIVE_DATA + "=\"" 978 + report.isHideSensitiveData() + "\" " 979 + ControllerXmlTags.ATT_REPORT_GENERATE_ON_FATAL + "=\"" 980 + report.isGenerateOnFatal() + "\" " 981 + ControllerXmlTags.ATT_REPORT_GENERATE_ON_SHUTDOWN + "=\"" 982 + report.isGenerateOnShutdown() + "\" " 983 + ControllerXmlTags.ATT_REPORT_REPORT_LOCATION + "=\"" 984 + report.getReportLocation() + "\" />"); 985 } 986 987 if (getJmxEnable()) 988 { 989 info.append("<" + ControllerXmlTags.ELT_JMX + ">"); 990 if (configuration.containsKey(JmxConstants.ADAPTOR_TYPE_HTTP)) 991 { 992 info.append("<" + ControllerXmlTags.ELT_HTTP_JMX_ADAPTOR + " " 993 + ControllerXmlTags.ATT_JMX_ADAPTOR_PORT + "=\"" 994 + configuration.get(JmxConstants.ADAPTOR_TYPE_HTTP) + "\" />"); 995 } 996 if (configuration.containsKey(JmxConstants.ADAPTOR_TYPE_RMI)) 997 { 998 info.append("<" + ControllerXmlTags.ELT_RMI_JMX_ADAPTOR + " " 999 + ControllerXmlTags.ATT_JMX_ADAPTOR_PORT + "=\"" 1000 + configuration.get(JmxConstants.ADAPTOR_TYPE_RMI) + "\" />"); 1001 } 1002 1003 info.append("</" + ControllerXmlTags.ELT_JMX + ">"); 1004 } 1005 1006 if (this.isSecurityEnabled()) 1007 info.append(this.getSecurity().getXml()); 1008 info.append("</" + ControllerXmlTags.ELT_CONTROLLER + ">"); 1009 info.append("</C-JDBC-CONTROLLER>"); 1010 return info.toString(); 1011 } 1012 1013 1018 public String getXmlVirtualDatabases() 1019 { 1020 try 1021 { 1022 StringBuffer info = new StringBuffer (); 1023 info.append(XmlComponent.XML_VERSION); 1024 info.append("\n"); 1025 info.append("<" + DatabasesXmlTags.ELT_CJDBC + ">"); 1026 ArrayList vdbs = this.getVirtualDatabases(); 1027 for (int i = 0, size = vdbs.size(); i < size; i++) 1028 info.append(((VirtualDatabase) vdbs.get(i)).getXml()); 1029 info.append("</" + DatabasesXmlTags.ELT_CJDBC + ">"); 1030 return info.toString(); 1031 } 1032 catch (Exception e) 1033 { 1034 logger.error(e.getMessage(), e); 1035 return e.getMessage(); 1036 } 1037 } 1038 1039 1042 public String generateLogReport() throws Exception 1043 { 1044 ReportManager logReport = new ReportManager(this, true); 1045 return logReport.generateJustLogs(); 1046 } 1047 1048 1052 1055 public void refreshLogConfiguration() throws ControllerException 1056 { 1057 try 1058 { 1059 LogManager.configure(URLDecoder.decode(this.getClass().getResource( 1060 ControllerConstants.LOG4J_RESOURCE).getFile())); 1061 if (logger.isDebugEnabled()) 1062 logger.info(Translate.get("controller.refresh.log.success")); 1063 } 1064 catch (Exception e) 1065 { 1066 throw new ControllerException(Translate 1067 .get("controller.logconfigfile.not.found")); 1068 } 1069 } 1070 1071 1074 public void updateLogConfigurationFile(String newConfiguration) 1075 throws IOException , ControllerException 1076 { 1077 File logFile = new File (URLDecoder.decode(getClass().getResource( 1078 ControllerConstants.LOG4J_RESOURCE).getFile())); 1079 BufferedWriter writer = new BufferedWriter (new FileWriter (logFile)); 1080 writer.write(newConfiguration); 1081 writer.flush(); 1082 writer.close(); 1083 refreshLogConfiguration(); 1084 } 1085 1086 1089 public String viewLogConfigurationFile() throws IOException 1090 { 1091 File logFile = new File (URLDecoder.decode(getClass().getResource( 1092 ControllerConstants.LOG4J_RESOURCE).getFile())); 1093 BufferedReader reader = new BufferedReader (new FileReader (logFile)); 1094 StringBuffer buffer = new StringBuffer (); 1095 String line; 1096 while ((line = reader.readLine()) != null) 1097 buffer.append(line + System.getProperty("line.separator")); 1098 reader.close(); 1099 return buffer.toString(); 1100 } 1101 1102 1107 public ReportManager getReport() 1108 { 1109 return report; 1110 } 1111 1112 1117 public void setReport(ReportManager report) 1118 { 1119 this.report = report; 1120 } 1121} | Popular Tags |