Package us.codecraft.tinyioc.context

Source Code of us.codecraft.tinyioc.context.ClassPathXmlApplicationContext

package us.codecraft.tinyioc.context;

import us.codecraft.tinyioc.beans.BeanDefinition;
import us.codecraft.tinyioc.beans.factory.AbstractBeanFactory;
import us.codecraft.tinyioc.beans.factory.AutowireCapableBeanFactory;
import us.codecraft.tinyioc.beans.io.ResourceLoader;
import us.codecraft.tinyioc.beans.xml.XmlBeanDefinitionReader;

import java.util.Map;

/**
* @author yihua.huang@dianping.com
*/
public class ClassPathXmlApplicationContext extends AbstractApplicationContext {

  private String configLocation;

  public ClassPathXmlApplicationContext(String configLocation) throws Exception {
    this(configLocation, new AutowireCapableBeanFactory());
  }

  public ClassPathXmlApplicationContext(String configLocation, AbstractBeanFactory beanFactory) throws Exception {
    super(beanFactory);
    this.configLocation = configLocation;
    refresh();
  }

  @Override
  protected void loadBeanDefinitions(AbstractBeanFactory beanFactory) throws Exception {
    XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(new ResourceLoader());
    xmlBeanDefinitionReader.loadBeanDefinitions(configLocation);
    for (Map.Entry<String, BeanDefinition> beanDefinitionEntry : xmlBeanDefinitionReader.getRegistry().entrySet()) {
      beanFactory.registerBeanDefinition(beanDefinitionEntry.getKey(), beanDefinitionEntry.getValue());
    }
  }

}
TOP

Related Classes of us.codecraft.tinyioc.context.ClassPathXmlApplicationContext

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.