class SofaGenericApplicationContext extends GenericApplicationContext {

    private static final Method             GET_APPLICATION_EVENT_MULTICASTER_METHOD;

    private static final Field              EARLY_APPLICATION_EVENTS_FIELD;

    private List<ContextRefreshInterceptor> interceptors = new ArrayList<>();

    private boolean                         publishEventToParent;

    static {
        try {
            GET_APPLICATION_EVENT_MULTICASTER_METHOD = AbstractApplicationContext.class
                .getDeclaredMethod("getApplicationEventMulticaster");
            GET_APPLICATION_EVENT_MULTICASTER_METHOD.setAccessible(true);
            EARLY_APPLICATION_EVENTS_FIELD = AbstractApplicationContext.class
                .getDeclaredField("earlyApplicationEvents");
            EARLY_APPLICATION_EVENTS_FIELD.setAccessible(true);
        } catch (Throwable t) {
            throw new RuntimeException(t);
        }
    }

    public SofaGenericApplicationContext() {
        this(new SofaDefaultListableBeanFactory());
    }

    /**
     * Create a new SofaApplicationContext with the given DefaultListableBeanFactory.
     * @param beanFactory the DefaultListableBeanFactory instance to use for this context
     * @see #registerBeanDefinition
     * @see #refresh
     */
    public SofaGenericApplicationContext(SofaDefaultListableBeanFactory beanFactory) {
        super(beanFactory);
    }

    @Override
    public void refresh() throws BeansException, IllegalStateException {
        if (CollectionUtils.isEmpty(interceptors)) {
            super.refresh();
            return;
        }
        Throwable throwable = null;
        try {
            applyInterceptorBeforeRefresh();
            super.refresh();
        } catch (Throwable t) {
            throwable = t;
            throw t;
        } finally {
            applyInterceptorAfterRefresh(throwable);
        }
    }

    /**
     * @see org.springframework.context.support.AbstractApplicationContext#publishEvent(java.lang.Object, org.springframework.core.ResolvableType)
     */
    @Override
    protected void publishEvent(Object event, ResolvableType eventType) {<FILL_FUNCTION_BODY>}

    protected void applyInterceptorBeforeRefresh() {
        interceptors.forEach(interceptor -> interceptor.beforeRefresh(this));
    }

    protected void applyInterceptorAfterRefresh(Throwable throwable) {
        interceptors.forEach(interceptor -> interceptor.afterRefresh(this, throwable));
    }

    public void setPublishEventToParent(boolean publishEventToParent) {
        this.publishEventToParent = publishEventToParent;
    }

    public void setInterceptors(List<ContextRefreshInterceptor> interceptors) {
        this.interceptors = interceptors;
    }

    @SuppressWarnings("unchecked")
    private <T> T getFieldValueByReflect(Field field, Object obj) {
        try {
            return (T) field.get(obj);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }

    @SuppressWarnings("unchecked")
    private <T> T getMethodValueByReflect(Method method, Object obj, Object... args) {
        try {
            return (T) method.invoke(obj, args);
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }
}

        if (publishEventToParent) {
            super.publishEvent(event, eventType);
            return;
        }
        Assert.notNull(event, "Event must not be null");

        // Decorate event as an ApplicationEvent if necessary
        ApplicationEvent applicationEvent;
        if (event instanceof ApplicationEvent) {
            applicationEvent = (ApplicationEvent) event;
        } else {
            applicationEvent = new PayloadApplicationEvent<>(this, event);
            if (eventType == null) {
                eventType = ((PayloadApplicationEvent<?>) applicationEvent).getResolvableType();
            }
        }

        Set<ApplicationEvent> earlyApplicationEvents = getFieldValueByReflect(
            EARLY_APPLICATION_EVENTS_FIELD, this);
        if (earlyApplicationEvents != null) {
            earlyApplicationEvents.add(applicationEvent);
        } else {
            ApplicationEventMulticaster applicationEventMulticaster = getMethodValueByReflect(
                GET_APPLICATION_EVENT_MULTICASTER_METHOD, this);
            applicationEventMulticaster.multicastEvent(applicationEvent, eventType);
        }
    
<methods>public void <init>() ,public void <init>(org.springframework.beans.factory.support.DefaultListableBeanFactory) ,public void <init>(org.springframework.context.ApplicationContext) ,public void <init>(org.springframework.beans.factory.support.DefaultListableBeanFactory, org.springframework.context.ApplicationContext) ,public org.springframework.beans.factory.config.AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws java.lang.IllegalStateException,public org.springframework.beans.factory.config.BeanDefinition getBeanDefinition(java.lang.String) throws org.springframework.beans.factory.NoSuchBeanDefinitionException,public final org.springframework.beans.factory.config.ConfigurableListableBeanFactory getBeanFactory() ,public java.lang.ClassLoader getClassLoader() ,public final org.springframework.beans.factory.support.DefaultListableBeanFactory getDefaultListableBeanFactory() ,public org.springframework.core.io.Resource getResource(java.lang.String) ,public org.springframework.core.io.Resource[] getResources(java.lang.String) throws java.io.IOException,public boolean isAlias(java.lang.String) ,public boolean isBeanDefinitionOverridable(java.lang.String) ,public boolean isBeanNameInUse(java.lang.String) ,public void refreshForAotProcessing(org.springframework.aot.hint.RuntimeHints) ,public void registerAlias(java.lang.String, java.lang.String) ,public transient void registerBean(Class<T>, java.lang.Object[]) ,public final transient void registerBean(Class<T>, org.springframework.beans.factory.config.BeanDefinitionCustomizer[]) ,public transient void registerBean(java.lang.String, Class<T>, java.lang.Object[]) ,public final transient void registerBean(java.lang.String, Class<T>, org.springframework.beans.factory.config.BeanDefinitionCustomizer[]) ,public final transient void registerBean(Class<T>, Supplier<T>, org.springframework.beans.factory.config.BeanDefinitionCustomizer[]) ,public transient void registerBean(java.lang.String, Class<T>, Supplier<T>, org.springframework.beans.factory.config.BeanDefinitionCustomizer[]) ,public void registerBeanDefinition(java.lang.String, org.springframework.beans.factory.config.BeanDefinition) throws org.springframework.beans.factory.BeanDefinitionStoreException,public void removeAlias(java.lang.String) ,public void removeBeanDefinition(java.lang.String) throws org.springframework.beans.factory.NoSuchBeanDefinitionException,public void setAllowBeanDefinitionOverriding(boolean) ,public void setAllowCircularReferences(boolean) ,public void setApplicationStartup(org.springframework.core.metrics.ApplicationStartup) ,public void setClassLoader(java.lang.ClassLoader) ,public void setParent(org.springframework.context.ApplicationContext) ,public void setResourceLoader(org.springframework.core.io.ResourceLoader) <variables>private final org.springframework.beans.factory.support.DefaultListableBeanFactory beanFactory,private boolean customClassLoader,private final java.util.concurrent.atomic.AtomicBoolean refreshed,private org.springframework.core.io.ResourceLoader resourceLoader