1 /**
2 * LOGBack: the reliable, fast and flexible logging library for Java.
3 *
4 * Copyright (C) 1999-2005, QOS.ch, LOGBack.com
5 *
6 * This library is free software, you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation.
9 */
10 package ch.qos.logback.core.pattern;
11
12 /**
13 * A minimal converter which sets up the general interface for derived classes.
14 * It also implements the functionality to chain converters in a linked list.
15 *
16 * @author ceki
17 */
18 abstract public class Converter<E> {
19
20 Converter<E> next;
21
22 /**
23 * The convert method is responsible for extracting data from the event and
24 * storing it for later use by the write method.
25 *
26 * @param event
27 */
28 public abstract String convert(E event);
29
30 /**
31 * In its simplest incarnation, a convert simply appends the data extracted from
32 * the event to the buffer passed as parameter.
33 *
34 * @param buf The input buffer where data is appended
35 * @param event The event from where data is extracted
36 */
37 public void write(StringBuffer buf, E event) {
38 buf.append(convert(event));
39 }
40
41 public final void setNext(Converter<E> next) {
42 if (this.next != null) {
43 throw new IllegalStateException("Next converter has been already set");
44 }
45 this.next = next;
46 }
47
48 public final Converter<E> getNext() {
49 return next;
50 }
51 }