KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > lf5 > viewer > categoryexplorer > CategoryExplorerLogRecordFilter


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.log4j.lf5.viewer.categoryexplorer;
17
18 import org.apache.log4j.lf5.LogRecord;
19 import org.apache.log4j.lf5.LogRecordFilter;
20
21 import java.util.Enumeration JavaDoc;
22
23 /**
24  * An implementation of LogRecordFilter based on a CategoryExplorerModel
25  *
26  * @author Richard Wan
27  */

28
29 // Contributed by ThoughtWorks Inc.
30

31 public class CategoryExplorerLogRecordFilter implements LogRecordFilter {
32   //--------------------------------------------------------------------------
33
// Constants:
34
//--------------------------------------------------------------------------
35

36   //--------------------------------------------------------------------------
37
// Protected Variables:
38
//--------------------------------------------------------------------------
39

40   protected CategoryExplorerModel _model;
41
42   //--------------------------------------------------------------------------
43
// Private Variables:
44
//--------------------------------------------------------------------------
45

46   //--------------------------------------------------------------------------
47
// Constructors:
48
//--------------------------------------------------------------------------
49

50   public CategoryExplorerLogRecordFilter(CategoryExplorerModel model) {
51     _model = model;
52   }
53
54   //--------------------------------------------------------------------------
55
// Public Methods:
56
//--------------------------------------------------------------------------
57

58   /**
59    * @return true if the CategoryExplorer model specified at construction
60    * is accepting the category of the specified LogRecord. Has a side-effect
61    * of adding the CategoryPath of the LogRecord to the explorer model
62    * if the CategoryPath is new.
63    */

64   public boolean passes(LogRecord record) {
65     CategoryPath path = new CategoryPath(record.getCategory());
66     return _model.isCategoryPathActive(path);
67   }
68
69   /**
70    * Resets the counters for the contained CategoryNodes to zero.
71    */

72   public void reset() {
73     resetAllNodes();
74   }
75
76   //--------------------------------------------------------------------------
77
// Protected Methods:
78
//--------------------------------------------------------------------------
79

80   protected void resetAllNodes() {
81     Enumeration JavaDoc nodes = _model.getRootCategoryNode().depthFirstEnumeration();
82     CategoryNode current;
83     while (nodes.hasMoreElements()) {
84       current = (CategoryNode) nodes.nextElement();
85       current.resetNumberOfContainedRecords();
86       _model.nodeChanged(current);
87     }
88   }
89   //--------------------------------------------------------------------------
90
// Private Methods:
91
//--------------------------------------------------------------------------
92

93   //--------------------------------------------------------------------------
94
// Nested Top-Level Classes or Interfaces
95
//--------------------------------------------------------------------------
96
}
97
98
Popular Tags