博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
XMLConfigBuilder文件
阅读量:4689 次
发布时间:2019-06-09

本文共 3435 字,大约阅读时间需要 11 分钟。

1.package —— org.apache.ibatis.builder.xml

2.extends —— BaseBuilder

3.参数

private boolean parsed; //判断是否已经解析过,使用于parse()    private XPathParser parser;//xml配置文件Context内容    private String environment;//环境参数    private ReflectorFactory localReflectorFactory;

4.构造方法

public XMLConfigBuilder(Reader reader) {        this((Reader)reader, (String)null, (Properties)null);    }    public XMLConfigBuilder(Reader reader, String environment) {        this((Reader)reader, environment, (Properties)null);    }    public XMLConfigBuilder(Reader reader, String environment, Properties props) {        this(new XPathParser(reader, true, props, new XMLMapperEntityResolver()), environment, props);    }       public XMLConfigBuilder(InputStream inputStream) {        this((InputStream)inputStream, (String)null, (Properties)null);    }    public XMLConfigBuilder(InputStream inputStream, String environment) {        this((InputStream)inputStream, environment, (Properties)null);    }    public XMLConfigBuilder(InputStream inputStream, String environment, Properties props) {        this(new XPathParser(inputStream, true, props, new XMLMapperEntityResolver()), environment, props);    }    private XMLConfigBuilder(XPathParser parser, String environment, Properties props) {        super(new Configuration());        this.localReflectorFactory = new DefaultReflectorFactory();        ErrorContext.instance().resource("SQL Mapper Configuration");        this.configuration.setVariables(props);        this.parsed = false;        this.environment = environment;        this.parser = parser;    }

  6个public和1个private的构造方法,前6个public构造方法都是根据mybatis配置文件的文件流创建XPathParser对象,然后调用private的构造方法,显示调用了父类构造方法,然后给本地参数赋值。

5.成员方法

   public Configuration parse() {        if (this.parsed) {//初始化时候赋值为false,判断是否解析过,Configuration是全局变量,只需要解析一次            throw new BuilderException("Each XMLConfigBuilder can only be used once.");        } else {            this.parsed = true;         //调用下面的方法,parser.evalNode("/configuration")是解析xml配置的configuration节点的内容,得到XNode对象            this.parseConfiguration(this.parser.evalNode("/configuration"));            return this.configuration;        }    }   //解析xml配置的的根节点    private void parseConfiguration(XNode root) {        try {            this.propertiesElement(root.evalNode("properties"));            Properties settings = this.settingsAsProperties(root.evalNode("settings"));            this.loadCustomVfs(settings);            this.typeAliasesElement(root.evalNode("typeAliases"));            this.pluginElement(root.evalNode("plugins"));            this.objectFactoryElement(root.evalNode("objectFactory"));            this.objectWrapperFactoryElement(root.evalNode("objectWrapperFactory"));            this.reflectorFactoryElement(root.evalNode("reflectorFactory"));            this.settingsElement(settings);            this.environmentsElement(root.evalNode("environments"));            this.databaseIdProviderElement(root.evalNode("databaseIdProvider"));            this.typeHandlerElement(root.evalNode("typeHandlers"));            this.mapperElement(root.evalNode("mappers"));        } catch (Exception var3) {            throw new BuilderException("Error parsing SQL Mapper Configuration. Cause: " + var3, var3);        }    }

  parse的作用是解析mybatis-config.xml的configuration节点的内容,挨个赋值给configuration对象的属性节点,剩余方法都为私有方法,根据XNode对象来给全局变量configuration的属性进行赋值

转载于:https://www.cnblogs.com/kongkongFabian/p/9601132.html

你可能感兴趣的文章
《构建之法》第一、二、十六章阅读笔记
查看>>
arrow:让Python的日期与时间变的更好
查看>>
(转)Excel的 OleDb 连接串的格式(连接Excel 2003-2013)
查看>>
Java并发编程
查看>>
Git Stash用法
查看>>
sql server 2008学习8 sql server存储和索引结构
查看>>
Jquery radio选中
查看>>
postgressql数据库中limit offset使用
查看>>
测试思想-集成测试 关于接口测试 Part 2
查看>>
windows下mysql密码忘了怎么办?【转】
查看>>
php生成器使用总结
查看>>
T-SQL中的indexof函数
查看>>
javascript基础之数组(Array)对象
查看>>
mysql DML DDL DCL
查看>>
RAMPS1.4 3d打印控制板接线与测试1
查看>>
python with语句中的变量有作用域吗?
查看>>
24@Servlet_day03
查看>>
初级ant的学习
查看>>
redis数据结构--String
查看>>
POJ 3279 Fliptile (二进制枚举)
查看>>