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.dto.openapi3; 014 015import static org.apache.juneau.common.internal.StringUtils.*; 016import static org.apache.juneau.internal.CollectionUtils.*; 017import static org.apache.juneau.internal.ConverterUtils.*; 018 019import org.apache.juneau.UriResolver; 020import org.apache.juneau.annotation.Bean; 021import org.apache.juneau.internal.*; 022 023import java.net.URI; 024import java.net.URL; 025import java.util.*; 026 027/** 028 * TODO 029 */ 030@Bean(properties="contentType,style,explode,headers,allowReserved,*") 031@FluentSetters 032public class Encoding extends OpenApiElement{ 033 034 private String contentType, 035 style; 036 private Map<String,HeaderInfo> headers; 037 private Boolean explode, 038 allowReserved; 039 040 /** 041 * Default constructor. 042 */ 043 public Encoding() { } 044 045 /** 046 * Copy constructor. 047 * 048 * @param copyFrom The object to copy. 049 */ 050 public Encoding(Encoding copyFrom) { 051 super(copyFrom); 052 053 this.contentType = copyFrom.contentType; 054 this.style = copyFrom.style; 055 this.explode = copyFrom.explode; 056 this.allowReserved = copyFrom.allowReserved; 057 if (copyFrom.headers == null) { 058 this.headers = null; 059 } else { 060 this.headers = new LinkedHashMap<>(); 061 for (Map.Entry<String,HeaderInfo> e : copyFrom.headers.entrySet()) 062 this.headers.put(e.getKey(), e.getValue().copy()); 063 } 064 } 065 066 /** 067 * Make a deep copy of this object. 068 * 069 * @return A deep copy of this object. 070 */ 071 public Encoding copy() { 072 return new Encoding(this); 073 } 074 075 @Override /* OpenApiElement */ 076 protected Encoding strict() { 077 super.strict(); 078 return this; 079 } 080 081 /** 082 * Bean property getter: <property>contentType</property>. 083 * 084 * <p> 085 * The URL pointing to the contact information. 086 * 087 * @return The property value, or <jk>null</jk> if it is not set. 088 */ 089 public String getContentType() { 090 return contentType; 091 } 092 093 /** 094 * Bean property setter: <property>url</property>. 095 * 096 * <p> 097 * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}. 098 * <br>Strings must be valid URIs. 099 * 100 * <p> 101 * URIs defined by {@link UriResolver} can be used for values. 102 * 103 * @param value 104 * The new value for this property. 105 * <br>Can be <jk>null</jk> to unset the property. 106 * @return This object 107 */ 108 public Encoding setContentType(String value) { 109 contentType = value; 110 return this; 111 } 112 113 /** 114 * Bean property getter: <property>style</property>. 115 * 116 * @return The property value, or <jk>null</jk> if it is not set. 117 */ 118 public String getStyle() { 119 return style; 120 } 121 122 /** 123 * Bean property setter: <property>description</property>. 124 * 125 * @param value 126 * The new value for this property. 127 * @return This object 128 */ 129 public Encoding setStyle(String value) { 130 style = value; 131 return this; 132 } 133 134 /** 135 * Bean property getter: <property>variables</property>. 136 * 137 * @return The property value, or <jk>null</jk> if it is not set. 138 */ 139 public Map<String, HeaderInfo> getHeaders() { 140 return headers; 141 } 142 143 /** 144 * Bean property setter: <property>variables</property>. 145 * 146 * @param value 147 * The new value for this property. 148 * @return This object 149 */ 150 public Encoding setHeaders(Map<String, HeaderInfo> value) { 151 headers = copyOf(value); 152 return this; 153 } 154 155 /** 156 * Adds one or more values to the <property>headers</property> property. 157 * 158 * @param key The mapping key. 159 * @param value 160 * The values to add to this property. 161 * <br>Ignored if <jk>null</jk>. 162 * @return This object 163 */ 164 public Encoding addHeader(String key, HeaderInfo value) { 165 headers = mapBuilder(headers).sparse().add(key, value).build(); 166 return this; 167 } 168 169 /** 170 * Bean property getter: <property>required</property>. 171 * 172 * <p> 173 * The type of the object. 174 * 175 * @return The property value, or <jk>null</jk> if it is not set. 176 */ 177 public Boolean getExplode() { 178 return explode; 179 } 180 181 /** 182 * Bean property setter: <property>explode</property>. 183 * 184 * <p> 185 * The type of the object. 186 * 187 * @param value 188 * The new value for this property. 189 * <br>Property value is required. 190 * </ul> 191 * @return This object 192 */ 193 public Encoding setExplode(Boolean value) { 194 explode = value; 195 return this; 196 } 197 198 /** 199 * Bean property getter: <property>required</property>. 200 * 201 * <p> 202 * The type of the object. 203 * 204 * @return The property value, or <jk>null</jk> if it is not set. 205 */ 206 public Boolean getAllowReserved() { 207 return allowReserved; 208 } 209 210 /** 211 * Bean property setter: <property>explode</property>. 212 * 213 * <p> 214 * The type of the object. 215 * 216 * @param value 217 * The new value for this property. 218 * <br>Property value is required. 219 * </ul> 220 * @return This object 221 */ 222 public Encoding setAllowReserved(Boolean value) { 223 allowReserved = value; 224 return this; 225 } 226 227 // <FluentSetters> 228 229 // </FluentSetters> 230 231 @Override /* OpenApiElement */ 232 public <T> T get(String property, Class<T> type) { 233 if (property == null) 234 return null; 235 switch (property) { 236 case "contentType": return toType(getContentType(), type); 237 case "style": return toType(getStyle(), type); 238 case "headers": return toType(getHeaders(), type); 239 case "explode": return toType(getExplode(), type); 240 case "allowReserved": return toType(getAllowReserved(), type); 241 default: return super.get(property, type); 242 } 243 } 244 245 @Override /* OpenApiElement */ 246 public Encoding set(String property, Object value) { 247 if (property == null) 248 return this; 249 switch (property) { 250 case "contentType": return setContentType(stringify(value)); 251 case "style": return setStyle(stringify(value)); 252 case "headers": return setHeaders(mapBuilder(String.class,HeaderInfo.class).sparse().addAny(value).build()); 253 case "explode": return setExplode(toBoolean(value)); 254 case "allowReserved": return setAllowReserved(toBoolean(value)); 255 default: 256 super.set(property, value); 257 return this; 258 } 259 } 260 261 @Override /* OpenApiElement */ 262 public Set<String> keySet() { 263 Set<String> s = setBuilder(String.class) 264 .addIf(contentType != null, "contentType") 265 .addIf(style != null, "style") 266 .addIf(headers != null, "headers") 267 .addIf(explode != null, "explode") 268 .addIf(allowReserved != null, "allowReserved") 269 .build(); 270 return new MultiSet<>(s, super.keySet()); 271 } 272}