Skip to content

Commit

Permalink
NodeHandler internal class cleanup
Browse files Browse the repository at this point in the history
Change NodeHandler to not be an internal class creating itself but
rather a method in default scope.  Have it perform the get and simply
return the NodeHandler as that is the only usage.
  • Loading branch information
hazendaz committed Sep 21, 2014
1 parent 3320543 commit 0a4dad5
Showing 1 changed file with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ List<SqlNode> parseDynamicTags(XNode node) {
}
} else if (child.getNode().getNodeType() == Node.ELEMENT_NODE) { // issue #628
String nodeName = child.getNode().getNodeName();
NodeHandler handler = nodeHandlers.get(nodeName);
NodeHandler handler = nodeHandlers(nodeName);
if (handler == null) {
throw new BuilderException("Unknown element <" + nodeName + "> in SQL statement.");
}
Expand All @@ -87,21 +87,19 @@ List<SqlNode> parseDynamicTags(XNode node) {
return contents;
}

private Map<String, NodeHandler> nodeHandlers = new HashMap<String, NodeHandler>() {
private static final long serialVersionUID = 7123056019193266281L;

{
put("trim", new TrimHandler());
put("where", new WhereHandler());
put("set", new SetHandler());
put("foreach", new ForEachHandler());
put("if", new IfHandler());
put("choose", new ChooseHandler());
put("when", new IfHandler());
put("otherwise", new OtherwiseHandler());
put("bind", new BindHandler());
}
};
NodeHandler nodeHandlers(String nodeName) {
Map<String, NodeHandler> map = new HashMap<String, NodeHandler>();
map.put("trim", new TrimHandler());
map.put("where", new WhereHandler());
map.put("set", new SetHandler());
map.put("foreach", new ForEachHandler());
map.put("if", new IfHandler());
map.put("choose", new ChooseHandler());
map.put("when", new IfHandler());
map.put("otherwise", new OtherwiseHandler());
map.put("bind", new BindHandler());
return map.get(nodeName);
}

private interface NodeHandler {
void handleNode(XNode nodeToHandle, List<SqlNode> targetContents);
Expand Down Expand Up @@ -234,7 +232,7 @@ private void handleWhenOtherwiseNodes(XNode chooseSqlNode, List<SqlNode> ifSqlNo
List<XNode> children = chooseSqlNode.getChildren();
for (XNode child : children) {
String nodeName = child.getNode().getNodeName();
NodeHandler handler = nodeHandlers.get(nodeName);
NodeHandler handler = nodeHandlers(nodeName);
if (handler instanceof IfHandler) {
handler.handleNode(child, ifSqlNodes);
} else if (handler instanceof OtherwiseHandler) {
Expand Down

0 comments on commit 0a4dad5

Please sign in to comment.