View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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   * A Container class used to hold unique LoggingEvent values
30   * and provide them as unique ListModels.
31   *
32   * @author Paul Smith
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 }