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.joran.replay;
015
016import java.util.List;
017
018import ch.qos.logback.core.Context;
019import ch.qos.logback.core.ContextBase;
020import ch.qos.logback.core.joran.event.SaxEvent;
021import ch.qos.logback.core.joran.spi.JoranException;
022
023public class FruitFactory {
024
025    static int count = 0;
026
027    private List<SaxEvent> eventList;
028    Fruit fruit;
029
030    public void setFruit(Fruit fruit) {
031        this.fruit = fruit;
032    }
033
034    public Fruit buildFruit() {
035
036        Context context = new ContextBase();
037        this.fruit = null;
038        context.putProperty("fruitKey", "orange-" + count);
039        // for next round
040        count++;
041        FruitConfigurator fruitConfigurator = new FruitConfigurator(this);
042        fruitConfigurator.setContext(context);
043        try {
044            fruitConfigurator.doConfigure(eventList);
045        } catch (JoranException je) {
046            je.printStackTrace();
047        }
048        return fruit;
049    }
050
051    public String toString() {
052        final String TAB = " ";
053
054        StringBuilder retValue = new StringBuilder();
055
056        retValue.append("FruitFactory ( ");
057        if (eventList != null && eventList.size() > 0) {
058            retValue.append("event1 = ").append(eventList.get(0)).append(TAB);
059        }
060        retValue.append(" )");
061
062        return retValue.toString();
063    }
064
065    public void setEventList(List<SaxEvent> eventList) {
066        this.eventList = eventList;
067    }
068
069}