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.marshall; 018 019import static org.apache.juneau.commons.utils.Shorts.*; 020 021import java.lang.annotation.*; 022 023import org.apache.juneau.commons.*; 024 025/** 026 * Utility classes and methods for the {@link MarshalledProp @MarshalledProp} annotation. 027 * 028 */ 029public class MarshalledPropAnnotation { 030 031 /** 032 * Prevents instantiation. 033 */ 034 private MarshalledPropAnnotation() {} 035 036 /** 037 * Builder class. 038 * 039 * <h5 class='section'>See Also:</h5><ul> 040 * <li class='jm'>{@link MarshallingContext.Builder#annotations(Annotation...)} 041 * </ul> 042 */ 043 public static class Builder extends AnnotationObject.Builder { 044 045 private String[] description = {}; 046 private Class<?>[] dictionary = new Class[0]; 047 private String format = ""; 048 private String[] view = {}; 049 private DurationFormat durationFormat = DurationFormat.NOT_SET; 050 private PeriodFormat periodFormat = PeriodFormat.NOT_SET; 051 private CalendarFormat calendarFormat = CalendarFormat.NOT_SET; 052 private DateFormat dateFormat = DateFormat.NOT_SET; 053 private TemporalFormat temporalFormat = TemporalFormat.NOT_SET; 054 private TimeZoneFormat timeZoneFormat = TimeZoneFormat.NOT_SET; 055 private LocaleFormat localeFormat = LocaleFormat.NOT_SET; 056 private BinaryFormat binaryFormat = BinaryFormat.NOT_SET; 057 private EnumFormat enumFormat = EnumFormat.NOT_SET; 058 private UuidFormat uuidFormat = UuidFormat.NOT_SET; 059 private BitSetFormat bitSetFormat = BitSetFormat.NOT_SET; 060 private BigNumberFormat bigNumberFormat = BigNumberFormat.NOT_SET; 061 private BooleanFormat booleanFormat = BooleanFormat.NOT_SET; 062 private FloatFormat floatFormat = FloatFormat.NOT_SET; 063 private CurrencyFormat currencyFormat = CurrencyFormat.NOT_SET; 064 private ClassFormat classFormat = ClassFormat.NOT_SET; 065 private Nulls nulls = Nulls.NOT_SET; 066 067 /** 068 * Constructor. 069 */ 070 protected Builder() { 071 super(MarshalledProp.class); 072 } 073 074 /** 075 * Instantiates a new {@link MarshalledProp @MarshalledProp} object initialized with this builder. 076 * 077 * @return A new {@link MarshalledProp @MarshalledProp} object. 078 */ 079 public MarshalledProp build() { 080 return new Object(this); 081 } 082 083 /** 084 * Sets the description property on this annotation. 085 * 086 * @param value The new value for this property. 087 * @return This object. 088 */ 089 public Builder description(String...value) { 090 description = value; 091 return this; 092 } 093 094 /** 095 * Sets the {@link MarshalledProp#dictionary()} property on this annotation. 096 * 097 * @param value The new value for this property. 098 * @return This object. 099 */ 100 public Builder dictionary(Class<?>...value) { 101 dictionary = value; 102 return this; 103 } 104 105 /** 106 * Sets the {@link MarshalledProp#format()} property on this annotation. 107 * 108 * @param value The new value for this property. 109 * @return This object. 110 */ 111 public Builder format(String value) { 112 format = value; 113 return this; 114 } 115 116 /** 117 * Sets the {@link MarshalledProp#durationFormat()} property on this annotation. 118 * 119 * @param value The new value for this property. 120 * @return This object. 121 */ 122 public Builder durationFormat(DurationFormat value) { 123 durationFormat = value; 124 return this; 125 } 126 127 /** 128 * Sets the {@link MarshalledProp#periodFormat()} property on this annotation. 129 * 130 * @param value The new value for this property. 131 * @return This object. 132 */ 133 public Builder periodFormat(PeriodFormat value) { 134 periodFormat = value; 135 return this; 136 } 137 138 /** 139 * Sets the {@link MarshalledProp#calendarFormat()} property on this annotation. 140 * 141 * @param value The new value for this property. 142 * @return This object. 143 */ 144 public Builder calendarFormat(CalendarFormat value) { 145 calendarFormat = value; 146 return this; 147 } 148 149 /** 150 * Sets the {@link MarshalledProp#dateFormat()} property on this annotation. 151 * 152 * @param value The new value for this property. 153 * @return This object. 154 */ 155 public Builder dateFormat(DateFormat value) { 156 dateFormat = value; 157 return this; 158 } 159 160 /** 161 * Sets the {@link MarshalledProp#temporalFormat()} property on this annotation. 162 * 163 * @param value The new value for this property. 164 * @return This object. 165 */ 166 public Builder temporalFormat(TemporalFormat value) { 167 temporalFormat = value; 168 return this; 169 } 170 171 /** 172 * Sets the {@link MarshalledProp#timeZoneFormat()} property on this annotation. 173 * 174 * @param value The new value for this property. 175 * @return This object. 176 */ 177 public Builder timeZoneFormat(TimeZoneFormat value) { 178 timeZoneFormat = value; 179 return this; 180 } 181 182 /** 183 * Sets the {@link MarshalledProp#localeFormat()} property on this annotation. 184 * 185 * @param value The new value for this property. 186 * @return This object. 187 */ 188 public Builder localeFormat(LocaleFormat value) { 189 localeFormat = value; 190 return this; 191 } 192 193 /** 194 * Sets the {@link MarshalledProp#binaryFormat()} property on this annotation. 195 * 196 * @param value The new value for this property. 197 * @return This object. 198 */ 199 public Builder binaryFormat(BinaryFormat value) { 200 binaryFormat = value; 201 return this; 202 } 203 204 /** 205 * Sets the {@link MarshalledProp#enumFormat()} property on this annotation. 206 * 207 * @param value The new value for this property. 208 * @return This object. 209 */ 210 public Builder enumFormat(EnumFormat value) { 211 enumFormat = value; 212 return this; 213 } 214 215 /** 216 * Sets the {@link MarshalledProp#uuidFormat()} property on this annotation. 217 * 218 * @param value The new value for this property. 219 * @return This object. 220 */ 221 public Builder uuidFormat(UuidFormat value) { 222 uuidFormat = value; 223 return this; 224 } 225 226 /** 227 * Sets the {@link MarshalledProp#bitSetFormat()} property on this annotation. 228 * 229 * @param value The new value for this property. 230 * @return This object. 231 */ 232 public Builder bitSetFormat(BitSetFormat value) { 233 bitSetFormat = value; 234 return this; 235 } 236 237 /** 238 * Sets the {@link MarshalledProp#bigNumberFormat()} property on this annotation. 239 * 240 * @param value The new value for this property. 241 * @return This object. 242 */ 243 public Builder bigNumberFormat(BigNumberFormat value) { 244 bigNumberFormat = value; 245 return this; 246 } 247 248 /** 249 * Sets the {@link MarshalledProp#booleanFormat()} property on this annotation. 250 * 251 * @param value The new value for this property. 252 * @return This object. 253 */ 254 public Builder booleanFormat(BooleanFormat value) { 255 booleanFormat = value; 256 return this; 257 } 258 259 /** 260 * Sets the {@link MarshalledProp#floatFormat()} property on this annotation. 261 * 262 * @param value The new value for this property. 263 * @return This object. 264 */ 265 public Builder floatFormat(FloatFormat value) { 266 floatFormat = value; 267 return this; 268 } 269 270 /** 271 * Sets the {@link MarshalledProp#currencyFormat()} property on this annotation. 272 * 273 * @param value The new value for this property. 274 * @return This object. 275 */ 276 public Builder currencyFormat(CurrencyFormat value) { 277 currencyFormat = value; 278 return this; 279 } 280 281 /** 282 * Sets the {@link MarshalledProp#classFormat()} property on this annotation. 283 * 284 * @param value The new value for this property. 285 * @return This object. 286 */ 287 public Builder classFormat(ClassFormat value) { 288 classFormat = value; 289 return this; 290 } 291 292 /** 293 * Sets the {@link MarshalledProp#view()} property on this annotation. 294 * 295 * @param value The new value for this property. 296 * @return This object. 297 */ 298 public Builder view(String...value) { 299 view = value; 300 return this; 301 } 302 303 /** 304 * Sets the {@link MarshalledProp#nulls()} property on this annotation. 305 * 306 * @param value The new value for this property. 307 * @return This object. 308 * @since 10.0.0 309 */ 310 public Builder nulls(Nulls value) { 311 nulls = value; 312 return this; 313 } 314 315 } 316 317 @SuppressWarnings({ 318 "java:S2160" // equals() inherited from AnnotationObject compares all annotation interface methods; subclass fields are accessed via those methods 319 }) 320 private static class Object extends AnnotationObject implements MarshalledProp { 321 322 private final String[] description; 323 private final Class<?>[] dictionary; 324 private final String format; 325 private final String[] view; 326 private final DurationFormat durationFormat; 327 private final PeriodFormat periodFormat; 328 private final CalendarFormat calendarFormat; 329 private final DateFormat dateFormat; 330 private final TemporalFormat temporalFormat; 331 private final TimeZoneFormat timeZoneFormat; 332 private final LocaleFormat localeFormat; 333 private final BinaryFormat binaryFormat; 334 private final EnumFormat enumFormat; 335 private final UuidFormat uuidFormat; 336 private final BitSetFormat bitSetFormat; 337 private final BigNumberFormat bigNumberFormat; 338 private final BooleanFormat booleanFormat; 339 private final FloatFormat floatFormat; 340 private final CurrencyFormat currencyFormat; 341 private final ClassFormat classFormat; 342 private final Nulls nulls; 343 344 Object(MarshalledPropAnnotation.Builder b) { 345 super(b); 346 description = cp(b.description); 347 dictionary = cp(b.dictionary); 348 format = b.format; 349 view = cp(b.view); 350 durationFormat = b.durationFormat; 351 periodFormat = b.periodFormat; 352 calendarFormat = b.calendarFormat; 353 dateFormat = b.dateFormat; 354 temporalFormat = b.temporalFormat; 355 timeZoneFormat = b.timeZoneFormat; 356 localeFormat = b.localeFormat; 357 binaryFormat = b.binaryFormat; 358 enumFormat = b.enumFormat; 359 uuidFormat = b.uuidFormat; 360 bitSetFormat = b.bitSetFormat; 361 bigNumberFormat = b.bigNumberFormat; 362 booleanFormat = b.booleanFormat; 363 floatFormat = b.floatFormat; 364 currencyFormat = b.currencyFormat; 365 classFormat = b.classFormat; 366 nulls = b.nulls; 367 } 368 369 @Override /* Overridden from MarshalledProp */ 370 public Class<?>[] dictionary() { 371 return dictionary; 372 } 373 374 @Override /* Overridden from MarshalledProp */ 375 public String format() { 376 return format; 377 } 378 379 @Override /* Overridden from MarshalledProp */ 380 public DurationFormat durationFormat() { 381 return durationFormat; 382 } 383 384 @Override /* Overridden from MarshalledProp */ 385 public PeriodFormat periodFormat() { 386 return periodFormat; 387 } 388 389 @Override /* Overridden from MarshalledProp */ 390 public CalendarFormat calendarFormat() { 391 return calendarFormat; 392 } 393 394 @Override /* Overridden from MarshalledProp */ 395 public DateFormat dateFormat() { 396 return dateFormat; 397 } 398 399 @Override /* Overridden from MarshalledProp */ 400 public TemporalFormat temporalFormat() { 401 return temporalFormat; 402 } 403 404 @Override /* Overridden from MarshalledProp */ 405 public TimeZoneFormat timeZoneFormat() { 406 return timeZoneFormat; 407 } 408 409 @Override /* Overridden from MarshalledProp */ 410 public LocaleFormat localeFormat() { 411 return localeFormat; 412 } 413 414 @Override /* Overridden from MarshalledProp */ 415 public BinaryFormat binaryFormat() { 416 return binaryFormat; 417 } 418 419 @Override /* Overridden from MarshalledProp */ 420 public EnumFormat enumFormat() { 421 return enumFormat; 422 } 423 424 @Override /* Overridden from MarshalledProp */ 425 public UuidFormat uuidFormat() { 426 return uuidFormat; 427 } 428 429 @Override /* Overridden from MarshalledProp */ 430 public BitSetFormat bitSetFormat() { 431 return bitSetFormat; 432 } 433 434 @Override /* Overridden from MarshalledProp */ 435 public BigNumberFormat bigNumberFormat() { 436 return bigNumberFormat; 437 } 438 439 @Override /* Overridden from MarshalledProp */ 440 public BooleanFormat booleanFormat() { 441 return booleanFormat; 442 } 443 444 @Override /* Overridden from MarshalledProp */ 445 public FloatFormat floatFormat() { 446 return floatFormat; 447 } 448 449 @Override /* Overridden from MarshalledProp */ 450 public CurrencyFormat currencyFormat() { 451 return currencyFormat; 452 } 453 454 @Override /* Overridden from MarshalledProp */ 455 public ClassFormat classFormat() { 456 return classFormat; 457 } 458 459 @Override /* Overridden from annotation */ 460 public String[] description() { 461 return description; 462 } 463 464 @Override /* Overridden from MarshalledProp */ 465 public String[] view() { 466 return view; 467 } 468 469 @Override /* Overridden from MarshalledProp */ 470 public Nulls nulls() { 471 return nulls; 472 } 473 } 474 475 /** Default value */ 476 public static final MarshalledProp DEFAULT = create().build(); 477 478 /** 479 * Instantiates a new builder for this class. 480 * 481 * @return A new builder object. 482 */ 483 public static Builder create() { 484 return new Builder(); 485 } 486}