use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class InterceptorsBeanDefinitionParser method parse.
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
parserContext.pushContainingComponent(compDefinition);
RuntimeBeanReference pathMatcherRef = null;
if (element.hasAttribute("path-matcher")) {
pathMatcherRef = new RuntimeBeanReference(element.getAttribute("path-matcher"));
}
List<Element> interceptors = DomUtils.getChildElementsByTagName(element, "bean", "ref", "interceptor");
for (Element interceptor : interceptors) {
RootBeanDefinition mappedInterceptorDef = new RootBeanDefinition(MappedInterceptor.class);
mappedInterceptorDef.setSource(parserContext.extractSource(interceptor));
mappedInterceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
ManagedList<String> includePatterns = null;
ManagedList<String> excludePatterns = null;
Object interceptorBean;
if ("interceptor".equals(interceptor.getLocalName())) {
includePatterns = getIncludePatterns(interceptor, "mapping");
excludePatterns = getIncludePatterns(interceptor, "exclude-mapping");
Element beanElem = DomUtils.getChildElementsByTagName(interceptor, "bean", "ref").get(0);
interceptorBean = parserContext.getDelegate().parsePropertySubElement(beanElem, null);
} else {
interceptorBean = parserContext.getDelegate().parsePropertySubElement(interceptor, null);
}
mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, includePatterns);
mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, excludePatterns);
mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(2, interceptorBean);
if (pathMatcherRef != null) {
mappedInterceptorDef.getPropertyValues().add("pathMatcher", pathMatcherRef);
}
String beanName = parserContext.getReaderContext().registerWithGeneratedName(mappedInterceptorDef);
parserContext.registerComponent(new BeanComponentDefinition(mappedInterceptorDef, beanName));
}
parserContext.popAndRegisterContainingComponent();
return null;
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class MvcNamespaceUtils method registerBeanNameUrlHandlerMapping.
/**
* Registers an {@link HttpRequestHandlerAdapter} under a well-known
* name unless already registered.
*/
private static void registerBeanNameUrlHandlerMapping(ParserContext parserContext, Object source) {
if (!parserContext.getRegistry().containsBeanDefinition(BEAN_NAME_URL_HANDLER_MAPPING_BEAN_NAME)) {
RootBeanDefinition beanNameMappingDef = new RootBeanDefinition(BeanNameUrlHandlerMapping.class);
beanNameMappingDef.setSource(source);
beanNameMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
// consistent with WebMvcConfigurationSupport
beanNameMappingDef.getPropertyValues().add("order", 2);
RuntimeBeanReference corsConfigurationsRef = MvcNamespaceUtils.registerCorsConfigurations(null, parserContext, source);
beanNameMappingDef.getPropertyValues().add("corsConfigurations", corsConfigurationsRef);
parserContext.getRegistry().registerBeanDefinition(BEAN_NAME_URL_HANDLER_MAPPING_BEAN_NAME, beanNameMappingDef);
parserContext.registerComponent(new BeanComponentDefinition(beanNameMappingDef, BEAN_NAME_URL_HANDLER_MAPPING_BEAN_NAME));
}
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class ResourcesBeanDefinitionParser method parse.
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
Object source = parserContext.extractSource(element);
registerUrlProvider(parserContext, source);
String resourceHandlerName = registerResourceHandler(parserContext, element, source);
if (resourceHandlerName == null) {
return null;
}
Map<String, String> urlMap = new ManagedMap<>();
String resourceRequestPath = element.getAttribute("mapping");
if (!StringUtils.hasText(resourceRequestPath)) {
parserContext.getReaderContext().error("The 'mapping' attribute is required.", parserContext.extractSource(element));
return null;
}
urlMap.put(resourceRequestPath, resourceHandlerName);
RuntimeBeanReference pathMatcherRef = MvcNamespaceUtils.registerPathMatcher(null, parserContext, source);
RuntimeBeanReference pathHelperRef = MvcNamespaceUtils.registerUrlPathHelper(null, parserContext, source);
RootBeanDefinition handlerMappingDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
handlerMappingDef.setSource(source);
handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
handlerMappingDef.getPropertyValues().add("urlMap", urlMap);
handlerMappingDef.getPropertyValues().add("pathMatcher", pathMatcherRef).add("urlPathHelper", pathHelperRef);
String order = element.getAttribute("order");
// Use a default of near-lowest precedence, still allowing for even lower precedence in other mappings
handlerMappingDef.getPropertyValues().add("order", StringUtils.hasText(order) ? order : Ordered.LOWEST_PRECEDENCE - 1);
RuntimeBeanReference corsConfigurationsRef = MvcNamespaceUtils.registerCorsConfigurations(null, parserContext, source);
handlerMappingDef.getPropertyValues().add("corsConfigurations", corsConfigurationsRef);
String beanName = parserContext.getReaderContext().generateBeanName(handlerMappingDef);
parserContext.getRegistry().registerBeanDefinition(beanName, handlerMappingDef);
parserContext.registerComponent(new BeanComponentDefinition(handlerMappingDef, beanName));
// Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not "turned off"
// Register HttpRequestHandlerAdapter
MvcNamespaceUtils.registerDefaultComponents(parserContext, source);
return null;
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class ComplexWebApplicationContext method refresh.
@Override
public void refresh() throws BeansException {
registerSingleton(DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME, SessionLocaleResolver.class);
registerSingleton(DispatcherServlet.THEME_RESOLVER_BEAN_NAME, SessionThemeResolver.class);
LocaleChangeInterceptor interceptor1 = new LocaleChangeInterceptor();
LocaleChangeInterceptor interceptor2 = new LocaleChangeInterceptor();
interceptor2.setParamName("locale2");
ThemeChangeInterceptor interceptor3 = new ThemeChangeInterceptor();
ThemeChangeInterceptor interceptor4 = new ThemeChangeInterceptor();
interceptor4.setParamName("theme2");
UserRoleAuthorizationInterceptor interceptor5 = new UserRoleAuthorizationInterceptor();
interceptor5.setAuthorizedRoles("role1", "role2");
List<Object> interceptors = new ArrayList<>();
interceptors.add(interceptor5);
interceptors.add(interceptor1);
interceptors.add(interceptor2);
interceptors.add(interceptor3);
interceptors.add(interceptor4);
interceptors.add(new MyHandlerInterceptor1());
interceptors.add(new MyHandlerInterceptor2());
interceptors.add(new MyWebRequestInterceptor());
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("mappings", "/view.do=viewHandler\n/locale.do=localeHandler\nloc.do=anotherLocaleHandler");
pvs.add("interceptors", interceptors);
registerSingleton("myUrlMapping1", SimpleUrlHandlerMapping.class, pvs);
pvs = new MutablePropertyValues();
pvs.add("mappings", "/form.do=localeHandler\n/unknown.do=unknownHandler\nservlet.do=myServlet");
pvs.add("order", "2");
registerSingleton("myUrlMapping2", SimpleUrlHandlerMapping.class, pvs);
pvs = new MutablePropertyValues();
pvs.add("mappings", "/head.do=headController\n" + "body.do=bodyController\n/noview*=noviewController\n/noview/simple*=noviewController");
pvs.add("order", "1");
registerSingleton("handlerMapping", SimpleUrlHandlerMapping.class, pvs);
registerSingleton("myDummyAdapter", MyDummyAdapter.class);
registerSingleton("myHandlerAdapter", MyHandlerAdapter.class);
registerSingleton("standardHandlerAdapter", SimpleControllerHandlerAdapter.class);
registerSingleton("noviewController", NoViewController.class);
pvs = new MutablePropertyValues();
pvs.add("order", 0);
pvs.add("basename", "org.springframework.web.servlet.complexviews");
registerSingleton("viewResolver", ResourceBundleViewResolver.class, pvs);
pvs = new MutablePropertyValues();
pvs.add("suffix", ".jsp");
registerSingleton("viewResolver2", InternalResourceViewResolver.class, pvs);
pvs = new MutablePropertyValues();
pvs.add("viewName", "form");
registerSingleton("viewHandler", ParameterizableViewController.class, pvs);
registerSingleton("localeHandler", ComplexLocaleChecker.class);
registerSingleton("anotherLocaleHandler", ComplexLocaleChecker.class);
registerSingleton("unknownHandler", Object.class);
registerSingleton("headController", HeadController.class);
registerSingleton("bodyController", BodyController.class);
registerSingleton("servletPostProcessor", SimpleServletPostProcessor.class);
registerSingleton("handlerAdapter", SimpleServletHandlerAdapter.class);
registerSingleton("myServlet", MyServlet.class);
pvs = new MutablePropertyValues();
pvs.add("order", "1");
pvs.add("exceptionMappings", "java.lang.IllegalAccessException=failed2\n" + "ServletRequestBindingException=failed3");
pvs.add("defaultErrorView", "failed0");
registerSingleton("exceptionResolver1", SimpleMappingExceptionResolver.class, pvs);
pvs = new MutablePropertyValues();
pvs.add("order", "0");
pvs.add("exceptionMappings", "java.lang.Exception=failed1");
List<RuntimeBeanReference> mappedHandlers = new ManagedList<>();
mappedHandlers.add(new RuntimeBeanReference("anotherLocaleHandler"));
pvs.add("mappedHandlers", mappedHandlers);
pvs.add("defaultStatusCode", "500");
pvs.add("defaultErrorView", "failed2");
registerSingleton("handlerExceptionResolver", SimpleMappingExceptionResolver.class, pvs);
registerSingleton("multipartResolver", MockMultipartResolver.class);
registerSingleton("testListener", TestApplicationListener.class);
addMessage("test", Locale.ENGLISH, "test message");
addMessage("test", Locale.CANADA, "Canadian & test message");
super.refresh();
}
use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.
the class MessageBrokerBeanDefinitionParser method registerHandlerMapping.
private ManagedMap<String, Object> registerHandlerMapping(Element element, ParserContext context, Object source) {
RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class);
String orderAttribute = element.getAttribute("order");
int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute);
handlerMappingDef.getPropertyValues().add("order", order);
String pathHelper = element.getAttribute("path-helper");
if (StringUtils.hasText(pathHelper)) {
handlerMappingDef.getPropertyValues().add("urlPathHelper", new RuntimeBeanReference(pathHelper));
}
ManagedMap<String, Object> urlMap = new ManagedMap<>();
urlMap.setSource(source);
handlerMappingDef.getPropertyValues().add("urlMap", urlMap);
registerBeanDef(handlerMappingDef, context, source);
return urlMap;
}
Aggregations