Skip to content

Commit 7d95da4

Browse files
committed
Changing terms - using "variable" instead of "placeholder" (the same is used in configuration.getVariables)
1 parent f06a2e4 commit 7d95da4

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

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

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -41,40 +41,40 @@ public XMLIncludeTransformer(Configuration configuration, MapperBuilderAssistant
4141
}
4242

4343
public void applyIncludes(Node source) {
44-
Properties placeholderContext = new Properties();
44+
Properties variablesContext = new Properties();
4545
Properties configurationVariables = configuration.getVariables();
4646
if (configurationVariables != null) {
47-
placeholderContext.putAll(configurationVariables);
47+
variablesContext.putAll(configurationVariables);
4848
}
49-
applyIncludes(source, placeholderContext);
49+
applyIncludes(source, variablesContext);
5050
}
5151

5252
/**
5353
* Recursively apply includes through all SQL fragments.
5454
* @param source Include node in DOM tree
55-
* @param placeholderContext Current context for static placeholders with values
55+
* @param variablesContext Current context for static variables with values
5656
*/
57-
private void applyIncludes(Node source, final Properties placeholderContext) {
57+
private void applyIncludes(Node source, final Properties variablesContext) {
5858
if (source.getNodeName().equals("include")) {
5959
// new full context for included SQL - contains inherited context and new variables from current include node
6060
Properties fullContext;
6161

6262
String refid = getStringAttribute(source, "refid");
63-
// replace placeholders and variables in include refid value
64-
refid = PropertyParser.parse(refid, placeholderContext);
63+
// replace variables in include refid value
64+
refid = PropertyParser.parse(refid, variablesContext);
6565
Node toInclude = findSqlFragment(refid);
66-
Properties newPlaceholderContext = getPlaceholderContext(source);
67-
if (!newPlaceholderContext.isEmpty()) {
68-
// replace placeholders in new variables too
69-
for (Object name : newPlaceholderContext.keySet()) {
70-
newPlaceholderContext.put(name, PropertyParser.parse(newPlaceholderContext.get(name).toString(), placeholderContext));
66+
Properties newVariablesContext = getVariablesContext(source);
67+
if (!newVariablesContext.isEmpty()) {
68+
// replace variables in variable values too
69+
for (Object name : newVariablesContext.keySet()) {
70+
newVariablesContext.put(name, PropertyParser.parse(newVariablesContext.get(name).toString(), variablesContext));
7171
}
7272
// merge new and inherited into new full one
73-
applyInheritedContext(newPlaceholderContext, placeholderContext);
74-
fullContext = newPlaceholderContext;
73+
applyInheritedContext(newVariablesContext, variablesContext);
74+
fullContext = newVariablesContext;
7575
} else {
7676
// no new context - use inherited fully
77-
fullContext = placeholderContext;
77+
fullContext = variablesContext;
7878
}
7979
applyIncludes(toInclude, fullContext);
8080
if (toInclude.getOwnerDocument() != source.getOwnerDocument()) {
@@ -88,14 +88,14 @@ private void applyIncludes(Node source, final Properties placeholderContext) {
8888
} else if (source.getNodeType() == Node.ELEMENT_NODE) {
8989
NodeList children = source.getChildNodes();
9090
for (int i=0; i<children.getLength(); i++) {
91-
applyIncludes(children.item(i), placeholderContext);
91+
applyIncludes(children.item(i), variablesContext);
9292
}
93-
} else if (source.getNodeType() == Node.ATTRIBUTE_NODE && !placeholderContext.isEmpty()) {
94-
// replace placeholders in all attribute values
95-
source.setNodeValue(PropertyParser.parse(source.getNodeValue(), placeholderContext));
96-
} else if (source.getNodeType() == Node.TEXT_NODE && !placeholderContext.isEmpty()) {
97-
// replace placeholder ins all text nodes
98-
source.setNodeValue(PropertyParser.parse(source.getNodeValue(), placeholderContext));
93+
} else if (source.getNodeType() == Node.ATTRIBUTE_NODE && !variablesContext.isEmpty()) {
94+
// replace variables in all attribute values
95+
source.setNodeValue(PropertyParser.parse(source.getNodeValue(), variablesContext));
96+
} else if (source.getNodeType() == Node.TEXT_NODE && !variablesContext.isEmpty()) {
97+
// replace variables ins all text nodes
98+
source.setNodeValue(PropertyParser.parse(source.getNodeValue(), variablesContext));
9999
}
100100
}
101101

@@ -115,8 +115,8 @@ private String getStringAttribute(Node node, String name) {
115115

116116
/**
117117
* Add inherited context into newly created one.
118-
* @param newContext placeholders defined current include clause where inherited values will be placed
119-
* @param inheritedContext all inherited placeholder values
118+
* @param newContext variables defined current include clause where inherited values will be placed
119+
* @param inheritedContext all inherited variables values
120120
*/
121121
private void applyInheritedContext(Properties newContext, Properties inheritedContext) {
122122
for (Map.Entry<Object, Object> e : inheritedContext.entrySet()) {
@@ -129,24 +129,24 @@ private void applyInheritedContext(Properties newContext, Properties inheritedCo
129129
/**
130130
* Read placholders and their values from include node definition.
131131
* @param node Include node instance
132-
* @return placeholder context from include instance (no inherited values)
132+
* @return variables context from include instance (no inherited values)
133133
*/
134-
private Properties getPlaceholderContext(Node node) {
134+
private Properties getVariablesContext(Node node) {
135135
List<Node> subElements = getSubElements(node);
136136
if (subElements.isEmpty()) {
137137
return new Properties();
138138
} else {
139-
Properties placeholderContext = new Properties();
140-
for (Node placeholderValue : subElements) {
141-
String name = getStringAttribute(placeholderValue, "name");
142-
String value = getStringAttribute(placeholderValue, "value");
139+
Properties variablesContext = new Properties();
140+
for (Node variableValue : subElements) {
141+
String name = getStringAttribute(variableValue, "name");
142+
String value = getStringAttribute(variableValue, "value");
143143
// Push new value
144-
Object originalValue = placeholderContext.put(name, value);
144+
Object originalValue = variablesContext.put(name, value);
145145
if (originalValue != null) {
146-
throw new IllegalArgumentException("Placeholder " + name + " defined twice in the same include definition");
146+
throw new IllegalArgumentException("Variable " + name + " defined twice in the same include definition");
147147
}
148148
}
149-
return placeholderContext;
149+
return variablesContext;
150150
}
151151
}
152152

0 commit comments

Comments
 (0)