Example usage for org.springframework.context.event ContextRefreshedEvent getSource

List of usage examples for org.springframework.context.event ContextRefreshedEvent getSource

Introduction

In this page you can find the example usage for org.springframework.context.event ContextRefreshedEvent getSource.

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:tomekkup.helenos.context.PostConfiguringClusterListener.java

private boolean isReady(ContextRefreshedEvent event) {
    XmlWebApplicationContext context = (XmlWebApplicationContext) event.getSource();
    return context.getServletConfig() != null;
}

From source file:org.exoplatform.acceptance.lifecycle.ProductionInitializer.java

/**
 * {@inheritDoc}//from w  w w . j  av a  2  s .c o  m
 * Handle an application event.
 */
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    ApplicationContext context = (ApplicationContext) event.getSource();
    // Execute once at the root context only
    if (context.getParent() == null) {
        if (credentialService.findByType(Credential.Type.NONE).size() == 0) {
            // Always load the NO CREDENTIAL entry in the repository if it doesn't exist
            credentialService.updateOrCreate(Credential.NONE);
        }
        // Otherwise we load its ID in our Singleton
        Credential.NONE.setId(credentialService.findByName(Credential.NONE.getName()).getId());
        LOGGER.info("NoCredential ID : {}", Credential.NONE.getId());
        // We may add an upgrade system here if necessary
        LOGGER.info("Data are ready for production.");
    }
}

From source file:org.exoplatform.acceptance.lifecycle.DevelopmentInitializer.java

/**
 * {@inheritDoc}/*  w  w  w .  ja v a  2 s  .  c om*/
 * Handle an application event.
 */
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    super.onApplicationEvent(event);
    ApplicationContext context = (ApplicationContext) event.getSource();
    // Load data in the root context only
    if (context.getParent() == null) {
        devDataLoaderService.initializeData();
    }
    LOGGER.info("Data are ready for development.");
}

From source file:ch.ralscha.extdirectspring.controller.MethodRegistrar.java

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {

    ApplicationContext context = (ApplicationContext) event.getSource();

    String[] beanNames = context.getBeanNamesForType(Object.class);

    for (String beanName : beanNames) {

        Class<?> handlerType = context.getType(beanName);
        final Class<?> userType = ClassUtils.getUserClass(handlerType);

        Set<Method> methods = MethodIntrospector.selectMethods(userType, new MethodFilter() {
            @Override/*w  ww.  j  a v a2  s  .c om*/
            public boolean matches(Method method) {
                return AnnotationUtils.findAnnotation(method, ExtDirectMethod.class) != null;
            }
        });

        for (Method method : methods) {
            ExtDirectMethod directMethodAnnotation = AnnotationUtils.findAnnotation(method,
                    ExtDirectMethod.class);
            final String beanAndMethodName = beanName + "." + method.getName();
            if (directMethodAnnotation.value().isValid(beanAndMethodName, userType, method)) {
                this.methodInfoCache.put(beanName, handlerType, method, event.getApplicationContext());

                // /CLOVER:OFF
                if (log.isDebugEnabled()) {
                    String info = "Register " + beanAndMethodName + "(" + directMethodAnnotation.value();
                    if (StringUtils.hasText(directMethodAnnotation.group())) {
                        info += ", " + directMethodAnnotation.group();
                    }
                    info += ")";
                    log.debug(info);
                }
                // /CLOVER:ON
            }
        }

    }
}

From source file:com.kixeye.chassis.bootstrap.Application.java

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    logger.debug("Received ContextRefreshedEvent {}", event);

    if (event.getSource().equals(getBootstrapApplicationContext())) {
        //the root context is fully started
        appMetadata = bootstrapApplicationContext.getBean(AppMetadata.class);
        configuration = bootstrapApplicationContext.getBean(AbstractConfiguration.class);
        configurationProvider = bootstrapApplicationContext.getBean(ConfigurationProvider.class);

        logger.debug("Root context started");

        initClientApplication();//from  www .j a v  a 2s .co  m

        return;
    }

    if (event.getSource() instanceof ApplicationContext
            && ((ApplicationContext) event.getSource()).getId().equals(appMetadata.getName())) {
        //the child context is fully started
        this.applicationContext = (AbstractApplicationContext) event.getSource();

        logger.debug("Child context started");
    }

    state.compareAndSet(State.STARTING, State.RUNNING);
}