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