001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.core.pattern;
015
016abstract public class CompositeConverter<E> extends DynamicConverter<E> {
017
018    Converter<E> childConverter;
019
020    public String convert(E event) {
021        StringBuilder buf = new StringBuilder();
022
023        for (Converter<E> c = childConverter; c != null; c = c.next) {
024            c.write(buf, event);
025        }
026        String intermediary = buf.toString();
027        return transform(event, intermediary);
028    }
029
030    abstract protected String transform(E event, String in);
031
032    public Converter<E> getChildConverter() {
033        return childConverter;
034    }
035
036    public void setChildConverter(Converter<E> child) {
037        childConverter = child;
038    }
039
040    public String toString() {
041        StringBuilder buf = new StringBuilder();
042        buf.append("CompositeConverter<");
043
044        if (formattingInfo != null)
045            buf.append(formattingInfo);
046
047        if (childConverter != null) {
048            buf.append(", children: ").append(childConverter);
049        }
050        buf.append(">");
051        return buf.toString();
052    }
053}