File tree Expand file tree Collapse file tree 5 files changed +94
-3
lines changed
src/main/java/com/yocto/yoclib/jsonrpc Expand file tree Collapse file tree 5 files changed +94
-3
lines changed Original file line number Diff line number Diff line change 88 <version >1.0.0-SNAPSHOT</version >
99
1010 <properties >
11- <maven .compiler.source>18 </maven .compiler.source>
12- <maven .compiler.target>18 </maven .compiler.target>
11+ <maven .compiler.source>17 </maven .compiler.source>
12+ <maven .compiler.target>17 </maven .compiler.target>
1313 <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
1414 </properties >
1515
1616 <dependencies >
17+ <dependency >
18+ <groupId >org.json</groupId >
19+ <artifactId >json</artifactId >
20+ <version >20240303</version >
21+ </dependency >
1722 <dependency >
1823 <groupId >junit</groupId >
1924 <artifactId >junit</artifactId >
Original file line number Diff line number Diff line change 11package com .yocto .yoclib .jsonrpc ;
22
3- public class Message {
3+ import org .json .JSONObject ;
4+
5+ public abstract class Message {
6+
7+ private final JSONObject value ;
8+
9+ /**
10+ *
11+ * @param value The object value
12+ */
13+ protected Message (JSONObject value ){
14+ this .value = value ;
15+ }
16+
17+ /**
18+ *
19+ * @return The JSON-RPC version value
20+ */
21+ public String getJSONRPC (){
22+ return this .hasJSONRPC ()?this .value .getString ("jsonrpc" ):null ;
23+ }
24+
25+ /**
26+ * @return bool
27+ */
28+ public boolean hasJSONRPC (){
29+ return this .value .has ("jsonrpc" ) && this .value .get ("jsonrpc" )!=null ;
30+ }
31+
32+ /**
33+ *
34+ * @return True if message is a request, false if not.
35+ */
36+ public boolean isRequest (){
37+ return this .value .has ("method" ) || this .value .has ("params" );
38+ }
39+
40+ /**
41+ *
42+ * @return True if message is a response, false if not.
43+ */
44+ public boolean isResponse (){
45+ return this .value .has ("result" ) || this .value .has ("error" );
46+ }
47+
48+ /**
49+ *
50+ * @return True if message is version 2.0, false if not.
51+ */
52+ public boolean isVersion2 (){
53+ return "2.0" .equals (this .getJSONRPC ());
54+ }
55+
56+ /**
57+ *
58+ * @return The object value
59+ */
60+ public JSONObject toObject (){
61+ return this .value ;
62+ }
463
564}
Original file line number Diff line number Diff line change 11package com .yocto .yoclib .jsonrpc ;
22
3+ import org .json .JSONObject ;
4+
35public class NotificationMessage extends RequestMessage {
46
7+ /**
8+ * @param value The object value
9+ */
10+ protected NotificationMessage (JSONObject value ) {
11+ super (value );
12+ }
13+
514}
Original file line number Diff line number Diff line change 11package com .yocto .yoclib .jsonrpc ;
22
3+ import org .json .JSONObject ;
4+
35public class RequestMessage extends Message {
46
7+ /**
8+ * @param value The object value
9+ */
10+ protected RequestMessage (JSONObject value ) {
11+ super (value );
12+ }
13+
514}
Original file line number Diff line number Diff line change 11package com .yocto .yoclib .jsonrpc ;
22
3+ import org .json .JSONObject ;
4+
35public class ResponseMessage extends Message {
46
7+ /**
8+ * @param value The object value
9+ */
10+ protected ResponseMessage (JSONObject value ) {
11+ super (value );
12+ }
13+
514}
You can’t perform that action at this time.
0 commit comments