001 /*
002 GRANITE DATA SERVICES
003 Copyright (C) 2011 GRANITE DATA SERVICES S.A.S.
004
005 This file is part of Granite Data Services.
006
007 Granite Data Services is free software; you can redistribute it and/or modify
008 it under the terms of the GNU Library General Public License as published by
009 the Free Software Foundation; either version 2 of the License, or (at your
010 option) any later version.
011
012 Granite Data Services is distributed in the hope that it will be useful, but
013 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015 for more details.
016
017 You should have received a copy of the GNU Library General Public License
018 along with this library; if not, see <http://www.gnu.org/licenses/>.
019 */
020
021 package org.granite.tide.spring;
022
023 import org.granite.spring.FlexFilterBeanDefinitionParser;
024 import org.springframework.aop.config.AopNamespaceUtils;
025 import org.springframework.beans.factory.config.BeanDefinition;
026 import org.springframework.beans.factory.config.RuntimeBeanReference;
027 import org.springframework.beans.factory.parsing.BeanComponentDefinition;
028 import org.springframework.beans.factory.support.RootBeanDefinition;
029 import org.springframework.beans.factory.xml.BeanDefinitionParser;
030 import org.springframework.beans.factory.xml.ParserContext;
031 import org.w3c.dom.Element;
032
033 /**
034 * @author William Drai
035 */
036 public class TideDataPublishingAdviceBeanDefinitionParser implements BeanDefinitionParser {
037
038 public static final String DATA_PUBLISHING_ADVISOR_BEAN_NAME = "org.granite.tide.spring.DataPublishingAdvisor";
039
040
041 public BeanDefinition parse(Element element, ParserContext parserContext) {
042 AopAutoProxyConfigurer.configureAutoProxyCreator(element, parserContext);
043 return null;
044 }
045
046
047 /**
048 * Inner class to just introduce an AOP framework dependency when actually in proxy mode.
049 */
050 private static class AopAutoProxyConfigurer {
051
052 public static void configureAutoProxyCreator(Element element, ParserContext parserContext) {
053 AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element);
054
055 if (!parserContext.getRegistry().containsBeanDefinition(DATA_PUBLISHING_ADVISOR_BEAN_NAME)) {
056 // Create the TransactionInterceptor definition.
057 RootBeanDefinition interceptorDef = new RootBeanDefinition(TideDataPublishingInterceptor.class);
058 interceptorDef.setSource(parserContext.extractSource(element));
059 interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
060 interceptorDef.getPropertyValues().addPropertyValue("gravity", new RuntimeBeanReference(FlexFilterBeanDefinitionParser.GRAVITY_FACTORY_BEAN_NAME));
061
062 RootBeanDefinition advisorDef = new RootBeanDefinition(TideDataPublishingAdvisor.class);
063 advisorDef.setSource(parserContext.extractSource(element));
064 advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
065 advisorDef.getPropertyValues().addPropertyValue("dataPublishingInterceptor", interceptorDef);
066
067 parserContext.registerBeanComponent(new BeanComponentDefinition(advisorDef, DATA_PUBLISHING_ADVISOR_BEAN_NAME));
068 }
069 }
070 }
071 }