Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / android / android_api / base / src / main / java / org / iotivity / base / ErrorCode.java
1 /*\r
2  * //******************************************************************\r
3  * //\r
4  * // Copyright 2015 Intel Corporation.\r
5  * //\r
6  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
7  * //\r
8  * // Licensed under the Apache License, Version 2.0 (the "License");\r
9  * // you may not use this file except in compliance with the License.\r
10  * // You may obtain a copy of the License at\r
11  * //\r
12  * //      http://www.apache.org/licenses/LICENSE-2.0\r
13  * //\r
14  * // Unless required by applicable law or agreed to in writing, software\r
15  * // distributed under the License is distributed on an "AS IS" BASIS,\r
16  * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * // See the License for the specific language governing permissions and\r
18  * // limitations under the License.\r
19  * //\r
20  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
21  */\r
22 \r
23 package org.iotivity.base;\r
24 \r
25 public enum ErrorCode {\r
26     /* Success status code - START HERE */\r
27     OK("OK", ""),\r
28     RESOURCE_CREATED("RESOURCE_CREATED", ""),\r
29     RESOURCE_DELETED("RESOURCE_DELETED", ""),\r
30     CONTINUE("CONTINUE", ""),\r
31     /* Success status code - END HERE */\r
32         /* Error status code - START HERE */\r
33     INVALID_URI("INVALID_URI", ""),\r
34     INVALID_QUERY("INVALID_QUERY", ""),\r
35     INVALID_IP("INVALID_IP", ""),\r
36     INVALID_PORT("INVALID_PORT", ""),\r
37     INVALID_CALLBACK("INVALID_CALLBACK", ""),\r
38     INVALID_METHOD("INVALID_METHOD", ""),\r
39     INVALID_PARAM("INVALID_PARAM", ""),\r
40     INVALID_OBSERVE_PARAM("INVALID_OBSERVE_PARAM", ""),\r
41     NO_MEMORY("NO_MEMORY", ""),\r
42     COMM_ERROR("COMM_ERROR", ""),\r
43     NOT_IMPL("NOTIMPL", ""),\r
44     NO_RESOURCE("NO_RESOURCE", "Resource not found"),\r
45     RESOURCE_ERROR("RESOURCE_ERROR", "Not supported method or interface"),\r
46     SLOW_RESOURCE("SLOW_RESOURCE", ""),\r
47     NO_OBSERVERS("NO_OBSERVERS", "Resource has no registered observers"),\r
48     OBSERVER_NOT_FOUND("OBSERVER_NOT_FOUND", ""),\r
49     PRESENCE_STOPPED("PRESENCE_STOPPED", ""),\r
50     PRESENCE_TIMEOUT("PRESENCE_TIMEOUT", ""),\r
51     PRESENCE_DO_NOT_HANDLE("PRESENCE_DO_NOT_HANDLE", ""),\r
52     VIRTUAL_DO_NOT_HANDLE("VIRTUAL_DO_NOT_HANDLE", ""),\r
53     INVALID_OPTION("INVALID_OPTION", ""),\r
54     MALFORMED_RESPONSE("MALFORMED_RESPONSE", "Remote reply contained malformed data"),\r
55     PERSISTENT_BUFFER_REQUIRED("PERSISTENT_BUFFER_REQUIRED", ""),\r
56     INVALID_REQUEST_HANDLE("INVALID_REQUEST_HANDLE", ""),\r
57     INVALID_DEVICE_INFO("INVALID_DEVICE_INFO", ""),\r
58     ERROR("ERROR", "Generic error"),\r
59 \r
60     JNI_EXCEPTION("JNI_EXCEPTION", "Generic Java binder error"),\r
61     JNI_NO_NATIVE_OBJECT("JNI_NO_NATIVE_OBJECT", ""),\r
62     JNI_INVALID_VALUE("JNI_INVALID_VALUE", ""),\r
63 \r
64     INVALID_CLASS_CAST("INVALID_CLASS_CAST", ""),;\r
65 \r
66     private String error;\r
67     private String description;\r
68 \r
69     private ErrorCode(String error, String description) {\r
70         this.error = error;\r
71         this.description = description;\r
72     }\r
73 \r
74     public String getError() {\r
75         return error;\r
76     }\r
77 \r
78     public String getDescription() {\r
79         return description;\r
80     }\r
81 \r
82     public static ErrorCode get(String errorCode) {\r
83         for (ErrorCode eCode : ErrorCode.values()) {\r
84             if (eCode.getError().equals(errorCode)) {\r
85                 return eCode;\r
86             }\r
87         }\r
88         throw new IllegalArgumentException("Unexpected ErrorCode value");\r
89     }\r
90 \r
91     @Override\r
92     public String toString() {\r
93         return error + (description.isEmpty() ? "" : " : " + description);\r
94     }\r
95 }\r