pulse - the web application framework Get pulse at SourceForge.net. Fast, secure and Free Open Source software downloads Ohloh project report for pulse-java

org.torweg.pulse.configuration
Class PoorMansCache

java.lang.Object
  extended by org.torweg.pulse.configuration.PoorMansCache
All Implemented Interfaces:
LifecycleResource

public final class PoorMansCache
extends java.lang.Object
implements LifecycleResource

a simple cache for configurations stored in ConfigBeans and XSL stylesheets.

The cache is a singleton and may be used concurrently. Cached values are stored as SoftReferences to avoid java.lang.OutOfMemoryErrors due to a growing cache.

Version:
$Revision: 2071 $
Author:
Thomas Weber

Method Summary
static void flushBundle(Bundle b)
          flush all configs from a bundle from the cache.
static ConfigBean getBundleConfig(java.lang.Class<? extends java.lang.Object> c, Bundle bundle)
          Deprecated. 
static Configuration getBundleConfiguration(java.lang.Class<? extends java.lang.Object> c, Bundle bundle)
          get the configuration registered for the given class of a bundle.
static ConfigBean getConfig(java.lang.Class<? extends java.lang.Object> c)
          Deprecated. 
static ConfigBean getConfig(java.io.File f)
          Deprecated. 
static Configuration getConfiguration(java.lang.Class<? extends java.lang.Object> c)
          get the configuration registered for the given class.
static Configuration getConfiguration(java.io.File f)
          get the Configuration defined in the given file.
static java.io.InputStream getFromCache(VirtualFile f)
          returns an InputStream for the given VirtualFile using the in-memory cache, if possible and otherwise delegates to VirtualFileSystem.getInputStream(VirtualFile).
static PoorMansCache getInstance()
          return the singleton instance of the config configBeanPool.
static org.jdom.Document getJDOMResource(Bundle b, java.io.File f)
          Deprecated. 
static org.jdom.Document getJDOMResource(java.io.File f)
          Deprecated. 
static XSLHandle getXSLHandle(java.io.File file)
          returns an XSLHandle for a given File.
static void init(java.io.File cp)
          initialises the singleton instance of the config configBeanPool.
 boolean isModified()
          true, if any config file served by the cache has been changed since the last check.
 void restart()
          reloads the cache.
 void shutdown()
          shuts the cache down.
 void startup()
          starts the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getConfiguration

public static Configuration getConfiguration(java.io.File f)
get the Configuration defined in the given file.

Parameters:
f - the config file to be read
Returns:
the desired configuration
Throws:
ConfigurationException - if the configuration could not be built

getConfiguration

public static Configuration getConfiguration(java.lang.Class<? extends java.lang.Object> c)
get the configuration registered for the given class.

Parameters:
c - the class that needs its configuration
Returns:
the desired configuration
Throws:
ConfigurationException - if the configuration could not be built

getBundleConfiguration

public static Configuration getBundleConfiguration(java.lang.Class<? extends java.lang.Object> c, Bundle bundle)
get the configuration registered for the given class of a bundle.

Parameters:
c - the class that needs its configuration
bundle - the bundle
Returns:
the desired configuration
Throws:
ConfigurationException - if the configuration could not be built

getConfig

@Deprecated
public static ConfigBean getConfig(java.io.File f)
Deprecated. 

get the ConfigBean defined in the given file.

Parameters:
f - the config file to be read
Returns:
the desired config bean or null, if no configuration could be found

getConfig

@Deprecated
public static ConfigBean getConfig(java.lang.Class<? extends java.lang.Object> c)
Deprecated. 

get the configuration registered for the given class.

Parameters:
c - the class that needs its configuration
Returns:
the desired config bean or null, if no configuration could be found

getBundleConfig

@Deprecated
public static ConfigBean getBundleConfig(java.lang.Class<? extends java.lang.Object> c, Bundle bundle)
Deprecated. 

get the configuration registered for the given class of a bundle.

Parameters:
c - the class that needs its configuration
bundle - the bundle
Returns:
the desired config bean or null, if no configuration could be found

getXSLHandle

public static XSLHandle getXSLHandle(java.io.File file)
returns an XSLHandle for a given File.

Parameters:
file - the XSL file
Returns:
the XSLHandle for the given File.

getJDOMResource

@Deprecated
public static org.jdom.Document getJDOMResource(java.io.File f)
                                         throws java.io.FileNotFoundException
Deprecated. 

returns a cached JDOM Document for the given XML file.

Parameters:
f - the file
Returns:
a cached JDOM Document for the given XML file.
Throws:
java.io.FileNotFoundException - if the given XML File cannot be found

getJDOMResource

@Deprecated
public static org.jdom.Document getJDOMResource(Bundle b,
                                                           java.io.File f)
                                         throws java.io.FileNotFoundException
Deprecated. 

returns a cached JDOM Document for the given XML file of the given Bundle.

Parameters:
f - the relative file
b - the Bundle
Returns:
a cached JDOM Document for the given XML file.
Throws:
java.io.FileNotFoundException - if the given XML File cannot be found

getFromCache

public static java.io.InputStream getFromCache(VirtualFile f)
                                        throws java.io.IOException
returns an InputStream for the given VirtualFile using the in-memory cache, if possible and otherwise delegates to VirtualFileSystem.getInputStream(VirtualFile).

Parameters:
f - the virtual file
Returns:
the input stream
Throws:
java.io.IOException - on errors

getInstance

public static PoorMansCache getInstance()
return the singleton instance of the config configBeanPool.

Returns:
the singleton instance

init

public static void init(java.io.File cp)
initialises the singleton instance of the config configBeanPool.

Parameters:
cp - the path to the main configuration directory

flushBundle

public static void flushBundle(Bundle b)
flush all configs from a bundle from the cache.

Parameters:
b - the bundle for which all configs will be flushed

isModified

public boolean isModified()
true, if any config file served by the cache has been changed since the last check.

Specified by:
isModified in interface LifecycleResource
Returns:
true, if any config file served by the cache has been changed since the last check.

startup

public void startup()
starts the cache.

Actually does nothing.

Specified by:
startup in interface LifecycleResource

shutdown

public void shutdown()
shuts the cache down.

Clears all internal lists and maps.

Specified by:
shutdown in interface LifecycleResource

restart

public void restart()
reloads the cache.

Clears all ConfigBeans and subresources, and removes all modified XSLHandles and JDOMHandles.

Specified by:
restart in interface LifecycleResource