1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
21 package org.iotivity.service.server;
23 import org.iotivity.service.RcsResourceAttributes;
26 * This class provides methods to create the response for a received set
29 * @see RcsResourceObject
32 public final class RcsSetResponse extends RcsResponse {
34 * Options for handling a set request.
36 * This overrides {@link RcsResourceObject.SetRequestHandlerPolicy}.
39 public enum AcceptanceMethod {
41 * Follow {@link RcsResourceObject.SetRequestHandlerPolicy}.
46 * Accept the request attributes even if there is an unknown key or
52 * Ignore the request attributes.
57 private AcceptanceMethod mAcceptanceMethod = AcceptanceMethod.DEFAULT;
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
66 public static RcsSetResponse defaultAction() {
67 return new RcsSetResponse();
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
77 public static RcsSetResponse accept() {
78 return new RcsSetResponse()
79 .setAcceptanceMethod(AcceptanceMethod.ACCEPT);
83 * Creates a RcsSetResponse with {@link AcceptanceMethod#ACCEPT} and error
85 * The attributes of the {@link RcsResourceObject} will be set as the result
89 * error code to be set in response
92 public static RcsSetResponse accept(int errorCode) {
93 return new RcsSetResponse(errorCode)
94 .setAcceptanceMethod(AcceptanceMethod.ACCEPT);
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
104 public static RcsSetResponse ignore() {
105 return new RcsSetResponse()
106 .setAcceptanceMethod(AcceptanceMethod.IGNORE);
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.
115 * error code to be set in response
118 public static RcsSetResponse ignore(int errorCode) {
119 return new RcsSetResponse(errorCode)
120 .setAcceptanceMethod(AcceptanceMethod.IGNORE);
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.
129 * error code to be set in response
132 public static RcsSetResponse create(int errorCode) {
133 return new RcsSetResponse(errorCode);
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.
142 * attributes to be sent as the result
145 public static RcsSetResponse create(RcsResourceAttributes attributes) {
146 return new RcsSetResponse(attributes);
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.
155 * attributes to be sent as the result
157 * error code for response
160 public static RcsSetResponse create(RcsResourceAttributes attributes,
162 return new RcsSetResponse(attributes, errorCode);
166 * Returns the acceptance method.
169 public AcceptanceMethod getAcceptanceMethod() {
170 return mAcceptanceMethod;
174 * Sets the acceptance method.
179 * @return The reference to this RcsSetResponse
182 public RcsSetResponse setAcceptanceMethod(AcceptanceMethod method) {
183 mAcceptanceMethod = method;
187 private RcsSetResponse() {
191 private RcsSetResponse(int errorCode) {
195 private RcsSetResponse(RcsResourceAttributes attrs) {
199 private RcsSetResponse(RcsResourceAttributes attrs, int errorCode) {
200 super(attrs, errorCode);