Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / resource-encapsulation / android / service / src / main / java / org / iotivity / service / server / RcsSetResponse.java
1 /******************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20
21 package org.iotivity.service.server;
22
23 import org.iotivity.service.RcsResourceAttributes;
24
25 /**
26  * This class provides methods to create the response for a received set
27  * request.
28  *
29  * @see RcsResourceObject
30  * @see RcsSetResponse
31  */
32 public final class RcsSetResponse extends RcsResponse {
33     /**
34      * Options for handling a set request.
35      *
36      * This overrides {@link RcsResourceObject.SetRequestHandlerPolicy}.
37      *
38      */
39     public enum AcceptanceMethod {
40         /**
41          * Follow {@link RcsResourceObject.SetRequestHandlerPolicy}.
42          */
43         DEFAULT,
44
45         /**
46          * Accept the request attributes even if there is an unknown key or
47          * mismatched type.
48          */
49         ACCEPT,
50
51         /**
52          * Ignore the request attributes.
53          */
54         IGNORE
55     };
56
57     private AcceptanceMethod mAcceptanceMethod = AcceptanceMethod.DEFAULT;
58
59     /**
60      * Creates a default RcsSetResponse with {@link AcceptanceMethod#DEFAULT}.
61      * The response will have {@link #DEFAULT_ERROR_CODE} for the errorCode. The
62      * attributes of {@link RcsResourceObject} will be set as the result
63      * attributes.
64      *
65      */
66     public static RcsSetResponse defaultAction() {
67         return new RcsSetResponse();
68     }
69
70     /**
71      * Creates a default RcsSetResponse with {@link AcceptanceMethod#ACCEPT}
72      * The response will have {@link #DEFAULT_ERROR_CODE} for the errorCode. The
73      * attributes of {@link RcsResourceObject} will be set as the result
74      * attributes.
75      *
76      */
77     public static RcsSetResponse accept() {
78         return new RcsSetResponse()
79                 .setAcceptanceMethod(AcceptanceMethod.ACCEPT);
80     }
81
82     /**
83      * Creates a RcsSetResponse with {@link AcceptanceMethod#ACCEPT} and error
84      * code passed.
85      * The attributes of the {@link RcsResourceObject} will be set as the result
86      * attributes.
87      *
88      * @param errorCode
89      *            error code to be set in response
90      *
91      */
92     public static RcsSetResponse accept(int errorCode) {
93         return new RcsSetResponse(errorCode)
94                 .setAcceptanceMethod(AcceptanceMethod.ACCEPT);
95     }
96
97     /**
98      * Creates a default RcsSetResponse with {@link AcceptanceMethod#IGNORE}.
99      * The response will have {@link #DEFAULT_ERROR_CODE} for the errorCode. The
100      * attributes of {@link RcsResourceObject} will be set as the result
101      * attributes.
102      *
103      */
104     public static RcsSetResponse ignore() {
105         return new RcsSetResponse()
106                 .setAcceptanceMethod(AcceptanceMethod.IGNORE);
107     }
108
109     /**
110      * Creates a RcsSetResponse with {@link AcceptanceMethod#IGNORE} and error
111      * code passed. The attributes of the {@link RcsResourceObject} will be set
112      * as the result attributes.
113      *
114      * @param errorCode
115      *            error code to be set in response
116      *
117      */
118     public static RcsSetResponse ignore(int errorCode) {
119         return new RcsSetResponse(errorCode)
120                 .setAcceptanceMethod(AcceptanceMethod.IGNORE);
121     }
122
123     /**
124      * Creates a RcsSetResponse with error code passed and
125      * {@link AcceptanceMethod#DEFAULT}. The attributes of the
126      * {@link RcsResourceObject} will be set as the result attributes.
127      *
128      * @param errorCode
129      *            error code to be set in response
130      *
131      */
132     public static RcsSetResponse create(int errorCode) {
133         return new RcsSetResponse(errorCode);
134     }
135
136     /**
137      * Creates a RcsSetResponse with custom attributes and
138      * {@link AcceptanceMethod#DEFAULT}. This sends the passed attributes as the
139      * result attributes instead of one the {@link RcsResourceObject} holds.
140      *
141      * @param attributes
142      *            attributes to be sent as the result
143      *
144      */
145     public static RcsSetResponse create(RcsResourceAttributes attributes) {
146         return new RcsSetResponse(attributes);
147     }
148
149     /**
150      * Creates a RcsSetResponse with error code passed and
151      * {@link AcceptanceMethod#DEFAULT}. This sends the passed attributes as the
152      * result attributes instead of one the {@link RcsResourceObject} holds.
153      *
154      * @param attributes
155      *            attributes to be sent as the result
156      * @param errorCode
157      *            error code for response
158      *
159      */
160     public static RcsSetResponse create(RcsResourceAttributes attributes,
161             int errorCode) {
162         return new RcsSetResponse(attributes, errorCode);
163     }
164
165     /**
166      * Returns the acceptance method.
167      *
168      */
169     public AcceptanceMethod getAcceptanceMethod() {
170         return mAcceptanceMethod;
171     }
172
173     /**
174      * Sets the acceptance method.
175      *
176      * @param method
177      *            method to be set
178      *
179      * @return The reference to this RcsSetResponse
180      *
181      */
182     public RcsSetResponse setAcceptanceMethod(AcceptanceMethod method) {
183         mAcceptanceMethod = method;
184         return this;
185     }
186
187     private RcsSetResponse() {
188         super();
189     }
190
191     private RcsSetResponse(int errorCode) {
192         super(errorCode);
193     }
194
195     private RcsSetResponse(RcsResourceAttributes attrs) {
196         super(attrs);
197     }
198
199     private RcsSetResponse(RcsResourceAttributes attrs, int errorCode) {
200         super(attrs, errorCode);
201     }
202
203 }