KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jms > connection > ChainedExceptionListener


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22
23 import javax.jms.ExceptionListener JavaDoc;
24 import javax.jms.JMSException JavaDoc;
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 JavaDoc {
36
37     /** List of ExceptionListeners */
38     private final List JavaDoc delegates = new ArrayList JavaDoc(2);
39
40
41     /**
42      * Add an ExceptionListener to the chained delegate list.
43      */

44     public final void addDelegate(ExceptionListener JavaDoc listener) {
45         Assert.notNull(listener, "ExceptionListener must not be null");
46         this.delegates.add(listener);
47     }
48
49     /**
50      * Return all registered ExceptionListener delegates (as array).
51      */

52     public final ExceptionListener JavaDoc[] getDelegates() {
53         return (ExceptionListener JavaDoc[]) this.delegates.toArray(new ExceptionListener JavaDoc[this.delegates.size()]);
54     }
55
56
57     public void onException(JMSException JavaDoc ex) {
58         for (Iterator JavaDoc it = this.delegates.iterator(); it.hasNext();) {
59             ExceptionListener JavaDoc listener = (ExceptionListener JavaDoc) it.next();
60             listener.onException(ex);
61         }
62     }
63
64 }
65
Popular Tags