KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > lf5 > viewer > LogTableColumn


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;
17
18 import java.util.Arrays JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Map JavaDoc;
22
23 /**
24  * LogTableColumn
25  *
26  * @author Michael J. Sikorsky
27  * @author Brad Marlborough
28  */

29
30 // Contributed by ThoughtWorks Inc.
31

32 public class LogTableColumn implements java.io.Serializable JavaDoc {
33
34   // log4j table columns.
35
public final static LogTableColumn DATE = new LogTableColumn("Date");
36   public final static LogTableColumn THREAD = new LogTableColumn("Thread");
37   public final static LogTableColumn MESSAGE_NUM = new LogTableColumn("Message #");
38   public final static LogTableColumn LEVEL = new LogTableColumn("Level");
39   public final static LogTableColumn NDC = new LogTableColumn("NDC");
40   public final static LogTableColumn CATEGORY = new LogTableColumn("Category");
41   public final static LogTableColumn MESSAGE = new LogTableColumn("Message");
42   public final static LogTableColumn LOCATION = new LogTableColumn("Location");
43   public final static LogTableColumn THROWN = new LogTableColumn("Thrown");
44
45
46   //--------------------------------------------------------------------------
47
// Protected Variables:
48
//--------------------------------------------------------------------------
49
protected String JavaDoc _label;
50
51   //--------------------------------------------------------------------------
52
// Private Variables:
53
//--------------------------------------------------------------------------
54
private static LogTableColumn[] _log4JColumns;
55   private static Map JavaDoc _logTableColumnMap;
56
57   //--------------------------------------------------------------------------
58
// Constructors:
59
//--------------------------------------------------------------------------
60
static {
61     _log4JColumns = new LogTableColumn[]{DATE, THREAD, MESSAGE_NUM, LEVEL, NDC, CATEGORY,
62                                          MESSAGE, LOCATION, THROWN};
63
64     _logTableColumnMap = new HashMap JavaDoc();
65
66     for (int i = 0; i < _log4JColumns.length; i++) {
67       _logTableColumnMap.put(_log4JColumns[i].getLabel(), _log4JColumns[i]);
68     }
69   }
70
71
72   public LogTableColumn(String JavaDoc label) {
73     _label = label;
74   }
75
76   //--------------------------------------------------------------------------
77
// Public Methods:
78
//--------------------------------------------------------------------------
79

80   /**
81    * Return the Label of the LogLevel.
82    */

83   public String JavaDoc getLabel() {
84     return _label;
85   }
86
87   /**
88    * Convert a column label into a LogTableColumn object.
89    *
90    * @param level The label of a level to be converted into a LogTableColumn.
91    * @return LogTableColumn The LogTableColumn with a label equal to column.
92    * @throws LogTableColumnFormatException Is thrown when the column can not be
93    * converted into a LogTableColumn.
94    */

95   public static LogTableColumn valueOf(String JavaDoc column)
96       throws LogTableColumnFormatException {
97     LogTableColumn tableColumn = null;
98     if (column != null) {
99       column = column.trim();
100       tableColumn = (LogTableColumn) _logTableColumnMap.get(column);
101     }
102
103     if (tableColumn == null) {
104       StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
105       buf.append("Error while trying to parse (" + column + ") into");
106       buf.append(" a LogTableColumn.");
107       throw new LogTableColumnFormatException(buf.toString());
108     }
109     return tableColumn;
110   }
111
112
113   public boolean equals(Object JavaDoc o) {
114     boolean equals = false;
115
116     if (o instanceof LogTableColumn) {
117       if (this.getLabel() ==
118           ((LogTableColumn) o).getLabel()) {
119         equals = true;
120       }
121     }
122
123     return equals;
124   }
125
126   public int hashCode() {
127     return _label.hashCode();
128   }
129
130   public String JavaDoc toString() {
131     return _label;
132   }
133
134   /**
135    * @return A <code>List</code> of <code>LogTableColumn/code> objects that map
136    * to log4j <code>Column</code> objects.
137    */

138   public static List JavaDoc getLogTableColumns() {
139     return Arrays.asList(_log4JColumns);
140   }
141
142   public static LogTableColumn[] getLogTableColumnArray() {
143     return _log4JColumns;
144   }
145
146   //--------------------------------------------------------------------------
147
// Protected Methods:
148
//--------------------------------------------------------------------------
149

150   //--------------------------------------------------------------------------
151
// Private Methods:
152
//--------------------------------------------------------------------------
153

154   //--------------------------------------------------------------------------
155
// Nested Top-Level Classes or Interfaces:
156
//--------------------------------------------------------------------------
157

158 }
159
160
161
162
163
164
165
Popular Tags