jfun.yan.spring
Class Container2ApplicationContext

java.lang.Object
  extended by jfun.yan.spring.Container2ApplicationContext
All Implemented Interfaces:
org.springframework.beans.factory.BeanFactory, org.springframework.beans.factory.HierarchicalBeanFactory, org.springframework.beans.factory.ListableBeanFactory, org.springframework.context.ApplicationContext, org.springframework.context.ApplicationEventPublisher, org.springframework.context.MessageSource, org.springframework.core.io.ResourceLoader, org.springframework.core.io.support.ResourcePatternResolver

public class Container2ApplicationContext
extends java.lang.Object
implements org.springframework.beans.factory.ListableBeanFactory, org.springframework.context.ApplicationContext

This class adapts a yan Container object to Spring's ApplicationContext (primarily ListableBeanFactory) interface.

Many Thanks to spring for making ApplicationContext an interface! It helped.

Author:
Ben Yu Nov 16, 2005 11:40:13 PM

Field Summary
 
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.beans.factory.BeanFactory
FACTORY_BEAN_PREFIX
 
Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_URL_PREFIX
 
Constructor Summary
Container2ApplicationContext(org.springframework.context.MessageSource message_source, org.springframework.core.io.support.ResourcePatternResolver resource_loader, org.springframework.context.ApplicationEventPublisher publisher, java.lang.String name, long startup_timestamp, Container yan)
          Create a Container2BeanFactory object.
 
Method Summary
 boolean containsBean(java.lang.String name)
          Same as containsBeanDefinition(String) since this class does not care about hierarchy.
 boolean containsBeanDefinition(java.lang.String beanName)
           
 java.lang.String[] getAliases(java.lang.String name)
          Always returns empty.
 java.lang.Object getBean(java.lang.String name)
          Get a bean object.
 java.lang.Object getBean(java.lang.String beanname, java.lang.Class requiredType)
          Get a bean object.
 int getBeanDefinitionCount()
          Get the number of components registered under a string key.
 java.lang.String[] getBeanDefinitionNames()
          Get all the component keys that are of String type.
 java.lang.String[] getBeanDefinitionNames(java.lang.Class type)
          retrieves the string keys of all components whose's static instance type is a subtype of the required type.
 java.lang.String[] getBeanNamesForType(java.lang.Class type)
          retrieves the string keys of all components whose's static instance type is a subtype of the required type.
 java.lang.String[] getBeanNamesForType(java.lang.Class type, boolean includePrototypes, boolean includeFactoryBeans)
           
 java.util.Map getBeansOfType(java.lang.Class type)
          Get the (String,Object) map of all components with the given type.
 java.util.Map getBeansOfType(java.lang.Class type, boolean includePrototypes, boolean includeFactoryBeans)
          Get the (String,Object) map of all components with the given type.
 Container getContainer()
          Get the container in this object.
 java.lang.String getDisplayName()
           
 java.lang.String getMessage(org.springframework.context.MessageSourceResolvable resolvable, java.util.Locale locale)
           
 java.lang.String getMessage(java.lang.String code, java.lang.Object[] args, java.util.Locale locale)
           
 java.lang.String getMessage(java.lang.String code, java.lang.Object[] args, java.lang.String defaultMessage, java.util.Locale locale)
           
 org.springframework.context.ApplicationContext getParent()
           
 org.springframework.beans.factory.BeanFactory getParentBeanFactory()
           
 org.springframework.core.io.Resource getResource(java.lang.String location)
           
 org.springframework.core.io.Resource[] getResources(java.lang.String locationPattern)
           
 long getStartupDate()
           
 java.lang.Class getType(java.lang.String name)
          Get the static type of a component identified by the name.
 boolean isSingleton(java.lang.String name)
          Is the component identified by the name a singleton? FactoryBean is instantiated if the name doesn't start with '&' and the bean is a FactoryBean.
 void publishEvent(org.springframework.context.ApplicationEvent event)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Container2ApplicationContext

