ReconfiguratorXml.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * Initial developer(s): Florent Benoit
00022  * Contributor(s):
00023  *
00024  * --------------------------------------------------------------------------
00025  * $Id: ReconfiguratorXml.java,v 1.2 2004/09/22 17:30:36 ehardesty Exp $
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 }

Generated on Tue Feb 15 15:05:18 2005 for JOnAS by  doxygen 1.3.9.1