@@ -41,40 +41,40 @@ public XMLIncludeTransformer(Configuration configuration, MapperBuilderAssistant
41
41
}
42
42
43
43
public void applyIncludes (Node source ) {
44
- Properties placeholderContext = new Properties ();
44
+ Properties variablesContext = new Properties ();
45
45
Properties configurationVariables = configuration .getVariables ();
46
46
if (configurationVariables != null ) {
47
- placeholderContext .putAll (configurationVariables );
47
+ variablesContext .putAll (configurationVariables );
48
48
}
49
- applyIncludes (source , placeholderContext );
49
+ applyIncludes (source , variablesContext );
50
50
}
51
51
52
52
/**
53
53
* Recursively apply includes through all SQL fragments.
54
54
* @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
56
56
*/
57
- private void applyIncludes (Node source , final Properties placeholderContext ) {
57
+ private void applyIncludes (Node source , final Properties variablesContext ) {
58
58
if (source .getNodeName ().equals ("include" )) {
59
59
// new full context for included SQL - contains inherited context and new variables from current include node
60
60
Properties fullContext ;
61
61
62
62
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 );
65
65
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 ));
71
71
}
72
72
// merge new and inherited into new full one
73
- applyInheritedContext (newPlaceholderContext , placeholderContext );
74
- fullContext = newPlaceholderContext ;
73
+ applyInheritedContext (newVariablesContext , variablesContext );
74
+ fullContext = newVariablesContext ;
75
75
} else {
76
76
// no new context - use inherited fully
77
- fullContext = placeholderContext ;
77
+ fullContext = variablesContext ;
78
78
}
79
79
applyIncludes (toInclude , fullContext );
80
80
if (toInclude .getOwnerDocument () != source .getOwnerDocument ()) {
@@ -88,14 +88,14 @@ private void applyIncludes(Node source, final Properties placeholderContext) {
88
88
} else if (source .getNodeType () == Node .ELEMENT_NODE ) {
89
89
NodeList children = source .getChildNodes ();
90
90
for (int i =0 ; i <children .getLength (); i ++) {
91
- applyIncludes (children .item (i ), placeholderContext );
91
+ applyIncludes (children .item (i ), variablesContext );
92
92
}
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 ));
99
99
}
100
100
}
101
101
@@ -115,8 +115,8 @@ private String getStringAttribute(Node node, String name) {
115
115
116
116
/**
117
117
* 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
120
120
*/
121
121
private void applyInheritedContext (Properties newContext , Properties inheritedContext ) {
122
122
for (Map .Entry <Object , Object > e : inheritedContext .entrySet ()) {
@@ -129,24 +129,24 @@ private void applyInheritedContext(Properties newContext, Properties inheritedCo
129
129
/**
130
130
* Read placholders and their values from include node definition.
131
131
* @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)
133
133
*/
134
- private Properties getPlaceholderContext (Node node ) {
134
+ private Properties getVariablesContext (Node node ) {
135
135
List <Node > subElements = getSubElements (node );
136
136
if (subElements .isEmpty ()) {
137
137
return new Properties ();
138
138
} 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" );
143
143
// Push new value
144
- Object originalValue = placeholderContext .put (name , value );
144
+ Object originalValue = variablesContext .put (name , value );
145
145
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" );
147
147
}
148
148
}
149
- return placeholderContext ;
149
+ return variablesContext ;
150
150
}
151
151
}
152
152
0 commit comments