public Container2ApplicationContext(org.springframework.context.MessageSource message_source,
                                    org.springframework.core.io.support.ResourcePatternResolver resource_loader,
                                    org.springframework.context.ApplicationEventPublisher publisher,
                                    java.lang.String name,
                                    long startup_timestamp,
                                    Container yan)
Create a Container2BeanFactory object.

Parameters:
message_source - the MessageSource object.
resource_loader - the ResourcePatternResolver object.
publisher - the ApplicationEventPublisher object.
name - the name of the ApplicationContext.
startup_timestamp - the startup timestamp.
yan - the yan Container object.
Method Detail

getContainer

public Container getContainer()
Get the container in this object.


getBeanDefinitionCount

public int getBeanDefinitionCount()
Get the number of components registered under a string key.

Specified by:
getBeanDefinitionCount in interface org.springframework.beans.factory.ListableBeanFactory

getBeanDefinitionNames

public java.lang.String[] getBeanDefinitionNames()
Get all the component keys that are of String type.

Specified by:
getBeanDefinitionNames in interface org.springframework.beans.factory.ListableBeanFactory

getBeanDefinitionNames

public java.lang.String[] getBeanDefinitionNames(java.lang.Class type)
retrieves the string keys of all components whose's static instance type is a subtype of the required type.

FactoryBean's are not instantiated.

Specified by:
getBeanDefinitionNames in interface org.springframework.beans.factory.ListableBeanFactory
Parameters:
type - the type to match. Null indicates all.
Returns:
the keys.

getBeanNamesForType

public java.lang.String[] getBeanNamesForType(java.lang.Class type)
retrieves the string keys of all components whose's static instance type is a subtype of the required type.

FactoryBean's are instantiated if necessary to find out the product type.

Parameters:
type - the type to match. Null indicates all.
Returns:
the keys.

getBeanNamesForType

public java.lang.String[] getBeanNamesForType(java.lang.Class type,
                                              boolean includePrototypes,
                                              boolean includeFactoryBeans)

containsBeanDefinition

public boolean containsBeanDefinition(java.lang.String beanName)
Specified by:
containsBeanDefinition in interface org.springframework.beans.factory.ListableBeanFactory

getBeansOfType

public java.util.Map getBeansOfType(java.lang.Class type)
                             throws org.springframework.beans.BeansException
Get the (String,Object) map of all components with the given type.

Specified by:
getBeansOfType in interface org.springframework.beans.factory.ListableBeanFactory
Parameters:
type - the expected type. If this type is FactoryBean, the component is adapted to FactoryBean without actually instantiating instance.
Returns:
the Map object containing component instances (if the type is not BeanFactory), otherwise BeanFactory objects.
Throws:
org.springframework.beans.BeansException

getBeansOfType

public java.util.Map getBeansOfType(java.lang.Class type,
                                    boolean includePrototypes,
                                    boolean includeFactoryBeans)
                             throws org.springframework.beans.BeansException
Get the (String,Object) map of all components with the given type.

Specified by:
getBeansOfType in interface org.springframework.beans.factory.ListableBeanFactory
Parameters:
type - the expected type.
includePrototypes - Are the components who may not be singletons included?
includeFactoryBeans - Are FactoryBean objects included?
Returns:
the Map object containing component instances.
Throws:
org.springframework.beans.BeansException

getBean

public java.lang.Object getBean(java.lang.String name)
                         throws org.springframework.beans.BeansException
Get a bean object.

Specified by:
getBean in interface org.springframework.beans.factory.BeanFactory
Parameters:
name - the name of the component. If the name starts with a "&", as specified by Spring, a FactoryBean object is returned corresponding to the component, otherwise the component itself is instantiated.
Throws:
org.springframework.beans.BeansException

getBean

public java.lang.Object getBean(java.lang.String beanname,
                                java.lang.Class requiredType)
                         throws org.springframework.beans.BeansException
Get a bean object.

