1 28 29 package org.objectweb.jonas.management; 30 31 import java.io.BufferedWriter ; 32 import java.io.File ; 33 import java.io.FileNotFoundException ; 34 import java.io.FileWriter ; 35 import java.io.IOException ; 36 37 import org.objectweb.util.monolog.api.BasicLevel; 38 39 43 public class ReconfiguratorXml extends AbsReconfigurator { 44 45 46 49 private String xml = null; 50 51 57 public ReconfiguratorXml(String name, String configFileName, String xml) { 58 super(name, configFileName); 59 this.xml = xml; 60 } 61 62 67 void updateConfig(String xml, long sequence) { 68 if (sequence > lastSequence) { 69 this.xml = xml; 70 lastSequence = sequence; 71 } else { 72 logger.log(BasicLevel.WARN, "Received out of order reconfiguration message !"); 73 } 74 } 75 76 77 82 public void saveConfig(long sequence) throws ReconfigException { 83 if (sequence > lastSequence) { 84 try { 85 86 BufferedWriter out = new BufferedWriter (new FileWriter (new File (configFileName))); 87 out.write(xml); 88 out.flush(); 89 out.close(); 90 lastSequence = sequence; 91 if (logger.isLoggable(BasicLevel.DEBUG)) { 92 logger.log(BasicLevel.DEBUG, "Configuration file " + configFileName + " updated"); 93 } 94 } catch (FileNotFoundException e) { 95 throw new ReconfigException("Cant' save configuration file: " + e.toString()); 96 } catch(IOException ioe) { 97 throw new ReconfigException("Cant' save configuration file: " + ioe.toString()); 98 } 99 } else { 100 logger.log(BasicLevel.WARN, "Received out of order save reconfiguration message for " + name + " !"); 101 logger.log(BasicLevel.WARN, "Can not save !!"); 102 logger.log(BasicLevel.WARN, "Please reconfigure and than save !!"); 103 } 104 105 } 106 107 108 } 109 | Popular Tags |