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.arg;
014
015import static org.apache.juneau.common.internal.ArgUtils.*;
016import static org.apache.juneau.internal.CollectionUtils.*;
017
018import java.util.*;
019
020import org.apache.juneau.*;
021import org.apache.juneau.cp.*;
022import org.apache.juneau.internal.*;
023
024/**
025 * A list of {@link RestOpArg} classes.
026 *
027 * <h5 class='section'>See Also:</h5><ul>
028 *    <li class='link'><a class="doclink" href="../../../../../index.html#jrs.RestOpAnnotatedMethods">@RestOp-Annotated Methods</a>
029 * </ul>
030 */
031public class RestOpArgList {
032
033   //-----------------------------------------------------------------------------------------------------------------
034   // Static
035   //-----------------------------------------------------------------------------------------------------------------
036
037   /**
038    * Static creator.
039    *
040    * @param beanStore The bean store to use for creating beans.
041    * @return A new builder for this object.
042    */
043   public static Builder create(BeanStore beanStore) {
044      return new Builder(beanStore);
045   }
046
047   //-----------------------------------------------------------------------------------------------------------------
048   // Builder
049   //-----------------------------------------------------------------------------------------------------------------
050
051   /**
052    * Builder class.
053    */
054   @FluentSetters
055   public static class Builder extends BeanBuilder<RestOpArgList> {
056
057      List<Class<? extends RestOpArg>> entries;
058
059      /**
060       * Constructor.
061       *
062       * @param beanStore The bean store to use for creating beans.
063       */
064      protected Builder(BeanStore beanStore) {
065         super(RestOpArgList.class, beanStore);
066         entries = list();
067      }
068
069      @Override /* BeanBuilder */
070      protected RestOpArgList buildDefault() {
071         return new RestOpArgList(this);
072      }
073
074      //-------------------------------------------------------------------------------------------------------------
075      // Properties
076      //-------------------------------------------------------------------------------------------------------------
077
078      /**
079       * Prepends the specified rest op arg classes to the list.
080       *
081       * @param values The values to add.
082       * @return This object.
083       * @throws IllegalArgumentException if any class does not extend from {@link RestOpArg}.
084       */
085      public Builder add(Class<?>...values) {
086         prependAll(entries, assertClassArrayArgIsType("values", RestOpArg.class, values));
087         return this;
088      }
089
090      // <FluentSetters>
091
092      @Override /* GENERATED - org.apache.juneau.BeanBuilder */
093      public Builder impl(Object value) {
094         super.impl(value);
095         return this;
096      }
097
098      @Override /* GENERATED - org.apache.juneau.BeanBuilder */
099      public Builder type(Class<?> value) {
100         super.type(value);
101         return this;
102      }
103
104      // </FluentSetters>
105   }
106
107   //-----------------------------------------------------------------------------------------------------------------
108   // Instance
109   //-----------------------------------------------------------------------------------------------------------------
110
111   private final Class<? extends RestOpArg>[] entries;
112
113   /**
114    * Constructor.
115    *
116    * @param builder The builder containing the contents for this list.
117    */
118   protected RestOpArgList(Builder builder) {
119      entries =
120         builder
121            .entries
122            .stream()
123            .toArray(Class[]::new);
124   }
125
126   /**
127    * Returns the contents of this list as a {@link Class} array.
128    *
129    * @return The contents of this list as a {@link Class} array.
130    */
131   public Class<? extends RestOpArg>[] asArray() {
132      return entries;
133   }
134}