Config.java :  » Net » jMOS » com » aranova » java » jmos » util » Java Open Source

Java Open Source » Net » jMOS 
jMOS » com » aranova » java » jmos » util » Config.java
/*
 * File: Config.java
 * Project: jMOS, com.aranova.java.jmos.util
 * Revision: 0.9 - Inicial
 * Date: 07-sep-2005 11:46:00
 *
 * Copyright (C) Aragn Innovacin Tecnolgica S.L.L.
 * All rights reserved.
 *
 * This software is distributed under the terms of the Aranova License version 1.0.
 * See the terms of the Aranova License in the documentation provided with this software.
 */

package com.aranova.java.jmos.util;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.aranova.java.util.AraConfig;
import com.aranova.java.util.AraError;
import com.aranova.java.util.AraException;

 /**
 * Clase de configuracion.
 *
 * @author <a href="http://www.aranova.net/contactar/">Daniel Snchez</a>
 * @version     0.9.1
 * @since       0.9
 */
public final class Config {
  private static final String PROPERTIES_DEFAULT = "DefaultProperties.xml";
  private static final String PROPERTIES_INSTALL = "jMOS.xml";
  private static final String PROPERTIES_FOLDER = "conf/";
  private static final Log _log = LogFactory.getLog(Config.class);
  private static AraConfig _config;

  private Config() {
    super();
  }

  static {
    try {
      _config = AraConfig.getPropertiesFromResource(PROPERTIES_DEFAULT);
    } catch (AraException e) {
      throw new AraError("No se ha podido leer la configuracin base del cliente.", e);
    }
    try {
      _config = AraConfig.getPropertiesFromFile(getFullNameFile(PROPERTIES_INSTALL), _config);
    } catch (AraException e1) {
      _log.warn("No se ha podido leer la configuracin del cliente.", e1);
    }
    _log.info("Configurarcin del cliente inicializada");
  }

  /**
   * Guarda la configuracin en el fichero.
   */
  public static void store() {
    try {
      FileOutputStream os = new FileOutputStream(getFullNameFile(PROPERTIES_INSTALL));
      _config.storeToXML(os, "", "utf-8");
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  /**
   * @return Retorna la configuracin para el servidor
   */
  public static AraConfig getConfig() {
    return _config;
  }

  private static String getFullNameFile(final String name) {
    return PROPERTIES_FOLDER + name;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.