Skip to content

Commit 85f3e2d

Browse files
committed
metamorph/ (main): Fix Checkstyle violations.
1 parent 0fc0346 commit 85f3e2d

File tree

105 files changed

+786
-582
lines changed

Some content is hidden

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

105 files changed

+786
-582
lines changed

metamorph/src/main/java/org/metafacture/metamorph/AbstractMetamorphDomWalker.java

Lines changed: 72 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,22 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.metafacture.metamorph;
1716

18-
import java.util.HashMap;
19-
import java.util.Map;
17+
package org.metafacture.metamorph;
2018

2119
import org.metafacture.commons.StringUtil;
2220
import org.metafacture.commons.types.ScopedHashMap;
2321
import org.metafacture.metamorph.api.MorphBuildException;
2422
import org.metafacture.metamorph.xml.DomLoader;
23+
2524
import org.w3c.dom.Document;
2625
import org.w3c.dom.Element;
2726
import org.w3c.dom.NamedNodeMap;
2827
import org.w3c.dom.Node;
2928
import org.xml.sax.InputSource;
3029

30+
import java.util.HashMap;
31+
import java.util.Map;
3132

3233
/**
3334
* Builds a {@link Metamorph} from an xml description
@@ -99,15 +100,56 @@ protected final MapFactory getMapFactory() {
99100
return mapFactory;
100101
}
101102

102-
public final void walk(final InputSource morphScript, final Map<String, String> vars) {
103-
this.vars.putAll(vars);
103+
public final void walk(final InputSource morphScript, final Map<String, String> newVars) {
104+
vars.putAll(newVars);
104105
walk(morphScript);
105106
}
106107

107108
public final void walk(final InputSource morphScript) {
108109
walk(DomLoader.parse(SCHEMA_FILE, morphScript));
109110
}
110111

112+
protected final void walk(final Document doc) {
113+
functionFactory = new FunctionFactory();
114+
collectFactory = new CollectFactory();
115+
collectFactory.registerClass(ENTITY, Entity.class);
116+
mapFactory = new MapFactory();
117+
118+
init();
119+
120+
final Element root = doc.getDocumentElement();
121+
final int version = Integer.parseInt(attribute(root, AttributeName.VERSION));
122+
checkVersionCompatibility(version);
123+
124+
setEntityMarker(attribute(root, AttributeName.ENTITY_MARKER));
125+
126+
for (Node node = root.getFirstChild(); node != null; node = node.getNextSibling()) {
127+
switch (tagOf(node)) {
128+
case META:
129+
handleMeta(node);
130+
break;
131+
case FUNCTIONS:
132+
handleFunctionDefinitions(node);
133+
break;
134+
case RULES:
135+
handleRules(node);
136+
break;
137+
case MAPS:
138+
handleMaps(node);
139+
break;
140+
case VARS:
141+
handleVars(node);
142+
break;
143+
case MACROS:
144+
handleMacros(node);
145+
break;
146+
default:
147+
illegalChild(node);
148+
}
149+
}
150+
finish();
151+
}
152+
111153
private static Tags tagOf(final Node child) {
112154
return Tags.valueOf(child.getLocalName().toUpperCase());
113155
}
@@ -131,7 +173,7 @@ protected static Map<String, String> attributeMap(final Node elementNode) {
131173
return attributes;
132174
}
133175

134-
protected final String resolveVars(final String string){
176+
protected final String resolveVars(final String string) {
135177
return StringUtil.format(string, Metamorph.VAR_START, Metamorph.VAR_END, ignoreMissingVars, vars);
136178
}
137179

@@ -141,7 +183,7 @@ protected final void setIgnoreMissingVars(final boolean ignoreMissingVars) {
141183

142184
protected final String resolvedAttribute(final Node node, final AttributeName attr) {
143185
final String value = attribute(node, attr);
144-
if(null==value){
186+
if (null == value) {
145187
return null;
146188
}
147189
return resolveVars(value);
@@ -159,48 +201,6 @@ protected final Map<String, String> resolvedAttributeMap(final Node node) {
159201
return attributes;
160202
}
161203

162-
protected final void walk(final Document doc) {
163-
functionFactory = new FunctionFactory();
164-
collectFactory = new CollectFactory();
165-
collectFactory.registerClass(ENTITY, Entity.class);
166-
mapFactory = new MapFactory();
167-
168-
init();
169-
170-
final Element root = doc.getDocumentElement();
171-
final int version = Integer.parseInt(attribute(root, AttributeName.VERSION));
172-
checkVersionCompatibility(version);
173-
174-
setEntityMarker(attribute(root, AttributeName.ENTITY_MARKER));
175-
176-
for (Node node = root.getFirstChild(); node != null; node = node.getNextSibling()) {
177-
178-
switch (tagOf(node)) {
179-
case META:
180-
handleMeta(node);
181-
break;
182-
case FUNCTIONS:
183-
handleFunctionDefinitions(node);
184-
break;
185-
case RULES:
186-
handleRules(node);
187-
break;
188-
case MAPS:
189-
handleMaps(node);
190-
break;
191-
case VARS:
192-
handleVars(node);
193-
break;
194-
case MACROS:
195-
handleMacros(node);
196-
break;
197-
default:
198-
illegalChild(node);
199-
}
200-
}
201-
finish();
202-
}
203-
204204
private void handleMeta(final Node node) {
205205
for (Node metaEntryNode = node.getFirstChild(); metaEntryNode != null; metaEntryNode = metaEntryNode
206206
.getNextSibling()) {
@@ -231,39 +231,44 @@ private void handleRule(final Node node) {
231231
enterIf(child);
232232
handleRule(child.getFirstChild());
233233
exitIf(child);
234-
} else if (POSTPROCESS.equals(child.getLocalName())) {
234+
}
235+
else if (POSTPROCESS.equals(child.getLocalName())) {
235236
handlePostprocess(child);
236-
} else if (ENTITY_NAME.equals(child.getLocalName())) {
237+
}
238+
else if (ENTITY_NAME.equals(child.getLocalName())) {
237239
enterName(child);
238240
handleRule(child.getFirstChild());
239241
exitName(child);
240-
} else {
242+
}
243+
else {
241244
handleRule(child);
242245
}
243246
}
244247
exitCollect(node);
245-
} else if (DATA.equals(nodeName)) {
248+
}
249+
else if (DATA.equals(nodeName)) {
246250
enterData(node);
247251
handlePostprocess(node);
248252
exitData(node);
249-
} else if (CALL_MACRO.equals(nodeName)){
253+
}
254+
else if (CALL_MACRO.equals(nodeName)) {
250255
final String macroName = attribute(node, AttributeName.NAME);
251256
final Node macroNode = macros.get(macroName);
252-
if (macroNode==null){
257+
if (macroNode == null) {
253258
throw new MorphBuildException("Macro '" + macroName + "' undefined!");
254259
}
255260
vars = new ScopedHashMap<String, String>(vars);
256261
vars.putAll(resolvedAttributeMap(node));
257262
handleRules(macroNode);
258263
vars = vars.getOuterScope();
259-
}else {
264+
}
265+
else {
260266
illegalChild(node);
261267
}
262268
}
263269

264270
private void handlePostprocess(final Node node) {
265-
for (Node functionNode = node.getFirstChild(); functionNode != null; functionNode = functionNode
266-
.getNextSibling()) {
271+
for (Node functionNode = node.getFirstChild(); functionNode != null; functionNode = functionNode.getNextSibling()) {
267272
handleFunction(functionNode);
268273
}
269274
}
@@ -272,7 +277,8 @@ private void handleMaps(final Node node) {
272277
for (Node mapNode = node.getFirstChild(); mapNode != null; mapNode = mapNode.getNextSibling()) {
273278
if (MAP.equals(mapNode.getLocalName())) {
274279
handleInternalMap(mapNode);
275-
} else {
280+
}
281+
else {
276282
handleMapClass(mapNode);
277283
}
278284
}
@@ -296,29 +302,27 @@ private void handleMacros(final Node node) {
296302

297303
private void checkVersionCompatibility(final int version) {
298304
if (version < LOWEST_COMPATIBLE_VERSION || version > CURRENT_VERSION) {
299-
throw new MorphBuildException("Version " + version
300-
+ " of definition file not supported by metamorph version " + CURRENT_VERSION);
305+
throw new MorphBuildException("Version " + version + " of definition file not supported by metamorph version " + CURRENT_VERSION);
301306
}
302307
}
303308

304309
protected final void illegalChild(final Node child) {
305-
throw new MorphBuildException("Schema mismatch: illegal tag " + child.getLocalName() + " in node "
306-
+ child.getParentNode().getLocalName());
310+
throw new MorphBuildException("Schema mismatch: illegal tag " + child.getLocalName() + " in node " + child.getParentNode().getLocalName());
307311
}
308312

309313
protected abstract void init();
310314

311315
protected abstract void finish();
312316

313-
protected abstract void setEntityMarker(final String entityMarker);
317+
protected abstract void setEntityMarker(String entityMarker);
314318

315-
protected abstract void handleInternalMap(final Node mapNode);
319+
protected abstract void handleInternalMap(Node mapNode);
316320

317-
protected abstract void handleMapClass(final Node mapNode);
321+
protected abstract void handleMapClass(Node mapNode);
318322

319-
protected abstract void handleMetaEntry(final String name, final String value);
323+
protected abstract void handleMetaEntry(String name, String value);
320324

321-
protected abstract void handleFunctionDefinition(final Node functionDefNode);
325+
protected abstract void handleFunctionDefinition(Node functionDefNode);
322326

323327
protected abstract void enterData(Node node);
324328

metamorph/src/main/java/org/metafacture/metamorph/CollectFactory.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.metafacture.metamorph;
17-
1816

19-
import java.io.IOException;
17+
package org.metafacture.metamorph;
2018

2119
import org.metafacture.commons.ResourceUtil;
2220
import org.metafacture.commons.reflection.ObjectFactory;
2321
import org.metafacture.framework.MetafactureException;
2422
import org.metafacture.metamorph.api.Collect;
2523

24+
import java.io.IOException;
25+
2626
/**
2727
* Creates the collectors available in Metamorph.
2828
*
@@ -33,9 +33,9 @@ final class CollectFactory extends ObjectFactory<Collect> {
3333

3434
CollectFactory() {
3535
try {
36-
loadClassesFromMap(ResourceUtil.loadProperties(
37-
"morph-collectors.properties"), Collect.class);
38-
} catch (IOException e) {
36+
loadClassesFromMap(ResourceUtil.loadProperties("morph-collectors.properties"), Collect.class);
37+
}
38+
catch (final IOException e) {
3939
throw new MetafactureException("Failed to load collectors list", e);
4040
}
4141
}

metamorph/src/main/java/org/metafacture/metamorph/Data.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.metamorph;
1718

1819
import org.metafacture.commons.StringUtil;
@@ -28,13 +29,12 @@ final class Data extends AbstractNamedValuePipe {
2829

2930
private String name;
3031

31-
@Override
32-
public void receive(final String recName, final String recValue,
33-
final NamedValueSource source, final int recordCount,
34-
final int entityCount) {
32+
Data() {
33+
}
3534

36-
getNamedValueReceiver().receive(StringUtil.fallback(name, recName),
37-
recValue, this, recordCount, entityCount);
35+
@Override
36+
public void receive(final String recName, final String recValue, final NamedValueSource source, final int recordCount, final int entityCount) {
37+
getNamedValueReceiver().receive(StringUtil.fallback(name, recName), recValue, this, recordCount, entityCount);
3838
}
3939

4040
public void setName(final String name) {

metamorph/src/main/java/org/metafacture/metamorph/DefaultErrorHandler.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.metafacture.metamorph;
1716

17+
package org.metafacture.metamorph;
1818

1919
import org.metafacture.metamorph.api.MorphErrorHandler;
2020

@@ -26,11 +26,12 @@
2626
*/
2727
public final class DefaultErrorHandler implements MorphErrorHandler {
2828

29+
public DefaultErrorHandler() {
30+
}
31+
2932
@Override
3033
public void error(final Exception exception) {
31-
throw new MetamorphException(
32-
"Error while executing the Metamorph transformation pipeline: " +
33-
exception.getMessage(), exception);
34+
throw new MetamorphException("Error while executing the Metamorph transformation pipeline: " + exception.getMessage(), exception);
3435
}
3536

3637
}

0 commit comments

Comments
 (0)