View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.joran.replay;
15  
16  import java.util.List;
17  
18  import ch.qos.logback.core.Context;
19  import ch.qos.logback.core.ContextBase;
20  import ch.qos.logback.core.joran.event.SaxEvent;
21  import ch.qos.logback.core.joran.spi.JoranException;
22  
23  public class FruitFactory {
24  
25      static int count = 0;
26  
27      private List<SaxEvent> eventList;
28      Fruit fruit;
29  
30      public void setFruit(Fruit fruit) {
31          this.fruit = fruit;
32      }
33  
34      public Fruit buildFruit() {
35  
36          Context context = new ContextBase();
37          this.fruit = null;
38          context.putProperty("fruitKey", "orange-" + count);
39          // for next round
40          count++;
41          FruitConfigurator fruitConfigurator = new FruitConfigurator(this);
42          fruitConfigurator.setContext(context);
43          try {
44              fruitConfigurator.doConfigure(eventList);
45          } catch (JoranException je) {
46              je.printStackTrace();
47          }
48          return fruit;
49      }
50  
51      public String toString() {
52          final String TAB = " ";
53  
54          StringBuilder retValue = new StringBuilder();
55  
56          retValue.append("FruitFactory ( ");
57          if (eventList != null && eventList.size() > 0) {
58              retValue.append("event1 = ").append(eventList.get(0)).append(TAB);
59          }
60          retValue.append(" )");
61  
62          return retValue.toString();
63      }
64  
65      public void setEventList(List<SaxEvent> eventList) {
66          this.eventList = eventList;
67      }
68  
69  }