2 * Copyright 2005-2011 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.xmlrouter.listener;
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
24 import javax.print.attribute.standard.Destination;
26 import org.wamblee.concurrency.ReadLock;
27 import org.wamblee.concurrency.WriteLock;
28 import org.wamblee.xmlrouter.common.Id;
29 import org.wamblee.xmlrouter.config.Transformation;
31 public class CompositeEventListener implements EventListener {
33 private static final Logger LOGGER = Logger
34 .getLogger(CompositeEventListener.class.getName());
35 private List<EventListener> loggers;
37 public CompositeEventListener() {
38 loggers = new ArrayList<EventListener>();
48 public void addListener(EventListener aLogger) {
57 * @return True iff the logger was removed.
60 public boolean removeListener(EventListener aLogger) {
61 Iterator<EventListener> logger = loggers.iterator();
62 while (logger.hasNext()) {
63 EventListener value = logger.next();
64 if (value == aLogger) {
74 public void delivered(EventInfo aInfo, List<Transformation> aSequence,
75 Id<Destination> aDestination, String aDestinationName,
76 boolean aSuccessFlag) {
77 for (EventListener logger : loggers) {
79 logger.delivered(aInfo, aSequence, aDestination,
80 aDestinationName, aSuccessFlag);
81 } catch (Exception e) {
82 LOGGER.log(Level.WARNING, "Logger threw exception", e);
89 public void notDelivered(EventInfo aInfo) {
90 for (EventListener logger : loggers) {
92 logger.notDelivered(aInfo);
93 } catch (Exception e) {
94 LOGGER.log(Level.WARNING, "Logger threw exception", e);