1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.log4j.chainsaw.filter;
21
22 import javax.swing.*;
23 import java.util.HashMap;
24 import java.util.HashSet;
25 import java.util.Map;
26 import java.util.Set;
27
28
29
30
31
32
33
34 public class EventTypeEntryContainer {
35 private Set<String> ColumnNames = new HashSet<>();
36 private Set<String> Methods = new HashSet<>();
37 private Set<String> Classes = new HashSet<>();
38 private Set<String> NDCs = new HashSet<>();
39 private Set Levels = new HashSet();
40 private Set<String> Loggers = new HashSet<>();
41 private Set<String> Threads = new HashSet<>();
42 private Set<String> FileNames = new HashSet<>();
43 private DefaultListModel<String> columnNameListModel = new DefaultListModel<>();
44 private DefaultListModel methodListModel = new DefaultListModel();
45 private DefaultListModel classesListModel = new DefaultListModel();
46 private DefaultListModel propListModel = new DefaultListModel();
47 private DefaultListModel ndcListModel = new DefaultListModel();
48 private DefaultListModel levelListModel = new DefaultListModel();
49 private DefaultListModel loggerListModel = new DefaultListModel();
50 private DefaultListModel threadListModel = new DefaultListModel();
51 private DefaultListModel fileNameListModel = new DefaultListModel();
52 private Map modelMap = new HashMap();
53 private static final String LOGGER_FIELD = "LOGGER";
54 private static final String LEVEL_FIELD = "LEVEL";
55 private static final String CLASS_FIELD = "CLASS";
56 private static final String FILE_FIELD = "FILE";
57 private static final String THREAD_FIELD = "THREAD";
58 private static final String METHOD_FIELD = "METHOD";
59 private static final String PROP_FIELD = "PROP.";
60 private static final String NDC_FIELD = "NDC";
61
62 public EventTypeEntryContainer() {
63 modelMap.put(LOGGER_FIELD, loggerListModel);
64 modelMap.put(LEVEL_FIELD, levelListModel);
65 modelMap.put(CLASS_FIELD, classesListModel);
66 modelMap.put(FILE_FIELD, fileNameListModel);
67 modelMap.put(THREAD_FIELD, threadListModel);
68 modelMap.put(METHOD_FIELD, methodListModel);
69 modelMap.put(NDC_FIELD, ndcListModel);
70 modelMap.put(PROP_FIELD, propListModel);
71 }
72
73 public boolean modelExists(String fieldName) {
74 return fieldName != null && modelMap.keySet().contains(fieldName.toUpperCase());
75 }
76
77 public ListModel getModel(String fieldName) {
78 if (fieldName != null) {
79 ListModel model = (ListModel) modelMap.get(fieldName.toUpperCase());
80 if (model != null) {
81 return model;
82 }
83 }
84 return null;
85 }
86
87 void addLevel(Object level) {
88 if (Levels.add(level)) {
89 levelListModel.addElement(level);
90 }
91 }
92
93 void addLogger(String logger) {
94 if (Loggers.add(logger)) {
95 loggerListModel.addElement(logger);
96 }
97 }
98
99 void addFileName(String filename) {
100 if (FileNames.add(filename)) {
101 fileNameListModel.addElement(filename);
102 }
103 }
104
105 void addThread(String thread) {
106 if (Threads.add(thread)) {
107 threadListModel.addElement(thread);
108 }
109 }
110
111 void addNDC(String ndc) {
112 if (NDCs.add(ndc)) {
113 ndcListModel.addElement(ndc);
114 }
115 }
116
117 void addColumnName(String name) {
118 if (ColumnNames.add(name)) {
119 columnNameListModel.addElement(name);
120 }
121 }
122
123 void addMethod(String method) {
124 if (Methods.add(method)) {
125 methodListModel.addElement(method);
126 }
127 }
128
129 void addClass(String className) {
130 if (Classes.add(className)) {
131 classesListModel.addElement(className);
132 }
133 }
134
135 void addProperties(Map properties) {
136 if (properties == null) {
137 return;
138 }
139 for (Object o : properties.entrySet()) {
140 Map.Entry entry = (Map.Entry) o;
141 if (!(propListModel.contains(entry.getKey()))) {
142 propListModel.addElement(entry.getKey());
143 }
144 }
145 }
146 }