1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau;
18
19 import static org.apache.juneau.commons.utils.Utils.*;
20
21 import java.lang.annotation.*;
22 import java.util.*;
23
24 import org.apache.juneau.commons.collections.*;
25 import org.apache.juneau.commons.function.*;
26 import org.apache.juneau.commons.reflect.*;
27
28
29
30
31
32
33
34
35
36
37
38
39
40 public abstract class BeanTraverseContext extends BeanContextable {
41
42
43
44 public abstract static class Builder extends BeanContextable.Builder {
45
46 private boolean detectRecursions;
47 private boolean ignoreRecursions;
48 private int initialDepth;
49 private int maxDepth;
50
51
52
53
54 protected Builder() {
55 detectRecursions = env("BeanTraverseContext.detectRecursions", false);
56 ignoreRecursions = env("BeanTraverseContext.ignoreRecursions", false);
57 initialDepth = env("BeanTraverseContext.initialDepth", 0);
58 maxDepth = env("BeanTraverseContext.maxDepth", 100);
59 }
60
61
62
63
64
65
66 protected Builder(BeanTraverseContext copyFrom) {
67 super(copyFrom);
68 detectRecursions = copyFrom.getDetectRecursions();
69 ignoreRecursions = copyFrom.getIgnoreRecursions();
70 initialDepth = copyFrom.getInitialDepth();
71 maxDepth = copyFrom.getMaxDepth();
72 }
73
74
75
76
77
78
79 protected Builder(Builder copyFrom) {
80 super(copyFrom);
81 detectRecursions = copyFrom.detectRecursions;
82 ignoreRecursions = copyFrom.ignoreRecursions;
83 initialDepth = copyFrom.initialDepth;
84 maxDepth = copyFrom.maxDepth;
85 }
86
87 @Override
88 public Builder annotations(Annotation...values) {
89 super.annotations(values);
90 return this;
91 }
92
93 @Override
94 public Builder apply(AnnotationWorkList work) {
95 super.apply(work);
96 return this;
97 }
98
99 @Override
100 public Builder applyAnnotations(Class<?>...from) {
101 super.applyAnnotations(from);
102 return this;
103 }
104
105 @Override
106 public Builder applyAnnotations(Object...from) {
107 super.applyAnnotations(from);
108 return this;
109 }
110
111 @Override
112 public Builder beanClassVisibility(Visibility value) {
113 super.beanClassVisibility(value);
114 return this;
115 }
116
117 @Override
118 public Builder beanConstructorVisibility(Visibility value) {
119 super.beanConstructorVisibility(value);
120 return this;
121 }
122
123 @Override
124 public Builder beanContext(BeanContext value) {
125 super.beanContext(value);
126 return this;
127 }
128
129 @Override
130 public Builder beanContext(BeanContext.Builder value) {
131 super.beanContext(value);
132 return this;
133 }
134
135 @Override
136 public Builder beanDictionary(java.lang.Class<?>...values) {
137 super.beanDictionary(values);
138 return this;
139 }
140
141 @Override
142 public Builder beanFieldVisibility(Visibility value) {
143 super.beanFieldVisibility(value);
144 return this;
145 }
146
147 @Override
148 public Builder beanInterceptor(Class<?> on, Class<? extends org.apache.juneau.swap.BeanInterceptor<?>> value) {
149 super.beanInterceptor(on, value);
150 return this;
151 }
152
153 @Override
154 public Builder beanMapPutReturnsOldValue() {
155 super.beanMapPutReturnsOldValue();
156 return this;
157 }
158
159 @Override
160 public Builder beanMethodVisibility(Visibility value) {
161 super.beanMethodVisibility(value);
162 return this;
163 }
164
165 @Override
166 public Builder beanProperties(Class<?> beanClass, String properties) {
167 super.beanProperties(beanClass, properties);
168 return this;
169 }
170
171 @Override
172 public Builder beanProperties(Map<String,Object> values) {
173 super.beanProperties(values);
174 return this;
175 }
176
177 @Override
178 public Builder beanProperties(String beanClassName, String properties) {
179 super.beanProperties(beanClassName, properties);
180 return this;
181 }
182
183 @Override
184 public Builder beanPropertiesExcludes(Class<?> beanClass, String properties) {
185 super.beanPropertiesExcludes(beanClass, properties);
186 return this;
187 }
188
189 @Override
190 public Builder beanPropertiesExcludes(Map<String,Object> values) {
191 super.beanPropertiesExcludes(values);
192 return this;
193 }
194
195 @Override
196 public Builder beanPropertiesExcludes(String beanClassName, String properties) {
197 super.beanPropertiesExcludes(beanClassName, properties);
198 return this;
199 }
200
201 @Override
202 public Builder beanPropertiesReadOnly(Class<?> beanClass, String properties) {
203 super.beanPropertiesReadOnly(beanClass, properties);
204 return this;
205 }
206
207 @Override
208 public Builder beanPropertiesReadOnly(Map<String,Object> values) {
209 super.beanPropertiesReadOnly(values);
210 return this;
211 }
212
213 @Override
214 public Builder beanPropertiesReadOnly(String beanClassName, String properties) {
215 super.beanPropertiesReadOnly(beanClassName, properties);
216 return this;
217 }
218
219 @Override
220 public Builder beanPropertiesWriteOnly(Class<?> beanClass, String properties) {
221 super.beanPropertiesWriteOnly(beanClass, properties);
222 return this;
223 }
224
225 @Override
226 public Builder beanPropertiesWriteOnly(Map<String,Object> values) {
227 super.beanPropertiesWriteOnly(values);
228 return this;
229 }
230
231 @Override
232 public Builder beanPropertiesWriteOnly(String beanClassName, String properties) {
233 super.beanPropertiesWriteOnly(beanClassName, properties);
234 return this;
235 }
236
237 @Override
238 public Builder beansRequireDefaultConstructor() {
239 super.beansRequireDefaultConstructor();
240 return this;
241 }
242
243 @Override
244 public Builder beansRequireSerializable() {
245 super.beansRequireSerializable();
246 return this;
247 }
248
249 @Override
250 public Builder beansRequireSettersForGetters() {
251 super.beansRequireSettersForGetters();
252 return this;
253 }
254
255 @Override
256 public Builder cache(Cache<HashKey,? extends org.apache.juneau.Context> value) {
257 super.cache(value);
258 return this;
259 }
260
261 @Override
262 public abstract Builder copy();
263
264 @Override
265 public Builder debug() {
266 super.debug();
267 return this;
268 }
269
270 @Override
271 public Builder debug(boolean value) {
272 super.debug(value);
273 return this;
274 }
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313 public Builder detectRecursions() {
314 return detectRecursions(true);
315 }
316
317
318
319
320
321
322
323 public Builder detectRecursions(boolean value) {
324 detectRecursions = value;
325 return this;
326 }
327
328 @Override
329 public Builder dictionaryOn(Class<?> on, java.lang.Class<?>...values) {
330 super.dictionaryOn(on, values);
331 return this;
332 }
333
334 @Override
335 public Builder disableBeansRequireSomeProperties() {
336 super.disableBeansRequireSomeProperties();
337 return this;
338 }
339
340 @Override
341 public Builder disableIgnoreMissingSetters() {
342 super.disableIgnoreMissingSetters();
343 return this;
344 }
345
346 @Override
347 public Builder disableIgnoreTransientFields() {
348 super.disableIgnoreTransientFields();
349 return this;
350 }
351
352 @Override
353 public Builder disableIgnoreUnknownNullBeanProperties() {
354 super.disableIgnoreUnknownNullBeanProperties();
355 return this;
356 }
357
358 @Override
359 public Builder disableInterfaceProxies() {
360 super.disableInterfaceProxies();
361 return this;
362 }
363
364 @Override
365 public <T> Builder example(Class<T> pojoClass, String json) {
366 super.example(pojoClass, json);
367 return this;
368 }
369
370 @Override
371 public <T> Builder example(Class<T> pojoClass, T o) {
372 super.example(pojoClass, o);
373 return this;
374 }
375
376 @Override
377 public Builder findFluentSetters() {
378 super.findFluentSetters();
379 return this;
380 }
381
382 @Override
383 public Builder findFluentSetters(Class<?> on) {
384 super.findFluentSetters(on);
385 return this;
386 }
387
388 @Override
389 public HashKey hashKey() {
390
391 return HashKey.of(
392 super.hashKey(),
393 detectRecursions,
394 ignoreRecursions,
395 initialDepth,
396 maxDepth
397 );
398
399 }
400
401 @Override
402 public Builder ignoreInvocationExceptionsOnGetters() {
403 super.ignoreInvocationExceptionsOnGetters();
404 return this;
405 }
406
407 @Override
408 public Builder ignoreInvocationExceptionsOnSetters() {
409 super.ignoreInvocationExceptionsOnSetters();
410 return this;
411 }
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453 public Builder ignoreRecursions() {
454 return ignoreRecursions(true);
455 }
456
457
458
459
460
461
462
463 public Builder ignoreRecursions(boolean value) {
464 ignoreRecursions = value;
465 return this;
466 }
467
468 @Override
469 public Builder ignoreUnknownBeanProperties() {
470 super.ignoreUnknownBeanProperties();
471 return this;
472 }
473
474 @Override
475 public Builder ignoreUnknownEnumValues() {
476 super.ignoreUnknownEnumValues();
477 return this;
478 }
479
480 @Override
481 public Builder impl(Context value) {
482 super.impl(value);
483 return this;
484 }
485
486 @Override
487 public Builder implClass(Class<?> interfaceClass, Class<?> implClass) {
488 super.implClass(interfaceClass, implClass);
489 return this;
490 }
491
492 @Override
493 public Builder implClasses(Map<Class<?>,Class<?>> values) {
494 super.implClasses(values);
495 return this;
496 }
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525 public Builder initialDepth(int value) {
526 initialDepth = value;
527 return this;
528 }
529
530 @Override
531 public Builder interfaceClass(Class<?> on, Class<?> value) {
532 super.interfaceClass(on, value);
533 return this;
534 }
535
536 @Override
537 public Builder interfaces(java.lang.Class<?>...value) {
538 super.interfaces(value);
539 return this;
540 }
541
542 @Override
543 public Builder locale(Locale value) {
544 super.locale(value);
545 return this;
546 }
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578 public Builder maxDepth(int value) {
579 maxDepth = value;
580 return this;
581 }
582
583 @Override
584 public Builder mediaType(MediaType value) {
585 super.mediaType(value);
586 return this;
587 }
588
589 @Override
590 public Builder notBeanClasses(java.lang.Class<?>...values) {
591 super.notBeanClasses(values);
592 return this;
593 }
594
595 @Override
596 public Builder notBeanPackages(String...values) {
597 super.notBeanPackages(values);
598 return this;
599 }
600
601 @Override
602 public Builder propertyNamer(Class<?> on, Class<? extends org.apache.juneau.PropertyNamer> value) {
603 super.propertyNamer(on, value);
604 return this;
605 }
606
607 @Override
608 public Builder propertyNamer(Class<? extends org.apache.juneau.PropertyNamer> value) {
609 super.propertyNamer(value);
610 return this;
611 }
612
613 @Override
614 public Builder sortProperties() {
615 super.sortProperties();
616 return this;
617 }
618
619 @Override
620 public Builder sortProperties(java.lang.Class<?>...on) {
621 super.sortProperties(on);
622 return this;
623 }
624
625 @Override
626 public Builder stopClass(Class<?> on, Class<?> value) {
627 super.stopClass(on, value);
628 return this;
629 }
630
631 @Override
632 public <T,S> Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T,S> swapFunction) {
633 super.swap(normalClass, swappedClass, swapFunction);
634 return this;
635 }
636
637 @Override
638 public <T,S> Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T,S> swapFunction, ThrowingFunction<S,T> unswapFunction) {
639 super.swap(normalClass, swappedClass, swapFunction, unswapFunction);
640 return this;
641 }
642
643 @Override
644 public Builder swaps(Class<?>...values) {
645 super.swaps(values);
646 return this;
647 }
648
649 @Override
650 public Builder swaps(Object...values) {
651 super.swaps(values);
652 return this;
653 }
654
655 @Override
656 public Builder timeZone(TimeZone value) {
657 super.timeZone(value);
658 return this;
659 }
660
661 @Override
662 public Builder type(Class<? extends org.apache.juneau.Context> value) {
663 super.type(value);
664 return this;
665 }
666
667 @Override
668 public Builder typeName(Class<?> on, String value) {
669 super.typeName(on, value);
670 return this;
671 }
672
673 @Override
674 public Builder typePropertyName(Class<?> on, String value) {
675 super.typePropertyName(on, value);
676 return this;
677 }
678
679 @Override
680 public Builder typePropertyName(String value) {
681 super.typePropertyName(value);
682 return this;
683 }
684
685 @Override
686 public Builder useEnumNames() {
687 super.useEnumNames();
688 return this;
689 }
690
691 @Override
692 public Builder useJavaBeanIntrospector() {
693 super.useJavaBeanIntrospector();
694 return this;
695 }
696 }
697
698 private final boolean detectRecursions;
699 private final boolean ignoreRecursions;
700 private final int initialDepth;
701 private final int maxDepth;
702 private final boolean actualDetectRecursions;
703
704
705
706
707
708
709 protected BeanTraverseContext(Builder builder) {
710 super(builder);
711
712 detectRecursions = builder.detectRecursions;
713 ignoreRecursions = builder.ignoreRecursions;
714 initialDepth = builder.initialDepth;
715 maxDepth = builder.maxDepth;
716
717 actualDetectRecursions = detectRecursions || ignoreRecursions || super.isDebug();
718 }
719
720 @Override
721 public abstract Builder copy();
722
723
724
725
726
727
728
729
730 public final int getInitialDepth() { return initialDepth; }
731
732
733
734
735
736
737
738
739
740 public final int getMaxDepth() { return maxDepth; }
741
742
743
744
745
746
747
748
749 public final boolean isDetectRecursions() { return actualDetectRecursions; }
750
751
752
753
754
755
756
757
758
759 public final boolean isIgnoreRecursions() { return ignoreRecursions; }
760
761
762
763
764
765
766 protected final boolean getDetectRecursions() { return detectRecursions; }
767
768
769
770
771
772
773 protected final boolean getIgnoreRecursions() { return ignoreRecursions; }
774
775 @Override
776 protected FluentMap<String,Object> properties() {
777 return super.properties()
778 .a("detectRecursions", detectRecursions)
779 .a("ignoreRecursions", ignoreRecursions)
780 .a("initialDepth", initialDepth)
781 .a("maxDepth", maxDepth);
782 }
783 }