class OnceApplicationContextEventListener implements ApplicationContextAware, ApplicationListener<ApplicationEvent> {

    private ApplicationContext applicationContext;

    protected OnceApplicationContextEventListener() { }

    @Override
    public void onApplicationEvent(ApplicationEvent event) {<FILL_FUNCTION_BODY>}

    /**
     * The subclass overrides this method to handle {@link ContextRefreshedEvent}
     *
     * @param event {@link ContextRefreshedEvent}
     */
    protected void onContextRefreshedEvent(ContextRefreshedEvent event) {
    }

    /**
     * The subclass overrides this method to handle {@link ContextStartedEvent}
     *
     * @param event {@link ContextStartedEvent}
     */
    protected void onContextStartedEvent(ContextStartedEvent event) {
    }

    /**
     * The subclass overrides this method to handle {@link ContextStoppedEvent}
     *
     * @param event {@link ContextStoppedEvent}
     */
    protected void onContextStoppedEvent(ContextStoppedEvent event) {
    }

    /**
     * The subclass overrides this method to handle {@link ContextClosedEvent}
     *
     * @param event {@link ContextClosedEvent}
     */
    protected void onContextClosedEvent(ContextClosedEvent event) {
    }

    /**
     * Is original {@link ApplicationContext} as the event source
     * @param event {@link ApplicationEvent}
     * @return if original, return <code>true</code>, or <code>false</code>
     */
    private boolean isOriginalEventSource(ApplicationEvent event) {
        return nullSafeEquals(this.applicationContext, event.getSource());
    }

    @Override
    public final void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }
}

        if (isOriginalEventSource(event) && event instanceof ApplicationContextEvent) {
            if (event instanceof ContextRefreshedEvent) {
                onContextRefreshedEvent((ContextRefreshedEvent) event);
            } else if (event instanceof ContextStartedEvent) {
                onContextStartedEvent((ContextStartedEvent) event);
            } else if (event instanceof ContextStoppedEvent) {
                onContextStoppedEvent((ContextStoppedEvent) event);
            } else if (event instanceof ContextClosedEvent) {
                onContextClosedEvent((ContextClosedEvent) event);
            }
        }
    
<no_super_class>