* @author Phillip Webb
*/
class MvcSupportBeanDefinitionParser implements BeanDefinitionParser {
public BeanDefinition parse(Element element, ParserContext parserContext) {
BeanDefinitionParserHelper helper = new BeanDefinitionParserHelper(element, parserContext);
parserContext.pushContainingComponent(helper.getComponentDefinition());
// Dispatcher + DispatcherAwareBeanPostProcessor
RuntimeBeanReference dispatcher = getOrRegister(helper, "dispatcher", DefaultDispatcher.class);
RootBeanDefinition postProcessor = helper.rootBeanDefinition(DispatcherAwareBeanPostProcessor.class);
postProcessor.getConstructorArgumentValues().addIndexedArgumentValue(0, dispatcher);
helper.register(postProcessor);
// State Handler
RuntimeBeanReference stateHandler = getOrRegister(helper, "state-handler", ClientFacesViewStateHandler.class);
// Postback Handler
RootBeanDefinition postbackHandler = helper.rootBeanDefinition(FacesPostbackHandler.class);
postbackHandler.getConstructorArgumentValues().addIndexedArgumentValue(0, stateHandler);
helper.register(postbackHandler);
// Exception Handler
helper.register(MvcExceptionHandler.class);
// Destination View Resolvers
RuntimeBeanReference destinationViewResolvers = createResolverChain(helper, DestinationViewResolverChain.class,
"destination-view-resolvers", RequestMappedRedirectDestinationViewResolver.class,
DefaultDestinationViewResolver.class);
// Navigation View Resolvers
RuntimeBeanReference navigationViewResolvers = createResolverChain(helper,
NavigationOutcomeResolverChain.class, "navigation-outcome-resolvers",
ImplicitNavigationOutcomeResolver.class, NavigationMethodOutcomeResolver.class);
// Spring Faces Factories
RootBeanDefinition factories = helper.rootBeanDefinition(SpringFacesFactories.class);
factories.getConstructorArgumentValues().addIndexedArgumentValue(0, stateHandler);
factories.getConstructorArgumentValues().addIndexedArgumentValue(1, destinationViewResolvers);
factories.getPropertyValues().addPropertyValue("navigationOutcomeResolver", navigationViewResolvers);
helper.register(factories);
// Interceptor
RootBeanDefinition interceptor = helper.rootBeanDefinition(FacesHandlerInterceptor.class);
RootBeanDefinition mappedInterceptor = helper.rootBeanDefinition(MappedInterceptor.class);
mappedInterceptor.getConstructorArgumentValues().addIndexedArgumentValue(0, (Object) null);
mappedInterceptor.getConstructorArgumentValues().addIndexedArgumentValue(1, interceptor);
helper.register(mappedInterceptor);
parserContext.popAndRegisterContainingComponent();
return null;
}