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