1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.pattern;
15
16 import ch.qos.logback.core.Context;
17 import ch.qos.logback.core.spi.ContextAware;
18
19 public class ConverterUtil {
20
21
22
23
24
25
26 public static <E> void startConverters(Converter<E> head) {
27 Converter<E> c = head;
28 while (c != null) {
29
30 if (c instanceof CompositeConverter) {
31 CompositeConverter<E> cc = (CompositeConverter<E>) c;
32 Converter<E> childConverter = cc.childConverter;
33 startConverters(childConverter);
34 cc.start();
35 } else if (c instanceof DynamicConverter) {
36 DynamicConverter<E> dc = (DynamicConverter<E>) c;
37 dc.start();
38 }
39 c = c.getNext();
40 }
41 }
42
43 public static <E> Converter<E> findTail(Converter<E> head) {
44 Converter<E> p = head;
45 while (p != null) {
46 Converter<E> next = p.getNext();
47 if (next == null) {
48 break;
49 } else {
50 p = next;
51 }
52 }
53 return p;
54 }
55
56 public static <E> void setContextForConverters(Context context, Converter<E> head) {
57 Converter<E> c = head;
58 while (c != null) {
59 if (c instanceof ContextAware) {
60 ((ContextAware) c).setContext(context);
61 }
62 if (c instanceof CompositeConverter) {
63 CompositeConverter<E> cc = (CompositeConverter<E>) c;
64 Converter<E> childConverter = cc.childConverter;
65 setContextForConverters(context, childConverter);
66 }
67 c = c.getNext();
68 }
69 }
70 }