01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.
15: */
16:
17: package org.springframework.jms.connection;
18:
19: import java.util.ArrayList;
20: import java.util.Iterator;
21: import java.util.List;
22:
23: import javax.jms.ExceptionListener;
24: import javax.jms.JMSException;
25:
26: import org.springframework.util.Assert;
27:
28: /**
29: * Implementation of the JMS ExceptionListener interface that supports chaining,
30: * allowing the addition of multiple ExceptionListener instances in order.
31: *
32: * @author Juergen Hoeller
33: * @since 2.0
34: */
35: public class ChainedExceptionListener implements ExceptionListener {
36:
37: /** List of ExceptionListeners */
38: private final List delegates = new ArrayList(2);
39:
40: /**
41: * Add an ExceptionListener to the chained delegate list.
42: */
43: public final void addDelegate(ExceptionListener listener) {
44: Assert.notNull(listener, "ExceptionListener must not be null");
45: this .delegates.add(listener);
46: }
47:
48: /**
49: * Return all registered ExceptionListener delegates (as array).
50: */
51: public final ExceptionListener[] getDelegates() {
52: return (ExceptionListener[]) this .delegates
53: .toArray(new ExceptionListener[this .delegates.size()]);
54: }
55:
56: public void onException(JMSException ex) {
57: for (Iterator it = this .delegates.iterator(); it.hasNext();) {
58: ExceptionListener listener = (ExceptionListener) it.next();
59: listener.onException(ex);
60: }
61: }
62:
63: }
|