01: /*
02: * File: Config.java
03: * Project: jMOS, com.aranova.java.jmos.util
04: * Revision: 0.9 - Inicial
05: * Date: 07-sep-2005 11:46:00
06: *
07: * Copyright (C) Aragón Innovación Tecnológica S.L.L.
08: * All rights reserved.
09: *
10: * This software is distributed under the terms of the Aranova License version 1.0.
11: * See the terms of the Aranova License in the documentation provided with this software.
12: */
13:
14: package com.aranova.java.jmos.util;
15:
16: import java.io.FileNotFoundException;
17: import java.io.FileOutputStream;
18: import java.io.IOException;
19:
20: import org.apache.commons.logging.Log;
21: import org.apache.commons.logging.LogFactory;
22:
23: import com.aranova.java.util.AraConfig;
24: import com.aranova.java.util.AraError;
25: import com.aranova.java.util.AraException;
26:
27: /**
28: * Clase de configuracion.
29: *
30: * @author <a href="http://www.aranova.net/contactar/">Daniel Sánchez</a>
31: * @version 0.9.1
32: * @since 0.9
33: */
34: public final class Config {
35: private static final String PROPERTIES_DEFAULT = "DefaultProperties.xml";
36: private static final String PROPERTIES_INSTALL = "jMOS.xml";
37: private static final String PROPERTIES_FOLDER = "conf/";
38: private static final Log _log = LogFactory.getLog(Config.class);
39: private static AraConfig _config;
40:
41: private Config() {
42: super ();
43: }
44:
45: static {
46: try {
47: _config = AraConfig
48: .getPropertiesFromResource(PROPERTIES_DEFAULT);
49: } catch (AraException e) {
50: throw new AraError(
51: "No se ha podido leer la configuración base del cliente.",
52: e);
53: }
54: try {
55: _config = AraConfig.getPropertiesFromFile(
56: getFullNameFile(PROPERTIES_INSTALL), _config);
57: } catch (AraException e1) {
58: _log
59: .warn(
60: "No se ha podido leer la configuración del cliente.",
61: e1);
62: }
63: _log.info("Configurarción del cliente inicializada");
64: }
65:
66: /**
67: * Guarda la configuración en el fichero.
68: */
69: public static void store() {
70: try {
71: FileOutputStream os = new FileOutputStream(
72: getFullNameFile(PROPERTIES_INSTALL));
73: _config.storeToXML(os, "", "utf-8");
74: } catch (FileNotFoundException e) {
75: // TODO Auto-generated catch block
76: e.printStackTrace();
77: } catch (IOException e) {
78: // TODO Auto-generated catch block
79: e.printStackTrace();
80: }
81: }
82:
83: /**
84: * @return Retorna la configuración para el servidor
85: */
86: public static AraConfig getConfig() {
87: return _config;
88: }
89:
90: private static String getFullNameFile(final String name) {
91: return PROPERTIES_FOLDER + name;
92: }
93: }
|