001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.log4j.lf5.viewer; 018 019import java.util.Arrays; 020import java.util.HashMap; 021import java.util.List; 022import java.util.Map; 023 024/** 025 * LogTableColumn 026 * 027 * @author Michael J. Sikorsky 028 * @author Brad Marlborough 029 */ 030 031// Contributed by ThoughtWorks Inc. 032 033public class LogTableColumn implements java.io.Serializable { 034 private static final long serialVersionUID = -4275827753626456547L; 035 036 // log4j table columns. 037 public final static LogTableColumn DATE = new LogTableColumn("Date"); 038 public final static LogTableColumn THREAD = new LogTableColumn("Thread"); 039 public final static LogTableColumn MESSAGE_NUM = new LogTableColumn("Message #"); 040 public final static LogTableColumn LEVEL = new LogTableColumn("Level"); 041 public final static LogTableColumn NDC = new LogTableColumn("NDC"); 042 public final static LogTableColumn CATEGORY = new LogTableColumn("Category"); 043 public final static LogTableColumn MESSAGE = new LogTableColumn("Message"); 044 public final static LogTableColumn LOCATION = new LogTableColumn("Location"); 045 public final static LogTableColumn THROWN = new LogTableColumn("Thrown"); 046 047 048 //-------------------------------------------------------------------------- 049 // Protected Variables: 050 //-------------------------------------------------------------------------- 051 protected String _label; 052 053 //-------------------------------------------------------------------------- 054 // Private Variables: 055 //-------------------------------------------------------------------------- 056 private static LogTableColumn[] _log4JColumns; 057 private static Map _logTableColumnMap; 058 059 //-------------------------------------------------------------------------- 060 // Constructors: 061 //-------------------------------------------------------------------------- 062 static { 063 _log4JColumns = new LogTableColumn[]{DATE, THREAD, MESSAGE_NUM, LEVEL, NDC, CATEGORY, 064 MESSAGE, LOCATION, THROWN}; 065 066 _logTableColumnMap = new HashMap(); 067 068 for (int i = 0; i < _log4JColumns.length; i++) { 069 _logTableColumnMap.put(_log4JColumns[i].getLabel(), _log4JColumns[i]); 070 } 071 } 072 073 074 public LogTableColumn(String label) { 075 _label = label; 076 } 077 078 //-------------------------------------------------------------------------- 079 // Public Methods: 080 //-------------------------------------------------------------------------- 081 082 /** 083 * Return the Label of the LogLevel. 084 */ 085 public String getLabel() { 086 return _label; 087 } 088 089 /** 090 * Convert a column label into a LogTableColumn object. 091 * 092 * @param column The label of a level to be converted into a LogTableColumn. 093 * @return LogTableColumn The LogTableColumn with a label equal to column. 094 * @throws LogTableColumnFormatException Is thrown when the column can not be 095 * converted into a LogTableColumn. 096 */ 097 public static LogTableColumn valueOf(String column) 098 throws LogTableColumnFormatException { 099 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