3737
3838/**
3939 * Builds a {@link Metamorph} from an xml description
40- *
40+ *
4141 * @author Markus Michael Geipel
4242 */
4343public abstract class AbstractMetamorphDomWalker {
4444
4545 /**
4646 * XML tags
4747 */
48- public static enum MMTAG {
48+ public static enum Tags {
4949 META , FUNCTIONS , RULES , MACROS , MACRO , MAPS , ENTITY , MAP , ENTRY , TEXT , VARS
5050 }
5151
5252 /**
5353 * XML attributes
5454 */
55- public static enum ATTRITBUTE {
55+ public static enum AttributeName {
5656 VERSION ("version" ),
5757 SOURCE ("source" ),
5858 VALUE ("value" ),
@@ -64,7 +64,7 @@ public static enum ATTRITBUTE {
6464
6565 private final String string ;
6666
67- private ATTRITBUTE (final String string ) {
67+ private AttributeName (final String string ) {
6868 this .string = string ;
6969 }
7070
@@ -75,7 +75,7 @@ public String getString() {
7575
7676 private static final String DATA = "data" ;
7777 private static final String MAP = "map" ;
78- private static final String MACRO = "call-macro" ;
78+ private static final String CALL_MACRO = "call-macro" ;
7979 private static final String IF = "if" ;
8080 private static final String POSTPROCESS = "postprocess" ;
8181 private static final String ENTITY_NAME = "entity-name" ;
@@ -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,53 +135,53 @@ 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 );
142142 }
143143
144- private static MMTAG tagOf (final Node child ) {
145- return MMTAG .valueOf (child .getLocalName ().toUpperCase ());
144+ private static Tags tagOf (final Node child ) {
145+ return Tags .valueOf (child .getLocalName ().toUpperCase ());
146146 }
147147
148- protected static String attribute (final Node node , final ATTRITBUTE attr ) {
149- final Node attribute = node .getAttributes ().getNamedItem (attr .getString ());
150- if (attribute != null ) {
151- return attribute .getNodeValue ();
148+ protected static String attribute (final Node node , final AttributeName attr ) {
149+ final Node attrNode = node .getAttributes ().getNamedItem (attr .getString ());
150+ if (attrNode != null ) {
151+ return attrNode .getNodeValue ();
152152 }
153153 return null ;
154154 }
155155
156- protected static Map <String , String > attributeMap (final Node node ) {
156+ protected static Map <String , String > attributeMap (final Node elementNode ) {
157157 final Map <String , String > attributes = new HashMap <String , String >();
158- final NamedNodeMap attrNode = node .getAttributes ();
158+ final NamedNodeMap attrNodes = elementNode .getAttributes ();
159159
160- for (int i = 0 ; i < attrNode .getLength (); ++i ) {
161- final Node itemNode = attrNode .item (i );
162- attributes .put (itemNode .getLocalName (), itemNode .getNodeValue ());
160+ for (int i = 0 ; i < attrNodes .getLength (); ++i ) {
161+ final Node attrNode = attrNodes .item (i );
162+ attributes .put (attrNode .getLocalName (), attrNode .getNodeValue ());
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-
175- protected final String resolvedAttribute (final Node node , final ATTRITBUTE attr ){
174+
175+ protected final String resolvedAttribute (final Node node , final AttributeName attr ){
176176 final String value = attribute (node , attr );
177177 if (null ==value ){
178178 return null ;
179179 }
180180 return resolveVars (value );
181-
181+
182182 }
183-
184- protected final Map <String , String > resolvedAttributeMap (final Node node ){
183+
184+ 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 ();
187187
@@ -191,11 +191,11 @@ protected final Map<String, String> resolvedAttributeMap(final Node node){
191191 }
192192 return attributes ;
193193 }
194-
194+
195195 private void handleVars (final Node varsNode ) {
196196 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 );
197+ final String varName = attribute (varNode , AttributeName .NAME );
198+ final String varValue = attribute (varNode , AttributeName .VALUE );
199199 vars .put (varName , varValue );
200200 }
201201 vars = new ScopedHashMap <String , String >(vars );
@@ -209,10 +209,10 @@ protected final void walk(final Document doc) {
209209 init ();
210210
211211 final Element root = doc .getDocumentElement ();
212- final int version = Integer .parseInt (attribute (root , ATTRITBUTE .VERSION ));
212+ final int version = Integer .parseInt (attribute (root , AttributeName .VERSION ));
213213 checkVersionCompatibility (version );
214214
215- setEntityMarker (attribute (root , ATTRITBUTE .ENTITY_MARKER ));
215+ setEntityMarker (attribute (root , AttributeName .ENTITY_MARKER ));
216216
217217 for (Node node = root .getFirstChild (); node != null ; node = node .getNextSibling ()) {
218218
@@ -244,7 +244,7 @@ protected final void walk(final Document doc) {
244244
245245 private void handleMacros (final Node node ) {
246246 for (Node macroNode = node .getFirstChild (); macroNode != null ; macroNode = macroNode .getNextSibling ()) {
247- final String name = attribute (macroNode , ATTRITBUTE .NAME );
247+ final String name = attribute (macroNode , AttributeName .NAME );
248248 macros .put (name , macroNode );
249249 }
250250 }
@@ -272,11 +272,11 @@ private void handleMacros(final Node node) {
272272 protected abstract void exitCollect (Node node );
273273
274274 protected abstract void enterName (Node node );
275-
275+
276276 protected abstract void exitName (Node node );
277277
278278 protected abstract void enterIf (Node node );
279-
279+
280280 protected abstract void exitIf (Node node );
281281
282282 protected abstract void handleFunction (Node functionNode );
@@ -305,8 +305,8 @@ private void handleRule(final Node node) {
305305 enterData (node );
306306 handlePostprocess (node );
307307 exitData (node );
308- } else if (MACRO .equals (nodeName )){
309- final String macroName = attribute (node , ATTRITBUTE .NAME );
308+ } else if (CALL_MACRO .equals (nodeName )){
309+ final String macroName = attribute (node , AttributeName .NAME );
310310 final Node macroNode = macros .get (macroName );
311311 if (macroNode ==null ){
312312 throw new MorphDefException ("Macro '" + macroName + "' undefined!" );
@@ -320,10 +320,6 @@ private void handleRule(final Node node) {
320320 }
321321 }
322322
323- private void handleIf (final Node node ) {
324-
325- }
326-
327323 private void handlePostprocess (final Node node ) {
328324 for (Node functionNode = node .getFirstChild (); functionNode != null ; functionNode = functionNode
329325 .getNextSibling ()) {
0 commit comments