PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/apache-log4j-1.2.17/src/main/java/org/apache/log4j/lf5/viewer/categoryexplorer/CategoryExplorerLogRecordFilter.java

#
Java | 98 lines | 26 code | 17 blank | 55 comment | 1 complexity | db86a5df2a056f885e019166fe0d453a MD5 | raw file
Possible License(s): Apache-2.0
  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. package org.apache.log4j.lf5.viewer.categoryexplorer;
  18. import org.apache.log4j.lf5.LogRecord;
  19. import org.apache.log4j.lf5.LogRecordFilter;
  20. import java.util.Enumeration;
  21. /**
  22. * An implementation of LogRecordFilter based on a CategoryExplorerModel
  23. *
  24. * @author Richard Wan
  25. */
  26. // Contributed by ThoughtWorks Inc.
  27. public class CategoryExplorerLogRecordFilter implements LogRecordFilter {
  28. //--------------------------------------------------------------------------
  29. // Constants:
  30. //--------------------------------------------------------------------------
  31. //--------------------------------------------------------------------------
  32. // Protected Variables:
  33. //--------------------------------------------------------------------------
  34. protected CategoryExplorerModel _model;
  35. //--------------------------------------------------------------------------
  36. // Private Variables:
  37. //--------------------------------------------------------------------------
  38. //--------------------------------------------------------------------------
  39. // Constructors:
  40. //--------------------------------------------------------------------------
  41. public CategoryExplorerLogRecordFilter(CategoryExplorerModel model) {
  42. _model = model;
  43. }
  44. //--------------------------------------------------------------------------
  45. // Public Methods:
  46. //--------------------------------------------------------------------------
  47. /**
  48. * @return true if the CategoryExplorer model specified at construction
  49. * is accepting the category of the specified LogRecord. Has a side-effect
  50. * of adding the CategoryPath of the LogRecord to the explorer model
  51. * if the CategoryPath is new.
  52. */
  53. public boolean passes(LogRecord record) {
  54. CategoryPath path = new CategoryPath(record.getCategory());
  55. return _model.isCategoryPathActive(path);
  56. }
  57. /**
  58. * Resets the counters for the contained CategoryNodes to zero.
  59. */
  60. public void reset() {
  61. resetAllNodes();
  62. }
  63. //--------------------------------------------------------------------------
  64. // Protected Methods:
  65. //--------------------------------------------------------------------------
  66. protected void resetAllNodes() {
  67. Enumeration nodes = _model.getRootCategoryNode().depthFirstEnumeration();
  68. CategoryNode current;
  69. while (nodes.hasMoreElements()) {
  70. current = (CategoryNode) nodes.nextElement();
  71. current.resetNumberOfContainedRecords();
  72. _model.nodeChanged(current);
  73. }
  74. }
  75. //--------------------------------------------------------------------------
  76. // Private Methods:
  77. //--------------------------------------------------------------------------
  78. //--------------------------------------------------------------------------
  79. // Nested Top-Level Classes or Interfaces
  80. //--------------------------------------------------------------------------
  81. }