Skip to content

Commit 7931ba0

Browse files
committed
Improved code formatting and added documentation.
Brought the formatting of the code in the metamorph package in line with the rest of metafacture-core. Additionally, the javadoc comments were improved and misleading comments removed.
1 parent e2152f4 commit 7931ba0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+597
-561
lines changed

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

Lines changed: 67 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

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

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
* @author Markus Michael Geipel
2121
*
2222
*/
23-
public abstract class AbstractNamedValuePipeHead implements NamedValuePipeHead{
23+
public abstract class AbstractNamedValuePipeHead implements NamedValuePipeHead {
24+
2425
private NamedValueReceiver namedValueReceiver;
2526
private NamedValuePipe last = this;
26-
27+
2728
protected final NamedValueReceiver getNamedValueReceiver() {
2829
return namedValueReceiver;
2930
}
@@ -33,18 +34,19 @@ public final <R extends NamedValueReceiver> R setNamedValueReceiver(final R rece
3334
this.namedValueReceiver = receiver;
3435
return receiver;
3536
}
36-
37+
3738
@Override
3839
public final void appendPipe(final NamedValuePipe namedValuePipe) {
3940
if(last==null){
4041
throw new IllegalStateException("NamedValuePipe already finalyzed.");
4142
}
4243
last = last.setNamedValueReceiver(namedValuePipe);
4344
}
44-
45+
4546
@Override
4647
public final void endPipe(final NamedValueReceiver lastReceiver) {
4748
last.setNamedValueReceiver(lastReceiver);
4849
last = null;
4950
}
51+
5052
}

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,23 @@
1717

1818
import org.culturegraph.mf.util.StringUtil;
1919

20-
2120
/**
2221
* Implementation of the <code>&lt;data&gt;</code> tag.
23-
*
22+
*
2423
* @author Markus Michael Geipel
2524
*/
26-
final class Data extends AbstractNamedValuePipeHead{
25+
final class Data extends AbstractNamedValuePipeHead {
2726

2827
private String name;
2928

30-
3129
@Override
32-
public void receive(final String recName, final String recValue, final NamedValueSource source, final int recordCount, final int entityCount) {
33-
getNamedValueReceiver().receive(StringUtil.fallback(name, recName), recValue, this, recordCount, entityCount);
34-
}
30+
public void receive(final String recName, final String recValue,
31+
final NamedValueSource source, final int recordCount,
32+
final int entityCount) {
3533

36-
/**
37-
* @param name
38-
* the defaultName to set
39-
*/
34+
getNamedValueReceiver().receive(StringUtil.fallback(name, recName),
35+
recValue, this, recordCount, entityCount);
36+
}
4037

4138
public void setName(final String name) {
4239
this.name = name;
@@ -46,4 +43,5 @@ public void setName(final String name) {
4643
public String toString() {
4744
return name;
4845
}
46+
4947
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@
1919

2020

2121
/**
22+
<<<<<<< HEAD
2223
* Default error handler used by {@link Metamorph}. Just repackages
2324
* exceptions as {@link MorphException}s.
25+
=======
26+
* Default error handler used by {@link Metamorph}. Just
27+
* repackages exceptions as {@link MorphException}s.
28+
>>>>>>> Improved code formatting and added documentation.
2429
*
2530
* @author Markus Michael Geipel
2631
*

0 commit comments

Comments
 (0)