SDL_Android/SmartDeviceLinkAndroidProxy - added the correct version of the proxy
[profile/ivi/smartdevicelink.git] / SDL_Android / SmartDeviceLinkProxyAndroid / src / com / smartdevicelink / proxy / RPCResponse.java
1 /**\r
2  * \r
3  */\r
4 package com.smartdevicelink.proxy;\r
5 \r
6 import java.util.Hashtable;\r
7 \r
8 import com.smartdevicelink.proxy.constants.Names;\r
9 import com.smartdevicelink.proxy.rpc.enums.Result;\r
10 import com.smartdevicelink.util.DebugTool;\r
11 \r
12 /**\r
13  * Result sent by SMARTDEVICELINK after an RPC is processed, consists of four parts: \r
14  * <ul>\r
15  * <li>\r
16  * CorrelationID:\r
17  * <ul>\r
18  * An integer value correlating the response to the corresponding request.\r
19  * </ul>\r
20  * </li> <li>Success:\r
21  * <ul>\r
22  * A Boolean indicating whether the original request was successfully processed.\r
23  * </ul>\r
24  * </li> <li>ResultCode:\r
25  * <ul>\r
26  * \r
27  * The result code provides additional information about a response returning a\r
28  * failed outcome.\r
29  * <br>\r
30  * \r
31  * Any response can have at least one, or possibly more, of the following result\r
32  * code values: SUCCESS, INVALID_DATA, OUT_OF_MEMORY, TOO_MANY_PENDING_REQUESTS,\r
33  * APPLICATION_NOT_REGISTERED, GENERIC_ERROR,REJECTED.\r
34  * <br>\r
35  * \r
36  * Any additional result codes for a given operation can be found in related\r
37  * RPCs\r
38  * <br>\r
39  * </ul>\r
40  * </li> <li>Info:\r
41  * <ul>\r
42  * A string of text representing additional information returned from SMARTDEVICELINK. This\r
43  * could be useful in debugging.\r
44  * </ul>\r
45  * </li>\r
46  * </ul>\r
47  */\r
48 public class RPCResponse extends RPCMessage {\r
49         /**\r
50         *<p>Constructs a newly allocated RPCResponse object using function name</p>\r
51         *@param functionName a string that indicates the function's name\r
52         */\r
53         public RPCResponse(String functionName) {\r
54                 super(functionName, "response");\r
55         }\r
56         /**\r
57      *<p>Constructs a newly allocated RPCResponse object indicated by the Hashtable parameter</p>\r
58      *@param hash The Hashtable to use\r
59      */   \r
60         public RPCResponse(Hashtable hash) {\r
61                 super(hash);\r
62         }\r
63         /**\r
64      *<p>Constructs a newly allocated RPCResponse object using a RPCMessage object</p>\r
65      *@param rpcMsg The {@linkplain RPCMessage} to use\r
66      */   \r
67         public RPCResponse(RPCMessage rpcMsg) {\r
68                 super(rpcMsg);\r
69         }\r
70 \r
71         /**\r
72          * <p>\r
73          * Returns correlationID the ID of the request\r
74          * </p>\r
75          * \r
76          * @return int  the ID of the request\r
77          */\r
78         public Integer getCorrelationID() {\r
79                 return (Integer)function.get(Names.correlationID);\r
80         }\r
81         \r
82         /**\r
83          * <p>\r
84          * Set the correlationID\r
85          * </p>\r
86          * \r
87          * @param correlationID\r
88          *            the ID of the response\r
89          */\r
90         public void setCorrelationID(Integer correlationID) {\r
91                 if (correlationID != null) {\r
92             function.put(Names.correlationID, correlationID );\r
93         } else if (parameters.contains(Names.correlationID)){\r
94                 function.remove(Names.correlationID);\r
95         }\r
96         }\r
97         /**\r
98          * <p>\r
99          * Returns Success whether the request is successfully processed\r
100          * </p>\r
101          * \r
102          * @return Boolean  the status of whether the request is successfully done\r
103          */\r
104         public Boolean getSuccess() {\r
105         return (Boolean) parameters.get( Names.success );\r
106     }\r
107         /**\r
108          * <p>\r
109          * Set the Success status\r
110          * </p>\r
111          * \r
112          * @param success\r
113          *             whether the request is successfully processed\r
114          */\r
115     public void setSuccess( Boolean success ) {\r
116         if (success != null) {\r
117             parameters.put(Names.success, success );\r
118         }\r
119     }\r
120         /**\r
121          * <p>\r
122          * Returns ResultCode additional information about a response returning a failed outcome\r
123          * </p>\r
124          * \r
125          * @return {@linkplain Result}  the status of whether the request is successfully done\r
126          */\r
127     public Result getResultCode() {\r
128         Object obj = parameters.get(Names.resultCode);\r
129         if (obj instanceof Result) {\r
130             return (Result) obj;\r
131         } else if (obj instanceof String) {\r
132             Result theCode = null;\r
133             try {\r
134                 theCode = Result.valueForString((String) obj);\r
135             } catch (Exception e) {\r
136                 DebugTool.logError("Failed to parse " + getClass().getSimpleName() + "." + Names.resultCode, e);\r
137             }\r
138             return theCode;\r
139         }\r
140         return null;\r
141     }\r
142         /**\r
143          * <p>\r
144          * Set the additional information about a response returning a failed outcome\r
145          * </p>\r
146          * \r
147          * @param resultCode\r
148          *             whether the request is successfully processed\r
149          */\r
150     public void setResultCode( Result resultCode ) {\r
151         if (resultCode != null) {\r
152             parameters.put(Names.resultCode, resultCode );\r
153         }\r
154     }\r
155         /**\r
156          * <p>\r
157          * Returns a string of text representing additional information returned from SMARTDEVICELINK\r
158          * </p>\r
159          * \r
160          * @return String  A string of text representing additional information returned from SMARTDEVICELINK\r
161          */\r
162     public String getInfo() {\r
163         return (String) parameters.get( Names.info );\r
164     }\r
165         /**\r
166          * <p>\r
167          * Set a string of text representing additional information returned from SMARTDEVICELINK\r
168          * </p>\r
169          * \r
170          * @param info\r
171          *             a string of text representing additional information returned from SMARTDEVICELINK\r
172          */\r
173     public void setInfo( String info ) {\r
174         if (info != null) {\r
175             parameters.put(Names.info, info );\r
176         }\r
177     }\r
178 }\r