src/org/sonews/config/BackendConfig.java
changeset 45 7e24949b87b0
parent 35 ed84c8bdd87b
child 49 8df94bfd3e2f
     1.1 --- a/src/org/sonews/config/BackendConfig.java	Sun Aug 29 17:28:58 2010 +0200
     1.2 +++ b/src/org/sonews/config/BackendConfig.java	Sat Sep 10 18:18:05 2011 +0200
     1.3 @@ -33,83 +33,67 @@
     1.4  class BackendConfig extends AbstractConfig
     1.5  {
     1.6  
     1.7 -  private static BackendConfig instance = new BackendConfig();
     1.8 -  
     1.9 -  public static BackendConfig getInstance()
    1.10 -  {
    1.11 -    return instance;
    1.12 -  }
    1.13 -  
    1.14 -  private final TimeoutMap<String, String> values 
    1.15 -    = new TimeoutMap<String, String>();
    1.16 -  
    1.17 -  private BackendConfig()
    1.18 -  {
    1.19 -    super();
    1.20 -  }
    1.21 -  
    1.22 -  /**
    1.23 -   * Returns the config value for the given key or the defaultValue if the
    1.24 -   * key is not found in config.
    1.25 -   * @param key
    1.26 -   * @param defaultValue
    1.27 -   * @return
    1.28 -   */
    1.29 -  @Override
    1.30 -  public String get(String key, String defaultValue)
    1.31 -  {
    1.32 -    try
    1.33 -    {
    1.34 -      String configValue = values.get(key);
    1.35 -      if(configValue == null)
    1.36 -      {
    1.37 -        if(StorageManager.current() == null)
    1.38 -        {
    1.39 -          Log.get().warning("BackendConfig not available, using default.");
    1.40 -          return defaultValue;
    1.41 -        }
    1.42 +	private static BackendConfig instance = new BackendConfig();
    1.43  
    1.44 -        configValue = StorageManager.current().getConfigValue(key);
    1.45 -        if(configValue == null)
    1.46 -        {
    1.47 -          return defaultValue;
    1.48 -        }
    1.49 -        else
    1.50 -        {
    1.51 -          values.put(key, configValue);
    1.52 -          return configValue;
    1.53 -        }
    1.54 -      }
    1.55 -      else
    1.56 -      {
    1.57 -        return configValue;
    1.58 -      }
    1.59 -    }
    1.60 -    catch(StorageBackendException ex)
    1.61 -    {
    1.62 -      Log.get().log(Level.SEVERE, "Storage backend problem", ex);
    1.63 -      return defaultValue;
    1.64 -    }
    1.65 -  }
    1.66 -  
    1.67 -  /**
    1.68 -   * Sets the config value which is identified by the given key.
    1.69 -   * @param key
    1.70 -   * @param value
    1.71 -   */
    1.72 -  public void set(String key, String value)
    1.73 -  {
    1.74 -    values.put(key, value);
    1.75 -    
    1.76 -    try
    1.77 -    {
    1.78 -      // Write values to database
    1.79 -      StorageManager.current().setConfigValue(key, value);
    1.80 -    }
    1.81 -    catch(StorageBackendException ex)
    1.82 -    {
    1.83 -      ex.printStackTrace();
    1.84 -    }
    1.85 -  }
    1.86 -  
    1.87 +	public static BackendConfig getInstance()
    1.88 +	{
    1.89 +		return instance;
    1.90 +	}
    1.91 +	private final TimeoutMap<String, String> values = new TimeoutMap<String, String>();
    1.92 +
    1.93 +	private BackendConfig()
    1.94 +	{
    1.95 +		super();
    1.96 +	}
    1.97 +
    1.98 +	/**
    1.99 +	 * Returns the config value for the given key or the defaultValue if the
   1.100 +	 * key is not found in config.
   1.101 +	 * @param key
   1.102 +	 * @param defaultValue
   1.103 +	 * @return
   1.104 +	 */
   1.105 +	@Override
   1.106 +	public String get(String key, String defaultValue)
   1.107 +	{
   1.108 +		try {
   1.109 +			String configValue = values.get(key);
   1.110 +			if (configValue == null) {
   1.111 +				if (StorageManager.current() == null) {
   1.112 +					Log.get().warning("BackendConfig not available, using default.");
   1.113 +					return defaultValue;
   1.114 +				}
   1.115 +
   1.116 +				configValue = StorageManager.current().getConfigValue(key);
   1.117 +				if (configValue == null) {
   1.118 +					return defaultValue;
   1.119 +				} else {
   1.120 +					values.put(key, configValue);
   1.121 +					return configValue;
   1.122 +				}
   1.123 +			} else {
   1.124 +				return configValue;
   1.125 +			}
   1.126 +		} catch (StorageBackendException ex) {
   1.127 +			Log.get().log(Level.SEVERE, "Storage backend problem", ex);
   1.128 +			return defaultValue;
   1.129 +		}
   1.130 +	}
   1.131 +
   1.132 +	/**
   1.133 +	 * Sets the config value which is identified by the given key.
   1.134 +	 * @param key
   1.135 +	 * @param value
   1.136 +	 */
   1.137 +	public void set(String key, String value)
   1.138 +	{
   1.139 +		values.put(key, value);
   1.140 +
   1.141 +		try {
   1.142 +			// Write values to database
   1.143 +			StorageManager.current().setConfigValue(key, value);
   1.144 +		} catch (StorageBackendException ex) {
   1.145 +			ex.printStackTrace();
   1.146 +		}
   1.147 +	}
   1.148  }