com.opensymphony.oscache.base
Class Config

java.lang.Object
  extended by com.opensymphony.oscache.base.Config
All Implemented Interfaces:
Serializable

public class Config
extends Object
implements Serializable

Responsible for holding the Cache configuration properties. If the default constructor is used, this class will load the properties from the cache.configuration.

Version:
$Revision: 412 $
Author:
Fabian Crabus
See Also:
Serialized Form

Field Summary
private static org.apache.commons.logging.Log log
           
private  Properties properties
          Properties map to hold the cache configuration.
private static String PROPERTIES_FILENAME
          Name of the properties file.
 
Constructor Summary
Config()
          Create an OSCache Config that loads properties from oscache.properties.
Config(Properties p)
          Create an OSCache configuration with the specified properties.
 
Method Summary
 Object get(Object key)
           
 Properties getProperties()
          Retrieves all of the configuration properties.
 String getProperty(String key)
          Retrieve the value of the named configuration property.
static Properties loadProperties(String filename, String info)
          Load the specified properties file from the classpath.
static Properties loadProperties(URL url, String info)
          Load the properties from the specified URL.
 void set(Object key, Object value)
          Sets a configuration property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final transient org.apache.commons.logging.Log log

PROPERTIES_FILENAME

private static final String PROPERTIES_FILENAME
Name of the properties file.

See Also:
Constant Field Values

properties

private Properties properties
Properties map to hold the cache configuration.

Constructor Detail

Config

public Config()
Create an OSCache Config that loads properties from oscache.properties. The file must be present in the root of OSCache's classpath. If the file cannot be loaded, an error will be logged and the configuration will remain empty.


Config

public Config(Properties p)
Create an OSCache configuration with the specified properties. Note that it is the responsibility of the caller to provide valid properties as no error checking is done to ensure that required keys are present. If you're unsure of what keys should be present, have a look at a sample oscache.properties file.

Parameters:
p - The properties to use for this configuration. If null, then the default properties are loaded from the oscache.properties file.
Method Detail

getProperty

public String getProperty(String key)
Retrieve the value of the named configuration property. If the property cannot be found this method will return null.

Parameters:
key - The name of the property.
Returns:
The property value, or null if the value could not be found.
Throws:
IllegalArgumentException - if the supplied key is null.

getProperties

public Properties getProperties()
Retrieves all of the configuration properties. This property set should be treated as immutable.

Returns:
The configuration properties.

get

public Object get(Object key)

set

public void set(Object key,
                Object value)
Sets a configuration property.

Parameters:
key - The unique name for this property.
value - The value assigned to this property.
Throws:
IllegalArgumentException - if the supplied key is null.

loadProperties

public static Properties loadProperties(URL url,
                                        String info)
Load the properties from the specified URL.

Parameters:
url - a non null value of the URL to the properties
info - additional logger information if the properties can't be read
Returns:
the loaded properties specified by the URL
Since:
2.4

loadProperties

public static Properties loadProperties(String filename,
                                        String info)
Load the specified properties file from the classpath. If the file cannot be found or loaded, an error will be logged and no properties will be set.

Parameters:
filename - the properties file with path
info - additional logger information if file can't be read
Returns:
the loaded properties specified by the filename
Since:
2.4


Copyright © 2011 OpenSymphony. All Rights Reserved.