/** * Close the view bean factory on context shutdown. */ @Override public void destroy() throws BeansException { if (this.cachedFactory != null) { this.cachedFactory.close(); } }
/** * Retrieve the message for the given code and the given Locale. * @param code code of the message * @param locale the Locale in which to do lookup * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ public String getMessage(String code, Locale locale) throws NoSuchMessageException { return this.messageSource.getMessage(code, null, locale); }
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { for (ViewResolver viewResolver : this.viewResolvers) { if (viewResolver instanceof ApplicationContextAware) { ((ApplicationContextAware)viewResolver).setApplicationContext(applicationContext); } } }
/** * Overridden as we can't trust superclass method * @see org.springframework.context.AbstractApplicationContextTests#testEvents() */ @Override protected void doTestEvents(TestListener listener, TestListener parentListener, MyEvent event) { TestListener listenerBean = (TestListener) this.applicationContext.getBean("testListener"); TestListener parentListenerBean = (TestListener) this.applicationContext.getParent().getBean("parentListener"); super.doTestEvents(listenerBean, parentListenerBean, event); }
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { ContextHierarchyDirtiesContextTests.context = applicationContext; ContextHierarchyDirtiesContextTests.baz = applicationContext.getBean("bean", String.class); ContextHierarchyDirtiesContextTests.bar = applicationContext.getParent().getBean("bean", String.class); ContextHierarchyDirtiesContextTests.foo = applicationContext.getParent().getParent().getBean("bean", String.class); } }
@Override protected FooDao fooDao() { return context.getBean(FooDao.class); } };
/** * Notify all <strong>matching</strong> listeners registered with this * application of an application event. Events may be framework events * (such as RequestHandledEvent) or application-specific events. * @param event the event to publish * @see org.springframework.web.context.support.RequestHandledEvent */ default void publishEvent(ApplicationEvent event) { publishEvent((Object) event); }
/** * Refresh the given application context, if necessary. */ protected void refreshApplicationContext(ApplicationContext context) { if (context instanceof ConfigurableApplicationContext) { ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context; if (!cac.isActive()) { cac.refresh(); } } }
/** * Copy constructor: Create a new instance from another resolvable. * @param resolvable the resolvable to copy from */ public DefaultMessageSourceResolvable(MessageSourceResolvable resolvable) { this(resolvable.getCodes(), resolvable.getArguments(), resolvable.getDefaultMessage()); }
protected void doStart() { if (this.requestUpgradeStrategy instanceof Lifecycle) { ((Lifecycle) this.requestUpgradeStrategy).start(); } }
protected void doStop() { if (this.requestUpgradeStrategy instanceof Lifecycle) { ((Lifecycle) this.requestUpgradeStrategy).stop(); } }
@Override public boolean isRunning() { if (this.webSocketClient instanceof Lifecycle) { return ((Lifecycle) this.webSocketClient).isRunning(); } else { return this.running; } }
protected void doTestEvents(TestListener listener, TestListener parentListener, MyEvent event) { listener.zeroCounter(); parentListener.zeroCounter(); assertTrue("0 events before publication", listener.getEventCount() == 0); assertTrue("0 parent events before publication", parentListener.getEventCount() == 0); this.applicationContext.publishEvent(event); assertTrue("1 events after publication, not " + listener.getEventCount(), listener.getEventCount() == 1); assertTrue("1 parent events after publication", parentListener.getEventCount() == 1); }
/** * Return default exception message. */ protected String getNoSuchMessageExceptionDescription(NoSuchMessageException ex) { return ex.getMessage(); }
/** * Determine the lifecycle phase of the given bean. * <p>The default implementation checks for the {@link Phased} interface, using * a default of 0 otherwise. Can be overridden to apply other/further policies. * @param bean the bean to introspect * @return the phase (an integer value) * @see Phased#getPhase() * @see SmartLifecycle */ protected int getPhase(Lifecycle bean) { return (bean instanceof Phased ? ((Phased) bean).getPhase() : 0); }
@Override public void contextDestroyed(ServletContextEvent sce) { this.applicationContext.close(); } }
/** * Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance) * in the given Locale. * @param resolvable the MessageSourceResolvable * @param locale the Locale in which to do lookup * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ public String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException { return this.messageSource.getMessage(resolvable, locale); }
@Override public Object initializeBean(Object existingBean, String beanName) throws BeansException { if (existingBean instanceof ApplicationContextAware) { ((ApplicationContextAware) existingBean).setApplicationContext(StubWebApplicationContext.this); } return existingBean; }
@Override protected final void onTearDown() throws Exception { if (ctx != null) { ctx.close(); } }
/** * Retrieve the message for the given code and the given Locale. * @param code code of the message * @param defaultMessage the String to return if the lookup fails * @param locale the Locale in which to do lookup * @return the message */ public String getMessage(String code, String defaultMessage, Locale locale) { String msg = this.messageSource.getMessage(code, null, defaultMessage, locale); return (msg != null ? msg : ""); }