1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.mina.coap; 21 22 /** 23 * Extract of the CoAP RFC : 24 * 25 * <pre> 26 * | 1 | GET | [RFCXXXX] | 27 * | 2 | POST | [RFCXXXX] | 28 * | 3 | PUT | [RFCXXXX] | 29 * | 4 | DELETE | [RFCXXXX] | 30 * 31 * | 65 | 2.01 Created | [RFCXXXX] | 32 * | 66 | 2.02 Deleted | [RFCXXXX] | 33 * | 67 | 2.03 Valid | [RFCXXXX] | 34 * | 68 | 2.04 Changed | [RFCXXXX] | 35 * | 69 | 2.05 Content | [RFCXXXX] | 36 * | 128 | 4.00 Bad Request | [RFCXXXX] | 37 * | 129 | 4.01 Unauthorized | [RFCXXXX] | 38 * | 130 | 4.02 Bad Option | [RFCXXXX] | 39 * | 131 | 4.03 Forbidden | [RFCXXXX] | 40 * | 132 | 4.04 Not Found | [RFCXXXX] | 41 * | 133 | 4.05 Method Not Allowed | [RFCXXXX] | 42 * | 134 | 4.06 Not Acceptable | [RFCXXXX] | 43 * | 140 | 4.12 Precondition Failed | [RFCXXXX] | 44 * | 141 | 4.13 Request Entity Too Large | [RFCXXXX] | 45 * | 143 | 4.15 Unsupported Content-Format | [RFCXXXX] | 46 * | 160 | 5.00 Internal Server Error | [RFCXXXX] | 47 * | 161 | 5.01 Not Implemented | [RFCXXXX] | 48 * | 162 | 5.02 Bad Gateway | [RFCXXXX] | 49 * | 163 | 5.03 Service Unavailable | [RFCXXXX] | 50 * | 164 | 5.04 Gateway Timeout | [RFCXXXX] | 51 * | 165 | 5.05 Proxying Not Supported | [RFCXXXX] | 52 * </pre> 53 * 54 * @author <a href="http://mina.apache.org">Apache MINA Project</a> 55 */ 56 public enum CoapCode { 57 GET("GET", 1), POST("POST", 2), PUT("PUT", 3), DELETE("DELETE", 4), CREATED("2.01", 65), DELETED("2.02", 66), 58 VALID("2.03", 67), CHANGED("2.04", 68), CONTENT("2.05", 69), BAD_REQUEST("4.00", 128), UNAUTHORIZED("4.01", 129), 59 BAD_OPTION("4.02", 130), FORBIDDEN("4.03", 131), NOT_FOUND("4.04", 132), METHOD_NOT_ALLOWED("4.05", 133), 60 NOT_ACCEPTABLE("4.06", 134), PRECONDITION_FAILED("4.12", 140), REQUEST_ENTITY_TOO_LARGE("4.13", 141), 61 UNSUPPORTED_CONTENT_FORMAT("4.15", 143), INTERNAL_SERVER_ERROR("5.00", 160), NOT_IMPLEMENTED("5.01", 161), 62 BAD_GATEWAY("5.02", 162), SERVICE_UNAVAILABLE("5.03", 163), GATEWAY_TIMEOUT("5.04", 164), PROXYING_NOT_SUPPORTED( 63 "5.05", 165) 64 65 ; 66 67 private final String text; 68 private final int code; 69 70 private CoapCode(String text, int code) { 71 this.text = text; 72 this.code = code; 73 } 74 75 public String getText() { 76 return text; 77 } 78 79 public int getCode() { 80 return code; 81 } 82 83 /** 84 * Find the {@link CoapCode} for the given value code (<code>null</code> if not found) 85 */ 86 public static CoapCode fromCode(int code) { 87 for (CoapCode t : CoapCode.values()) { 88 if (t.getCode() == code) { 89 return t; 90 } 91 } 92 return null; 93 } 94 }