org.springframework.extensions.config
Class BaseConfigService

java.lang.Object
  extended by org.springframework.extensions.surf.util.AbstractLifecycleBean
      extended by org.springframework.extensions.config.BaseConfigService
All Implemented Interfaces:
EventListener, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener, ConfigService
Direct Known Subclasses:
XMLConfigService

public abstract class BaseConfigService
extends AbstractLifecycleBean
implements ConfigService

Base class for all config service implementations. This class implements the basic algorithm for performing lookups, concrete classes read their configuration medium and populate this object ready for lookups. The algorithm used is as follows:

Lookup methods go through the list of sections (maybe restricted to an area) and looks at the evaluator for each one. The Evaluator implementation is extracted and applies() is called on it. If applies() returns true all the ConfigElements from it are added to the Config object. If the ConfigElement already exists in the Config object being built up the new one is combined() with the existing one.

Author:
gavinc

Field Summary
protected  List<ConfigDeployer> configDeployers
           
protected  ConfigSource configSource
           
 
Fields inherited from class org.springframework.extensions.surf.util.AbstractLifecycleBean
log
 
Constructor Summary
BaseConfigService(ConfigSource configSource)
          Construct the service with the source from which it must read
 
Method Summary
protected  void addConfigSection(ConfigSection section, String area)
          Adds the given config section to the config service and optionally within a named area
 void addDeployer(ConfigDeployer configDeployer)
          Register deployer
protected  void addEvaluator(String name, Evaluator evaluator)
          Adds the evaluator to the config service
 List<ConfigDeployment> appendConfig(ConfigSource configSource)
           
protected  Evaluator createEvaluator(String name, String className)
          Instantiate the evaluator with the given name and class
 void destroy()
          Cleans up all the resources used by the config service
 Config getConfig(Object object)
          Retrieves the configuration for the given object
 Config getConfig(Object object, ConfigLookupContext context)
          Retrieves the configuration for the given object using the given context
protected  Evaluator getEvaluator(String name)
          Retrieves the implementation of the named evaluator
protected  Map<String,Evaluator> getEvaluators()
          Get evaluators from the in-memory 'cache'
 Config getGlobalConfig()
          Returns just the global configuration, this allows the config service to be used independently of objects if desired (all config is placed in a global section).
protected  ConfigImpl getGlobalConfigImpl()
          Get globalConfig from the in-memory 'cache'
protected  List<ConfigSection> getSections()
          Get the sections from the in-memory 'cache'
protected  Map<String,List<ConfigSection>> getSectionsByArea()
          Get the sectionsByArea from the in-memory 'cache'
 void init()
          Deprecated. Should now be initialised via bootstrap mechanism.
 List<ConfigDeployment> initConfig()
          Initialises the config service - via bootstrap
protected  void onBootstrap(org.springframework.context.ApplicationEvent event)
          Initialise config on bootstrap
protected  void onShutdown(org.springframework.context.ApplicationEvent event)
          Destroy config in shutdown
protected  List<ConfigDeployment> parse()
          Parses all the files passed to this config service
protected abstract  void parse(InputStream stream)
          Parses the given config stream
protected  void processSection(ConfigSection section, Object object, ConfigLookupContext context, ConfigImpl results)
          Determines whether the given section applies for the given object, if it does, the section is added to given results object.
protected  void putEvaluators(Map<String,Evaluator> evaluators)
          Put evaluators into the in-memory 'cache'
protected  void putGlobalConfig(ConfigImpl globalConfig)
          Put globalConfig into the in-memory 'cache'
protected  void putSections(List<ConfigSection> sections)
          Put the sections into the in-memory 'cache'
protected  void putSectionsByArea(Map<String,List<ConfigSection>> sectionsByArea)
          Put the sectionsByArea into the in-memory 'cache'
protected  void removeEvaluators()
          Remove evaluators from in-memory 'cache'
protected  void removeGlobalConfig()
          Remove globalConfig from the in-memory 'cache'
protected  void removeSections()
          Remove the sections from the in-memory 'cache'
protected  void removeSectionsByArea()
          Remove the sectionsByArea from the in-memory 'cache'
 void reset()
          Resets the config service
 
Methods inherited from class org.springframework.extensions.surf.util.AbstractLifecycleBean
getApplicationContext, onApplicationEvent, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configSource

protected ConfigSource configSource

configDeployers

protected List<ConfigDeployer> configDeployers
Constructor Detail

BaseConfigService

public BaseConfigService(ConfigSource configSource)
Construct the service with the source from which it must read

Parameters:
configSource - the source of the configurations
Method Detail

init

public void init()
Deprecated. Should now be initialised via bootstrap mechanism.

Initialises the config service - via init-method


initConfig

public List<ConfigDeployment> initConfig()
Initialises the config service - via bootstrap


destroy

public void destroy()
Cleans up all the resources used by the config service


reset

public void reset()
Resets the config service

Specified by:
reset in interface ConfigService

addDeployer

