Class SpringApplicationContextFacade

java.lang.Object
uk.ac.gda.core.tool.spring.SpringApplicationContextFacade
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationEventPublisherAware

@Component public class SpringApplicationContextFacade extends Object implements org.springframework.context.ApplicationEventPublisherAware, org.springframework.context.ApplicationContextAware
This class exposes Spring ApplicationEventPublisher to components as Views or Perspectives which are directly managed by Eclipse and consequently cannot be initialised by Spring
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static final void
    addApplicationContextAsParent(org.springframework.context.support.AbstractApplicationContext child)
    Associates an ApplicationContext parent to the ApplicationContext defined in this instance
    static final boolean
    addApplicationListener(org.springframework.context.ApplicationListener<?> listener)
    Attached a listener to the application context in order to be notified when new events occur.
    static final void
    addDisposableApplicationListener(Object object, org.springframework.context.ApplicationListener<?> listener)
    Registers a listener and removes it when the related object became a PhantomReference.
    void
    Close the running spring framework.
    static <T> T
    getBean(Class<T> requiredType)
    Return the bean instance that uniquely matches the given object type, if any.
    static <T> T
    getBean(String name, Class<T> requiredType)
    Return the bean instance that uniquely matches the given object type, if any.
    static <T> T
    getBean(String name, Class<T> requiredType, boolean fromParent)
    Return an instance, which may be shared or independent, of the specified bean.
    static Object
    getBean(String name, Object... args)
    Return an instance, which may be shared or independent, of the specified bean.
    static <T> Optional<T>
     
    static void
    There are cases where closing Spring is not enough to make an instance unavailable.
    static final void
    publishEvent(org.springframework.context.ApplicationEvent event)
     
    static final void
    removeApplicationListener(org.springframework.context.ApplicationListener<?> listener)
    Removes a listener from the ApplicationContext.
    void
    setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
     
    void
    setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationPublisher)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SpringApplicationContextFacade

      public SpringApplicationContextFacade()
  • Method Details

    • preDestroy

      @PreDestroy public static void preDestroy()
      There are cases where closing Spring is not enough to make an instance unavailable. This class contains as static some properties which are still available after spring, not the JVM, is destroyed. This method guarantee to clean up this component when spring is destroyed
    • setApplicationEventPublisher

      public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationPublisher)
      Specified by:
      setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAware
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
    • closeSpringFramework

      public void closeSpringFramework()
      Close the running spring framework.

      Use carefully!

    • publishEvent

      public static final void publishEvent(org.springframework.context.ApplicationEvent event)
    • addApplicationListener

      public static final boolean addApplicationListener(org.springframework.context.ApplicationListener<?> listener)
      Attached a listener to the application context in order to be notified when new events occur.
      Parameters:
      listener -
      Returns:
      true if succeed, false if SpringApplicationContextFacade no access to Spring ConfigurableApplicationContext
    • removeApplicationListener

      public static final void removeApplicationListener(org.springframework.context.ApplicationListener<?> listener)
      Removes a listener from the ApplicationContext.
      Parameters:
      listener - the listener to remove. If null does nothing
    • getBean

      public static <T> T getBean(Class<T> requiredType)
      Return the bean instance that uniquely matches the given object type, if any.
      Parameters:
      requiredType - type the bean must match; can be an interface or superclass. null is disallowed.

      This method goes into ListableBeanFactory by-type lookup territory but may also be translated into a conventional by-name lookup based on the name of the given type. For more extensive retrieval operations across sets of beans, use ListableBeanFactory and/or BeanFactoryUtils.

      Returns:
      an instance of the single bean matching the required type
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException - if no bean of the given type was found
      org.springframework.beans.factory.NoUniqueBeanDefinitionException - if more than one bean of the given type was found
    • getBean

      public static <T> T getBean(String name, Class<T> requiredType)
      Return the bean instance that uniquely matches the given object type, if any.
      Parameters:
      name - the name of the bean to retrieve
      requiredType - type the bean must match; can be an interface or superclass. null is disallowed.

      This method goes into ListableBeanFactory by-type lookup territory but may also be translated into a conventional by-name lookup based on the name of the given type. For more extensive retrieval operations across sets of beans, use ListableBeanFactory and/or BeanFactoryUtils.

      Returns:
      an instance of the single bean matching the required type
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException - if no bean of the given type was found
      org.springframework.beans.factory.NoUniqueBeanDefinitionException - if more than one bean of the given type was found
    • getBean

      public static <T> T getBean(String name, Class<T> requiredType, boolean fromParent)
      Return an instance, which may be shared or independent, of the specified bean.
      Type Parameters:
      T -
      Parameters:
      name - the name of the bean to retrieve
      requiredType - type the bean must match. Can be an interface or superclass of the actual class, or null for any match. For example, if the value is Object.class, this method will succeed whatever the class of the returned instance.
      fromParent - if true the bean is requested from the parent ApplicationContext, otherwise from the one in this instance.
      Returns:
      an instance of the single bean matching the required type
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException - if no bean of the given type was found
      org.springframework.beans.factory.NoUniqueBeanDefinitionException - if more than one bean of the given type was found
    • getBean

      public static Object getBean(String name, Object... args)
      Return an instance, which may be shared or independent, of the specified bean.

      Allows for specifying explicit constructor arguments / factory method arguments, overriding the specified default arguments (if any) in the bean definition.

      Parameters:
      name - the name of the bean to retrieve
      args - arguments to use if creating a prototype using explicit arguments to a static factory method. It is invalid to use a non-null args value in any other case.
      Returns:
      an instance of the bean
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException - if there is no such bean definition
      org.springframework.beans.factory.BeanDefinitionStoreException - if arguments have been given but the affected bean isn't a prototype
    • getOptionalBean

      public static <T> Optional<T> getOptionalBean(Class<T> bean)
    • addDisposableApplicationListener

      public static final void addDisposableApplicationListener(Object object, org.springframework.context.ApplicationListener<?> listener)
      Registers a listener and removes it when the related object became a PhantomReference.
      Parameters:
      object - the element publishing the dispose event which causes listener to be removed
      listener - the application lister to
    • addApplicationContextAsParent

      public static final void addApplicationContextAsParent(org.springframework.context.support.AbstractApplicationContext child)
      Associates an ApplicationContext parent to the ApplicationContext defined in this instance
      Parameters:
      child -