LogTableColumn xref

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  package org.apache.log4j.lf5.viewer;
    18
    19  import java.util.Arrays;
    20  import java.util.HashMap;
    21  import java.util.List;
    22  import java.util.Map;
    23
    24  /**
    25   * LogTableColumn
    26   *
    27   * @author Michael J. Sikorsky
    28   * @author Brad Marlborough
    29   */
    30
    31  // Contributed by ThoughtWorks Inc.
    32
    33  public class LogTableColumn implements java.io.Serializable {
    34    private static final long serialVersionUID = -4275827753626456547L;
    35
    36    // log4j table columns.
    37    public final static LogTableColumn DATE = new LogTableColumn("Date");
    38    public final static LogTableColumn THREAD = new LogTableColumn("Thread");
    39    public final static LogTableColumn MESSAGE_NUM = new LogTableColumn("Message #");
    40    public final static LogTableColumn LEVEL = new LogTableColumn("Level");
    41    public final static LogTableColumn NDC = new LogTableColumn("NDC");
    42    public final static LogTableColumn CATEGORY = new LogTableColumn("Category");
    43    public final static LogTableColumn MESSAGE = new LogTableColumn("Message");
    44    public final static LogTableColumn LOCATION = new LogTableColumn("Location");
    45    public final static LogTableColumn THROWN = new LogTableColumn("Thrown");
    46
    47
    48    //--------------------------------------------------------------------------
    49    //   Protected Variables:
    50    //--------------------------------------------------------------------------
    51    protected String _label;
    52
    53    //--------------------------------------------------------------------------
    54    //   Private Variables:
    55    //--------------------------------------------------------------------------
    56    private static LogTableColumn[] _log4JColumns;
    57    private static Map _logTableColumnMap;
    58
    59    //--------------------------------------------------------------------------
    60    //   Constructors:
    61    //--------------------------------------------------------------------------
    62    static {
    63      _log4JColumns = new LogTableColumn[]{DATE, THREAD, MESSAGE_NUM, LEVEL, NDC, CATEGORY,
    64                                           MESSAGE, LOCATION, THROWN};
    65
    66      _logTableColumnMap = new HashMap();
    67
    68      for (int i = 0; i < _log4JColumns.length; i++) {
    69        _logTableColumnMap.put(_log4JColumns[i].getLabel(), _log4JColumns[i]);
    70      }
    71    }
    72
    73
    74    public LogTableColumn(String label) {
    75      _label = label;
    76    }
    77
    78    //--------------------------------------------------------------------------
    79    //   Public Methods:
    80    //--------------------------------------------------------------------------
    81
    82    /**
    83     * Return the Label of the LogLevel.
    84     */
    85    public String getLabel() {
    86      return _label;
    87    }
    88
    89    /**
    90     * Convert a column label into a LogTableColumn object.
    91     *
    92     * @param column The label of a level to be converted into a LogTableColumn.
    93     * @return LogTableColumn The LogTableColumn with a label equal to column.
    94     * @throws LogTableColumnFormatException Is thrown when the column can not be
    95     *         converted into a LogTableColumn.
    96     */
    97    public static LogTableColumn valueOf(String column)
    98        throws LogTableColumnFormatException {
    99      LogTableColumn tableColumn = null;
    100     if (column != null) {
    101       column = column.trim();
    102       tableColumn = (LogTableColumn) _logTableColumnMap.get(column);
    103     }
    104
    105     if (tableColumn == null) {
    106       StringBuffer buf = new StringBuffer();
    107       buf.append("Error while trying to parse (" + column + ") into");
    108       buf.append(" a LogTableColumn.");
    109       throw new LogTableColumnFormatException(buf.toString());
    110     }
    111     return tableColumn;
    112   }
    113
    114
    115   public boolean equals(Object o) {
    116     boolean equals = false;
    117
    118     if (o instanceof LogTableColumn) {
    119       if (this.getLabel() ==
    120           ((LogTableColumn) o).getLabel()) {
    121         equals = true;
    122       }
    123     }
    124
    125     return equals;
    126   }
    127
    128   public int hashCode() {
    129     return _label.hashCode();
    130   }
    131
    132   public String toString() {
    133     return _label;
    134   }
    135
    136   /**
    137    * @return A <code>List</code> of <code>LogTableColumn/code> objects that map
    138    * to log4j <code>Column</code> objects.
    139    */
    140   public static List getLogTableColumns() {
    141     return Arrays.asList(_log4JColumns);
    142   }
    143
    144   public static LogTableColumn[] getLogTableColumnArray() {
    145     return _log4JColumns;
    146   }
    147
    148   //--------------------------------------------------------------------------
    149   //   Protected Methods:
    150   //--------------------------------------------------------------------------
    151
    152   //--------------------------------------------------------------------------
    153   //   Private Methods:
    154   //--------------------------------------------------------------------------
    155
    156   //--------------------------------------------------------------------------
    157   //   Nested Top-Level Classes or Interfaces:
    158   //--------------------------------------------------------------------------
    159
    160 }
    161
    162
    163
    164
    165
    166