Skip to content

Commit 7d010c1

Browse files
committed
Merge pull request #677 from kazuki43zoo/allow-customize-ReflectorFactory
Allow customize a ReflectorFactory using mybatis configuration xml file #675
2 parents 023df8a + df27c3e commit 7d010c1

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
/**
5050
* @author Clinton Begin
51+
* @author Kazuki Shimizu
5152
*/
5253
public class XMLConfigBuilder extends BaseBuilder {
5354

@@ -108,7 +109,7 @@ private void parseConfiguration(XNode root) {
108109
pluginElement(root.evalNode("plugins"));
109110
objectFactoryElement(root.evalNode("objectFactory"));
110111
objectWrapperFactoryElement(root.evalNode("objectWrapperFactory"));
111-
reflectionFactoryElement(root.evalNode("reflectionFactory"));
112+
reflectorFactoryElement(root.evalNode("reflectorFactory"));
112113
settingsElement(settings);
113114
// read it after objectFactory and objectWrapperFactory issue #631
114115
environmentsElement(root.evalNode("environments"));
@@ -203,7 +204,7 @@ private void objectWrapperFactoryElement(XNode context) throws Exception {
203204
}
204205
}
205206

206-
private void reflectionFactoryElement(XNode context) throws Exception {
207+
private void reflectorFactoryElement(XNode context) throws Exception {
207208
if (context != null) {
208209
String type = context.getStringAttribute("type");
209210
ReflectorFactory factory = (ReflectorFactory) resolveClass(type).newInstance();

src/main/java/org/apache/ibatis/builder/xml/mybatis-3-config.dtd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
limitations under the License.
1717
1818
-->
19-
<!ELEMENT configuration (properties?, settings?, typeAliases?, typeHandlers?, objectFactory?, objectWrapperFactory?, plugins?, environments?, databaseIdProvider?, mappers?)>
19+
<!ELEMENT configuration (properties?, settings?, typeAliases?, typeHandlers?, objectFactory?, objectWrapperFactory?, reflectorFactory?, plugins?, environments?, databaseIdProvider?, mappers?)>
2020

2121
<!ELEMENT databaseIdProvider (property*)>
2222
<!ATTLIST databaseIdProvider
@@ -70,6 +70,11 @@ type CDATA #REQUIRED
7070
type CDATA #REQUIRED
7171
>
7272

73+
<!ELEMENT reflectorFactory EMPTY>
74+
<!ATTLIST reflectorFactory
75+
type CDATA #REQUIRED
76+
>
77+
7378
<!ELEMENT plugins (plugin+)>
7479

7580
<!ELEMENT plugin (property*)>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright 2009-2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.ibatis.builder;
17+
18+
import org.apache.ibatis.reflection.DefaultReflectorFactory;
19+
20+
public class CustomReflectorFactory extends DefaultReflectorFactory {
21+
22+
}

src/test/java/org/apache/ibatis/builder/CustomizedSettingsMapperConfig.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
</objectFactory>
7373

7474
<objectWrapperFactory type="org.apache.ibatis.builder.CustomObjectWrapperFactory" />
75+
76+
<reflectorFactory type="org.apache.ibatis.builder.CustomReflectorFactory"/>
7577

7678
<plugins>
7779
<plugin interceptor="org.apache.ibatis.builder.ExamplePlugin">

src/test/java/org/apache/ibatis/builder/XmlConfigBuilderTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ public void shouldSuccessfullyLoadXMLConfigFile() throws Exception {
207207

208208
assertThat(config.getObjectWrapperFactory(), is(instanceOf(CustomObjectWrapperFactory.class)));
209209

210+
assertThat(config.getReflectorFactory(), is(instanceOf(CustomReflectorFactory.class)));
211+
210212
ExamplePlugin plugin = (ExamplePlugin)config.getInterceptors().get(0);
211213
assertThat(plugin.getProperties().size(), is(1));
212214
assertThat(plugin.getProperties().getProperty("pluginProperty"), is("100"));

0 commit comments

Comments
 (0)