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