Skip to content

Commit 4df0298

Browse files
committed
Reflecting feedback on pull request - merging two methods into one (simplification)
1 parent aca6951 commit 4df0298

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

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

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
import org.w3c.dom.Node;
2525
import org.w3c.dom.NodeList;
2626

27-
import java.util.ArrayList;
28-
import java.util.Collections;
29-
import java.util.List;
3027
import java.util.Properties;
3128

3229
/**
@@ -119,14 +116,13 @@ private String getStringAttribute(Node node, String name) {
119116
* @return variables context from include instance (no inherited values)
120117
*/
121118
private Properties getVariablesContext(Node node, Properties inheritedVariablesContext) {
122-
List<Node> subElements = getSubElements(node);
123-
if (subElements.isEmpty()) {
124-
return new Properties();
125-
} else {
126-
Properties variablesContext = new Properties();
127-
for (Node variableValue : subElements) {
128-
String name = getStringAttribute(variableValue, "name");
129-
String value = getStringAttribute(variableValue, "value");
119+
Properties variablesContext = new Properties();
120+
NodeList children = node.getChildNodes();
121+
for (int i = 0; i < children.getLength(); i++) {
122+
Node n = children.item(i);
123+
if (n.getNodeType() == Node.ELEMENT_NODE) {
124+
String name = getStringAttribute(n, "name");
125+
String value = getStringAttribute(n, "value");
130126
// Replace variables inside
131127
value = PropertyParser.parse(value, inheritedVariablesContext);
132128
// Push new value
@@ -135,24 +131,8 @@ private Properties getVariablesContext(Node node, Properties inheritedVariablesC
135131
throw new BuilderException("Variable " + name + " defined twice in the same include definition");
136132
}
137133
}
138-
return variablesContext;
139-
}
140-
}
141-
142-
private List<Node> getSubElements(Node node) {
143-
NodeList children = node.getChildNodes();
144-
if (children.getLength() == 0) {
145-
return Collections.emptyList();
146-
} else {
147-
List<Node> elements = new ArrayList<Node>();
148-
for (int i = 0; i < children.getLength(); i++) {
149-
Node n = children.item(i);
150-
if (n.getNodeType() == Node.ELEMENT_NODE) {
151-
elements.add(n);
152-
}
153-
}
154-
return elements;
155134
}
135+
return variablesContext;
156136
}
157137

158138
}

0 commit comments

Comments
 (0)