37
37
38
38
/**
39
39
* Builds a {@link Metamorph} from an xml description
40
- *
40
+ *
41
41
* @author Markus Michael Geipel
42
42
*/
43
43
public abstract class AbstractMetamorphDomWalker {
@@ -124,7 +124,7 @@ public final void walk(final Reader reader) {
124
124
}
125
125
walk (DomLoader .parse (SCHEMA_FILE , new InputSource (reader )));
126
126
}
127
-
127
+
128
128
public final void walk (final Reader morphDefReader , final Map <String , String > vars ) {
129
129
this .vars .putAll (vars );
130
130
walk (morphDefReader );
@@ -135,7 +135,7 @@ public final void walk(final String morphDef, final Map<String, String> vars) {
135
135
this .vars .putAll (vars );
136
136
walk (morphDef );
137
137
}
138
-
138
+
139
139
public final void walk (final InputStream inputStream , final Map <String , String > vars ) {
140
140
this .vars .putAll (vars );
141
141
walk (inputStream );
@@ -163,24 +163,24 @@ protected static Map<String, String> attributeMap(final Node node) {
163
163
}
164
164
return attributes ;
165
165
}
166
-
166
+
167
167
protected final String resolveVars (final String string ){
168
168
return StringUtil .format (string , Metamorph .VAR_START , Metamorph .VAR_END , ignoreMissingVars , vars );
169
169
}
170
-
170
+
171
171
protected final void setIgnoreMissingVars (final boolean ignoreMissingVars ) {
172
172
this .ignoreMissingVars = ignoreMissingVars ;
173
173
}
174
-
174
+
175
175
protected final String resolvedAttribute (final Node node , final ATTRITBUTE attr ){
176
176
final String value = attribute (node , attr );
177
177
if (null ==value ){
178
178
return null ;
179
179
}
180
180
return resolveVars (value );
181
-
181
+
182
182
}
183
-
183
+
184
184
protected final Map <String , String > resolvedAttributeMap (final Node node ){
185
185
final Map <String , String > attributes = new HashMap <String , String >();
186
186
final NamedNodeMap attrNode = node .getAttributes ();
@@ -191,15 +191,6 @@ protected final Map<String, String> resolvedAttributeMap(final Node node){
191
191
}
192
192
return attributes ;
193
193
}
194
-
195
- private void handleVars (final Node varsNode ) {
196
- for (Node varNode = varsNode .getFirstChild (); varNode != null ; varNode = varNode .getNextSibling ()) {
197
- final String varName = attribute (varNode , ATTRITBUTE .NAME );
198
- final String varValue = attribute (varNode , ATTRITBUTE .VALUE );
199
- vars .put (varName , varValue );
200
- }
201
- vars = new ScopedHashMap <String , String >(vars );
202
- }
203
194
204
195
protected final void walk (final Document doc ) {
205
196
functionFactory = new FunctionFactory ();
@@ -242,44 +233,26 @@ protected final void walk(final Document doc) {
242
233
finish ();
243
234
}
244
235
245
- private void handleMacros (final Node node ) {
246
- for (Node macroNode = node .getFirstChild (); macroNode != null ; macroNode = macroNode .getNextSibling ()) {
247
- final String name = attribute (macroNode , ATTRITBUTE .NAME );
248
- macros .put (name , macroNode );
236
+ private void handleMeta (final Node node ) {
237
+ for (Node metaEntryNode = node .getFirstChild (); metaEntryNode != null ; metaEntryNode = metaEntryNode
238
+ .getNextSibling ()) {
239
+
240
+ handleMetaEntry (metaEntryNode .getLocalName (), metaEntryNode .getTextContent ());
249
241
}
250
242
}
251
243
252
- protected abstract void init ();
253
-
254
- protected abstract void finish ();
255
-
256
- protected abstract void setEntityMarker (final String entityMarker );
257
-
258
- protected abstract void handleInternalMap (final Node mapNode );
259
-
260
- protected abstract void handleMapClass (final Node mapNode );
261
-
262
- protected abstract void handleMetaEntry (final String name , final String value );
263
-
264
- protected abstract void handleFunctionDefinition (final Node functionDefNode );
265
-
266
- protected abstract void enterData (Node node );
267
-
268
- protected abstract void exitData (Node node );
269
-
270
- protected abstract void enterCollect (Node node );
271
-
272
- protected abstract void exitCollect (Node node );
273
-
274
- protected abstract void enterName (Node node );
275
-
276
- protected abstract void exitName (Node node );
277
-
278
- protected abstract void enterIf (Node node );
279
-
280
- protected abstract void exitIf (Node node );
244
+ private void handleFunctionDefinitions (final Node node ) {
245
+ for (Node functionDefNode = node .getFirstChild (); functionDefNode != null ; functionDefNode = functionDefNode
246
+ .getNextSibling ()) {
247
+ handleFunctionDefinition (functionDefNode );
248
+ }
249
+ }
281
250
282
- protected abstract void handleFunction (Node functionNode );
251
+ private void handleRules (final Node node ) {
252
+ for (Node ruleNode = node .getFirstChild (); ruleNode != null ; ruleNode = ruleNode .getNextSibling ()) {
253
+ handleRule (ruleNode );
254
+ }
255
+ }
283
256
284
257
private void handleRule (final Node node ) {
285
258
final String nodeName = node .getLocalName ();
@@ -320,10 +293,6 @@ private void handleRule(final Node node) {
320
293
}
321
294
}
322
295
323
- private void handleIf (final Node node ) {
324
-
325
- }
326
-
327
296
private void handlePostprocess (final Node node ) {
328
297
for (Node functionNode = node .getFirstChild (); functionNode != null ; functionNode = functionNode
329
298
.getNextSibling ()) {
@@ -341,9 +310,19 @@ private void handleMaps(final Node node) {
341
310
}
342
311
}
343
312
344
- private void handleRules (final Node node ) {
345
- for (Node ruleNode = node .getFirstChild (); ruleNode != null ; ruleNode = ruleNode .getNextSibling ()) {
346
- handleRule (ruleNode );
313
+ private void handleVars (final Node varsNode ) {
314
+ for (Node varNode = varsNode .getFirstChild (); varNode != null ; varNode = varNode .getNextSibling ()) {
315
+ final String varName = attribute (varNode , ATTRITBUTE .NAME );
316
+ final String varValue = attribute (varNode , ATTRITBUTE .VALUE );
317
+ vars .put (varName , varValue );
318
+ }
319
+ vars = new ScopedHashMap <String , String >(vars );
320
+ }
321
+
322
+ private void handleMacros (final Node node ) {
323
+ for (Node macroNode = node .getFirstChild (); macroNode != null ; macroNode = macroNode .getNextSibling ()) {
324
+ final String name = attribute (macroNode , ATTRITBUTE .NAME );
325
+ macros .put (name , macroNode );
347
326
}
348
327
}
349
328
@@ -359,18 +338,36 @@ protected final void illegalChild(final Node child) {
359
338
+ child .getParentNode ().getLocalName ());
360
339
}
361
340
362
- private void handleFunctionDefinitions (final Node node ) {
363
- for (Node functionDefNode = node .getFirstChild (); functionDefNode != null ; functionDefNode = functionDefNode
364
- .getNextSibling ()) {
365
- handleFunctionDefinition (functionDefNode );
366
- }
367
- }
341
+ protected abstract void init ();
368
342
369
- private void handleMeta (final Node node ) {
370
- for (Node metaEntryNode = node .getFirstChild (); metaEntryNode != null ; metaEntryNode = metaEntryNode
371
- .getNextSibling ()) {
343
+ protected abstract void finish ();
344
+
345
+ protected abstract void setEntityMarker (final String entityMarker );
346
+
347
+ protected abstract void handleInternalMap (final Node mapNode );
348
+
349
+ protected abstract void handleMapClass (final Node mapNode );
350
+
351
+ protected abstract void handleMetaEntry (final String name , final String value );
352
+
353
+ protected abstract void handleFunctionDefinition (final Node functionDefNode );
354
+
355
+ protected abstract void enterData (Node node );
356
+
357
+ protected abstract void exitData (Node node );
358
+
359
+ protected abstract void enterCollect (Node node );
360
+
361
+ protected abstract void exitCollect (Node node );
362
+
363
+ protected abstract void enterName (Node node );
364
+
365
+ protected abstract void exitName (Node node );
366
+
367
+ protected abstract void enterIf (Node node );
368
+
369
+ protected abstract void exitIf (Node node );
370
+
371
+ protected abstract void handleFunction (Node functionNode );
372
372
373
- handleMetaEntry (metaEntryNode .getLocalName (), metaEntryNode .getTextContent ());
374
- }
375
- }
376
373
}
0 commit comments