001 /* 002 * Copyright 2008-2009 the original author or authors. 003 * The contents of this file are subject to the Mozilla Public License 004 * Version 1.1 (the "License"); you may not use this file except in 005 * compliance with the License. You may obtain a copy of the License at 006 * http://www.mozilla.org/MPL/ 007 * 008 * Software distributed under the License is distributed on an "AS IS" 009 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 010 * License for the specific language governing rights and limitations 011 * under the License. 012 */ 013 014 package com.mtgi.analytics.aop.config.v11; 015 016 import static com.mtgi.analytics.aop.config.TemplateBeanDefinitionParser.overrideProperty; 017 018 import org.springframework.beans.factory.config.BeanDefinitionHolder; 019 import org.springframework.beans.factory.support.AbstractBeanDefinition; 020 import org.springframework.beans.factory.support.BeanDefinitionBuilder; 021 import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; 022 import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; 023 import org.springframework.beans.factory.xml.ParserContext; 024 import org.w3c.dom.Element; 025 import org.w3c.dom.NodeList; 026 027 import com.mtgi.analytics.JdbcBehaviorEventPersisterImpl; 028 029 /** 030 * Parses the <code>bt:jdbc-persister</code> tag to produce an {@link JdbcBehaviorEventPersisterImpl} bean, 031 * for inclusion in an enclosing <code>bt:manager</code> tag or as a standalone managed bean. 032 */ 033 public class BtJdbcPersisterBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { 034 035 @Override 036 protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { 037 overrideProperty("id-sql", builder.getRawBeanDefinition(), element, false); 038 NodeList nodes = element.getElementsByTagNameNS("*", "data-source"); 039 if (nodes.getLength() == 1) { 040 Element ds = (Element)nodes.item(0); 041 ds.setAttribute("name", "dataSource"); 042 parserContext.getDelegate().parsePropertyElement(ds, builder.getRawBeanDefinition()); 043 } 044 045 if (parserContext.isNested()) { 046 AbstractBeanDefinition def = builder.getBeanDefinition(); 047 String id = element.hasAttribute("id") ? element.getAttribute("id") 048 : BeanDefinitionReaderUtils.generateBeanName(def, parserContext.getReaderContext().getRegistry(), true); 049 BeanDefinitionHolder holder = new BeanDefinitionHolder(def, id); 050 BtManagerBeanDefinitionParser.registerNestedBean(holder, "persister", parserContext); 051 } 052 } 053 054 @Override 055 protected Class<?> getBeanClass(Element element) { 056 return JdbcBehaviorEventPersisterImpl.class; 057 } 058 059 @Override 060 protected boolean shouldGenerateIdAsFallback() { 061 return true; 062 } 063 064 }