public void addDeployer(ConfigDeployer configDeployer)
Register deployer

Specified by:
addDeployer in interface ConfigService
Parameters:
configDeployer -

getConfig

public Config getConfig(Object object)
Description copied from interface: ConfigService
Retrieves the configuration for the given object

Specified by:
getConfig in interface ConfigService
Parameters:
object - The object to use as the basis of the lookup
Returns:
The Config object containing all the matching configuration data
See Also:
ConfigService.getConfig(java.lang.Object)

getConfig

public Config getConfig(Object object,
                        ConfigLookupContext context)
Description copied from interface: ConfigService
Retrieves the configuration for the given object using the given context

Specified by:
getConfig in interface ConfigService
Parameters:
object - The object to use as the basis of the lookup
context - The context to use for the lookup
Returns:
The Config object containing all the matching configuration data
See Also:
ConfigService.getConfig(java.lang.Object, org.springframework.extensions.config.ConfigLookupContext)

getGlobalConfig

public Config getGlobalConfig()
Description copied from interface: ConfigService
Returns just the global configuration, this allows the config service to be used independently of objects if desired (all config is placed in a global section).

Specified by:
getGlobalConfig in interface ConfigService
Returns:
The global config section or null if there isn't one
See Also:
ConfigService.getGlobalConfig()

appendConfig

public List<ConfigDeployment> appendConfig(ConfigSource configSource)
Specified by:
appendConfig in interface ConfigService
See Also:
ConfigService.appendConfig(org.springframework.extensions.config.ConfigSource)

parse

protected List<ConfigDeployment> parse()
Parses all the files passed to this config service


parse

protected abstract void parse(InputStream stream)
Parses the given config stream

Parameters:
stream - The input stream representing the config data

addConfigSection

protected void addConfigSection(ConfigSection section,
                                String area)
Adds the given config section to the config service and optionally within a named area

Parameters:
section - The config section to add
area - The name of the area to add the section to, if null the section is only added to the global section list

getEvaluator

protected Evaluator getEvaluator(String name)
Retrieves the implementation of the named evaluator

Parameters:
name - Name of the evaluator to retrieve
Returns:
The evaluator, null if it doesn't exist

addEvaluator

protected void addEvaluator(String name,
                            Evaluator evaluator)
Adds the evaluator to the config service

Parameters:
name - Name of the evaluator
evaluator - The evaluator

createEvaluator

protected Evaluator createEvaluator(String name,
                                    String className)
Instantiate the evaluator with the given name and class

Parameters:
name - Name of the evaluator
className - Class name of the evaluator

processSection

protected void processSection(ConfigSection section,
                              Object object,
                              ConfigLookupContext context,
                              ConfigImpl results)
Determines whether the given section applies for the given object, if it does, the section is added to given results object.

Parameters:
section - The section to process
object - The object to retrieve config for
context - The context to use for the lookup
results - The resulting config object for the search

getGlobalConfigImpl

protected ConfigImpl getGlobalConfigImpl()
Get globalConfig from the in-memory 'cache'

Returns:
globalConfig

putGlobalConfig

protected void putGlobalConfig(ConfigImpl globalConfig)
Put globalConfig into the in-memory 'cache'

Parameters:
globalConfig -

removeGlobalConfig

protected void removeGlobalConfig()
Remove globalConfig from the in-memory 'cache'


getEvaluators

protected Map<String,Evaluator> getEvaluators()
Get evaluators from the in-memory 'cache'

Returns:

putEvaluators

protected void putEvaluators(Map<String,Evaluator> evaluators)
Put evaluators into the in-memory 'cache'

Parameters:
evaluators -

removeEvaluators

protected void removeEvaluators()
Remove evaluators from in-memory 'cache'


getSectionsByArea

protected Map<String,List<ConfigSection>> getSectionsByArea()
Get the sectionsByArea from the in-memory 'cache'

Returns:
sectionsByArea

putSectionsByArea

protected void putSectionsByArea(Map<String,List<ConfigSection>> sectionsByArea)
Put the sectionsByArea into the in-memory 'cache'

Parameters:
sectionsByArea -

removeSectionsByArea

protected void removeSectionsByArea()
Remove the sectionsByArea from the in-memory 'cache'


getSections

protected List<ConfigSection> getSections()
Get the sections from the in-memory 'cache'

Returns:
sections

putSections

protected void putSections(List<ConfigSection> sections)
Put the sections into the in-memory 'cache'

Parameters:
sections -

removeSections

protected void removeSections()
Remove the sections from the in-memory 'cache'


onBootstrap

protected void onBootstrap(org.springframework.context.ApplicationEvent event)
Initialise config on bootstrap

Specified by:
onBootstrap in class AbstractLifecycleBean

onShutdown

protected void onShutdown(org.springframework.context.ApplicationEvent event)
Destroy config in shutdown

Specified by:
onShutdown in class AbstractLifecycleBean


Copyright © 2009 SpringSource, Inc. All Rights Reserved.