org.abstracthorizon.extend.support.spring.deployment
Class AbstractApplicationContextModule

java.lang.Object
  extended by org.springframework.core.io.DefaultResourceLoader
      extended by org.springframework.context.support.AbstractApplicationContext
          extended by org.springframework.context.support.AbstractRefreshableApplicationContext
              extended by org.springframework.context.support.AbstractXmlApplicationContext
                  extended by org.abstracthorizon.extend.support.spring.deployment.AbstractApplicationContextModule
All Implemented Interfaces:
Module, BeanFactory, DisposableBean, HierarchicalBeanFactory, ListableBeanFactory, ApplicationContext, ApplicationEventPublisher, ConfigurableApplicationContext, Lifecycle, MessageSource, ResourceLoader, ResourcePatternResolver
Direct Known Subclasses:
ServiceApplicationContextModule

public abstract class AbstractApplicationContextModule
extends AbstractXmlApplicationContext
implements Module

This class is base class for spring application context modules. That means module represents a kind of application context in spring terms loaded from module's location.

Author:
Daniel Sendula

Nested Class Summary
 class AbstractApplicationContextModule.DeployersDefaultListableBeanFactory
          Class that tries to load beans from current context or any context this context depends on.
 
Field Summary
protected  LinkedHashSet<Module> dependOnThis
          List of modules that depend on this module
protected  LinkedHashSet<Module> dependsOn
          List of modules this module depends on
protected  DeploymentManager deploymentManager
          Deployment manager
protected  ClassLoader internalClassLoader
          Internal class loader
protected  ModuleId moduleId
          Module id
protected  URL originalLocation
          Original location this archive was unpacked from
protected  ModuleClassLoader overallClassLoader
          Application context's class loader
protected  URL serviceFile
          Application context xml file
protected  int state
          Module's state
protected  URL workingLocation
          Module's location
 
Fields inherited from class org.springframework.context.support.AbstractApplicationContext
APPLICATION_EVENT_MULTICASTER_BEAN_NAME, MESSAGE_SOURCE_BEAN_NAME
 
Fields inherited from interface org.abstracthorizon.extend.server.deployment.Module
CREATED, DEFINED, STARTED, UNDEFINED, WAITING_ON_CREATE, WAITING_ON_CREATE_TO_START, WAITING_ON_START
 
Fields inherited from interface org.springframework.beans.factory.BeanFactory
FACTORY_BEAN_PREFIX
 
Fields inherited from interface org.springframework.beans.factory.BeanFactory
FACTORY_BEAN_PREFIX
 
Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX
 
Fields inherited from interface org.springframework.core.io.ResourceLoader
CLASSPATH_URL_PREFIX
 
