Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 19 | package org.apache.felix.dm; |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 20 | |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 21 | import org.apache.felix.dm.impl.Logger; |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 22 | import org.osgi.framework.BundleActivator; |
| 23 | import org.osgi.framework.BundleContext; |
| 24 | |
| 25 | /** |
| 26 | * Base bundle activator class. Subclass this activator if you want to use dependency |
| 27 | * management in your bundle. There are two methods you should implement: |
| 28 | * <code>init()</code> and <code>destroy()</code>. Both methods take two arguments, |
| 29 | * the bundle context and the dependency manager. The dependency manager can be used |
| 30 | * to define all the dependencies. |
| 31 | * |
| 32 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 33 | */ |
| 34 | public abstract class DependencyActivatorBase implements BundleActivator { |
| 35 | private BundleContext m_context; |
| 36 | private DependencyManager m_manager; |
| 37 | private Logger m_logger; |
| 38 | |
| 39 | /** |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 40 | * Initialize the dependency manager. Here you can add all components and their dependencies. |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 41 | * If something goes wrong and you do not want your bundle to be started, you can throw an |
| 42 | * exception. This exception will be passed on to the <code>start()</code> method of the |
| 43 | * bundle activator, causing the bundle not to start. |
| 44 | * |
| 45 | * @param context the bundle context |
| 46 | * @param manager the dependency manager |
| 47 | * @throws Exception if the initialization fails |
| 48 | */ |
| 49 | public abstract void init(BundleContext context, DependencyManager manager) throws Exception; |
| 50 | |
| 51 | /** |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 52 | * Destroy the dependency manager. Here you can remove all components and their dependencies. |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 53 | * Actually, the base class will clean up your dependencies anyway, so most of the time you |
| 54 | * don't need to do anything here. |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 55 | * <p> |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 56 | * If something goes wrong and you do not want your bundle to be stopped, you can throw an |
| 57 | * exception. This exception will be passed on to the <code>stop()</code> method of the |
| 58 | * bundle activator, causing the bundle not to stop. |
| 59 | * |
| 60 | * @param context the bundle context |
| 61 | * @param manager the dependency manager |
| 62 | * @throws Exception if the destruction fails |
| 63 | */ |
Pierre De Rop | 1d14e8b | 2013-10-26 14:47:47 +0000 | [diff] [blame] | 64 | public void destroy(BundleContext context, DependencyManager manager) throws Exception { } |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * Start method of the bundle activator. Initializes the dependency manager |
| 68 | * and calls <code>init()</code>. |
| 69 | * |
| 70 | * @param context the bundle context |
| 71 | */ |
| 72 | public void start(BundleContext context) throws Exception { |
| 73 | m_context = context; |
| 74 | m_logger = new Logger(context); |
| 75 | m_manager = new DependencyManager(context, m_logger); |
| 76 | init(m_context, m_manager); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Stop method of the bundle activator. Calls the <code>destroy()</code> method |
| 81 | * and cleans up all left over dependencies. |
| 82 | * |
| 83 | * @param context the bundle context |
| 84 | */ |
| 85 | public void stop(BundleContext context) throws Exception { |
| 86 | destroy(m_context, m_manager); |
Marcel Offermans | 0709583 | 2011-11-16 06:28:10 +0000 | [diff] [blame] | 87 | m_manager.clear(); |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 88 | m_manager = null; |
| 89 | m_context = null; |
| 90 | } |
| 91 | |
| 92 | /** |
Marcel Offermans | f83871d | 2010-07-16 09:07:56 +0000 | [diff] [blame] | 93 | * Returns the bundle context that is associated with this bundle. |
| 94 | * |
| 95 | * @return the bundle context |
| 96 | */ |
| 97 | public BundleContext getBundleContext() { |
| 98 | return m_context; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Returns the dependency manager that is associated with this bundle. |
| 103 | * |
| 104 | * @return the dependency manager |
| 105 | */ |
| 106 | public DependencyManager getDependencyManager() { |
| 107 | return m_manager; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Returns the logger that is associated with this bundle. A logger instance |
| 112 | * is a proxy that will log to a real OSGi logservice if available and standard |
| 113 | * out if not. |
| 114 | * |
| 115 | * @return the logger |
| 116 | */ |
| 117 | public Logger getLogger() { |
| 118 | return m_logger; |
| 119 | } |
| 120 | |
| 121 | /** |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 122 | * Creates a new component. |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 123 | * |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 124 | * @return the new component |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 125 | */ |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 126 | public Component createComponent() { |
| 127 | return m_manager.createComponent(); |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Creates a new service dependency. |
| 132 | * |
| 133 | * @return the service dependency |
| 134 | */ |
| 135 | public ServiceDependency createServiceDependency() { |
Marcel Offermans | e14b342 | 2009-11-25 23:04:32 +0000 | [diff] [blame] | 136 | return m_manager.createServiceDependency(); |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /** |
Marcel Offermans | 74363c3 | 2009-11-23 19:56:08 +0000 | [diff] [blame] | 140 | * Creates a new temporal service dependency. |
| 141 | * |
| 142 | * @param timeout the max number of milliseconds to wait for a service availability. |
| 143 | * @return the service dependency |
| 144 | */ |
| 145 | public TemporalServiceDependency createTemporalServiceDependency() { |
Marcel Offermans | e14b342 | 2009-11-25 23:04:32 +0000 | [diff] [blame] | 146 | return m_manager.createTemporalServiceDependency(); |
Marcel Offermans | 74363c3 | 2009-11-23 19:56:08 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /** |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 150 | * Creates a new configuration dependency. |
| 151 | * |
| 152 | * @return the configuration dependency |
| 153 | */ |
| 154 | public ConfigurationDependency createConfigurationDependency() { |
Marcel Offermans | d66c5ce | 2009-11-26 09:58:44 +0000 | [diff] [blame] | 155 | return m_manager.createConfigurationDependency(); |
| 156 | } |
Pierre De Rop | a0204f5 | 2010-03-06 22:23:57 +0000 | [diff] [blame] | 157 | |
| 158 | /** |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 159 | * Creates a new configuration property metadata. |
| 160 | * |
| 161 | * @return the configuration property metadata |
Pierre De Rop | a0204f5 | 2010-03-06 22:23:57 +0000 | [diff] [blame] | 162 | */ |
| 163 | public PropertyMetaData createPropertyMetaData() { |
| 164 | return m_manager.createPropertyMetaData(); |
| 165 | } |
Marcel Offermans | d66c5ce | 2009-11-26 09:58:44 +0000 | [diff] [blame] | 166 | |
| 167 | /** |
| 168 | * Creates a new bundle dependency. |
| 169 | * |
| 170 | * @return the bundle dependency |
| 171 | */ |
| 172 | public BundleDependency createBundleDependency() { |
| 173 | return m_manager.createBundleDependency(); |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 174 | } |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 175 | |
| 176 | /** |
| 177 | * Creates a new resource dependency. |
| 178 | * |
| 179 | * @return the resource dependency |
| 180 | */ |
Marcel Offermans | d665eaf | 2010-02-16 15:56:35 +0000 | [diff] [blame] | 181 | public ResourceDependency createResourceDependency() { |
| 182 | return m_manager.createResourceDependency(); |
| 183 | } |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 184 | |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 185 | /** |
| 186 | * Creates a new aspect service. |
| 187 | * |
| 188 | * @return the aspect service |
Marcel Offermans | a8818d5 | 2011-03-09 10:03:35 +0000 | [diff] [blame] | 189 | * @see DependencyManager#createAspectService(Class, String, int, String) |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 190 | */ |
| 191 | public Component createAspectService(Class serviceInterface, String serviceFilter, int ranking, String attributeName) { |
Pierre De Rop | 19476fe | 2010-05-23 08:13:58 +0000 | [diff] [blame] | 192 | return m_manager.createAspectService(serviceInterface, serviceFilter, ranking, attributeName); |
Marcel Offermans | a6ffb99 | 2010-05-19 11:56:44 +0000 | [diff] [blame] | 193 | } |
Marcel Offermans | a8818d5 | 2011-03-09 10:03:35 +0000 | [diff] [blame] | 194 | |
| 195 | /** |
| 196 | * Creates a new aspect service. |
| 197 | * |
| 198 | * @return the aspect service |
| 199 | * @see DependencyManager#createAspectService(Class, String, int) |
| 200 | */ |
| 201 | public Component createAspectService(Class serviceInterface, String serviceFilter, int ranking) { |
| 202 | return m_manager.createAspectService(serviceInterface, serviceFilter, ranking); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Creates a new aspect service. |
| 207 | * |
| 208 | * @return the aspect service |
| 209 | * @see DependencyManager#createAspectService(Class, String, int, String, String, String) |
| 210 | */ |
| 211 | public Component createAspectService(Class serviceInterface, String serviceFilter, int ranking, String add, String change, String remove) { |
| 212 | return m_manager.createAspectService(serviceInterface, serviceFilter, ranking, add, change, remove); |
| 213 | } |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 214 | |
| 215 | /** |
| 216 | * Creates a new adapter service. |
| 217 | * |
| 218 | * @return the adapter service |
Marcel Offermans | a8818d5 | 2011-03-09 10:03:35 +0000 | [diff] [blame] | 219 | * @see DependencyManager#createAdapterService(Class, String) |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 220 | */ |
| 221 | public Component createAdapterService(Class serviceInterface, String serviceFilter) { |
Pierre De Rop | 3423158 | 2010-05-23 20:05:16 +0000 | [diff] [blame] | 222 | return m_manager.createAdapterService(serviceInterface, serviceFilter); |
Marcel Offermans | d665eaf | 2010-02-16 15:56:35 +0000 | [diff] [blame] | 223 | } |
Marcel Offermans | a8818d5 | 2011-03-09 10:03:35 +0000 | [diff] [blame] | 224 | |
| 225 | /** |
| 226 | * Creates a new adapter service. |
| 227 | * |
| 228 | * @return the adapter service |
| 229 | * @see DependencyManager#createAdapterService(Class, String, String) |
| 230 | */ |
| 231 | public Component createAdapterService(Class serviceInterface, String serviceFilter, String autoConfig) { |
| 232 | return m_manager.createAdapterService(serviceInterface, serviceFilter, autoConfig); |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Creates a new adapter service. |
| 237 | * |
| 238 | * @return the adapter service |
| 239 | * @see DependencyManager#createAdapterService(Class, String, String, String, String) |
| 240 | */ |
| 241 | public Component createAdapterService(Class serviceInterface, String serviceFilter, String add, String change, String remove) { |
| 242 | return m_manager.createAdapterService(serviceInterface, serviceFilter, add, change, remove); |
| 243 | } |
Marcel Offermans | d26f2bd | 2012-01-02 14:53:17 +0000 | [diff] [blame] | 244 | |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 245 | /** |
Marcel Offermans | 4aa032c | 2012-01-02 19:18:22 +0000 | [diff] [blame] | 246 | * Creates a new adapter service. |
| 247 | * @return the adapter service |
| 248 | * @see DependencyManager#createAdapterService(Class, String, String, String, String, String) |
| 249 | */ |
| 250 | public Component createAdapterService(Class serviceInterface, String serviceFilter, String add, String change, String remove, String swap) { |
| 251 | return m_manager.createAdapterService(serviceInterface, serviceFilter, add, change, remove, swap); |
| 252 | } |
| 253 | |
| 254 | /** |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 255 | * Creates a new resource adapter service. |
| 256 | * |
| 257 | * @return the resource adapter service |
| 258 | */ |
| 259 | public Component createResourceAdapter(String resourceFilter, boolean propagate, Object callbackInstance, String callbackChanged) { |
Marcel Offermans | e9c13d9 | 2010-07-01 14:01:02 +0000 | [diff] [blame] | 260 | return m_manager.createResourceAdapterService(resourceFilter, propagate, callbackInstance, callbackChanged); |
Marcel Offermans | d665eaf | 2010-02-16 15:56:35 +0000 | [diff] [blame] | 261 | } |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 262 | |
| 263 | /** |
| 264 | * Creates a new resource adapter service. |
| 265 | * |
| 266 | * @return the resource adapter service |
| 267 | */ |
Marcel Offermans | d26f2bd | 2012-01-02 14:53:17 +0000 | [diff] [blame] | 268 | public Component createResourceAdapter(String resourceFilter, boolean propagate, Object callbackInstance, String callbackSet, String callbackChanged) { |
| 269 | return m_manager.createResourceAdapterService(resourceFilter, propagate, callbackInstance, callbackSet, callbackChanged); |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Creates a new resource adapter service. |
| 274 | * |
| 275 | * @return the resource adapter service |
| 276 | */ |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 277 | public Component createResourceAdapter(String resourceFilter, Object propagateCallbackInstance, String propagateCallbackMethod, Object callbackInstance, String callbackChanged) { |
Marcel Offermans | d26f2bd | 2012-01-02 14:53:17 +0000 | [diff] [blame] | 278 | return m_manager.createResourceAdapterService(resourceFilter, propagateCallbackInstance, propagateCallbackMethod, callbackInstance, null, callbackChanged); |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * Creates a new resource adapter service. |
| 283 | * |
| 284 | * @return the resource adapter service |
| 285 | */ |
| 286 | public Component createResourceAdapter(String resourceFilter, Object propagateCallbackInstance, String propagateCallbackMethod, Object callbackInstance, String callbackSet, String callbackChanged) { |
| 287 | return m_manager.createResourceAdapterService(resourceFilter, propagateCallbackInstance, propagateCallbackMethod, callbackInstance, callbackSet, callbackChanged); |
Marcel Offermans | 26081d3 | 2010-07-12 12:43:42 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 290 | /** |
| 291 | * Creates a new bundle adapter service. |
| 292 | * |
| 293 | * @return the bundle adapter service |
| 294 | */ |
| 295 | public Component createBundleAdapterService(int bundleStateMask, String bundleFilter, boolean propagate) { |
Pierre De Rop | 13dd63d | 2010-05-23 21:58:28 +0000 | [diff] [blame] | 296 | return m_manager.createBundleAdapterService(bundleStateMask, bundleFilter, propagate); |
Marcel Offermans | 61a8114 | 2010-04-02 15:16:50 +0000 | [diff] [blame] | 297 | } |
Marcel Offermans | 80eeafe | 2009-12-01 22:12:26 +0000 | [diff] [blame] | 298 | |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 299 | /** |
| 300 | * Creates a new factory configuration adapter service. |
| 301 | * |
| 302 | * @return the factory configuration adapter service |
| 303 | */ |
| 304 | public Component createFactoryConfigurationAdapterService(String factoryPid, String update, boolean propagate) { |
Pierre De Rop | 3e10037 | 2010-05-24 12:43:44 +0000 | [diff] [blame] | 305 | return m_manager.createFactoryConfigurationAdapterService(factoryPid, update, propagate); |
Pierre De Rop | ef94c88 | 2010-04-17 18:23:35 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 308 | /** |
| 309 | * Creates a new factory configuration adapter service. |
| 310 | * |
| 311 | * @return the factory configuration adapter service |
| 312 | */ |
Marcel Offermans | 0709583 | 2011-11-16 06:28:10 +0000 | [diff] [blame] | 313 | public Component createFactoryConfigurationAdapterService(String factoryPid, String update, boolean propagate, String heading, String desc, String localization, PropertyMetaData[] propertiesMetaData) { |
| 314 | return m_manager.createFactoryConfigurationAdapterService(factoryPid, update, propagate, heading, desc, localization, propertiesMetaData); |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 315 | } |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 316 | } |