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.ArrayList; 017import java.util.List; 018 019import org.xml.sax.Attributes; 020 021import ch.qos.logback.core.joran.action.Action; 022import ch.qos.logback.core.joran.event.InPlayListener; 023import ch.qos.logback.core.joran.event.SaxEvent; 024import ch.qos.logback.core.joran.spi.ActionException; 025import ch.qos.logback.core.joran.spi.InterpretationContext; 026 027public class FruitFactoryAction extends Action implements InPlayListener { 028 029 List<SaxEvent> seList = new ArrayList<SaxEvent>(); 030 031 @Override 032 public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { 033 ec.addInPlayListener(this); 034 } 035 036 @Override 037 public void end(InterpretationContext ec, String name) throws ActionException { 038 ec.removeInPlayListener(this); 039 040 Object o = ec.peekObject(); 041 if (o instanceof FruitShell) { 042 FruitShell fs = (FruitShell) o; 043 FruitFactory fruitFactory = new FruitFactory(); 044 fruitFactory.setEventList(new ArrayList<SaxEvent>(seList)); 045 fs.setFruitFactory(fruitFactory); 046 } 047 } 048 049 public void inPlay(SaxEvent event) { 050 seList.add(event); 051 } 052 053 public List<SaxEvent> getSeList() { 054 return seList; 055 } 056 057}