Skip to content

Commit 56a7698

Browse files
committed
Improve code style
Fix a couple of type names which are not following the coding conventions. Change some variable names so that they are easier to understand.
1 parent 72a75ba commit 56a7698

File tree

3 files changed

+64
-68
lines changed

3 files changed

+64
-68
lines changed

src/main/java/org/culturegraph/mf/morph/AbstractMetamorphDomWalker.java

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,22 @@
3737

3838
/**
3939
* Builds a {@link Metamorph} from an xml description
40-
*
40+
*
4141
* @author Markus Michael Geipel
4242
*/
4343
public 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()) {

src/main/java/org/culturegraph/mf/morph/MorphBuilder.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ protected void setEntityMarker(final String entityMarker) {
6464

6565
@Override
6666
protected void handleInternalMap(final Node mapNode) {
67-
final String mapName = resolvedAttribute(mapNode, ATTRITBUTE.NAME);
67+
final String mapName = resolvedAttribute(mapNode, AttributeName.NAME);
6868

69-
final String mapDefault = resolvedAttribute(mapNode, ATTRITBUTE.DEFAULT);
69+
final String mapDefault = resolvedAttribute(mapNode, AttributeName.DEFAULT);
7070

7171
for (Node entryNode = mapNode.getFirstChild(); entryNode != null; entryNode = entryNode.getNextSibling()) {
72-
final String entryName = resolvedAttribute(entryNode, ATTRITBUTE.NAME);
73-
final String entryValue = resolvedAttribute(entryNode, ATTRITBUTE.VALUE);
72+
final String entryName = resolvedAttribute(entryNode, AttributeName.NAME);
73+
final String entryValue = resolvedAttribute(entryNode, AttributeName.VALUE);
7474
metamorph.putValue(mapName, entryName, entryValue);
7575
}
7676

@@ -83,13 +83,13 @@ protected void handleInternalMap(final Node mapNode) {
8383
@Override
8484
protected void handleMapClass(final Node mapNode) {
8585
final Map<String, String> attributes = resolvedAttributeMap(mapNode);
86-
final String mapName = resolveVars(attributes.remove(ATTRITBUTE.NAME.getString()));
86+
final String mapName = resolveVars(attributes.remove(AttributeName.NAME.getString()));
8787
final Map<String, String> map;
8888

8989
if (mapNode.getLocalName().equals(JAVAMAP)) {
90-
final String className = resolvedAttribute(mapNode, ATTRITBUTE.CLASS);
90+
final String className = resolvedAttribute(mapNode, AttributeName.CLASS);
9191
map = ObjectFactory.newInstance(ObjectFactory.loadClass(className, Map.class));
92-
attributes.remove(ATTRITBUTE.CLASS.getString());
92+
attributes.remove(AttributeName.CLASS.getString());
9393
ObjectFactory.applySetters(map, attributes);
9494
} else if (getMapFactory().containsKey(mapNode.getLocalName())) {
9595
map = getMapFactory().newInstance(mapNode.getLocalName(), attributes);
@@ -105,14 +105,14 @@ protected void handleMapClass(final Node mapNode) {
105105
// protected by 'if (Function.class.isAssignableFrom(clazz))'
106106
protected void handleFunctionDefinition(final Node functionDefNode) {
107107
final Class<?> clazz;
108-
final String className = resolvedAttribute(functionDefNode, ATTRITBUTE.CLASS);
108+
final String className = resolvedAttribute(functionDefNode, AttributeName.CLASS);
109109
try {
110110
clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
111111
} catch (final ClassNotFoundException e) {
112112
throw new MorphDefException("Function " + className + NOT_FOUND, e);
113113
}
114114
if (Function.class.isAssignableFrom(clazz)) {
115-
getFunctionFactory().registerClass(resolvedAttribute(functionDefNode, ATTRITBUTE.NAME),
115+
getFunctionFactory().registerClass(resolvedAttribute(functionDefNode, AttributeName.NAME),
116116
(Class<Function>) clazz);
117117
} else {
118118
throw new MorphDefException(className + " does not implement interface 'Function'");
@@ -136,9 +136,9 @@ protected void finish() {
136136

137137
@Override
138138
protected void enterData(final Node dataNode) {
139-
final String source = resolvedAttribute(dataNode, ATTRITBUTE.SOURCE);
139+
final String source = resolvedAttribute(dataNode, AttributeName.SOURCE);
140140
data = new Data();
141-
data.setName(resolvedAttribute(dataNode, ATTRITBUTE.NAME));
141+
data.setName(resolvedAttribute(dataNode, AttributeName.NAME));
142142
metamorph.registerNamedValueReceiver(source, data);
143143

144144
if (setEntityName) {
@@ -188,7 +188,7 @@ protected void exitIf(final Node nameNode) {
188188
protected void enterCollect(final Node node) {
189189
final Map<String, String> attributes = resolvedAttributeMap(node);
190190
// must be set after recursive calls to flush descendants before parent
191-
attributes.remove(ATTRITBUTE.FLUSH_WITH.getString());
191+
attributes.remove(AttributeName.FLUSH_WITH.getString());
192192

193193
if (!getCollectFactory().containsKey(node.getLocalName())) {
194194
throw new IllegalArgumentException("Collector " + node.getLocalName() + NOT_FOUND);
@@ -219,7 +219,7 @@ protected void exitCollect(final Node node) {
219219
collect.endPipe(parent);
220220
}
221221
// must be set after recursive calls to flush descendants before parent
222-
final String flushWith = resolvedAttribute(node, ATTRITBUTE.FLUSH_WITH);
222+
final String flushWith = resolvedAttribute(node, AttributeName.FLUSH_WITH);
223223
if (null != flushWith) {
224224
collect.setWaitForFlush(true);
225225
registerFlush(flushWith, collect);
@@ -242,13 +242,13 @@ protected void handleFunction(final Node functionNode) {
242242
final Function function;
243243
final Map<String, String> attributes = resolvedAttributeMap(functionNode);
244244
if (functionNode.getLocalName().equals(JAVA)) {
245-
final String className = resolvedAttribute(functionNode, ATTRITBUTE.CLASS);
245+
final String className = resolvedAttribute(functionNode, AttributeName.CLASS);
246246
function = ObjectFactory.newInstance(ObjectFactory.loadClass(className, Function.class));
247247

248-
attributes.remove(ATTRITBUTE.CLASS.getString());
248+
attributes.remove(AttributeName.CLASS.getString());
249249
ObjectFactory.applySetters(function, attributes);
250250
} else if (getFunctionFactory().containsKey(functionNode.getLocalName())) {
251-
final String flushWith = attributes.remove(ATTRITBUTE.FLUSH_WITH.getString());
251+
final String flushWith = attributes.remove(AttributeName.FLUSH_WITH.getString());
252252
function = getFunctionFactory().newInstance(functionNode.getLocalName(), attributes);
253253
if (null != flushWith) {
254254
registerFlush(flushWith, function);
@@ -263,8 +263,8 @@ protected void handleFunction(final Node functionNode) {
263263
// add key value entries...
264264
for (Node mapEntryNode = functionNode.getFirstChild(); mapEntryNode != null; mapEntryNode = mapEntryNode
265265
.getNextSibling()) {
266-
final String entryName = resolvedAttribute(mapEntryNode, ATTRITBUTE.NAME);
267-
final String entryValue = resolvedAttribute(mapEntryNode, ATTRITBUTE.VALUE);
266+
final String entryName = resolvedAttribute(mapEntryNode, AttributeName.NAME);
267+
final String entryValue = resolvedAttribute(mapEntryNode, AttributeName.VALUE);
268268
function.putValue(entryName, entryValue);
269269
}
270270
if (data == null) {

src/main/java/org/culturegraph/mf/morph/MorphVisualizer.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,28 +146,28 @@ protected void setEntityMarker(final String entityMarker) {
146146

147147
@Override
148148
protected void handleInternalMap(final Node mapNode) {
149-
final String mapName = resolvedAttribute(mapNode, ATTRITBUTE.NAME);
149+
final String mapName = resolvedAttribute(mapNode, AttributeName.NAME);
150150
final Map<String, String> map = getMap(mapNode);
151151
writer.println(buildMap(mapName, mapName, map));
152152
}
153153

154154
@Override
155155
protected void handleMapClass(final Node mapNode) {
156-
final String mapName = resolvedAttribute(mapNode, ATTRITBUTE.NAME);
156+
final String mapName = resolvedAttribute(mapNode, AttributeName.NAME);
157157
final Map<String, String> emptyMap = Collections.emptyMap();
158158
writer.println(buildMap(mapName, mapName, emptyMap));
159159
}
160160

161161
private Map<String, String> getMap(final Node mapNode) {
162162
final Map<String, String> map = new HashMap<String, String>();
163-
final String mapDefault = resolvedAttribute(mapNode, ATTRITBUTE.DEFAULT);
163+
final String mapDefault = resolvedAttribute(mapNode, AttributeName.DEFAULT);
164164
if (mapDefault != null) {
165165
map.put("_default", mapDefault);
166166
}
167167

168168
for (Node entryNode = mapNode.getFirstChild(); entryNode != null; entryNode = entryNode.getNextSibling()) {
169-
final String entryName = resolvedAttribute(entryNode, ATTRITBUTE.NAME);
170-
final String entryValue = resolvedAttribute(entryNode, ATTRITBUTE.VALUE);
169+
final String entryName = resolvedAttribute(entryNode, AttributeName.NAME);
170+
final String entryValue = resolvedAttribute(entryNode, AttributeName.VALUE);
171171
map.put(entryName, entryValue);
172172
}
173173
return map;
@@ -197,14 +197,14 @@ private String newOutNode() {
197197
@Override
198198
protected void enterData(final Node node) {
199199
incrementChildCount();
200-
lastProcessorStack.push(resolvedAttribute(node, ATTRITBUTE.SOURCE));
200+
lastProcessorStack.push(resolvedAttribute(node, AttributeName.SOURCE));
201201
}
202202

203203

204204

205205
@Override
206206
protected void exitData(final Node node) {
207-
sources.add(resolvedAttribute(node, ATTRITBUTE.SOURCE));
207+
sources.add(resolvedAttribute(node, AttributeName.SOURCE));
208208
exit(node);
209209
}
210210

@@ -218,7 +218,7 @@ protected void enterCollect(final Node node) {
218218
idStack.push(identifier);
219219

220220
final Map<String, String> attributes = resolvedAttributeMap(node);
221-
attributes.remove(ATTRITBUTE.NAME.getString());
221+
attributes.remove(AttributeName.NAME.getString());
222222
writer.println(buildRecord(identifier, node.getLocalName(), "lightgray", attributes));
223223
}
224224

@@ -232,7 +232,7 @@ protected void exitCollect(final Node node) {
232232

233233
@Override
234234
protected void enterName(final Node node) {
235-
((Element)node.getFirstChild()).setAttribute(ATTRITBUTE.NAME.getString(), "<entity-name>");
235+
((Element)node.getFirstChild()).setAttribute(AttributeName.NAME.getString(), "<entity-name>");
236236
}
237237

238238
@Override
@@ -241,7 +241,7 @@ protected void exitName(final Node node) {
241241
}
242242

243243
private void exit(final Node node) {
244-
String name = resolvedAttribute(node, ATTRITBUTE.NAME);
244+
String name = resolvedAttribute(node, AttributeName.NAME);
245245
if (name == null) {
246246
name = "";
247247
}
@@ -301,7 +301,7 @@ private void incrementChildCount() {
301301

302302
@Override
303303
protected void enterIf(final Node node) {
304-
((Element)node.getFirstChild()).setAttribute(ATTRITBUTE.NAME.getString(), "<if>");
304+
((Element)node.getFirstChild()).setAttribute(AttributeName.NAME.getString(), "<if>");
305305
}
306306

307307
@Override

0 commit comments

Comments
 (0)