3737
3838/**
3939 * Builds a {@link Metamorph} from an xml description
40- *
40+ *
4141 * @author Markus Michael Geipel
4242 */
4343public abstract class AbstractMetamorphDomWalker {
@@ -124,7 +124,7 @@ public final void walk(final Reader reader) {
124124 }
125125 walk (DomLoader .parse (SCHEMA_FILE , new InputSource (reader )));
126126 }
127-
127+
128128 public final void walk (final Reader morphDefReader , final Map <String , String > vars ) {
129129 this .vars .putAll (vars );
130130 walk (morphDefReader );
@@ -135,7 +135,7 @@ public final void walk(final String morphDef, final Map<String, String> vars) {
135135 this .vars .putAll (vars );
136136 walk (morphDef );
137137 }
138-
138+
139139 public final void walk (final InputStream inputStream , final Map <String , String > vars ) {
140140 this .vars .putAll (vars );
141141 walk (inputStream );
@@ -163,24 +163,24 @@ protected static Map<String, String> attributeMap(final Node node) {
163163 }
164164 return attributes ;
165165 }
166-
166+
167167 protected final String resolveVars (final String string ){
168168 return StringUtil .format (string , Metamorph .VAR_START , Metamorph .VAR_END , ignoreMissingVars , vars );
169169 }
170-
170+
171171 protected final void setIgnoreMissingVars (final boolean ignoreMissingVars ) {
172172 this .ignoreMissingVars = ignoreMissingVars ;
173173 }
174-
174+
175175 protected final String resolvedAttribute (final Node node , final ATTRITBUTE attr ){
176176 final String value = attribute (node , attr );
177177 if (null ==value ){
178178 return null ;
179179 }
180180 return resolveVars (value );
181-
181+
182182 }
183-
183+
184184 protected final Map <String , String > resolvedAttributeMap (final Node node ){
185185 final Map <String , String > attributes = new HashMap <String , String >();
186186 final NamedNodeMap attrNode = node .getAttributes ();
@@ -191,15 +191,6 @@ protected final Map<String, String> resolvedAttributeMap(final Node node){
191191 }
192192 return attributes ;
193193 }
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- }
203194
204195 protected final void walk (final Document doc ) {
205196 functionFactory = new FunctionFactory ();
@@ -242,44 +233,26 @@ protected final void walk(final Document doc) {
242233 finish ();
243234 }
244235
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 ());
249241 }
250242 }
251243
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+ }
281250
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+ }
283256
284257 private void handleRule (final Node node ) {
285258 final String nodeName = node .getLocalName ();
@@ -320,10 +293,6 @@ private void handleRule(final Node node) {
320293 }
321294 }
322295
323- private void handleIf (final Node node ) {
324-
325- }
326-
327296 private void handlePostprocess (final Node node ) {
328297 for (Node functionNode = node .getFirstChild (); functionNode != null ; functionNode = functionNode
329298 .getNextSibling ()) {
@@ -341,9 +310,19 @@ private void handleMaps(final Node node) {
341310 }
342311 }
343312
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 );
347326 }
348327 }
349328
@@ -359,18 +338,36 @@ protected final void illegalChild(final Node child) {
359338 + child .getParentNode ().getLocalName ());
360339 }
361340
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 ();
368342
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 );
372372
373- handleMetaEntry (metaEntryNode .getLocalName (), metaEntryNode .getTextContent ());
374- }
375- }
376373}
0 commit comments