View Javadoc

1   /*
2    * Copyright 2006-2008 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.osgi.extender.internal.activator;
18  
19  import java.util.Iterator;
20  import java.util.List;
21  
22  import org.springframework.osgi.context.event.OsgiBundleApplicationContextEvent;
23  import org.springframework.osgi.context.event.OsgiBundleApplicationContextListener;
24  import org.springframework.util.Assert;
25  
26  /**
27   * Listener interface that delegates to a list of listener. This is useful in
28   * OSGi environments when dealing with dynamic collections which can be updated
29   * during iteration.
30   * 
31   * @author Costin Leau
32   * 
33   */
34  class ListListenerAdapter implements OsgiBundleApplicationContextListener {
35  
36  	private final List listeners;
37  
38  
39  	/**
40  	 * Constructs a new <code>ListListenerAdapter</code> instance.
41  	 * 
42  	 * @param listeners
43  	 */
44  	public ListListenerAdapter(List listeners) {
45  		Assert.notNull(listeners);
46  		this.listeners = listeners;
47  	}
48  
49  	public void onOsgiApplicationEvent(OsgiBundleApplicationContextEvent event) {
50  		for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
51  			OsgiBundleApplicationContextListener osgiListener = (OsgiBundleApplicationContextListener) iterator.next();
52  			osgiListener.onOsgiApplicationEvent(event);
53  		}
54  	}
55  }