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