001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.rest.annotation; 018 019import static org.apache.juneau.internal.ArrayUtils.*; 020 021import java.lang.annotation.*; 022import java.nio.charset.*; 023 024import org.apache.juneau.*; 025import org.apache.juneau.annotation.*; 026import org.apache.juneau.encoders.*; 027import org.apache.juneau.http.*; 028import org.apache.juneau.reflect.*; 029import org.apache.juneau.rest.*; 030import org.apache.juneau.rest.guard.*; 031import org.apache.juneau.rest.httppart.*; 032import org.apache.juneau.rest.matcher.*; 033import org.apache.juneau.svl.*; 034 035/** 036 * Utility classes and methods for the {@link RestDelete @RestDelete} annotation. 037 * 038 * <h5 class='section'>See Also:</h5><ul> 039 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestOpAnnotatedMethodBasics">@RestOp-Annotated Method Basics</a> 040 * </ul> 041 */ 042public class RestDeleteAnnotation { 043 044 //----------------------------------------------------------------------------------------------------------------- 045 // Static 046 //----------------------------------------------------------------------------------------------------------------- 047 048 /** Default value */ 049 public static final RestDelete DEFAULT = create().build(); 050 051 /** 052 * Instantiates a new builder for this class. 053 * 054 * @return A new builder object. 055 */ 056 public static Builder create() { 057 return new Builder(); 058 } 059 060 //----------------------------------------------------------------------------------------------------------------- 061 // Builder 062 //----------------------------------------------------------------------------------------------------------------- 063 064 /** 065 * Builder class. 066 * 067 * <h5 class='section'>See Also:</h5><ul> 068 * <li class='jm'>{@link org.apache.juneau.BeanContext.Builder#annotations(Annotation...)} 069 * </ul> 070 */ 071 @SuppressWarnings("unchecked") 072 public static class Builder extends TargetedAnnotationMBuilder<Builder> { 073 074 Class<? extends RestGuard>[] guards = new Class[0]; 075 Class<? extends RestMatcher>[] matchers = new Class[0]; 076 Class<? extends Encoder>[] encoders = new Class[0]; 077 OpSwagger swagger = OpSwaggerAnnotation.DEFAULT; 078 String clientVersion="", debug="", defaultAccept="", defaultCharset="", rolesDeclared="", roleGuard="", summary="", value=""; 079 String[] defaultRequestQueryData={}, defaultRequestAttributes={}, defaultRequestHeaders={}, defaultResponseHeaders={}, path={}; 080 081 /** 082 * Constructor. 083 */ 084 protected Builder() { 085 super(RestDelete.class); 086 } 087 088 /** 089 * Instantiates a new {@link RestDelete @RestDelete} object initialized with this builder. 090 * 091 * @return A new {@link RestDelete @RestDelete} object. 092 */ 093 public RestDelete build() { 094 return new Impl(this); 095 } 096 097 /** 098 * Sets the {@link RestDelete#clientVersion()} property on this annotation. 099 * 100 * @param value The new value for this property. 101 * @return This object. 102 */ 103 public Builder clientVersion(String value) { 104 this.clientVersion = value; 105 return this; 106 } 107 108 /** 109 * Sets the {@link RestDelete#debug()} property on this annotation. 110 * 111 * @param value The new value for this property. 112 * @return This object. 113 */ 114 public Builder debug(String value) { 115 this.debug = value; 116 return this; 117 } 118 119 /** 120 * Sets the {@link RestDelete#defaultAccept()} property on this annotation. 121 * 122 * @param value The new value for this property. 123 * @return This object. 124 */ 125 public Builder defaultAccept(String value) { 126 this.defaultAccept = value; 127 return this; 128 } 129 130 /** 131 * Sets the {@link RestDelete#defaultCharset()} property on this annotation. 132 * 133 * @param value The new value for this property. 134 * @return This object. 135 */ 136 public Builder defaultCharset(String value) { 137 this.defaultCharset = value; 138 return this; 139 } 140 141 /** 142 * Sets the {@link RestDelete#defaultRequestQueryData()} property on this annotation. 143 * 144 * @param value The new value for this property. 145 * @return This object. 146 */ 147 public Builder defaultRequestQueryData(String...value) { 148 this.defaultRequestQueryData = value; 149 return this; 150 } 151 152 /** 153 * Sets the {@link RestDelete#defaultRequestAttributes()} property on this annotation. 154 * 155 * @param value The new value for this property. 156 * @return This object. 157 */ 158 public Builder defaultRequestAttributes(String...value) { 159 this.defaultRequestAttributes = value; 160 return this; 161 } 162 163 /** 164 * Sets the {@link RestDelete#defaultRequestHeaders()} property on this annotation. 165 * 166 * @param value The new value for this property. 167 * @return This object. 168 */ 169 public Builder defaultRequestHeaders(String...value) { 170 this.defaultRequestHeaders = value; 171 return this; 172 } 173 174 /** 175 * Sets the {@link RestDelete#defaultResponseHeaders()} property on this annotation. 176 * 177 * @param value The new value for this property. 178 * @return This object. 179 */ 180 public Builder defaultResponseHeaders(String...value) { 181 this.defaultResponseHeaders = value; 182 return this; 183 } 184 185 /** 186 * Sets the {@link RestDelete#encoders()} property on this annotation. 187 * 188 * @param value The new value for this property. 189 * @return This object. 190 */ 191 @SafeVarargs 192 public final Builder encoders(Class<? extends Encoder>...value) { 193 this.encoders = value; 194 return this; 195 } 196 197 /** 198 * Sets the {@link RestDelete#guards()} property on this annotation. 199 * 200 * @param value The new value for this property. 201 * @return This object. 202 */ 203 @SafeVarargs 204 public final Builder guards(Class<? extends RestGuard>...value) { 205 this.guards = value; 206 return this; 207 } 208 209 /** 210 * Sets the {@link RestDelete#matchers()} property on this annotation. 211 * 212 * @param value The new value for this property. 213 * @return This object. 214 */ 215 @SafeVarargs 216 public final Builder matchers(Class<? extends RestMatcher>...value) { 217 this.matchers = value; 218 return this; 219 } 220 221 /** 222 * Sets the {@link RestDelete#path()} property on this annotation. 223 * 224 * @param value The new value for this property. 225 * @return This object. 226 */ 227 public Builder path(String...value) { 228 this.path = value; 229 return this; 230 } 231 232 /** 233 * Sets the {@link RestDelete#roleGuard()} property on this annotation. 234 * 235 * @param value The new value for this property. 236 * @return This object. 237 */ 238 public Builder roleGuard(String value) { 239 this.roleGuard = value; 240 return this; 241 } 242 243 /** 244 * Sets the {@link RestDelete#rolesDeclared()} property on this annotation. 245 * 246 * @param value The new value for this property. 247 * @return This object. 248 */ 249 public Builder rolesDeclared(String value) { 250 this.rolesDeclared = value; 251 return this; 252 } 253 254 /** 255 * Sets the {@link RestDelete#summary()} property on this annotation. 256 * 257 * @param value The new value for this property. 258 * @return This object. 259 */ 260 public Builder summary(String value) { 261 this.summary = value; 262 return this; 263 } 264 265 /** 266 * Sets the {@link RestDelete#swagger()} property on this annotation. 267 * 268 * @param value The new value for this property. 269 * @return This object. 270 */ 271 public Builder swagger(OpSwagger value) { 272 this.swagger = value; 273 return this; 274 } 275 276 /** 277 * Sets the {@link RestDelete#value()} property on this annotation. 278 * 279 * @param value The new value for this property. 280 * @return This object. 281 */ 282 public Builder value(String value) { 283 this.value = value; 284 return this; 285 } 286 287 } 288 289 //----------------------------------------------------------------------------------------------------------------- 290 // Implementation 291 //----------------------------------------------------------------------------------------------------------------- 292 293 private static class Impl extends TargetedAnnotationImpl implements RestDelete { 294 295 private final Class<? extends RestGuard>[] guards; 296 private final Class<? extends RestMatcher>[] matchers; 297 private final Class<? extends Encoder>[] encoders; 298 private final OpSwagger swagger; 299 private final String clientVersion, debug, defaultAccept, defaultCharset, rolesDeclared, roleGuard, summary, value; 300 private final String[] defaultRequestQueryData, defaultRequestAttributes, defaultRequestHeaders, defaultResponseHeaders, path; 301 302 Impl(Builder b) { 303 super(b); 304 this.clientVersion = b.clientVersion; 305 this.debug = b.debug; 306 this.defaultAccept = b.defaultAccept; 307 this.defaultCharset = b.defaultCharset; 308 this.defaultRequestQueryData = copyOf(b.defaultRequestQueryData); 309 this.defaultRequestAttributes = copyOf(b.defaultRequestAttributes); 310 this.defaultRequestHeaders = copyOf(b.defaultRequestHeaders); 311 this.defaultResponseHeaders = copyOf(b.defaultResponseHeaders); 312 this.encoders = copyOf(b.encoders); 313 this.guards = copyOf(b.guards); 314 this.matchers = copyOf(b.matchers); 315 this.path = copyOf(b.path); 316 this.roleGuard = b.roleGuard; 317 this.rolesDeclared = b.rolesDeclared; 318 this.summary = b.summary; 319 this.swagger = b.swagger; 320 this.value = b.value; 321 postConstruct(); 322 } 323 324 @Override /* RestDelete */ 325 public String clientVersion() { 326 return clientVersion; 327 } 328 329 @Override /* RestDelete */ 330 public String debug() { 331 return debug; 332 } 333 334 @Override /* RestDelete */ 335 public String defaultAccept() { 336 return defaultAccept; 337 } 338 339 @Override /* RestDelete */ 340 public String defaultCharset() { 341 return defaultCharset; 342 } 343 344 @Override /* RestDelete */ 345 public String[] defaultRequestQueryData() { 346 return defaultRequestQueryData; 347 } 348 349 @Override /* RestDelete */ 350 public String[] defaultRequestAttributes() { 351 return defaultRequestAttributes; 352 } 353 354 @Override /* RestDelete */ 355 public String[] defaultRequestHeaders() { 356 return defaultRequestHeaders; 357 } 358 359 @Override /* RestDelete */ 360 public String[] defaultResponseHeaders() { 361 return defaultResponseHeaders; 362 } 363 364 @Override /* RestDelete */ 365 public Class<? extends Encoder>[] encoders() { 366 return encoders; 367 } 368 369 @Override /* RestDelete */ 370 public Class<? extends RestGuard>[] guards() { 371 return guards; 372 } 373 374 @Override /* RestDelete */ 375 public Class<? extends RestMatcher>[] matchers() { 376 return matchers; 377 } 378 379 @Override /* RestDelete */ 380 public String[] path() { 381 return path; 382 } 383 384 @Override /* RestDelete */ 385 public String roleGuard() { 386 return roleGuard; 387 } 388 389 @Override /* RestDelete */ 390 public String rolesDeclared() { 391 return rolesDeclared; 392 } 393 394 @Override /* RestDelete */ 395 public String summary() { 396 return summary; 397 } 398 399 @Override /* RestDelete */ 400 public OpSwagger swagger() { 401 return swagger; 402 } 403 404 @Override /* RestDelete */ 405 public String value() { 406 return value; 407 } 408 } 409 410 //----------------------------------------------------------------------------------------------------------------- 411 // Appliers 412 //----------------------------------------------------------------------------------------------------------------- 413 414 /** 415 * Applies {@link RestDelete} annotations to a {@link org.apache.juneau.rest.RestOpContext.Builder}. 416 */ 417 public static class RestOpContextApply extends AnnotationApplier<RestDelete,RestOpContext.Builder> { 418 419 /** 420 * Constructor. 421 * 422 * @param vr The resolver for resolving values in annotations. 423 */ 424 public RestOpContextApply(VarResolverSession vr) { 425 super(RestDelete.class, RestOpContext.Builder.class, vr); 426 } 427 428 @Override 429 public void apply(AnnotationInfo<RestDelete> ai, RestOpContext.Builder b) { 430 RestDelete a = ai.inner(); 431 432 b.httpMethod("delete"); 433 434 classes(a.encoders()).ifPresent(x -> b.encoders().set(x)); 435 stream(a.defaultRequestHeaders()).map(HttpHeaders::stringHeader).forEach(x -> b.defaultRequestHeaders().setDefault(x)); 436 stream(a.defaultResponseHeaders()).map(HttpHeaders::stringHeader).forEach(x -> b.defaultResponseHeaders().setDefault(x)); 437 stream(a.defaultRequestAttributes()).map(BasicNamedAttribute::ofPair).forEach(x -> b.defaultRequestAttributes().add(x)); 438 stream(a.defaultRequestQueryData()).map(HttpParts::basicPart).forEach(x -> b.defaultRequestQueryData().setDefault(x)); 439 string(a.defaultAccept()).map(HttpHeaders::accept).ifPresent(x -> b.defaultRequestHeaders().setDefault(x)); 440 b.guards().append(a.guards()); 441 b.matchers().append(a.matchers()); 442 string(a.clientVersion()).ifPresent(x -> b.clientVersion(x)); 443 string(a.defaultCharset()).map(Charset::forName).ifPresent(x -> b.defaultCharset(x)); 444 stream(a.path()).forEach(x -> b.path(x)); 445 string(a.value()).ifPresent(x -> b.path(x)); 446 cdl(a.rolesDeclared()).forEach(x -> b.rolesDeclared(x)); 447 string(a.roleGuard()).ifPresent(x -> b.roleGuard(x)); 448 string(a.debug()).map(Enablement::fromString).ifPresent(x -> b.debug(x)); 449 } 450 } 451}