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