Specified by:
getBean in interface org.springframework.beans.factory.BeanFactory
Parameters:
beanname - the name of the component. If the name starts with a "&", as specified by Spring, a FactoryBean object is returned corresponding to the component, otherwise the component itself is instantiated.
requiredType - the expecting type. If the name starts with a "&", as specified by Spring convention, the type has to be either null or FactoryBean or a super type of FactoryBean. And in that case, a FactoryBean object is returned. If the name is a regular bean name, the corresponding component is instantiated.
Throws:
org.springframework.beans.BeansException

containsBean

public boolean containsBean(java.lang.String name)
Same as containsBeanDefinition(String) since this class does not care about hierarchy. In fact, Yan does not create Spring hierarchies.

Specified by:
containsBean in interface org.springframework.beans.factory.BeanFactory

isSingleton

public boolean isSingleton(java.lang.String name)
                    throws org.springframework.beans.factory.NoSuchBeanDefinitionException
Is the component identified by the name a singleton? FactoryBean is instantiated if the name doesn't start with '&' and the bean is a FactoryBean.

Specified by:
isSingleton in interface org.springframework.beans.factory.BeanFactory
Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException

getType

public java.lang.Class getType(java.lang.String name)
                        throws org.springframework.beans.factory.NoSuchBeanDefinitionException
Get the static type of a component identified by the name.

Specified by:
getType in interface org.springframework.beans.factory.BeanFactory
Parameters:
name - the bean name. FactoryBean is instantiated if the name doesn't start with '&' and the bean is a FactoryBean.
Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException

getAliases

public java.lang.String[] getAliases(java.lang.String name)
                              throws org.springframework.beans.factory.NoSuchBeanDefinitionException
Always returns empty.

Specified by:
getAliases in interface org.springframework.beans.factory.BeanFactory
Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException

getDisplayName

public java.lang.String getDisplayName()
Specified by:
getDisplayName in interface org.springframework.context.ApplicationContext

getParent

public org.springframework.context.ApplicationContext getParent()
Specified by:
getParent in interface org.springframework.context.ApplicationContext

getStartupDate

public long getStartupDate()
Specified by:
getStartupDate in interface org.springframework.context.ApplicationContext

publishEvent

public void publishEvent(org.springframework.context.ApplicationEvent event)
Specified by:
publishEvent in interface org.springframework.context.ApplicationContext
Specified by:
publishEvent in interface org.springframework.context.ApplicationEventPublisher

getMessage

public java.lang.String getMessage(java.lang.String code,
                                   java.lang.Object[] args,
                                   java.util.Locale locale)
                            throws org.springframework.context.NoSuchMessageException
Specified by:
getMessage in interface org.springframework.context.MessageSource
Throws:
org.springframework.context.NoSuchMessageException

getMessage

public java.lang.String getMessage(org.springframework.context.MessageSourceResolvable resolvable,
                                   java.util.Locale locale)
                            throws org.springframework.context.NoSuchMessageException
Specified by:
getMessage in interface org.springframework.context.MessageSource
Throws:
org.springframework.context.NoSuchMessageException

getMessage

public java.lang.String getMessage(java.lang.String code,
                                   java.lang.Object[] args,
                                   java.lang.String defaultMessage,
                                   java.util.Locale locale)
Specified by:
getMessage in interface org.springframework.context.MessageSource

getResources

public org.springframework.core.io.Resource[] getResources(java.lang.String locationPattern)
                                                    throws java.io.IOException
Specified by:
getResources in interface org.springframework.core.io.support.ResourcePatternResolver
Throws:
java.io.IOException

getResource

public org.springframework.core.io.Resource getResource(java.lang.String location)
Specified by:
getResource in interface org.springframework.core.io.ResourceLoader

getParentBeanFactory

public org.springframework.beans.factory.BeanFactory getParentBeanFactory()
Specified by:
getParentBeanFactory in interface org.springframework.beans.factory.HierarchicalBeanFactory