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
64 * @return the created default RcsSetResponse
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
76 * @return the created default RcsSetResponse
78 public static RcsSetResponse accept() {
79 return new RcsSetResponse()
80 .setAcceptanceMethod(AcceptanceMethod.ACCEPT);
84 * Creates a RcsSetResponse with {@link AcceptanceMethod#ACCEPT} and error
86 * The attributes of the {@link RcsResourceObject} will be set as the result
90 * error code to be set in response
91 * @return the created RcsSetResponse
93 public static RcsSetResponse accept(int errorCode) {
94 return new RcsSetResponse(errorCode)
95 .setAcceptanceMethod(AcceptanceMethod.ACCEPT);
99 * Creates a default RcsSetResponse with {@link AcceptanceMethod#IGNORE}.
100 * The response will have {@link #DEFAULT_ERROR_CODE} for the errorCode. The
101 * attributes of {@link RcsResourceObject} will be set as the result
104 * @return the created default RcsSetResponse
106 public static RcsSetResponse ignore() {
107 return new RcsSetResponse()
108 .setAcceptanceMethod(AcceptanceMethod.IGNORE);
112 * Creates a RcsSetResponse with {@link AcceptanceMethod#IGNORE} and error
113 * code passed. The attributes of the {@link RcsResourceObject} will be set
114 * as the result attributes.
117 * error code to be set in response
118 * @return the created RcsSetResponse
120 public static RcsSetResponse ignore(int errorCode) {
121 return new RcsSetResponse(errorCode)
122 .setAcceptanceMethod(AcceptanceMethod.IGNORE);
126 * Creates a RcsSetResponse with error code passed and
127 * {@link AcceptanceMethod#DEFAULT}. The attributes of the
128 * {@link RcsResourceObject} will be set as the result attributes.
131 * error code to be set in response
132 * @return the created RcsSetResponse
134 public static RcsSetResponse create(int errorCode) {
135 return new RcsSetResponse(errorCode);
139 * Creates a RcsSetResponse with custom attributes and
140 * {@link AcceptanceMethod#DEFAULT}. This sends the passed attributes as the
141 * result attributes instead of one the {@link RcsResourceObject} holds.
144 * attributes to be sent as the result
145 * @return the created RcsSetResponse
147 public static RcsSetResponse create(RcsResourceAttributes attributes) {
148 return new RcsSetResponse(attributes);
152 * Creates a RcsSetResponse with error code passed and
153 * {@link AcceptanceMethod#DEFAULT}. This sends the passed attributes as the
154 * result attributes instead of one the {@link RcsResourceObject} holds.
157 * attributes to be sent as the result
159 * error code for response
160 * @return the created RcsSetResponse
162 public static RcsSetResponse create(RcsResourceAttributes attributes,
164 return new RcsSetResponse(attributes, errorCode);
168 * Get the acceptance method.
169 * @return the acceptance method
171 public AcceptanceMethod getAcceptanceMethod() {
172 return mAcceptanceMethod;
176 * Sets the acceptance method.
181 * @return The reference to this RcsSetResponse
184 public RcsSetResponse setAcceptanceMethod(AcceptanceMethod method) {
185 mAcceptanceMethod = method;
189 private RcsSetResponse() {
193 private RcsSetResponse(int errorCode) {
197 private RcsSetResponse(RcsResourceAttributes attrs) {
201 private RcsSetResponse(RcsResourceAttributes attrs, int errorCode) {
202 super(attrs, errorCode);