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.server;
018
019import static org.apache.juneau.commons.utils.Shorts.*;
020
021import java.lang.annotation.*;
022
023import org.apache.juneau.commons.*;
024import org.apache.juneau.marshall.encoders.*;
025import org.apache.juneau.marshall.serializer.*;
026import org.apache.juneau.rest.server.converter.*;
027import org.apache.juneau.rest.server.guard.*;
028import org.apache.juneau.rest.server.matcher.*;
029
030/**
031 * Utility classes and methods for the {@link RestGet @RestGet} annotation.
032 *
033 * <h5 class='section'>See Also:</h5><ul>
034 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestOpAnnotatedMethods">@RestOp-Annotated Method</a>
035 * </ul>
036 */
037public class RestGetAnnotation {
038
039   /**
040    * Private constructor to prevent instantiation.
041    */
042   private RestGetAnnotation() {
043      // Utility class - prevent instantiation
044   }
045
046   /**
047    * Builder class.
048    *
049    * <h5 class='section'>See Also:</h5><ul>
050    *    <li class='jm'>{@link org.apache.juneau.marshall.MarshallingContext.Builder#annotations(Annotation...)}
051    * </ul>
052    */
053   @SuppressWarnings({
054      "unchecked" // Type erasure requires cast for Builder inheritance
055   })
056   public static class Builder extends AnnotationObject.Builder {
057
058      private String[] description = {};
059      private Class<? extends RestConverter>[] converters = new Class[0];
060      private Class<? extends RestGuard>[] guards = new Class[0];
061      private Class<? extends RestMatcher>[] matchers = new Class[0];
062      private Class<? extends Encoder>[] encoders = new Class[0];
063      private Class<? extends Serializer>[] serializers = new Class[0];
064      private OpSwagger swagger = OpSwaggerAnnotation.DEFAULT;
065      private String clientVersion = "";
066      private String defaultAccept = "";
067      private String defaultCharset = "";
068      private String observability = "";
069      private String asyncCompletionExecutor = "";
070      private String metricName = "";
071      private String metricTags = "";
072      private String problemDetails = "";
073      private String debugMarshalling = "";
074      private String rolesDeclared = "";
075      private String roleGuard = "";
076      private String summary = "";
077      private String value = "";
078      private String[] defaultRequestQueryData = {};
079      private String[] defaultRequestAttributes = {};
080      private String[] defaultRequestHeaders = {};
081      private String[] defaultResponseHeaders = {};
082      private String[] allowedParserOptions = {};
083      private String[] allowedSerializerOptions = {};
084      private String[] noInherit = {};
085      private String[] path = {};
086      private String[] produces = {};
087
088      /**
089       * Constructor.
090       */
091      protected Builder() {
092         super(RestGet.class);
093      }
094
095      /**
096       * Instantiates a new {@link RestGet @RestGet} object initialized with this builder.
097       *
098       * @return A new {@link RestGet @RestGet} object.
099       */
100      public RestGet build() {
101         return new Object(this);
102      }
103
104      /**
105       * Sets the description property on this annotation.
106       *
107       * @param value The new value for this property.
108       * @return This object.
109       */
110      public Builder description(String...value) {
111         description = value;
112         return this;
113      }
114
115      /**
116       * Sets the {@link RestGet#clientVersion()} property on this annotation.
117       *
118       * @param value The new value for this property.
119       * @return This object.
120       */
121      public Builder clientVersion(String value) {
122         clientVersion = value;
123         return this;
124      }
125
126      /**
127       * Sets the {@link RestGet#converters()} property on this annotation.
128       *
129       * @param value The new value for this property.
130       * @return This object.
131       */
132      @SafeVarargs
133      public final Builder converters(Class<? extends RestConverter>...value) {
134         converters = value;
135         return this;
136      }
137
138      /**
139       * Sets the {@link RestGet#defaultAccept()} property on this annotation.
140       *
141       * @param value The new value for this property.
142       * @return This object.
143       */
144      public Builder defaultAccept(String value) {
145         defaultAccept = value;
146         return this;
147      }
148
149      /**
150       * Sets the {@link RestGet#defaultCharset()} property on this annotation.
151       *
152       * @param value The new value for this property.
153       * @return This object.
154       */
155      public Builder defaultCharset(String value) {
156         defaultCharset = value;
157         return this;
158      }
159
160      /**
161       * Sets the {@link RestGet#defaultRequestAttributes()} property on this annotation.
162       *
163       * @param value The new value for this property.
164       * @return This object.
165       */
166      public Builder defaultRequestAttributes(String...value) {
167         defaultRequestAttributes = value;
168         return this;
169      }
170
171      /**
172       * Sets the {@link RestGet#defaultRequestHeaders()} property on this annotation.
173       *
174       * @param value The new value for this property.
175       * @return This object.
176       */
177      public Builder defaultRequestHeaders(String...value) {
178         defaultRequestHeaders = value;
179         return this;
180      }
181
182      /**
183       * Sets the {@link RestGet#defaultRequestQueryData()} property on this annotation.
184       *
185       * @param value The new value for this property.
186       * @return This object.
187       */
188      public Builder defaultRequestQueryData(String...value) {
189         defaultRequestQueryData = value;
190         return this;
191      }
192
193      /**
194       * Sets the {@link RestGet#defaultResponseHeaders()} property on this annotation.
195       *
196       * @param value The new value for this property.
197       * @return This object.
198       */
199      public Builder defaultResponseHeaders(String...value) {
200         defaultResponseHeaders = value;
201         return this;
202      }
203
204      /**
205       * Sets the {@link RestGet#encoders()} property on this annotation.
206       *
207       * @param value The new value for this property.
208       * @return This object.
209       */
210      @SafeVarargs
211      public final Builder encoders(Class<? extends Encoder>...value) {
212         encoders = value;
213         return this;
214      }
215
216      /**
217       * Sets the {@link RestGet#guards()} property on this annotation.
218       *
219       * @param value The new value for this property.
220       * @return This object.
221       */
222      @SafeVarargs
223      public final Builder guards(Class<? extends RestGuard>...value) {
224         guards = value;
225         return this;
226      }
227
228      /**
229       * Sets the {@link RestGet#matchers()} property on this annotation.
230       *
231       * @param value The new value for this property.
232       * @return This object.
233       */
234      @SafeVarargs
235      public final Builder matchers(Class<? extends RestMatcher>...value) {
236         matchers = value;
237         return this;
238      }
239
240      /**
241       * Sets the {@link RestGet#path()} property on this annotation.
242       *
243       * @param value The new value for this property.
244       * @return This object.
245       */
246      public Builder path(String...value) {
247         path = value;
248         return this;
249      }
250
251      /**
252       * Sets the {@link RestGet#problemDetails()} property on this annotation.
253       *
254       * @param value The new value for this property.
255       * @return This object.
256       */
257      public Builder problemDetails(String value) {
258         problemDetails = value;
259         return this;
260      }
261
262      /**
263       * Sets the {@link RestGet#debugMarshalling()} property on this annotation.
264       *
265       * @param value The new value for this property.
266       * @return This object.
267       */
268      public Builder debugMarshalling(String value) {
269         debugMarshalling = value;
270         return this;
271      }
272
273      /**
274       * Sets the {@link RestGet#observability()} property on this annotation.
275       *
276       * @param value The new value for this property.
277       * @return This object.
278       */
279      public Builder observability(String value) {
280         observability = value;
281         return this;
282      }
283
284      /**
285       * Sets the {@link RestGet#asyncCompletionExecutor()} property on this annotation.
286       *
287       * @param value The new value for this property.
288       * @return This object.
289       */
290      public Builder asyncCompletionExecutor(String value) {
291         asyncCompletionExecutor = value;
292         return this;
293      }
294
295      /**
296       * Sets the {@link RestGet#metricName()} property on this annotation.
297       *
298       * @param value The new value for this property.
299       * @return This object.
300       */
301      public Builder metricName(String value) {
302         metricName = value;
303         return this;
304      }
305
306      /**
307       * Sets the {@link RestGet#metricTags()} property on this annotation.
308       *
309       * @param value The new value for this property.
310       * @return This object.
311       */
312      public Builder metricTags(String value) {
313         metricTags = value;
314         return this;
315      }
316
317      /**
318       * Sets the {@link RestGet#produces()} property on this annotation.
319       *
320       * @param value The new value for this property.
321       * @return This object.
322       */
323      public Builder produces(String...value) {
324         produces = value;
325         return this;
326      }
327
328      /**
329       * Sets the {@link RestGet#allowedSerializerOptions()} property on this annotation.
330       *
331       * @param value The new value for this property.
332       * @return This object.
333       */
334      public Builder allowedSerializerOptions(String...value) {
335         allowedSerializerOptions = value;
336         return this;
337      }
338
339      /**
340       * Sets the {@link RestGet#allowedParserOptions()} property on this annotation.
341       *
342       * @param value The new value for this property.
343       * @return This object.
344       */
345      public Builder allowedParserOptions(String...value) {
346         allowedParserOptions = value;
347         return this;
348      }
349
350      /**
351       * Sets the {@link RestGet#noInherit()} property on this annotation.
352       *
353       * @param value The new value for this property.
354       * @return This object.
355       */
356      public Builder noInherit(String...value) {
357         noInherit = value;
358         return this;
359      }
360
361      /**
362       * Sets the {@link RestGet#roleGuard()} property on this annotation.
363       *
364       * @param value The new value for this property.
365       * @return This object.
366       */
367      public Builder roleGuard(String value) {
368         roleGuard = value;
369         return this;
370      }
371
372      /**
373       * Sets the {@link RestGet#rolesDeclared()} property on this annotation.
374       *
375       * @param value The new value for this property.
376       * @return This object.
377       */
378      public Builder rolesDeclared(String value) {
379         rolesDeclared = value;
380         return this;
381      }
382
383      /**
384       * Sets the {@link RestGet#serializers()} property on this annotation.
385       *
386       * @param value The new value for this property.
387       * @return This object.
388       */
389      @SafeVarargs
390      public final Builder serializers(Class<? extends Serializer>...value) {
391         serializers = value;
392         return this;
393      }
394
395      /**
396       * Sets the {@link RestGet#summary()} property on this annotation.
397       *
398       * @param value The new value for this property.
399       * @return This object.
400       */
401      public Builder summary(String value) {
402         summary = value;
403         return this;
404      }
405
406      /**
407       * Sets the {@link RestGet#swagger()} property on this annotation.
408       *
409       * @param value The new value for this property.
410       * @return This object.
411       */
412      public Builder swagger(OpSwagger value) {
413         swagger = value;
414         return this;
415      }
416
417      /**
418       * Sets the {@link RestGet#value()} property on this annotation.
419       *
420       * @param value The new value for this property.
421       * @return This object.
422       */
423      public Builder value(String value) {
424         this.value = value;
425         return this;
426      }
427   }
428
429   @SuppressWarnings({
430      "java:S2160" // equals() inherited from AnnotationObject compares all annotation interface methods; subclass fields are accessed via those methods
431   })
432   private static class Object extends AnnotationObject implements RestGet {
433
434      private final String[] description;
435      private final Class<? extends RestConverter>[] converters;
436      private final Class<? extends RestGuard>[] guards;
437      private final Class<? extends RestMatcher>[] matchers;
438      private final Class<? extends Encoder>[] encoders;
439      private final Class<? extends Serializer>[] serializers;
440      private final OpSwagger swagger;
441      private final String clientVersion;
442      private final String defaultAccept;
443      private final String defaultCharset;
444      private final String observability;
445      private final String asyncCompletionExecutor;
446      private final String metricName;
447      private final String metricTags;
448      private final String problemDetails;
449      private final String debugMarshalling;
450      private final String rolesDeclared;
451      private final String roleGuard;
452      private final String summary;
453      private final String value;
454      private final String[] defaultRequestQueryData;
455      private final String[] defaultRequestAttributes;
456      private final String[] defaultRequestHeaders;
457      private final String[] defaultResponseHeaders;
458      private final String[] allowedParserOptions;
459      private final String[] allowedSerializerOptions;
460      private final String[] noInherit;
461      private final String[] path;
462      private final String[] produces;
463
464      Object(RestGetAnnotation.Builder b) {
465         super(b);
466         description = cp(b.description);
467         clientVersion = b.clientVersion;
468         converters = cp(b.converters);
469         defaultAccept = b.defaultAccept;
470         defaultCharset = b.defaultCharset;
471         defaultRequestQueryData = cp(b.defaultRequestQueryData);
472         defaultRequestAttributes = cp(b.defaultRequestAttributes);
473         defaultRequestHeaders = cp(b.defaultRequestHeaders);
474         defaultResponseHeaders = cp(b.defaultResponseHeaders);
475         encoders = cp(b.encoders);
476         guards = cp(b.guards);
477         matchers = cp(b.matchers);
478         allowedParserOptions = cp(b.allowedParserOptions);
479         allowedSerializerOptions = cp(b.allowedSerializerOptions);
480         noInherit = cp(b.noInherit);
481         path = cp(b.path);
482         observability = b.observability;
483         asyncCompletionExecutor = b.asyncCompletionExecutor;
484         metricName = b.metricName;
485         metricTags = b.metricTags;
486         problemDetails = b.problemDetails;
487         debugMarshalling = b.debugMarshalling;
488         produces = cp(b.produces);
489         roleGuard = b.roleGuard;
490         rolesDeclared = b.rolesDeclared;
491         serializers = cp(b.serializers);
492         summary = b.summary;
493         swagger = b.swagger;
494         value = b.value;
495      }
496
497      @Override /* Overridden from RestGet */
498      public String clientVersion() {
499         return clientVersion;
500      }
501
502      @Override /* Overridden from RestGet */
503      public Class<? extends RestConverter>[] converters() {
504         return converters;
505      }
506
507      @Override /* Overridden from RestGet */
508      public String defaultAccept() {
509         return defaultAccept;
510      }
511
512      @Override /* Overridden from RestGet */
513      public String defaultCharset() {
514         return defaultCharset;
515      }
516
517      @Override /* Overridden from RestGet */
518      public String[] defaultRequestAttributes() {
519         return defaultRequestAttributes;
520      }
521
522      @Override /* Overridden from RestGet */
523      public String[] defaultRequestHeaders() {
524         return defaultRequestHeaders;
525      }
526
527      @Override /* Overridden from RestGet */
528      public String[] defaultRequestQueryData() {
529         return defaultRequestQueryData;
530      }
531
532      @Override /* Overridden from RestGet */
533      public String[] defaultResponseHeaders() {
534         return defaultResponseHeaders;
535      }
536
537      @Override /* Overridden from RestGet */
538      public Class<? extends Encoder>[] encoders() {
539         return encoders;
540      }
541
542      @Override /* Overridden from RestGet */
543      public Class<? extends RestGuard>[] guards() {
544         return guards;
545      }
546
547      @Override /* Overridden from RestGet */
548      public Class<? extends RestMatcher>[] matchers() {
549         return matchers;
550      }
551
552      @Override /* Overridden from RestGet */
553      public String[] allowedParserOptions() {
554         return allowedParserOptions;
555      }
556
557      @Override /* Overridden from RestGet */
558      public String[] allowedSerializerOptions() {
559         return allowedSerializerOptions;
560      }
561
562      @Override /* Overridden from RestGet */
563      public String[] noInherit() {
564         return noInherit;
565      }
566
567      @Override /* Overridden from RestGet */
568      public String[] path() {
569         return path;
570      }
571
572      @Override /* Overridden from RestGet */
573      public String observability() {
574         return observability;
575      }
576
577      @Override /* Overridden from RestGet */
578      public String asyncCompletionExecutor() {
579         return asyncCompletionExecutor;
580      }
581
582      @Override /* Overridden from RestGet */
583      public String metricName() {
584         return metricName;
585      }
586
587      @Override /* Overridden from RestGet */
588      public String metricTags() {
589         return metricTags;
590      }
591
592      @Override /* Overridden from RestGet */
593      public String problemDetails() {
594         return problemDetails;
595      }
596
597      @Override /* Overridden from RestGet */
598      public String debugMarshalling() {
599         return debugMarshalling;
600      }
601
602      @Override /* Overridden from RestGet */
603      public String[] produces() {
604         return produces;
605      }
606
607      @Override /* Overridden from RestGet */
608      public String roleGuard() {
609         return roleGuard;
610      }
611
612      @Override /* Overridden from RestGet */
613      public String rolesDeclared() {
614         return rolesDeclared;
615      }
616
617      @Override /* Overridden from RestGet */
618      public Class<? extends Serializer>[] serializers() {
619         return serializers;
620      }
621
622      @Override /* Overridden from RestGet */
623      public String summary() {
624         return summary;
625      }
626
627      @Override /* Overridden from RestGet */
628      public OpSwagger swagger() {
629         return swagger;
630      }
631
632      @Override /* Overridden from RestGet */
633      public String value() {
634         return value;
635      }
636
637      @Override /* Overridden from annotation */
638      public String[] description() {
639         return description;
640      }
641   }
642
643   /** Default value */
644   public static final RestGet DEFAULT = create().build();
645
646   /**
647    * Instantiates a new builder for this class.
648    *
649    * @return A new builder object.
650    */
651   public static Builder create() {
652      return new Builder();
653   }
654}