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.cp.*;
022import org.apache.juneau.encoders.*;
023import org.apache.juneau.http.HttpHeaders;
024import org.apache.juneau.httppart.*;
025import org.apache.juneau.reflect.*;
026import org.apache.juneau.rest.*;
027import org.apache.juneau.rest.arg.*;
028import org.apache.juneau.rest.converter.*;
029import org.apache.juneau.rest.debug.*;
030import org.apache.juneau.rest.guard.*;
031import org.apache.juneau.rest.httppart.*;
032import org.apache.juneau.rest.logger.*;
033import org.apache.juneau.rest.processor.*;
034import org.apache.juneau.rest.staticfile.*;
035import org.apache.juneau.rest.swagger.*;
036import org.apache.juneau.serializer.*;
037import org.apache.juneau.svl.*;
038
039/**
040 * Utility classes and methods for the {@link Rest @Rest} annotation.
041 *
042 * <h5 class='section'>See Also:</h5><ul>
043 *    <li class='link'><a class="doclink" href="../../../../../index.html#jrs.AnnotatedClasses">@Rest-Annotated Classes</a>
044 * </ul>
045 */
046public class RestAnnotation {
047
048   //-----------------------------------------------------------------------------------------------------------------
049   // Static
050   //-----------------------------------------------------------------------------------------------------------------
051
052   /** Default value */
053   public static final Rest DEFAULT = create().build();
054
055   /**
056    * Instantiates a new builder for this class.
057    *
058    * @return A new builder object.
059    */
060   public static Builder create() {
061      return new Builder();
062   }
063
064   /**
065    * Instantiates a new builder for this class.
066    *
067    * @param on The targets this annotation applies to.
068    * @return A new builder object.
069    */
070   public static Builder create(Class<?>...on) {
071      return create().on(on);
072   }
073
074   /**
075    * Instantiates a new builder for this class.
076    *
077    * @param on The targets this annotation applies to.
078    * @return A new builder object.
079    */
080   public static Builder create(String...on) {
081      return create().on(on);
082   }
083
084   //-----------------------------------------------------------------------------------------------------------------
085   // Builder
086   //-----------------------------------------------------------------------------------------------------------------
087
088   /**
089    * Builder class.
090    *
091    * <h5 class='section'>See Also:</h5><ul>
092    *    <li class='jm'>{@link org.apache.juneau.BeanContext.Builder#annotations(Annotation...)}
093    * </ul>
094    */
095   @SuppressWarnings("unchecked")
096   public static class Builder extends TargetedAnnotationTBuilder {
097
098      Class<? extends Encoder>[] encoders = new Class[0];
099      Class<? extends HttpPartParser> partParser = HttpPartParser.Void.class;
100      Class<? extends HttpPartSerializer> partSerializer = HttpPartSerializer.Void.class;
101      Class<? extends StaticFiles> staticFiles = StaticFiles.Void.class;
102      Class<? extends ResponseProcessor>[] responseProcessors = new Class[0];
103      Class<? extends CallLogger> callLogger = CallLogger.Void.class;
104      Class<? extends RestConverter>[] converters = new Class[0];
105      Class<? extends RestGuard>[] guards = new Class[0];
106      Class<? extends SwaggerProvider> swaggerProvider = SwaggerProvider.Void.class;
107      Class<? extends RestOpArg>[] restOpArgs = new Class[0];
108      Class<? extends BeanStore> beanStore = BeanStore.Void.class;
109      Class<? extends RestChildren> restChildrenClass = RestChildren.Void.class;
110      Class<? extends RestOperations> restOperationsClass = RestOperations.Void.class;
111      Class<? extends DebugEnablement> debugEnablement = DebugEnablement.Void.class;
112      Class<? extends Serializer>[] serializers = new Class[0];
113      Class<?>[] children={}, parsers={};
114      Swagger swagger = SwaggerAnnotation.DEFAULT;
115      String disableContentParam="", allowedHeaderParams="", allowedMethodHeaders="", allowedMethodParams="", clientVersionHeader="", config="", debug="", debugOn="", defaultAccept="", defaultCharset="", defaultContentType="", maxInput="", messages="", path="", renderResponseStackTraces="", roleGuard="", rolesDeclared="", siteName="", uriAuthority="", uriContext="", uriRelativity="", uriResolution="";
116      String[] consumes={}, defaultRequestAttributes={}, defaultRequestHeaders={}, defaultResponseHeaders={}, description={}, produces={}, title={};
117
118      /**
119       * Constructor.
120       */
121      protected Builder() {
122         super(Rest.class);
123      }
124
125      /**
126       * Instantiates a new {@link Rest @Rest} object initialized with this builder.
127       *
128       * @return A new {@link Rest @Rest} object.
129       */
130      public Rest build() {
131         return new Impl(this);
132      }
133
134      /**
135       * Sets the {@link Rest#disableContentParam()} property on this annotation.
136       *
137       * @param value The new value for this property.
138       * @return This object.
139       */
140      public Builder disableContentParam(String value) {
141         this.disableContentParam = value;
142         return this;
143      }
144
145      /**
146       * Sets the {@link Rest#allowedHeaderParams()} property on this annotation.
147       *
148       * @param value The new value for this property.
149       * @return This object.
150       */
151      public Builder allowedHeaderParams(String value) {
152         this.allowedHeaderParams = value;
153         return this;
154      }
155
156      /**
157       * Sets the {@link Rest#allowedMethodHeaders()} property on this annotation.
158       *
159       * @param value The new value for this property.
160       * @return This object.
161       */
162      public Builder allowedMethodHeaders(String value) {
163         this.allowedMethodHeaders = value;
164         return this;
165      }
166
167      /**
168       * Sets the {@link Rest#allowedMethodParams()} property on this annotation.
169       *
170       * @param value The new value for this property.
171       * @return This object.
172       */
173      public Builder allowedMethodParams(String value) {
174         this.allowedMethodParams = value;
175         return this;
176      }
177
178      /**
179       * Sets the {@link Rest#beanStore()} property on this annotation.
180       *
181       * @param value The new value for this property.
182       * @return This object.
183       */
184      public Builder beanStore(Class<? extends BeanStore> value) {
185         this.beanStore = value;
186         return this;
187      }
188
189      /**
190       * Sets the {@link Rest#callLogger()} property on this annotation.
191       *
192       * @param value The new value for this property.
193       * @return This object.
194       */
195      public Builder callLogger(Class<? extends CallLogger> value) {
196         this.callLogger = value;
197         return this;
198      }
199
200      /**
201       * Sets the {@link Rest#children()} property on this annotation.
202       *
203       * @param value The new value for this property.
204       * @return This object.
205       */
206      public Builder children(Class<?>...value) {
207         this.children = value;
208         return this;
209      }
210
211      /**
212       * Sets the {@link Rest#clientVersionHeader()} property on this annotation.
213       *
214       * @param value The new value for this property.
215       * @return This object.
216       */
217      public Builder clientVersionHeader(String value) {
218         this.clientVersionHeader = value;
219         return this;
220      }
221
222      /**
223       * Sets the {@link Rest#config()} property on this annotation.
224       *
225       * @param value The new value for this property.
226       * @return This object.
227       */
228      public Builder config(String value) {
229         this.config = value;
230         return this;
231      }
232
233      /**
234       * Sets the {@link Rest#consumes()} property on this annotation.
235       *
236       * @param value The new value for this property.
237       * @return This object.
238       */
239      public Builder consumes(String...value) {
240         this.consumes = value;
241         return this;
242      }
243
244      /**
245       * Sets the {@link Rest#converters()} property on this annotation.
246       *
247       * @param value The new value for this property.
248       * @return This object.
249       */
250      public Builder converters(Class<? extends RestConverter>...value) {
251         this.converters = value;
252         return this;
253      }
254
255      /**
256       * Sets the {@link Rest#debug()} property on this annotation.
257       *
258       * @param value The new value for this property.
259       * @return This object.
260       */
261      public Builder debug(String value) {
262         this.debug = value;
263         return this;
264      }
265
266      /**
267       * Sets the {@link Rest#debugEnablement()} property on this annotation.
268       *
269       * @param value The new value for this property.
270       * @return This object.
271       */
272      public Builder debugEnablement(Class<? extends DebugEnablement> value) {
273         this.debugEnablement = value;
274         return this;
275      }
276
277      /**
278       * Sets the {@link Rest#debugOn()} property on this annotation.
279       *
280       * @param value The new value for this property.
281       * @return This object.
282       */
283      public Builder debugOn(String value) {
284         this.debugOn = value;
285         return this;
286      }
287
288      /**
289       * Sets the {@link Rest#defaultAccept()} property on this annotation.
290       *
291       * @param value The new value for this property.
292       * @return This object.
293       */
294      public Builder defaultAccept(String value) {
295         this.defaultAccept = value;
296         return this;
297      }
298
299      /**
300       * Sets the {@link Rest#defaultCharset()} property on this annotation.
301       *
302       * @param value The new value for this property.
303       * @return This object.
304       */
305      public Builder defaultCharset(String value) {
306         this.defaultCharset = value;
307         return this;
308      }
309
310      /**
311       * Sets the {@link Rest#defaultContentType()} property on this annotation.
312       *
313       * @param value The new value for this property.
314       * @return This object.
315       */
316      public Builder defaultContentType(String value) {
317         this.defaultContentType = value;
318         return this;
319      }
320
321      /**
322       * Sets the {@link Rest#defaultRequestAttributes()} property on this annotation.
323       *
324       * @param value The new value for this property.
325       * @return This object.
326       */
327      public Builder defaultRequestAttributes(String...value) {
328         this.defaultRequestAttributes = value;
329         return this;
330      }
331
332      /**
333       * Sets the {@link Rest#defaultRequestHeaders()} property on this annotation.
334       *
335       * @param value The new value for this property.
336       * @return This object.
337       */
338      public Builder defaultRequestHeaders(String...value) {
339         this.defaultRequestHeaders = value;
340         return this;
341      }
342
343      /**
344       * Sets the {@link Rest#defaultResponseHeaders()} property on this annotation.
345       *
346       * @param value The new value for this property.
347       * @return This object.
348       */
349      public Builder defaultResponseHeaders(String...value) {
350         this.defaultResponseHeaders = value;
351         return this;
352      }
353
354      /**
355       * Sets the {@link Rest#description()} property on this annotation.
356       *
357       * @param value The new value for this property.
358       * @return This object.
359       */
360      public Builder description(String...value) {
361         this.description = value;
362         return this;
363      }
364
365      /**
366       * Sets the {@link Rest#encoders()} property on this annotation.
367       *
368       * @param value The new value for this property.
369       * @return This object.
370       */
371      public Builder encoders(Class<? extends Encoder>...value) {
372         this.encoders = value;
373         return this;
374      }
375
376      /**
377       * Sets the {@link Rest#guards()} property on this annotation.
378       *
379       * @param value The new value for this property.
380       * @return This object.
381       */
382      public Builder guards(Class<? extends RestGuard>...value) {
383         this.guards = value;
384         return this;
385      }
386
387      /**
388       * Sets the {@link Rest#maxInput()} property on this annotation.
389       *
390       * @param value The new value for this property.
391       * @return This object.
392       */
393      public Builder maxInput(String value) {
394         this.maxInput = value;
395         return this;
396      }
397
398      /**
399       * Sets the {@link Rest#messages()} property on this annotation.
400       *
401       * @param value The new value for this property.
402       * @return This object.
403       */
404      public Builder messages(String value) {
405         this.messages = value;
406         return this;
407      }
408
409      /**
410       * Sets the {@link Rest#parsers()} property on this annotation.
411       *
412       * @param value The new value for this property.
413       * @return This object.
414       */
415      public Builder parsers(Class<?>...value) {
416         this.parsers = value;
417         return this;
418      }
419
420      /**
421       * Sets the {@link Rest#partParser()} property on this annotation.
422       *
423       * @param value The new value for this property.
424       * @return This object.
425       */
426      public Builder partParser(Class<? extends HttpPartParser> value) {
427         this.partParser = value;
428         return this;
429      }
430
431      /**
432       * Sets the {@link Rest#partSerializer()} property on this annotation.
433       *
434       * @param value The new value for this property.
435       * @return This object.
436       */
437      public Builder partSerializer(Class<? extends HttpPartSerializer> value) {
438         this.partSerializer = value;
439         return this;
440      }
441
442      /**
443       * Sets the {@link Rest#path()} property on this annotation.
444       *
445       * @param value The new value for this property.
446       * @return This object.
447       */
448      public Builder path(String value) {
449         this.path = value;
450         return this;
451      }
452
453      /**
454       * Sets the {@link Rest#produces()} property on this annotation.
455       *
456       * @param value The new value for this property.
457       * @return This object.
458       */
459      public Builder produces(String...value) {
460         this.produces = value;
461         return this;
462      }
463
464      /**
465       * Sets the {@link Rest#renderResponseStackTraces()} property on this annotation.
466       *
467       * @param value The new value for this property.
468       * @return This object.
469       */
470      public Builder renderResponseStackTraces(String value) {
471         this.renderResponseStackTraces = value;
472         return this;
473      }
474
475      /**
476       * Sets the {@link Rest#responseProcessors()} property on this annotation.
477       *
478       * @param value The new value for this property.
479       * @return This object.
480       */
481      public Builder responseProcessors(Class<? extends ResponseProcessor>...value) {
482         this.responseProcessors = value;
483         return this;
484      }
485
486      /**
487       * Sets the {@link Rest#restChildrenClass()} property on this annotation.
488       *
489       * @param value The new value for this property.
490       * @return This object.
491       */
492      public Builder restChildrenClass(Class<? extends RestChildren> value) {
493         this.restChildrenClass = value;
494         return this;
495      }
496
497      /**
498       * Sets the {@link Rest#restOpArgs()} property on this annotation.
499       *
500       * @param value The new value for this property.
501       * @return This object.
502       */
503      public Builder restOpArgs(Class<? extends RestOpArg>...value) {
504         this.restOpArgs = value;
505         return this;
506      }
507
508      /**
509       * Sets the {@link Rest#restOperationsClass()} property on this annotation.
510       *
511       * @param value The new value for this property.
512       * @return This object.
513       */
514      public Builder restOperationsClass(Class<? extends RestOperations> value) {
515         this.restOperationsClass = value;
516         return this;
517      }
518
519      /**
520       * Sets the {@link Rest#roleGuard()} property on this annotation.
521       *
522       * @param value The new value for this property.
523       * @return This object.
524       */
525      public Builder roleGuard(String value) {
526         this.roleGuard = value;
527         return this;
528      }
529
530      /**
531       * Sets the {@link Rest#rolesDeclared()} property on this annotation.
532       *
533       * @param value The new value for this property.
534       * @return This object.
535       */
536      public Builder rolesDeclared(String value) {
537         this.rolesDeclared = value;
538         return this;
539      }
540
541      /**
542       * Sets the {@link Rest#serializers()} property on this annotation.
543       *
544       * @param value The new value for this property.
545       * @return This object.
546       */
547      public Builder serializers(Class<? extends Serializer>...value) {
548         this.serializers = value;
549         return this;
550      }
551
552      /**
553       * Sets the {@link Rest#siteName()} property on this annotation.
554       *
555       * @param value The new value for this property.
556       * @return This object.
557       */
558      public Builder siteName(String value) {
559         this.siteName = value;
560         return this;
561      }
562
563      /**
564       * Sets the {@link Rest#staticFiles()} property on this annotation.
565       *
566       * @param value The new value for this property.
567       * @return This object.
568       */
569      public Builder staticFiles(Class<? extends StaticFiles> value) {
570         this.staticFiles = value;
571         return this;
572      }
573
574      /**
575       * Sets the {@link Rest#swagger()} property on this annotation.
576       *
577       * @param value The new value for this property.
578       * @return This object.
579       */
580      public Builder swagger(Swagger value) {
581         this.swagger = value;
582         return this;
583      }
584
585      /**
586       * Sets the {@link Rest#swaggerProvider()} property on this annotation.
587       *
588       * @param value The new value for this property.
589       * @return This object.
590       */
591      public Builder swaggerProvider(Class<? extends SwaggerProvider> value) {
592         this.swaggerProvider = value;
593         return this;
594      }
595
596      /**
597       * Sets the {@link Rest#title()} property on this annotation.
598       *
599       * @param value The new value for this property.
600       * @return This object.
601       */
602      public Builder title(String...value) {
603         this.title = value;
604         return this;
605      }
606
607      /**
608       * Sets the {@link Rest#uriAuthority()} property on this annotation.
609       *
610       * @param value The new value for this property.
611       * @return This object.
612       */
613      public Builder uriAuthority(String value) {
614         this.uriAuthority = value;
615         return this;
616      }
617
618      /**
619       * Sets the {@link Rest#uriContext()} property on this annotation.
620       *
621       * @param value The new value for this property.
622       * @return This object.
623       */
624      public Builder uriContext(String value) {
625         this.uriContext = value;
626         return this;
627      }
628
629      /**
630       * Sets the {@link Rest#uriRelativity()} property on this annotation.
631       *
632       * @param value The new value for this property.
633       * @return This object.
634       */
635      public Builder uriRelativity(String value) {
636         this.uriRelativity = value;
637         return this;
638      }
639
640      /**
641       * Sets the {@link Rest#uriResolution()} property on this annotation.
642       *
643       * @param value The new value for this property.
644       * @return This object.
645       */
646      public Builder uriResolution(String value) {
647         this.uriResolution = value;
648         return this;
649      }
650
651      // <FluentSetters>
652
653      @Override /* GENERATED - TargetedAnnotationBuilder */
654      public Builder on(String...values) {
655         super.on(values);
656         return this;
657      }
658
659      @Override /* GENERATED - TargetedAnnotationTBuilder */
660      public Builder on(java.lang.Class<?>...value) {
661         super.on(value);
662         return this;
663      }
664
665      @Override /* GENERATED - TargetedAnnotationTBuilder */
666      public Builder onClass(java.lang.Class<?>...value) {
667         super.onClass(value);
668         return this;
669      }
670
671      // </FluentSetters>
672   }
673
674   //-----------------------------------------------------------------------------------------------------------------
675   // Implementation
676   //-----------------------------------------------------------------------------------------------------------------
677
678   private static class Impl extends TargetedAnnotationTImpl implements Rest {
679
680      private final Class<? extends Encoder>[] encoders;
681      private final Class<? extends HttpPartParser> partParser;
682      private final Class<? extends HttpPartSerializer> partSerializer;
683      private final Class<? extends StaticFiles> staticFiles;
684      private final Class<? extends ResponseProcessor>[] responseProcessors;
685      private final Class<? extends CallLogger> callLogger;
686      private final Class<? extends RestConverter>[] converters;
687      private final Class<? extends RestGuard>[] guards;
688      private final Class<? extends SwaggerProvider> swaggerProvider;
689      private final Class<? extends RestOpArg>[] restOpArgs;
690      private final Class<? extends BeanStore> beanStore;
691      private final Class<? extends RestChildren> restChildrenClass;
692      private final Class<? extends RestOperations> restOperationsClass;
693      private final Class<? extends DebugEnablement> debugEnablement;
694      private final Class<? extends Serializer>[] serializers;
695      private final Class<?>[] children, parsers;
696      private final Swagger swagger;
697      private final String disableContentParam, allowedHeaderParams, allowedMethodHeaders, allowedMethodParams, clientVersionHeader, config, debug, debugOn, defaultAccept, defaultCharset, defaultContentType, maxInput, messages, path, renderResponseStackTraces, roleGuard, rolesDeclared, siteName, uriAuthority, uriContext, uriRelativity, uriResolution;
698      private final String[] consumes, description, produces, defaultRequestAttributes, defaultRequestHeaders, defaultResponserHeaders, title;
699
700      Impl(Builder b) {
701         super(b);
702         this.disableContentParam = b.disableContentParam;
703         this.allowedHeaderParams = b.allowedHeaderParams;
704         this.allowedMethodHeaders = b.allowedMethodHeaders;
705         this.allowedMethodParams = b.allowedMethodParams;
706         this.beanStore = b.beanStore;
707         this.callLogger = b.callLogger;
708         this.children = copyOf(b.children);
709         this.clientVersionHeader = b.clientVersionHeader;
710         this.config = b.config;
711         this.consumes = copyOf(b.consumes);
712         this.converters = copyOf(b.converters);
713         this.debug = b.debug;
714         this.debugEnablement = b.debugEnablement;
715         this.debugOn = b.debugOn;
716         this.defaultAccept = b.defaultAccept;
717         this.defaultCharset = b.defaultCharset;
718         this.defaultContentType = b.defaultContentType;
719         this.defaultRequestAttributes = copyOf(b.defaultRequestAttributes);
720         this.defaultRequestHeaders = copyOf(b.defaultRequestHeaders);
721         this.defaultResponserHeaders = copyOf(b.defaultResponseHeaders);
722         this.description = copyOf(b.description);
723         this.encoders = copyOf(b.encoders);
724         this.guards = copyOf(b.guards);
725         this.maxInput = b.maxInput;
726         this.messages = b.messages;
727         this.parsers = copyOf(b.parsers);
728         this.partParser = b.partParser;
729         this.partSerializer = b.partSerializer;
730         this.path = b.path;
731         this.produces = copyOf(b.produces);
732         this.renderResponseStackTraces = b.renderResponseStackTraces;
733         this.responseProcessors = copyOf(b.responseProcessors);
734         this.restChildrenClass = b.restChildrenClass;
735         this.restOperationsClass = b.restOperationsClass;
736         this.restOpArgs = copyOf(b.restOpArgs);
737         this.roleGuard = b.roleGuard;
738         this.rolesDeclared = b.rolesDeclared;
739         this.serializers = copyOf(b.serializers);
740         this.siteName = b.siteName;
741         this.staticFiles = b.staticFiles;
742         this.swagger = b.swagger;
743         this.swaggerProvider = b.swaggerProvider;
744         this.title = copyOf(b.title);
745         this.uriAuthority = b.uriAuthority;
746         this.uriContext = b.uriContext;
747         this.uriRelativity = b.uriRelativity;
748         this.uriResolution = b.uriResolution;
749         postConstruct();
750      }
751
752      @Override /* Rest */
753      public String disableContentParam() {
754         return disableContentParam;
755      }
756
757      @Override /* Rest */
758      public String allowedHeaderParams() {
759         return allowedHeaderParams;
760      }
761
762      @Override /* Rest */
763      public String allowedMethodHeaders() {
764         return allowedMethodHeaders;
765      }
766
767      @Override /* Rest */
768      public String allowedMethodParams() {
769         return allowedMethodParams;
770      }
771
772      @Override /* Rest */
773      public Class<? extends BeanStore> beanStore() {
774         return beanStore;
775      }
776
777      @Override /* Rest */
778      public Class<? extends CallLogger> callLogger() {
779         return callLogger;
780      }
781
782      @Override /* Rest */
783      public Class<?>[] children() {
784         return children;
785      }
786
787      @Override /* Rest */
788      public String clientVersionHeader() {
789         return clientVersionHeader;
790      }
791
792      @Override /* Rest */
793      public String config() {
794         return config;
795      }
796
797      @Override /* Rest */
798      public String[] consumes() {
799         return consumes;
800      }
801
802      @Override /* Rest */
803      public Class<? extends RestConverter>[] converters() {
804         return converters;
805      }
806
807      @Override /* Rest */
808      public String debug() {
809         return debug;
810      }
811
812      @Override /* Rest */
813      public Class<? extends DebugEnablement> debugEnablement() {
814         return debugEnablement;
815      }
816
817      @Override /* Rest */
818      public String debugOn() {
819         return debugOn;
820      }
821
822      @Override /* Rest */
823      public String defaultAccept() {
824         return defaultAccept;
825      }
826
827      @Override /* Rest */
828      public String defaultCharset() {
829         return defaultCharset;
830      }
831
832      @Override /* Rest */
833      public String defaultContentType() {
834         return defaultContentType;
835      }
836
837      @Override /* Rest */
838      public String[] defaultRequestAttributes() {
839         return defaultRequestAttributes;
840      }
841
842      @Override /* Rest */
843      public String[] defaultRequestHeaders() {
844         return defaultRequestHeaders;
845      }
846
847      @Override /* Rest */
848      public String[] defaultResponseHeaders() {
849         return defaultResponserHeaders;
850      }
851
852      @Override /* Rest */
853      public String[] description() {
854         return description;
855      }
856
857      @Override /* Rest */
858      public Class<? extends Encoder>[] encoders() {
859         return encoders;
860      }
861
862      @Override /* Rest */
863      public Class<? extends RestGuard>[] guards() {
864         return guards;
865      }
866
867      @Override /* Rest */
868      public String maxInput() {
869         return maxInput;
870      }
871
872      @Override /* Rest */
873      public String messages() {
874         return messages;
875      }
876
877      @Override /* Rest */
878      public Class<?>[] parsers() {
879         return parsers;
880      }
881
882      @Override /* Rest */
883      public Class<? extends HttpPartParser> partParser() {
884         return partParser;
885      }
886
887      @Override /* Rest */
888      public Class<? extends HttpPartSerializer> partSerializer() {
889         return partSerializer;
890      }
891
892      @Override /* Rest */
893      public String path() {
894         return path;
895      }
896
897      @Override /* Rest */
898      public String[] produces() {
899         return produces;
900      }
901
902      @Override /* Rest */
903      public String renderResponseStackTraces() {
904         return renderResponseStackTraces;
905      }
906
907      @Override /* Rest */
908      public Class<? extends ResponseProcessor>[] responseProcessors() {
909         return responseProcessors;
910      }
911
912      @Override /* Rest */
913      public Class<? extends RestChildren> restChildrenClass() {
914         return restChildrenClass;
915      }
916
917      @Override /* Rest */
918      public Class<? extends RestOpArg>[] restOpArgs() {
919         return restOpArgs;
920      }
921
922      @Override /* Rest */
923      public Class<? extends RestOperations> restOperationsClass() {
924         return restOperationsClass;
925      }
926
927      @Override /* Rest */
928      public String roleGuard() {
929         return roleGuard;
930      }
931
932      @Override /* Rest */
933      public String rolesDeclared() {
934         return rolesDeclared;
935      }
936
937      @Override /* Rest */
938      public Class<? extends Serializer>[] serializers() {
939         return serializers;
940      }
941
942      @Override /* Rest */
943      public String siteName() {
944         return siteName;
945      }
946
947      @Override /* Rest */
948      public Class<? extends StaticFiles> staticFiles() {
949         return staticFiles;
950      }
951
952      @Override /* Rest */
953      public Swagger swagger() {
954         return swagger;
955      }
956
957      @Override /* Rest */
958      public Class<? extends SwaggerProvider> swaggerProvider() {
959         return swaggerProvider;
960      }
961
962      @Override /* Rest */
963      public String[] title() {
964         return title;
965      }
966
967      @Override /* Rest */
968      public String uriAuthority() {
969         return uriAuthority;
970      }
971
972      @Override /* Rest */
973      public String uriContext() {
974         return uriContext;
975      }
976
977      @Override /* Rest */
978      public String uriRelativity() {
979         return uriRelativity;
980      }
981
982      @Override /* Rest */
983      public String uriResolution() {
984         return uriResolution;
985      }
986   }
987
988   //-----------------------------------------------------------------------------------------------------------------
989   // Appliers
990   //-----------------------------------------------------------------------------------------------------------------
991
992   /**
993    * Applies {@link Rest} annotations to a {@link org.apache.juneau.rest.RestContext.Builder}.
994    */
995   public static class RestContextApply extends AnnotationApplier<Rest,RestContext.Builder> {
996
997      /**
998       * Constructor.
999       *
1000       * @param vr The resolver for resolving values in annotations.
1001       */
1002      public RestContextApply(VarResolverSession vr) {
1003         super(Rest.class, RestContext.Builder.class, vr);
1004      }
1005
1006      @Override
1007      public void apply(AnnotationInfo<Rest> ai, RestContext.Builder b) {
1008         Rest a = ai.inner();
1009
1010         classes(a.serializers()).ifPresent(x -> b.serializers().add(x));
1011         classes(a.parsers()).ifPresent(x -> b.parsers().add(x));
1012         type(a.partSerializer()).ifPresent(x -> b.partSerializer().type(x));
1013         type(a.partParser()).ifPresent(x -> b.partParser().type(x));
1014         stream(a.produces()).map(MediaType::of).forEach(x -> b.produces(x));
1015         stream(a.consumes()).map(MediaType::of).forEach(x -> b.consumes(x));
1016         stream(a.defaultRequestAttributes()).map(BasicNamedAttribute::ofPair).forEach(x -> b.defaultRequestAttributes(x));
1017         stream(a.defaultRequestHeaders()).map(HttpHeaders::stringHeader).forEach(x -> b.defaultRequestHeaders(x));
1018         stream(a.defaultResponseHeaders()).map(HttpHeaders::stringHeader).forEach(x -> b.defaultResponseHeaders(x));
1019         string(a.defaultAccept()).map(HttpHeaders::accept).ifPresent(x -> b.defaultRequestHeaders(x));
1020         string(a.defaultContentType()).map(HttpHeaders::contentType).ifPresent(x -> b.defaultRequestHeaders(x));
1021         b.responseProcessors().add(a.responseProcessors());
1022         b.children((Object[])a.children());
1023         b.restOpArgs(a.restOpArgs());
1024         classes(a.encoders()).ifPresent(x -> b.encoders().add(x));
1025         string(a.uriContext()).ifPresent(x -> b.uriContext(x));
1026         string(a.uriAuthority()).ifPresent(x -> b.uriAuthority(x));
1027         string(a.uriRelativity()).map(UriRelativity::valueOf).ifPresent(x -> b.uriRelativity(x));
1028         string(a.uriResolution()).map(UriResolution::valueOf).ifPresent(x -> b.uriResolution(x));
1029         b.messages().location(string(a.messages()).orElse(null));
1030         type(a.staticFiles()).ifPresent(x -> b.staticFiles().type(x));
1031         string(a.path()).ifPresent(x -> b.path(x));
1032         string(a.clientVersionHeader()).ifPresent(x -> b.clientVersionHeader(x));
1033         type(a.callLogger()).ifPresent(x -> b.callLogger().type(x));
1034         type(a.swaggerProvider()).ifPresent(x -> b.swaggerProvider(x));
1035         type(a.restChildrenClass()).ifPresent(x -> b.restChildrenClass(x));
1036         type(a.restOperationsClass()).ifPresent(x -> b.restOperationsClass(x));
1037         type(a.debugEnablement()).ifPresent(x -> b.debugEnablement().type(x));
1038         string(a.disableContentParam()).map(Boolean::parseBoolean).ifPresent(x -> b.disableContentParam(x));
1039         string(a.allowedHeaderParams()).ifPresent(x -> b.allowedHeaderParams(x));
1040         string(a.allowedMethodHeaders()).ifPresent(x -> b.allowedMethodHeaders(x));
1041         string(a.allowedMethodParams()).ifPresent(x -> b.allowedMethodParams(x));
1042         bool(a.renderResponseStackTraces()).ifPresent(x -> b.renderResponseStackTraces(x));
1043      }
1044   }
1045
1046   /**
1047    * Applies {@link Rest} annotations to a {@link org.apache.juneau.rest.RestOpContext.Builder}.
1048    */
1049   public static class RestOpContextApply extends AnnotationApplier<Rest,RestOpContext.Builder> {
1050
1051      /**
1052       * Constructor.
1053       *
1054       * @param vr The resolver for resolving values in annotations.
1055       */
1056      public RestOpContextApply(VarResolverSession vr) {
1057         super(Rest.class, RestOpContext.Builder.class, vr);
1058      }
1059
1060      @Override
1061      public void apply(AnnotationInfo<Rest> ai, RestOpContext.Builder b) {
1062         Rest a = ai.inner();
1063
1064         stream(a.produces()).map(MediaType::of).forEach(x -> b.produces(x));
1065         stream(a.consumes()).map(MediaType::of).forEach(x -> b.consumes(x));
1066         b.converters().append(a.converters());
1067         b.guards().append(a.guards());
1068         string(a.defaultCharset()).map(Charset::forName).ifPresent(x -> b.defaultCharset(x));
1069         string(a.maxInput()).ifPresent(x -> b.maxInput(x));
1070         cdl(a.rolesDeclared()).forEach(x -> b.rolesDeclared(x));
1071         string(a.roleGuard()).ifPresent(x -> b.roleGuard(x));
1072      }
1073   }
1074}