Constructor Summary
AbstractApplicationContextModule(ModuleId moduleId)
          Constructor that creates overall class loader (context's class loader).
 
Method Summary
 void create()
          This method invokes createInternal() method.
 DefaultListableBeanFactory createBeanFactory()
          Creates AbstractApplicationContextModule.DeployersDefaultListableBeanFactory instead of original.
protected  void createClassLoaders()
          Called when location is set for class loader to be created.
protected abstract  void createInternal()
          This method is to be implemented by extension.
protected  URL createServiceFile()
          Creates service file URL
 void destroy()
          This method calls stopInternal() and then calls Module.stop() of all dependent modules.
protected abstract  void destroyInternal()
          This method is to be implemented by extension.
 boolean equals(Object o)
          Compares two modules and returns true if names are the same
 ClassLoader getClassLoader()
          Return's module's class loader (top most internalClassLoader).
protected  String[] getConfigLocations()
          This method returns config location for this AbstractXmlApplicationContext instance.
protected  String getContextFileName()
          This is template method for name of application context xml file.
 Set<Module> getDependOnThis()
          Returns set of modules that depend on this module.
 Set<Module> getDependsOn()
          Returns set of modules this module depends on.
 DeploymentManager getDeploymentManager()
          Returns deployment manager
 ModuleId getModuleId()
          Returns module's id
 URL getOriginalLocation()
          Returns original location this archive was unpacked from.
 Resource getResource(String location)
          Returns resource for given location
 URL getServiceFile()
          Returns service file url
 int getState()
          Returns module's state
 String getStateAsString()
          Returns module's state as a string
 URL getWorkingLocation()
          Returns the location.
protected  void initBeanDefinitionReader(XmlBeanDefinitionReader xmlbeandefinitionreader)
          Sets up parser for this application context.
protected  boolean processDependencies(List<Dependency> dependencies)
          This method is called by parser to process dependencies it collected before rest of bean information is processed by the parser.
 void setDeploymentManager(DeploymentManager deploymentManager)
          Sets deployment manager
 void setLocation(URL location)
          Sets the location.
 void setModuleId(ModuleId moduleId)
          Sets module's name
 void setOriginalLocation(URL originalLocation)
          Sets original location
 void setState(int state)
          Sets module's state
 void start()
          This method calls startInternal() and then calls Module.start() of all dependent modules.
protected abstract  void startInternal()
          This method is to be implemented by extension.
 void stop()
          This method calls stopInternal() and then calls Module.stop() of all dependent modules.
protected abstract  void stopInternal()
          This method is to be implemented by extension.
 String toString()
          Returns module's name followed by colon and string representation of AbstractXmlApplicationContext object.
 
Methods inherited from class org.springframework.context.support.AbstractXmlApplicationContext
getConfigResources, loadBeanDefinitions, loadBeanDefinitions
 
Methods inherited from class org.springframework.context.support.AbstractRefreshableApplicationContext
closeBeanFactory, customizeBeanFactory, getBeanFactory, refreshBeanFactory
 
Methods inherited from class org.springframework.context.support.AbstractApplicationContext
addApplicationListener, addBeanFactoryPostProcessor, addListener, close, containsBean, containsBeanDefinition, containsLocalBean, destroyBeans, doClose, getAliases, getApplicationListeners, getAutowireCapableBeanFactory, getBean, getBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanFactoryPostProcessors, getBeanNamesForType, getBeanNamesForType, getBeansOfType, getBeansOfType, getDisplayName, getInternalParentBeanFactory, getInternalParentMessageSource, getLifecycleBeans, getMessage, getMessage, getMessage, getParent, getParentBeanFactory, getResourcePatternResolver, getResources, getStartupDate, getType, initApplicationEventMulticaster, initMessageSource, invokeBeanFactoryPostProcessors, isActive, isPrototype, isRunning, isSingleton, isTypeMatch, obtainFreshBeanFactory, onClose, onRefresh, postProcessBeanFactory, prepareBeanFactory, prepareRefresh, publishEvent, refresh, registerBeanPostProcessors, registerListeners, registerShutdownHook, setDisplayName, setParent
 
Methods inherited from class org.springframework.core.io.DefaultResourceLoader
getResourceByPath, setClassLoader
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

moduleId

protected ModuleId moduleId
Module id


dependsOn

protected LinkedHashSet<Module> dependsOn
List of modules this module depends on


dependOnThis

protected LinkedHashSet<Module> dependOnThis
List of modules that depend on this module


internalClassLoader

protected ClassLoader internalClassLoader
Internal class loader


overallClassLoader

protected ModuleClassLoader overallClassLoader
Application context's class loader


originalLocation

protected URL originalLocation
Original location this archive was unpacked from


workingLocation

protected URL workingLocation
Module's location


serviceFile

protected URL serviceFile
Application context xml file


state

protected int state
Module's state


deploymentManager

protected DeploymentManager deploymentManager
Deployment manager

Constructor Detail

AbstractApplicationContextModule

public AbstractApplicationContextModule(ModuleId moduleId)
Constructor that creates overall class loader (context's class loader).

Method Detail

setDeploymentManager

public void setDeploymentManager(DeploymentManager deploymentManager)
Sets deployment manager

Parameters:
deploymentManager - deployment manager

getDeploymentManager

public DeploymentManager getDeploymentManager()
Returns deployment manager

Returns:
deployment manager

getConfigLocations

protected String[] getConfigLocations()
This method returns config location for this AbstractXmlApplicationContext instance. It uses serviceFile for it converted to a string.

Overrides:
getConfigLocations in class AbstractXmlApplicationContext
Returns:
serviceFile converted to a string.

create

public void create()
This method invokes createInternal() method. After that it loads modules context from serviceFile and invokes Module.create() method on all dependent modules.

Specified by:
create in interface Module

start

public void start()
This method calls startInternal() and then calls Module.start() of all dependent modules.

Specified by:
start in interface Module
Specified by:
start in interface Lifecycle
Overrides:
start in class AbstractApplicationContext

stop

public void stop()
This method calls stopInternal() and then calls Module.stop() of all dependent modules. If module's state is Module.WAITING_ON_START then only state of module is updated (to Module.CREATED.

Specified by:
stop in interface Module
Specified by:
stop in interface Lifecycle
Overrides:
stop in class AbstractApplicationContext

destroy

public void destroy()
This method calls stopInternal() and then calls Module.stop() of all dependent modules. At last it closes this application context releasing resources. If module's state is Module.WAITING_ON_CREATE then only state of module is updated (to Module.DEFINED.

Specified by:
destroy in interface Module
Specified by:
destroy in interface DisposableBean
Overrides:
destroy in class AbstractApplicationContext

createInternal

protected abstract void createInternal()
This method is to be implemented by extension. It is called when create() method is called


startInternal

protected abstract void startInternal()
This method is to be implemented by extension. It is called when start() method is called


stopInternal

protected abstract void stopInternal()
This method is to be implemented by extension. It is called when stop() method is called


destroyInternal

protected abstract void destroyInternal()
This method is to be implemented by extension. It is called when destroy() method is called


initBeanDefinitionReader

protected void initBeanDefinitionReader(XmlBeanDefinitionReader xmlbeandefinitionreader)
Sets up parser for this application context. This implementation uses ApplicationContextModuleXmlParser without validation with internalClassLoader.

Overrides:
initBeanDefinitionReader in class AbstractXmlApplicationContext

processDependencies

protected boolean processDependencies(List<Dependency> dependencies)
This method is called by parser to process dependencies it collected before rest of bean information is processed by the parser.

Parameters:
dependencies - list of dependencies (as Strings).
Returns:
true if all dependencies are resolved positively (modules are already defined). If any of modules is missing false is going to be returned.

getOriginalLocation

public URL getOriginalLocation()
Returns original location this archive was unpacked from. This value is going to be the same as getWorkingLocation() if archive is an directory.

Specified by:
getOriginalLocation in interface Module
Returns:
original location

setOriginalLocation

public void setOriginalLocation(URL originalLocation)
Sets original location

Parameters:
originalLocation - original location

getWorkingLocation

public URL getWorkingLocation()
Returns the location.

Specified by:
getWorkingLocation in interface Module
Returns:
the location.

setLocation

public void setLocation(URL location)
Sets the location. Location is top directory of this module. All module's files are under it.

Parameters:
location - the location to set.
Throws:
RuntimeException - in case of IOException

createServiceFile

protected URL createServiceFile()
                         throws IOException
Creates service file URL

Returns:
service file URL
Throws:
IOException

getServiceFile

public URL getServiceFile()
Returns service file url

Returns:
service file url

getContextFileName

protected String getContextFileName()
This is template method for name of application context xml file. This implementation returns "service.xml" but can be redefined by subclasses.

Returns:
"service.xml"

createClassLoaders

protected void createClassLoaders()
Called when location is set for class loader to be created.


getClassLoader

public ClassLoader getClassLoader()
Return's module's class loader (top most internalClassLoader).

Specified by:
getClassLoader in interface Module
Specified by:
getClassLoader in interface ResourceLoader
Overrides:
getClassLoader in class DefaultResourceLoader
Returns:
module's class loader

getDependsOn

public Set<Module> getDependsOn()
Returns set of modules this module depends on.

Specified by:
getDependsOn in interface Module
Returns:
set of modules this module depends on

getDependOnThis

public Set<Module> getDependOnThis()
Returns set of modules that depend on this module.

Specified by:
getDependOnThis in interface Module
Returns:
set of modules that depend on this module

setModuleId

public void setModuleId(ModuleId moduleId)
Sets module's name

Parameters:
moduleId - module's id

getModuleId

public ModuleId getModuleId()
Returns module's id

Specified by:
getModuleId in interface Module
Returns:
module's id

toString

public String toString()
Returns module's name followed by colon and string representation of AbstractXmlApplicationContext object.

Overrides:
toString in class AbstractApplicationContext
Returns:
this object as a string

createBeanFactory

public DefaultListableBeanFactory createBeanFactory()
Creates AbstractApplicationContextModule.DeployersDefaultListableBeanFactory instead of original.

Overrides:
createBeanFactory in class AbstractRefreshableApplicationContext
Returns:
new instance of AbstractApplicationContextModule.DeployersDefaultListableBeanFactory

getState

public int getState()
Returns module's state

Specified by:
getState in interface Module
Returns:
module's state

setState

public void setState(int state)
Sets module's state

Specified by:
setState in interface Module
Parameters:
state - module's state

getStateAsString

public String getStateAsString()
Returns module's state as a string

Returns:
module's state as a string

getResource

public Resource getResource(String location)
Returns resource for given location

Specified by:
getResource in interface ResourceLoader
Overrides:
getResource in class DefaultResourceLoader
Parameters:
location - location
Returns:
resource

equals

public boolean equals(Object o)
Compares two modules and returns true if names are the same

Overrides:
equals in class Object
Parameters:
o - other object
Returns:
true if names are the same


Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.