1 package ch.qos.logback.core.joran.replay;
2
3 import java.util.List;
4
5 import ch.qos.logback.core.Context;
6 import ch.qos.logback.core.ContextBase;
7 import ch.qos.logback.core.joran.event.SaxEvent;
8 import ch.qos.logback.core.joran.spi.JoranException;
9
10 public class FruitFactory {
11
12 static int count = 0;
13
14 private List<SaxEvent> eventList;
15 Fruit fruit;
16
17 public void setFruit(Fruit fruit) {
18 this.fruit = fruit;
19 }
20
21 public Fruit buildFruit() {
22
23 Context context = new ContextBase();
24 this.fruit = null;
25 context.putProperty("fruitKey", "orange-"+count);
26
27 count++;
28 FruitConfigurator fruitConfigurator = new FruitConfigurator(this);
29 fruitConfigurator.setContext(context);
30 try {
31 fruitConfigurator.doConfigure(eventList);
32 } catch(JoranException je) {
33 je.printStackTrace();
34 }
35 return fruit;
36 }
37
38 public String toString() {
39 final String TAB = " ";
40
41 StringBuilder retValue = new StringBuilder();
42
43 retValue.append("FruitFactory ( ");
44 if (eventList != null && eventList.size() > 0) {
45 retValue.append("event1 = ").append(eventList.get(0)).append(TAB);
46 }
47 retValue.append(" )");
48
49 return retValue.toString();
50 }
51
52 public void setEventList(List<SaxEvent> eventList) {
53 this.eventList = eventList;
54 }
55
56 }