Example usage for org.springframework.context ApplicationContext getDisplayName

List of usage examples for org.springframework.context ApplicationContext getDisplayName

Introduction

In this page you can find the example usage for org.springframework.context ApplicationContext getDisplayName.

Prototype

String getDisplayName();

Source Link

Document

Return a friendly name for this context.

Usage

From source file:org.springframework.context.RefreshedContextAttacherTest.java

@Test
public void testOnContextInitializedNotCalledIfNotContextRefreshedEvent() {
    final AtomicInteger counter = new AtomicInteger(0);
    RefreshedContextAttacher attacher = new RefreshedContextAttacher() {
        @Override//  w w  w  .  j  av a  2s.c om
        protected void onContextInitialized(ApplicationContext context) {
            super.onContextInitialized(context);
            logger.info("onContextInitialized(" + context.getDisplayName() + ") call count: "
                    + counter.incrementAndGet());
        }
    };
    Object[] args = { applicationContext };
    Class<?>[] parameterTypes = { ApplicationContext.class };
    for (Class<? extends ApplicationContextEvent> eventClass : Arrays.asList(ContextClosedEvent.class,
            ContextStartedEvent.class, ContextStoppedEvent.class)) {
        ApplicationContextEvent event = ExtendedConstructorUtils.newInstance(eventClass, args, parameterTypes);
        attacher.onApplicationEvent(event);
        Assert.assertEquals("Mismatched number of calls at for " + eventClass.getSimpleName(), 0,
                counter.get());
    }
}

From source file:org.springframework.context.support.AbstractApplicationContext.java

/**
 * Return information about this context.
 *//*from  w  ww  .ja v a2  s.  c  o  m*/
@Override
public String toString() {
    StringBuilder sb = new StringBuilder(getDisplayName());
    sb.append(": startup date [").append(new Date(getStartupDate()));
    sb.append("]; ");
    ApplicationContext parent = getParent();
    if (parent == null) {
        sb.append("root of context hierarchy");
    } else {
        sb.append("parent: ").append(parent.getDisplayName());
    }
    return sb.toString();
}