-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,64 @@ | ||
package com.yocto.yoclib.jsonrpc; | ||
|
||
public class Message{ | ||
import org.json.JSONObject; | ||
|
||
public abstract class Message{ | ||
|
||
private final JSONObject value; | ||
|
||
/** | ||
* | ||
* @param value The object value | ||
*/ | ||
protected Message(JSONObject value){ | ||
this.value = value; | ||
} | ||
|
||
/** | ||
* | ||
* @return The JSON-RPC version value | ||
*/ | ||
public String getJSONRPC(){ | ||
return this.hasJSONRPC()?this.value.getString("jsonrpc"):null; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public boolean hasJSONRPC(){ | ||
return this.value.has("jsonrpc") && this.value.get("jsonrpc")!=null; | ||
} | ||
|
||
/** | ||
* | ||
* @return True if message is a request, false if not. | ||
*/ | ||
public boolean isRequest(){ | ||
return this.value.has("method") || this.value.has("params"); | ||
} | ||
|
||
/** | ||
* | ||
* @return True if message is a response, false if not. | ||
*/ | ||
public boolean isResponse(){ | ||
return this.value.has("result") || this.value.has("error"); | ||
} | ||
|
||
/** | ||
* | ||
* @return True if message is version 2.0, false if not. | ||
*/ | ||
public boolean isVersion2(){ | ||
return "2.0".equals(this.getJSONRPC()); | ||
} | ||
|
||
/** | ||
* | ||
* @return The object value | ||
*/ | ||
public JSONObject toObject(){ | ||
return this.value; | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/yocto/yoclib/jsonrpc/NotificationMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
package com.yocto.yoclib.jsonrpc; | ||
|
||
import org.json.JSONObject; | ||
|
||
public class NotificationMessage extends RequestMessage{ | ||
|
||
/** | ||
* @param value The object value | ||
*/ | ||
protected NotificationMessage(JSONObject value) { | ||
super(value); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
package com.yocto.yoclib.jsonrpc; | ||
|
||
import org.json.JSONObject; | ||
|
||
public class RequestMessage extends Message{ | ||
|
||
/** | ||
* @param value The object value | ||
*/ | ||
protected RequestMessage(JSONObject value) { | ||
super(value); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
package com.yocto.yoclib.jsonrpc; | ||
|
||
import org.json.JSONObject; | ||
|
||
public class ResponseMessage extends Message{ | ||
|
||
/** | ||
* @param value The object value | ||
*/ | ||
protected ResponseMessage(JSONObject value) { | ||
super(value); | ||
} | ||
|
||
} |