Skip to content

Commit e730cd8

Browse files
committed
Make properties private in JSON RPC classes
Accessors are now provided instead. Fixes #429 (cherry picked from commit 57d4fff)
1 parent ced9e7a commit e730cd8

File tree

5 files changed

+82
-23
lines changed

5 files changed

+82
-23
lines changed

src/main/java/com/rabbitmq/tools/jsonrpc/JsonRpcException.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ public class JsonRpcException extends Exception {
2727
/**
2828
* Usually the constant string, "JSONRPCError"
2929
*/
30-
public String name;
30+
private String name;
3131
/**
3232
* Error code
3333
*/
34-
public int code;
34+
private int code;
3535
/**
3636
* Error message
3737
*/
38-
public String message;
38+
private String message;
3939
/**
4040
* Error detail object - may not always be present or meaningful
4141
*/
42-
public Object error;
42+
private Object error;
4343

4444
public JsonRpcException() {
4545
// no work needed in default no-arg constructor
@@ -52,4 +52,21 @@ public JsonRpcException(String detailMessage, String name, int code, String mess
5252
this.message = message;
5353
this.error = error;
5454
}
55+
56+
public String getName() {
57+
return name;
58+
}
59+
60+
public int getCode() {
61+
return code;
62+
}
63+
64+
@Override
65+
public String getMessage() {
66+
return message;
67+
}
68+
69+
public Object getError() {
70+
return error;
71+
}
5572
}

src/main/java/com/rabbitmq/tools/jsonrpc/JsonRpcServer.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,11 @@ public class JsonRpcServer extends StringRpcServer {
5252
/**
5353
* Holds the JSON-RPC service description for this client.
5454
*/
55-
public ServiceDescription serviceDescription;
56-
/**
57-
* The interface this server implements.
58-
*/
59-
public Class<?> interfaceClass;
55+
private ServiceDescription serviceDescription;
6056
/**
6157
* The instance backing this server.
6258
*/
63-
public Object interfaceInstance;
59+
private Object interfaceInstance;
6460

6561
public JsonRpcServer(Channel channel,
6662
Class<?> interfaceClass,
@@ -119,7 +115,9 @@ public JsonRpcServer(Channel channel,
119115
}
120116

121117
private void init(Class<?> interfaceClass, Object interfaceInstance) {
122-
this.interfaceClass = interfaceClass;
118+
/**
119+
* The interface this server implements.
120+
*/
123121
this.interfaceInstance = interfaceInstance;
124122
this.serviceDescription = new ServiceDescription(interfaceClass);
125123
}

src/main/java/com/rabbitmq/tools/jsonrpc/ParameterDescription.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
*/
2727
public class ParameterDescription {
2828
/** The parameter name. */
29-
public String name;
29+
private String name;
3030
/**
3131
* The parameter type - one of "bit", "num", "str", "arr",
3232
* "obj", "any" or "nil".
3333
*/
34-
public String type;
34+
private String type;
3535

3636
public ParameterDescription() {
3737
// Nothing to do here.
@@ -57,4 +57,12 @@ public static String lookup(Class<?> c) {
5757
if (Collection.class.isAssignableFrom(c)) return "arr";
5858
return "any";
5959
}
60+
61+
public String getName() {
62+
return name;
63+
}
64+
65+
public String getType() {
66+
return type;
67+
}
6068
}

src/main/java/com/rabbitmq/tools/jsonrpc/ProcedureDescription.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
*/
2828
public class ProcedureDescription {
2929
/** Procedure name */
30-
public String name;
30+
private String name;
3131
/** Human-readable procedure summary */
32-
public String summary;
32+
private String summary;
3333
/** Human-readable instructions for how to get information on the procedure's operation */
34-
public String help;
34+
private String help;
3535
/** True if this procedure is idempotent, that is, can be accessed via HTTP GET */
36-
public boolean idempotent;
36+
private boolean idempotent;
3737

3838
/** Descriptions of parameters for this procedure */
3939
private ParameterDescription[] params;
@@ -139,4 +139,20 @@ public int arity() {
139139
public ParameterDescription[] getParams() {
140140
return params;
141141
}
142+
143+
public String getName() {
144+
return name;
145+
}
146+
147+
public String getSummary() {
148+
return summary;
149+
}
150+
151+
public String getHelp() {
152+
return help;
153+
}
154+
155+
public boolean isIdempotent() {
156+
return idempotent;
157+
}
142158
}

src/main/java/com/rabbitmq/tools/jsonrpc/ServiceDescription.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ public class ServiceDescription {
3030
public static final String JSON_RPC_VERSION = "1.1";
3131

3232
/** The service name */
33-
public String name;
33+
private String name;
3434
/** ID for the service */
35-
public String id;
35+
private String id;
3636
/** Version of the service */
37-
public String version;
37+
private String version;
3838
/** Human-readable summary for the service */
39-
public String summary;
39+
private String summary;
4040
/** Human-readable instructions for how to get information on the service's operation */
41-
public String help;
41+
private String help;
4242

4343
/** Map from procedure name to {@link ProcedureDescription} */
4444
private Map<String, ProcedureDescription> procedures;
@@ -75,7 +75,7 @@ public void setProcs(Collection<Map<String, Object>> p) {
7575

7676
/** Private API - used during initialization */
7777
private void addProcedure(ProcedureDescription proc) {
78-
procedures.put(proc.name + "/" + proc.arity(), proc);
78+
procedures.put(proc.getName() + "/" + proc.arity(), proc);
7979
}
8080

8181
/**
@@ -91,4 +91,24 @@ public ProcedureDescription getProcedure(String newname, int arity) {
9191
}
9292
return proc;
9393
}
94+
95+
public String getName() {
96+
return name;
97+
}
98+
99+
public String getId() {
100+
return id;
101+
}
102+
103+
public String getVersion() {
104+
return version;
105+
}
106+
107+
public String getSummary() {
108+
return summary;
109+
}
110+
111+
public String getHelp() {
112+
return help;
113+
}
94114
}

0 commit comments

Comments
 (0)