package net.bull.javamelody;

import javax.sql.DataSource;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.AbstractFactoryBean;

/**
 * Spring {@link FactoryBean} for wrapping datasources with monitoring proxy.
 *
 * @see AbstractFactoryBean
 * @see JdbcWrapper
 *
 * @author et2448, Emeric Vernat
 */
public class SpringDataSourceFactoryBean extends AbstractFactoryBean {
	private String targetName;

	// exemple :
	//	<bean id="wrappedDataSource" class="net.bull.javamelody.SpringDataSourceFactoryBean">
	//		<property name="targetName" value="targetDataSource" />
	//	</bean>
	//	
	//	<bean id="targetDataSource" ...
	//	</bean>

	/**
	 * Name of target bean to instrument.
	 * This should implement {@linkplain DataSource}.
	 * @param targetName name of bean, not null.
	 */
	public void setTargetName(String targetName) {
		assert targetName != null;
		this.targetName = targetName;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected DataSource createInstance() {
		if (targetName == null) {
			throw new IllegalStateException("targetName must not be null");
		}
		final DataSource dataSource = (DataSource) getBeanFactory().getBean(targetName,
				DataSource.class);
		JdbcWrapper.registerSpringDataSource(targetName, dataSource);
		final DataSource result = JdbcWrapper.SINGLETON.createDataSourceProxy(targetName,
				dataSource);
		LOG.debug("Spring target datasource wrapped: " + targetName);
		return result;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Class<?> getObjectType() {
		return DataSource.class;
	}
}

@@ -1,8 +1,784 @@
+/*%0D%0A * Copyright 2008-2010 by Emeric Vernat%0D%0A *%0D%0A *     This file is part of Java Melody.%0D%0A *%0D%0A * Java Melody is free software: you can redistribute it and/or modify%0D%0A * it under the terms of the GNU Lesser General Public License as published by%0D%0A * the Free Software Foundation, either version 3 of the License, or%0D%0A * (at your option) any later version.%0D%0A *%0D%0A * Java Melody is distributed in the hope that it will be useful,%0D%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0D%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0D%0A * GNU Lesser General Public License for more details.%0D%0A *%0D%0A * You should have received a copy of the GNU Lesser General Public License%0D%0A * along with Java Melody.  If not, see %3Chttp://www.gnu.org/licenses/%3E.%0D%0A */%0D%0A
 package 
@@ -1117,14 +1117,55 @@
 hor 
-et2448
+David J. M. Karlsen (davidkarlsen at gmail.com)
 , Em

change author as request by the author and add the forgotten file header