Java tutorial
/** * Copyright (c)2010-2011 Enterprise Website Content Management System(EWCMS), All rights reserved. * EWCMS PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * http://www.ewcms.com */ package com.smhdemo.common.datasource.generate.factory.init; import java.util.HashMap; import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.smhdemo.common.datasource.entity.Bean; import com.smhdemo.common.datasource.entity.Custom; import com.smhdemo.common.datasource.entity.Jdbc; import com.smhdemo.common.datasource.entity.Jndi; import com.smhdemo.common.datasource.generate.factory.init.bean.BeanForInterfaceFactoryable; /** * ??,? * * @author ? */ @Service public class InitDataSourceFactory implements InitDataSourceFactoryable, InitializingBean { private static final Logger logger = LoggerFactory.getLogger(InitDataSourceFactory.class); @Autowired private BeanForInterfaceFactoryable factory = null; private Map<String, String> beanForInterfaceMappings = null; public BeanForInterfaceFactoryable getFactory() { return factory; } public void setFactory(BeanForInterfaceFactoryable factory) { this.factory = factory; } public Map<String, String> getBeanForInterfaceMappings() { return beanForInterfaceMappings; } public void setBeanForInterfaceMappings(Map<String, String> beanForInterfaceMappings) { this.beanForInterfaceMappings = beanForInterfaceMappings; } private static Map<String, String> serviceDefinitionMap; static { serviceDefinitionMap = new HashMap<String, String>(); serviceDefinitionMap.put(Jdbc.class.getName().toString(), "jdbcDataSourceFactory"); serviceDefinitionMap.put(Jndi.class.getName().toString(), "jndiDataSourceFactory"); serviceDefinitionMap.put(Bean.class.getName().toString(), "beanDataSourceFactory"); serviceDefinitionMap.put(Custom.class.getName().toString(), "customDataSourceFactory"); } @Override public void afterPropertiesSet() throws Exception { logger.info("EwcmsDataSourceServiceFactory Properties begin......"); setBeanForInterfaceMappings(serviceDefinitionMap); logger.info("EwcmsDataSourceServiceFactory Properties end"); } @SuppressWarnings("rawtypes") public Object getBean(Class itfClass) { return factory.getBean(getBeanForInterfaceMappings(), itfClass); } @SuppressWarnings("rawtypes") public String getBeanName(Class itfClass) { return factory.getBeanName(getBeanForInterfaceMappings(), itfClass); } }