View Javadoc

1   /*
2    * Copyright 2006-2009 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.context.event;
18  
19  import org.osgi.framework.Bundle;
20  import org.springframework.context.ApplicationContext;
21  import org.springframework.context.event.ApplicationContextEvent;
22  import org.springframework.osgi.context.ConfigurableOsgiBundleApplicationContext;
23  import org.springframework.util.Assert;
24  
25  /**
26   * Base class for events raised for an <code>ApplicationContext</code> created
27   * inside an OSGi environment. Normally, events of this type are raised by the
28   * OSGi extender to notify 3rd parties, external to the context, about changes
29   * in the life cycle of the application context.
30   * 
31   * <p/><b>Note:</b>While the context source is likely to be an implementation
32   * of {@link ConfigurableOsgiBundleApplicationContext}, this is not mandatory
33   * (it's entirely possible to have a non-OSGi aware {@link ApplicationContext}
34   * implementation).
35   * 
36   * @author Costin Leau
37   */
38  public abstract class OsgiBundleApplicationContextEvent extends ApplicationContextEvent {
39  
40  	private final Bundle bundle;
41  
42  
43  	/**
44  	 * Constructs a new <code>OsgiApplicationContextEvent</code> instance.
45  	 * 
46  	 * @param source the <code>ConfigurableOsgiBundleApplicationContext</code>
47  	 * that the event is raised for (must not be <code>null</code>)
48  	 */
49  	public OsgiBundleApplicationContextEvent(ApplicationContext source, Bundle bundle) {
50  		super(source);
51  		Assert.notNull(bundle);
52  		this.bundle = bundle;
53  	}
54  
55  	/**
56  	 * Returns the OSGi {@link Bundle} associated with the application context
57  	 * that triggers the event.
58  	 * 
59  	 * @return associated OSGi bundle
60  	 */
61  	public Bundle getBundle() {
62  		return bundle;
63  	}
64  }