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.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 * Bean name under which the OSGi bundle context is published as a 44 * singleton. 45 */ 46 static final String BUNDLE_CONTEXT_BEAN_NAME = "bundleContext"; 47 48 49 /** 50 * Sets the config locations for this OSGi bundle application context. If 51 * not set, the implementation is supposed to use a default for the given 52 * bundle. 53 * 54 * @param configLocations array of configuration locations 55 */ 56 void setConfigLocations(String[] configLocations); 57 58 /** 59 * Sets the <code>BundleContext</code> used by this OSGi bundle 60 * application context. Normally it's the <code>BundleContext</code> in 61 * which the context runs. 62 * 63 * <p> 64 * Does not cause an initialization of the context: {@link #refresh()} needs 65 * to be called after the setting of all configuration properties. 66 * 67 * @param bundleContext the <code>BundleContext</code> used by this 68 * application context. 69 * @see #refresh() 70 */ 71 void setBundleContext(BundleContext bundleContext); 72 73 /** 74 * Return the <code>BundleContext</code> for this application context. 75 * This method is offered as a helper since as of OSGi 4.1, the bundle 76 * context can be discovered directly from the given bundle. 77 * 78 * @return the <code>BundleContext</code> in which this application 79 * context runs 80 * 81 * @see #getBundle() 82 */ 83 BundleContext getBundleContext(); 84 85 /** 86 * Returns the OSGi <code>Bundle</code> for this application context. 87 * 88 * @return the <code>Bundle</code> for this OSGi bundle application 89 * context. 90 */ 91 Bundle getBundle(); 92 93 /** 94 * Indicates whether this application context should be publish as an OSGi 95 * service if successfully started. By default, this is set to 96 * <code>true</code>. 97 * 98 * @param publishContextAsService true if the application context should be 99 * published as a service, false otherwise 100 */ 101 void setPublishContextAsService(boolean publishContextAsService); 102 }