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 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 modelMap = new HashMap();
    57    private static final String LOGGER_FIELD = "LOGGER";
    58    private static final String LEVEL_FIELD = "LEVEL";
    59    private static final String CLASS_FIELD = "CLASS";
    60    private static final String FILE_FIELD = "FILE";
    61    private static final String THREAD_FIELD = "THREAD";
    62    private static final String METHOD_FIELD = "METHOD";
    63    private static final String PROP_FIELD = "PROP.";
    64    private static final String NDC_FIELD = "NDC";
    65
    66    public EventTypeEntryContainer() {
    67        modelMap.put(LOGGER_FIELD, loggerListModel);
    68        modelMap.put(LEVEL_FIELD, levelListModel);
    69        modelMap.put(CLASS_FIELD, classesListModel);
    70        modelMap.put(FILE_FIELD, fileNameListModel);
    71        modelMap.put(THREAD_FIELD, threadListModel);
    72        modelMap.put(METHOD_FIELD, methodListModel);
    73        modelMap.put(NDC_FIELD, ndcListModel);
    74        modelMap.put(PROP_FIELD, propListModel);
    75    }
    76
    77    public boolean modelExists(String fieldName) {
    78        if (fieldName != null) {
    79          return modelMap.keySet().contains(fieldName.toUpperCase());
    80        }
    81        return false;
    82    }
    83
    84    public ListModel getModel(String fieldName) {
    85        if (fieldName != null) {
    86            ListModel model = (ListModel)modelMap.get(fieldName.toUpperCase());
    87            if (model != null) {
    88                return model;
    89            }
    90        }
    91        return null;
    92    }
    93
    94    void addLevel(Object level) {
    95      if (Levels.add(level)) {
    96        levelListModel.addElement(level);
    97      }
    98    }
    99
    100   void addLogger(String logger) {
    101     if (Loggers.add(logger)) {
    102       loggerListModel.addElement(logger);
    103     }
    104   }
    105
    106   void addFileName(String filename) {
    107     if (FileNames.add(filename)) {
    108       fileNameListModel.addElement(filename);
    109     }
    110   }
    111
    112   void addThread(String thread) {
    113     if (Threads.add(thread)) {
    114       threadListModel.addElement(thread);
    115     }
    116   }
    117
    118   void addNDC(String ndc) {
    119     if (NDCs.add(ndc)) {
    120       ndcListModel.addElement(ndc);
    121     }
    122   }
    123
    124   void addColumnName(String name) {
    125     if (ColumnNames.add(name)) {
    126       columnNameListModel.addElement(name);
    127     }
    128   }
    129
    130   void addMethod(String method) {
    131     if (Methods.add(method)) {
    132       methodListModel.addElement(method);
    133     }
    134   }
    135
    136   void addClass(String className) {
    137     if (Classes.add(className)) {
    138       classesListModel.addElement(className);
    139     }
    140   }
    141
    142   void addProperties(Map properties) {
    143     if(properties == null) {
    144      return;
    145     }
    146         for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) {
    147             Map.Entry entry = (Map.Entry)iter.next();
    148             if (!(propListModel.contains(entry.getKey()))) {
    149                 propListModel.addElement(entry.getKey());
    150             }
    151         }
    152     }
    153 }