From df27c3e997c7f5757a298f37def995e752509da9 Mon Sep 17 00:00:00 2001 From: Kazuki Shimizu Date: Thu, 28 Apr 2016 08:20:59 +0900 Subject: [PATCH] Allow customize a ReflectorFactory using mybatis configuration xml file #675 --- .../ibatis/builder/xml/XMLConfigBuilder.java | 5 +++-- .../ibatis/builder/xml/mybatis-3-config.dtd | 7 +++++- .../builder/CustomReflectorFactory.java | 22 +++++++++++++++++++ .../CustomizedSettingsMapperConfig.xml | 2 ++ .../ibatis/builder/XmlConfigBuilderTest.java | 2 ++ 5 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/test/java/org/apache/ibatis/builder/CustomReflectorFactory.java diff --git a/src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java b/src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java index fb2c32c2621..9f693aa82b3 100644 --- a/src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java +++ b/src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java @@ -48,6 +48,7 @@ /** * @author Clinton Begin + * @author Kazuki Shimizu */ public class XMLConfigBuilder extends BaseBuilder { @@ -108,7 +109,7 @@ private void parseConfiguration(XNode root) { pluginElement(root.evalNode("plugins")); objectFactoryElement(root.evalNode("objectFactory")); objectWrapperFactoryElement(root.evalNode("objectWrapperFactory")); - reflectionFactoryElement(root.evalNode("reflectionFactory")); + reflectorFactoryElement(root.evalNode("reflectorFactory")); settingsElement(settings); // read it after objectFactory and objectWrapperFactory issue #631 environmentsElement(root.evalNode("environments")); @@ -203,7 +204,7 @@ private void objectWrapperFactoryElement(XNode context) throws Exception { } } - private void reflectionFactoryElement(XNode context) throws Exception { + private void reflectorFactoryElement(XNode context) throws Exception { if (context != null) { String type = context.getStringAttribute("type"); ReflectorFactory factory = (ReflectorFactory) resolveClass(type).newInstance(); diff --git a/src/main/java/org/apache/ibatis/builder/xml/mybatis-3-config.dtd b/src/main/java/org/apache/ibatis/builder/xml/mybatis-3-config.dtd index 3fafdf8fda2..fbda4f4ac3e 100644 --- a/src/main/java/org/apache/ibatis/builder/xml/mybatis-3-config.dtd +++ b/src/main/java/org/apache/ibatis/builder/xml/mybatis-3-config.dtd @@ -16,7 +16,7 @@ limitations under the License. --> - + + + + diff --git a/src/test/java/org/apache/ibatis/builder/CustomReflectorFactory.java b/src/test/java/org/apache/ibatis/builder/CustomReflectorFactory.java new file mode 100644 index 00000000000..f6681330541 --- /dev/null +++ b/src/test/java/org/apache/ibatis/builder/CustomReflectorFactory.java @@ -0,0 +1,22 @@ +/** + * Copyright 2009-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ibatis.builder; + +import org.apache.ibatis.reflection.DefaultReflectorFactory; + +public class CustomReflectorFactory extends DefaultReflectorFactory { + +} diff --git a/src/test/java/org/apache/ibatis/builder/CustomizedSettingsMapperConfig.xml b/src/test/java/org/apache/ibatis/builder/CustomizedSettingsMapperConfig.xml index c370e3a9ddd..88d69714e1e 100644 --- a/src/test/java/org/apache/ibatis/builder/CustomizedSettingsMapperConfig.xml +++ b/src/test/java/org/apache/ibatis/builder/CustomizedSettingsMapperConfig.xml @@ -72,6 +72,8 @@ + + diff --git a/src/test/java/org/apache/ibatis/builder/XmlConfigBuilderTest.java b/src/test/java/org/apache/ibatis/builder/XmlConfigBuilderTest.java index f90f392bc14..0f79b47b596 100644 --- a/src/test/java/org/apache/ibatis/builder/XmlConfigBuilderTest.java +++ b/src/test/java/org/apache/ibatis/builder/XmlConfigBuilderTest.java @@ -207,6 +207,8 @@ public void shouldSuccessfullyLoadXMLConfigFile() throws Exception { assertThat(config.getObjectWrapperFactory(), is(instanceOf(CustomObjectWrapperFactory.class))); + assertThat(config.getReflectorFactory(), is(instanceOf(CustomReflectorFactory.class))); + ExamplePlugin plugin = (ExamplePlugin)config.getInterceptors().get(0); assertThat(plugin.getProperties().size(), is(1)); assertThat(plugin.getProperties().getProperty("pluginProperty"), is("100"));