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 java.util.HashMap;
23 import java.util.HashSet;
24 import java.util.Iterator;
25 import java.util.Map;
26 import java.util.Set;
27
28 import javax.swing.DefaultListModel;
29 import javax.swing.ListModel;
30
31 /***
32 * A Container class used to hold unique LoggingEvent values
33 * and provide them as unique ListModels.
34 *
35 * @author Paul Smith
36 *
37 */
38 public class EventTypeEntryContainer {
39 private Set ColumnNames = new HashSet();
40 private Set Methods = new HashSet();
41 private Set Classes = new HashSet();
42 private Set NDCs = new HashSet();
43 private Set Levels = new HashSet();
44 private Set Loggers = new HashSet();
45 private Set Threads = new HashSet();
46 private Set FileNames = new HashSet();
47 private DefaultListModel columnNameListModel = new DefaultListModel();
48 private DefaultListModel methodListModel = new DefaultListModel();
49 private DefaultListModel classesListModel = new DefaultListModel();
50 private DefaultListModel propListModel = new DefaultListModel();
51 private DefaultListModel ndcListModel = new DefaultListModel();
52 private DefaultListModel levelListModel = new DefaultListModel();
53 private DefaultListModel loggerListModel = new DefaultListModel();
54 private DefaultListModel threadListModel = new DefaultListModel();
55 private DefaultListModel fileNameListModel = new DefaultListModel();
56 private Map propertiesListModelMap = new HashMap();
57 private Map modelMap = new HashMap();
58 private static final String LOGGER_FIELD = "LOGGER";
59 private static final String LEVEL_FIELD = "LEVEL";
60 private static final String CLASS_FIELD = "CLASS";
61 private static final String FILE_FIELD = "FILE";
62 private static final String THREAD_FIELD = "THREAD";
63 private static final String METHOD_FIELD = "METHOD";
64 private static final String PROP_FIELD = "PROP.";
65 private static final String NDC_FIELD = "NDC";
66
67 public EventTypeEntryContainer() {
68 modelMap.put(LOGGER_FIELD, loggerListModel);
69 modelMap.put(LEVEL_FIELD, levelListModel);
70 modelMap.put(CLASS_FIELD, classesListModel);
71 modelMap.put(FILE_FIELD, fileNameListModel);
72 modelMap.put(THREAD_FIELD, threadListModel);
73 modelMap.put(METHOD_FIELD, methodListModel);
74 modelMap.put(NDC_FIELD, ndcListModel);
75 modelMap.put(PROP_FIELD, propListModel);
76 }
77
78 public boolean modelExists(String fieldName) {
79 if (fieldName != null) {
80 return (fieldName.toUpperCase().startsWith(PROP_FIELD) || modelMap.keySet().contains(fieldName.toUpperCase()));
81 }
82 return false;
83 }
84
85 public ListModel getModel(String fieldName) {
86 if (fieldName != null) {
87 ListModel model = (ListModel)modelMap.get(fieldName.toUpperCase());
88 if (model != null) {
89 return model;
90 }
91
92 if (fieldName.startsWith(PROP_FIELD)) {
93 fieldName = fieldName.substring(PROP_FIELD.length());
94 if ((fieldName.startsWith("'")) && (fieldName.endsWith("'"))) {
95 fieldName = fieldName.substring(1, fieldName.length() - 1);
96 }
97 }
98 return (ListModel)propertiesListModelMap.get(fieldName);
99 }
100 return null;
101 }
102
103 void addLevel(Object level) {
104 if (Levels.add(level)) {
105 levelListModel.addElement(level);
106 }
107 }
108
109 void addLogger(String logger) {
110 if (Loggers.add(logger)) {
111 loggerListModel.addElement(logger);
112 }
113 }
114
115 void addFileName(String filename) {
116 if (FileNames.add(filename)) {
117 fileNameListModel.addElement(filename);
118 }
119 }
120
121 void addThread(String thread) {
122 if (Threads.add(thread)) {
123 threadListModel.addElement(thread);
124 }
125 }
126
127 void addNDC(String ndc) {
128 if (NDCs.add(ndc)) {
129 ndcListModel.addElement(ndc);
130 }
131 }
132
133 void addColumnName(String name) {
134 if (ColumnNames.add(name)) {
135 columnNameListModel.addElement(name);
136 }
137 }
138
139 void addMethod(String method) {
140 if (Methods.add(method)) {
141 methodListModel.addElement(method);
142 }
143 }
144
145 void addClass(String className) {
146 if (Classes.add(className)) {
147 classesListModel.addElement(className);
148 }
149 }
150
151 void addProperties(Map properties) {
152 if(properties == null) {
153 return;
154 }
155 for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) {
156 Map.Entry entry = (Map.Entry)iter.next();
157 if (!(propListModel.contains(entry.getKey()))) {
158 propListModel.addElement(entry.getKey());
159 }
160 DefaultListModel model = (DefaultListModel)propertiesListModelMap.get(entry.getKey());
161 if (model == null) {
162 model = new DefaultListModel();
163 propertiesListModelMap.put(entry.getKey(), model);
164 }
165 if (!(model.contains(entry.getValue()))) {
166 model.addElement(entry.getValue());
167 }
168 }
169 }
170 }