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;
18  
19  import org.osgi.framework.Bundle;
20  import org.osgi.framework.BundleContext;
21  import org.springframework.context.ConfigurableApplicationContext;
22  
23  /**
24   * Interface that extends <code>ConfigurableApplicationContext</code> to
25   * provides OSGi specific functionality.
26   * 
27   * <p>
28   * <strong>Note:</strong> Just like its ancestors,the setters of this interface
29   * should be called before <code>refresh</code>ing the
30   * <code>ApplicationContext</code>
31   * 
32   * @author Costin Leau
33   */
34  public interface ConfigurableOsgiBundleApplicationContext extends ConfigurableApplicationContext {
35  
36  	/**
37  	 * Service entry used for specifying the application context name when
38  	 * published as an OSGi service
39  	 */
40  	static final String APPLICATION_CONTEXT_SERVICE_PROPERTY_NAME = "org.springframework.context.service.name";
41  
42  	/**
43  	 * Name of the bundle context bean
44  	 */
45  	static final String BUNDLE_CONTEXT_BEAN_NAME = "bundleContext";
46  
47  	/**
48  	 * Name of the bundle bean
49  	 */
50  	static final String BUNDLE_BEAN_NAME = "bundle";
51  
52  
53  	/**
54  	 * Sets the config locations for this OSGi bundle application context. If
55  	 * not set, the implementation is supposed to use a default for the given
56  	 * bundle.
57  	 * 
58  	 * @param configLocations array of configuration locations
59  	 */
60  	void setConfigLocations(String[] configLocations);
61  
62  	/**
63  	 * Sets the <code>BundleContext</code> used by this OSGi bundle
64  	 * application context. Normally it's the <code>BundleContext</code> in
65  	 * which the context runs.
66  	 * 
67  	 * <p>
68  	 * Does not cause an initialization of the context: {@link #refresh()} needs
69  	 * to be called after the setting of all configuration properties.
70  	 * 
71  	 * @param bundleContext the <code>BundleContext</code> used by this
72  	 * application context.
73  	 * @see #refresh()
74  	 */
75  	void setBundleContext(BundleContext bundleContext);
76  
77  	/**
78  	 * Return the <code>BundleContext</code> for this application context.
79  	 * This method is offered as a helper since as of OSGi 4.1, the bundle
80  	 * context can be discovered directly from the given bundle.
81  	 * 
82  	 * @return the <code>BundleContext</code> in which this application
83  	 * context runs
84  	 * 
85  	 * @see #getBundle()
86  	 */
87  	BundleContext getBundleContext();
88  
89  	/**
90  	 * Returns the OSGi <code>Bundle</code> for this application context.
91  	 * 
92  	 * @return the <code>Bundle</code> for this OSGi bundle application
93  	 * context.
94  	 */
95  	Bundle getBundle();
96  
97  	/**
98  	 * Indicates whether this application context should be publish as an OSGi
99  	 * service if successfully started. By default, this is set to
100 	 * <code>true</code>.
101 	 * 
102 	 * @param publishContextAsService true if the application context should be
103 	 * published as a service, false otherwise
104 	 */
105 	void setPublishContextAsService(boolean publishContextAsService);
106 }