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 org.apache.juneau.commons.*; 022import org.apache.juneau.marshall.httppart.*; 023import org.apache.juneau.rest.server.converter.*; 024import org.apache.juneau.rest.server.guard.*; 025 026/** 027 * Utility classes and methods for the {@link Child @Child} annotation. 028 * 029 * <h5 class='section'>See Also:</h5><ul> 030 * <li class='ja'>{@link Child} 031 * <li class='ja'>{@link Rest#childrenDefs()} 032 * </ul> 033 * 034 * @since 10.0.0 035 */ 036public class ChildAnnotation { 037 038 /** 039 * Prevents instantiation. 040 */ 041 private ChildAnnotation() {} 042 043 /** 044 * Builder class. 045 */ 046 @SuppressWarnings({ 047 "unchecked" // Type erasure requires cast for generic class-array fields. 048 }) 049 public static class Builder extends AnnotationObject.Builder { 050 051 Class<?> type = Object.class; 052 Class<? extends RestGuard>[] guards = new Class[0]; 053 Class<? extends RestConverter>[] converters = new Class[0]; 054 String roleGuard = ""; 055 String rolesDeclared = ""; 056 Class<? extends HttpPartSerializer> partSerializer = HttpPartSerializer.Void.class; 057 Class<? extends HttpPartParser> partParser = HttpPartParser.Void.class; 058 String defaultCharset = ""; 059 String maxInput = ""; 060 061 /** 062 * Constructor. 063 */ 064 protected Builder() { 065 super(Child.class); 066 } 067 068 /** 069 * Sets the {@link Child#type()} property on this annotation. 070 * 071 * @param value The new value for this property. 072 * @return This object. 073 */ 074 public Builder type(Class<?> value) { type = value; return this; } 075 076 /** 077 * Sets the {@link Child#guards()} property on this annotation. 078 * 079 * @param value The new value for this property. 080 * @return This object. 081 */ 082 public Builder guards(Class<? extends RestGuard>... value) { guards = value; return this; } 083 084 /** 085 * Sets the {@link Child#converters()} property on this annotation. 086 * 087 * @param value The new value for this property. 088 * @return This object. 089 */ 090 public Builder converters(Class<? extends RestConverter>... value) { converters = value; return this; } 091 092 /** 093 * Sets the {@link Child#roleGuard()} property on this annotation. 094 * 095 * @param value The new value for this property. 096 * @return This object. 097 */ 098 public Builder roleGuard(String value) { roleGuard = value; return this; } 099 100 /** 101 * Sets the {@link Child#rolesDeclared()} property on this annotation. 102 * 103 * @param value The new value for this property. 104 * @return This object. 105 */ 106 public Builder rolesDeclared(String value) { rolesDeclared = value; return this; } 107 108 /** 109 * Sets the {@link Child#partSerializer()} property on this annotation. 110 * 111 * @param value The new value for this property. 112 * @return This object. 113 */ 114 public Builder partSerializer(Class<? extends HttpPartSerializer> value) { partSerializer = value; return this; } 115 116 /** 117 * Sets the {@link Child#partParser()} property on this annotation. 118 * 119 * @param value The new value for this property. 120 * @return This object. 121 */ 122 public Builder partParser(Class<? extends HttpPartParser> value) { partParser = value; return this; } 123 124 /** 125 * Sets the {@link Child#defaultCharset()} property on this annotation. 126 * 127 * @param value The new value for this property. 128 * @return This object. 129 */ 130 public Builder defaultCharset(String value) { defaultCharset = value; return this; } 131 132 /** 133 * Sets the {@link Child#maxInput()} property on this annotation. 134 * 135 * @param value The new value for this property. 136 * @return This object. 137 */ 138 public Builder maxInput(String value) { maxInput = value; return this; } 139 140 /** 141 * Instantiates a new {@link Child @Child} object initialized with this builder. 142 * 143 * @return A new {@link Child @Child} object. 144 */ 145 public Child build() { 146 return new Impl(this); 147 } 148 } 149 150 @SuppressWarnings({ 151 "java:S2160" // equals() inherited from AnnotationObject compares all annotation interface methods; subclass fields are accessed via those methods. 152 }) 153 private static class Impl extends AnnotationObject implements Child { 154 155 private final Class<?> type; 156 private final Class<? extends RestGuard>[] guards; 157 private final Class<? extends RestConverter>[] converters; 158 private final String roleGuard; 159 private final String rolesDeclared; 160 private final Class<? extends HttpPartSerializer> partSerializer; 161 private final Class<? extends HttpPartParser> partParser; 162 private final String defaultCharset; 163 private final String maxInput; 164 165 Impl(ChildAnnotation.Builder b) { 166 super(b); 167 type = b.type; 168 guards = cp(b.guards); 169 converters = cp(b.converters); 170 roleGuard = b.roleGuard; 171 rolesDeclared = b.rolesDeclared; 172 partSerializer = b.partSerializer; 173 partParser = b.partParser; 174 defaultCharset = b.defaultCharset; 175 maxInput = b.maxInput; 176 } 177 178 @Override /* Overridden from Child */ public Class<?> type() { return type; } 179 @Override /* Overridden from Child */ public Class<? extends RestGuard>[] guards() { return cp(guards); } 180 @Override /* Overridden from Child */ public Class<? extends RestConverter>[] converters() { return cp(converters); } 181 @Override /* Overridden from Child */ public String roleGuard() { return roleGuard; } 182 @Override /* Overridden from Child */ public String rolesDeclared() { return rolesDeclared; } 183 @Override /* Overridden from Child */ public Class<? extends HttpPartSerializer> partSerializer() { return partSerializer; } 184 @Override /* Overridden from Child */ public Class<? extends HttpPartParser> partParser() { return partParser; } 185 @Override /* Overridden from Child */ public String defaultCharset() { return defaultCharset; } 186 @Override /* Overridden from Child */ public String maxInput() { return maxInput; } 187 } 188 189 /** 190 * Builder creator. 191 * 192 * @return A new builder. 193 */ 194 public static Builder create() { 195 return new Builder(); 196 } 197 198 /** Default {@link Child} instance (empty seed slots; {@code type=Object.class}). */ 199 public static final Child DEFAULT = create().build(); 200}