1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.joran.spi;
15
16 import java.util.HashMap;
17 import java.util.Map;
18
19
20
21
22
23
24
25 public class DefaultNestedComponentRegistry {
26
27 Map<HostClassAndPropertyDouble, Class<?>> defaultComponentMap = new HashMap<HostClassAndPropertyDouble, Class<?>>();
28 Map<String, Class<?>> tagToClassMap = new HashMap<>();
29
30
31 public void duplicate(DefaultNestedComponentRegistry other) {
32 this.defaultComponentMap.putAll(other.defaultComponentMap);
33 this.tagToClassMap.putAll(other.tagToClassMap);
34 }
35
36 public void add(Class<?> hostClass, String propertyName, Class<?> componentClass) {
37 HostClassAndPropertyDouble hpDouble = new HostClassAndPropertyDouble(hostClass, propertyName.toLowerCase());
38 defaultComponentMap.put(hpDouble, componentClass);
39 tagToClassMap.put(propertyName, componentClass);
40 }
41
42
43
44 public String findDefaultComponentTypeByTag(String tagName) {
45 Class<?> defaultClass = tagToClassMap.get(tagName);
46 if (defaultClass == null)
47 return null;
48 else
49 return defaultClass.getCanonicalName();
50 }
51
52 public Class<?> findDefaultComponentType(Class<?> hostClass, String propertyName) {
53 propertyName = propertyName.toLowerCase();
54 while (hostClass != null) {
55 Class<?> componentClass = oneShotFind(hostClass, propertyName);
56 if (componentClass != null) {
57 return componentClass;
58 }
59 hostClass = hostClass.getSuperclass();
60 }
61 return null;
62 }
63
64 private Class<?> oneShotFind(Class<?> hostClass, String propertyName) {
65 HostClassAndPropertyDouble hpDouble = new HostClassAndPropertyDouble(hostClass, propertyName);
66 return defaultComponentMap.get(hpDouble);
67 }
68
69
70
71 }