Imported Upstream version 1.1.1
[platform/upstream/iotivity.git] / android / android_api / base / src / main / java / org / iotivity / base / OcHeaderOption.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 import java.security.InvalidParameterException;
26
27 /**
28  * OcHeaderOption class allows to create instances which comprises optionId
29  * and optionData as members. These are used in setting Header options.
30  * After creating instances of OcHeaderOptions, use setHeaderOptions API
31  * (in OcResource) to set header Options.
32  * NOTE: optionId  is an integer value which MUST be within
33  * range of 2048 to 3000 inclusive of lower and upper bound
34  * except for a few options including If-Match with empty(num : 1),
35  * If-None-Match(num : 5), Location-Path(num : 8),
36  * Location-Query(num : 20) CoAP option.
37  * HeaderOption instance creation fails if above condition is not satisfied.
38  */
39 public class OcHeaderOption {
40
41     public static final int MIN_HEADER_OPTION_ID = 2048;
42     public static final int MAX_HEADER_OPTION_ID = 3000;
43     public static final int IF_MATCH_OPTION_ID = 1;
44     public static final int IF_NONE_MATCH_OPTION_ID = 5;
45     public static final int LOCATION_PATH_OPTION_ID = 8;
46     public static final int LOCATION_QUERY_OPTION_ID = 20;
47
48     private int mOptionId;
49     private String mOptionData;
50
51     public OcHeaderOption(int optionId, String optionData) {
52         if (!(optionId >= MIN_HEADER_OPTION_ID && optionId <= MAX_HEADER_OPTION_ID)
53                 && optionId != IF_MATCH_OPTION_ID
54                 && optionId != IF_NONE_MATCH_OPTION_ID
55                 && optionId != LOCATION_PATH_OPTION_ID
56                 && optionId != LOCATION_QUERY_OPTION_ID) {
57             throw new InvalidParameterException("Option ID range is invalid");
58         }
59
60         this.mOptionId = optionId;
61         this.mOptionData = optionData;
62     }
63
64     /**
65      * API to get Option ID
66      *
67      * @return option ID
68      */
69     public int getOptionId() {
70         return mOptionId;
71     }
72
73     /**
74      * API to get Option data
75      *
76      * @return option data
77      */
78     public String getOptionData() {
79         return mOptionData;
80     }
81 }