00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 package org.objectweb.jonas.management;
00030
00031 import java.io.BufferedWriter;
00032 import java.io.File;
00033 import java.io.FileNotFoundException;
00034 import java.io.FileWriter;
00035 import java.io.IOException;
00036
00037 import org.objectweb.util.monolog.api.BasicLevel;
00038
00043 public class ReconfiguratorXml extends AbsReconfigurator {
00044
00045
00049 private String xml = null;
00050
00057 public ReconfiguratorXml(String name, String configFileName, String xml) {
00058 super(name, configFileName);
00059 this.xml = xml;
00060 }
00061
00067 void updateConfig(String xml, long sequence) {
00068 if (sequence > lastSequence) {
00069 this.xml = xml;
00070 lastSequence = sequence;
00071 } else {
00072 logger.log(BasicLevel.WARN, "Received out of order reconfiguration message !");
00073 }
00074 }
00075
00076
00082 public void saveConfig(long sequence) throws ReconfigException {
00083 if (sequence > lastSequence) {
00084 try {
00085
00086 BufferedWriter out = new BufferedWriter(new FileWriter(new File(configFileName)));
00087 out.write(xml);
00088 out.flush();
00089 out.close();
00090 lastSequence = sequence;
00091 logger.log(BasicLevel.DEBUG, "Configuration file " + configFileName + " updated");
00092 } catch (FileNotFoundException e) {
00093 throw new ReconfigException("Cant' save configuration file: " + e.toString());
00094 } catch(IOException ioe) {
00095 throw new ReconfigException("Cant' save configuration file: " + ioe.toString());
00096 }
00097 } else {
00098 logger.log(BasicLevel.WARN, "Received out of order save reconfiguration message for " + name + " !");
00099 logger.log(BasicLevel.WARN, "Can not save !!");
00100 logger.log(BasicLevel.WARN, "Please reconfigure and than save !!");
00101 }
00102
00103 }
00104
00105
00106 }