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