Skip to content

Commit 560650b

Browse files
committed
Making magic numbers into enums
1 parent d9e9248 commit 560650b

File tree

19 files changed

+110
-59
lines changed

19 files changed

+110
-59
lines changed

data-hub/src/main/java/com/marklogic/hub/collector/AbstractCollector.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@
2020
import javax.xml.stream.XMLStreamException;
2121
import javax.xml.stream.XMLStreamWriter;
2222

23+
import com.marklogic.hub.plugin.PluginType;
24+
2325
public abstract class AbstractCollector implements Collector {
2426

25-
private String type;
27+
private PluginType type;
2628

27-
public AbstractCollector(String type) {
29+
public AbstractCollector(PluginType type) {
2830
this.type = type;
2931
}
3032

3133
@Override
32-
public String getType() {
34+
public PluginType getType() {
3335
return this.type;
3436
}
3537

data-hub/src/main/java/com/marklogic/hub/collector/Collector.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
import javax.xml.stream.XMLStreamException;
2121
import javax.xml.stream.XMLStreamWriter;
2222

23+
import com.marklogic.hub.plugin.PluginType;
24+
2325
public interface Collector {
2426

25-
String getType();
27+
PluginType getType();
2628
List<String> run();
2729
void serialize(XMLStreamWriter serializer) throws XMLStreamException;
2830
}

data-hub/src/main/java/com/marklogic/hub/collector/QueryCollector.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818
import java.util.List;
1919

20+
import com.marklogic.hub.plugin.PluginType;
21+
2022
public class QueryCollector extends ServerCollector {
2123

2224
public static final String MODULE = "/com.marklogic.hub/collectors/query.xqy";
2325

2426
public QueryCollector() {
25-
super("xquery", MODULE);
27+
super(PluginType.XQUERY, MODULE);
2628
}
2729

2830
@Override

data-hub/src/main/java/com/marklogic/hub/collector/ServerCollector.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
import com.marklogic.client.extensions.ResourceServices.ServiceResultIterator;
2828
import com.marklogic.client.io.JacksonDatabindHandle;
2929
import com.marklogic.client.util.RequestParameters;
30+
import com.marklogic.hub.plugin.PluginType;
3031

3132
public class ServerCollector extends AbstractCollector {
3233

3334
private DatabaseClient client = null;
3435
private String module;
3536

36-
public ServerCollector(String type, String module) {
37+
public ServerCollector(PluginType type, String module) {
3738
super(type);
3839
this.module = module;
3940
}
@@ -53,7 +54,7 @@ public String getModule() {
5354
@Override
5455
public void serialize(XMLStreamWriter serializer) throws XMLStreamException {
5556
serializer.writeStartElement("collector");
56-
serializer.writeAttribute("type", getType());
57+
serializer.writeAttribute("type", getType().toString());
5758
serializer.writeAttribute("module", this.module);
5859
serializer.writeEndElement();
5960

data-hub/src/main/java/com/marklogic/hub/flow/AbstractFlow.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.marklogic.hub.plugin.ContentPlugin;
3737
import com.marklogic.hub.plugin.HeadersPlugin;
3838
import com.marklogic.hub.plugin.Plugin;
39+
import com.marklogic.hub.plugin.PluginType;
3940
import com.marklogic.hub.plugin.TriplesPlugin;
4041
import com.marklogic.hub.plugin.ServerPlugin;
4142
import com.marklogic.hub.writer.DefaultWriter;
@@ -96,8 +97,8 @@ private void deserialize(Node xml) {
9697
this.domainName = node.getTextContent();
9798
break;
9899
case "collector":
99-
String colType = node.getAttributes().getNamedItem("type").getNodeValue();
100-
if (colType.equals("xquery") || colType.equals("sjs") || colType.equals("xslt")) {
100+
PluginType colType = PluginType.getPluginType(node.getAttributes().getNamedItem("type").getNodeValue());
101+
if (colType.equals(PluginType.XQUERY) || colType.equals(PluginType.JAVASCRIPT) || colType.equals(PluginType.XSLT)) {
101102
String module = node.getAttributes().getNamedItem("module").getNodeValue();
102103
Collector collector = null;
103104
if (module.equals(QueryCollector.MODULE)) {
@@ -115,13 +116,13 @@ private void deserialize(Node xml) {
115116
case "plugin":
116117
String pluginDest = null;
117118
String module = null;
118-
String pluginType = node.getAttributes().getNamedItem("type").getNodeValue();
119-
if (!pluginType.equals("null")) {
119+
PluginType pluginType = PluginType.getPluginType(node.getAttributes().getNamedItem("type").getNodeValue());
120+
if (!pluginType.equals(PluginType.NULL)) {
120121
pluginDest = node.getAttributes().getNamedItem("dest").getNodeValue();
121122
module = node.getAttributes().getNamedItem("module").getNodeValue();
122123
}
123124

124-
if (pluginType.equals("xquery") || pluginType.equals("sjs") || pluginType.equals("xslt")) {
125+
if (pluginType.equals(PluginType.XQUERY) || pluginType.equals(PluginType.JAVASCRIPT) || pluginType.equals(PluginType.XSLT)) {
125126
if (pluginDest.equals(ContentPlugin.MODULE)) {
126127
ContentPlugin t = new ContentPlugin();
127128
this.plugins.add(t);
@@ -139,14 +140,14 @@ else if (pluginDest.equals(TriplesPlugin.MODULE)) {
139140
this.plugins.add(t);
140141
}
141142
}
142-
else if (pluginType.equals("null")) {
143+
else if (pluginType.equals(PluginType.NULL)) {
143144
this.plugins.add(null);
144145
}
145146
break;
146147
case "writer":
147148
module = null;
148-
pluginType = node.getAttributes().getNamedItem("type").getNodeValue();
149-
if (pluginType.equals("xquery") || pluginType.equals("sjs") || pluginType.equals("xslt")) {
149+
pluginType = PluginType.getPluginType(node.getAttributes().getNamedItem("type").getNodeValue());
150+
if (pluginType.equals(PluginType.XQUERY) || pluginType.equals(PluginType.JAVASCRIPT) || pluginType.equals(PluginType.XSLT)) {
150151
module = node.getAttributes().getNamedItem("module").getNodeValue();
151152
Writer w = null;
152153
if (module.equals(DefaultWriter.MODULE)) {

data-hub/src/main/java/com/marklogic/hub/plugin/ContentPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class ContentPlugin extends ServerPlugin {
1919
public static final String MODULE = "/com.marklogic.hub/plugins/content.xqy";
2020

2121
public ContentPlugin() {
22-
super("xquery", MODULE, "content");
22+
super(PluginType.XQUERY, MODULE, "content");
2323
}
2424

2525
@Override

data-hub/src/main/java/com/marklogic/hub/plugin/HeadersPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class HeadersPlugin extends ServerPlugin {
1919
public static final String MODULE = "/com.marklogic.hub/plugins/header.xqy";
2020

2121
public HeadersPlugin() {
22-
super("xquery", MODULE, "header");
22+
super(PluginType.XQUERY, MODULE, "header");
2323
}
2424

2525
@Override

data-hub/src/main/java/com/marklogic/hub/plugin/Plugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import javax.xml.stream.XMLStreamWriter;
2020

2121
public interface Plugin {
22-
String getType();
22+
PluginType getType();
2323
String getDest();
2424
void run(String identifier);
2525
void serialize(XMLStreamWriter serializer) throws XMLStreamException;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.marklogic.hub.plugin;
2+
3+
public enum PluginType {
4+
5+
XQUERY("xquery"), JAVASCRIPT("javascript"), XSLT("xslt"), XML("xml"), JSON("json"), NULL("null");
6+
7+
private String type;
8+
PluginType(String type) {
9+
this.type = type;
10+
}
11+
12+
public static PluginType getPluginType(String type) {
13+
for (PluginType pluginType : PluginType.values()) {
14+
if (pluginType.toString().equals(type)) {
15+
return pluginType;
16+
}
17+
}
18+
return null;
19+
}
20+
21+
public String toString() {
22+
return type;
23+
}
24+
}

data-hub/src/main/java/com/marklogic/hub/plugin/ServerPlugin.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
import com.marklogic.client.util.RequestParameters;
2424

2525
public class ServerPlugin extends AbstractPlugin {
26-
private String type;
26+
private PluginType type;
2727
private String module;
2828
private String destination;
2929
private DatabaseClient client;
3030

31-
public ServerPlugin(String type, String module, String destination) {
31+
public ServerPlugin(PluginType type, String module, String destination) {
3232
this.type = type;
3333
this.module = module;
3434
this.destination = destination;
@@ -46,7 +46,7 @@ public String getDest() {
4646
}
4747

4848
@Override
49-
public String getType() {
49+
public PluginType getType() {
5050
return this.type;
5151
}
5252

@@ -60,7 +60,7 @@ public void setClient(DatabaseClient client) {
6060

6161
public void serialize(XMLStreamWriter serializer) throws XMLStreamException {
6262
serializer.writeStartElement("plugin");
63-
serializer.writeAttribute("type", this.type);
63+
serializer.writeAttribute("type", this.type.toString());
6464
serializer.writeAttribute("module", this.module);
6565
serializer.writeAttribute("dest", this.destination);
6666
serializer.writeEndElement();

0 commit comments

Comments
 (0)