blob: fdb9d3a611e782b6d63da3b65c4a471b5b226707 [file] [log] [blame]
Marcel Offermansa962bc92009-11-21 17:59:33 +00001/*
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 Ropae4a5db2009-12-04 22:08:05 +000019package org.apache.felix.dm;
Marcel Offermansa962bc92009-11-21 17:59:33 +000020
Pierre De Ropae4a5db2009-12-04 22:08:05 +000021import org.apache.felix.dm.impl.Logger;
Marcel Offermansa962bc92009-11-21 17:59:33 +000022import org.osgi.framework.BundleActivator;
23import 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 */
34public abstract class DependencyActivatorBase implements BundleActivator {
35 private BundleContext m_context;
36 private DependencyManager m_manager;
37 private Logger m_logger;
38
39 /**
Marcel Offermansfaaed472010-09-08 10:07:32 +000040 * Initialize the dependency manager. Here you can add all components and their dependencies.
Marcel Offermansa962bc92009-11-21 17:59:33 +000041 * 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 Offermansfaaed472010-09-08 10:07:32 +000052 * Destroy the dependency manager. Here you can remove all components and their dependencies.
Marcel Offermansa962bc92009-11-21 17:59:33 +000053 * 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 Offermansfaaed472010-09-08 10:07:32 +000055 * <p>
Marcel Offermansa962bc92009-11-21 17:59:33 +000056 * 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 */
64 public abstract void destroy(BundleContext context, DependencyManager manager) throws Exception;
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 Offermans07095832011-11-16 06:28:10 +000087 m_manager.clear();
Marcel Offermansa962bc92009-11-21 17:59:33 +000088 m_manager = null;
89 m_context = null;
90 }
91
92 /**
Marcel Offermansf83871d2010-07-16 09:07:56 +000093 * 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 Offermansfaaed472010-09-08 10:07:32 +0000122 * Creates a new component.
Marcel Offermansa962bc92009-11-21 17:59:33 +0000123 *
Marcel Offermansfaaed472010-09-08 10:07:32 +0000124 * @return the new component
Marcel Offermansa962bc92009-11-21 17:59:33 +0000125 */
Marcel Offermansfaaed472010-09-08 10:07:32 +0000126 public Component createComponent() {
127 return m_manager.createComponent();
Marcel Offermansa962bc92009-11-21 17:59:33 +0000128 }
129
130 /**
131 * Creates a new service dependency.
132 *
133 * @return the service dependency
134 */
135 public ServiceDependency createServiceDependency() {
Marcel Offermanse14b3422009-11-25 23:04:32 +0000136 return m_manager.createServiceDependency();
Marcel Offermansa962bc92009-11-21 17:59:33 +0000137 }
138
139 /**
Marcel Offermans74363c32009-11-23 19:56:08 +0000140 * 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 Offermanse14b3422009-11-25 23:04:32 +0000146 return m_manager.createTemporalServiceDependency();
Marcel Offermans74363c32009-11-23 19:56:08 +0000147 }
148
149 /**
Marcel Offermansa962bc92009-11-21 17:59:33 +0000150 * Creates a new configuration dependency.
151 *
152 * @return the configuration dependency
153 */
154 public ConfigurationDependency createConfigurationDependency() {
Marcel Offermansd66c5ce2009-11-26 09:58:44 +0000155 return m_manager.createConfigurationDependency();
156 }
Pierre De Ropa0204f52010-03-06 22:23:57 +0000157
158 /**
Marcel Offermansfaaed472010-09-08 10:07:32 +0000159 * Creates a new configuration property metadata.
160 *
161 * @return the configuration property metadata
Pierre De Ropa0204f52010-03-06 22:23:57 +0000162 */
163 public PropertyMetaData createPropertyMetaData() {
164 return m_manager.createPropertyMetaData();
165 }
Marcel Offermansd66c5ce2009-11-26 09:58:44 +0000166
167 /**
168 * Creates a new bundle dependency.
169 *
170 * @return the bundle dependency
171 */
172 public BundleDependency createBundleDependency() {
173 return m_manager.createBundleDependency();
Marcel Offermansa962bc92009-11-21 17:59:33 +0000174 }
Marcel Offermansfaaed472010-09-08 10:07:32 +0000175
176 /**
177 * Creates a new resource dependency.
178 *
179 * @return the resource dependency
180 */
Marcel Offermansd665eaf2010-02-16 15:56:35 +0000181 public ResourceDependency createResourceDependency() {
182 return m_manager.createResourceDependency();
183 }
Marcel Offermansa962bc92009-11-21 17:59:33 +0000184
Marcel Offermansfaaed472010-09-08 10:07:32 +0000185 /**
186 * Creates a new aspect service.
187 *
188 * @return the aspect service
Marcel Offermansa8818d52011-03-09 10:03:35 +0000189 * @see DependencyManager#createAspectService(Class, String, int, String)
Marcel Offermansfaaed472010-09-08 10:07:32 +0000190 */
191 public Component createAspectService(Class serviceInterface, String serviceFilter, int ranking, String attributeName) {
Pierre De Rop19476fe2010-05-23 08:13:58 +0000192 return m_manager.createAspectService(serviceInterface, serviceFilter, ranking, attributeName);
Marcel Offermansa6ffb992010-05-19 11:56:44 +0000193 }
Marcel Offermansa8818d52011-03-09 10:03:35 +0000194
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 Offermansfaaed472010-09-08 10:07:32 +0000214
215 /**
216 * Creates a new adapter service.
217 *
218 * @return the adapter service
Marcel Offermansa8818d52011-03-09 10:03:35 +0000219 * @see DependencyManager#createAdapterService(Class, String)
Marcel Offermansfaaed472010-09-08 10:07:32 +0000220 */
221 public Component createAdapterService(Class serviceInterface, String serviceFilter) {
Pierre De Rop34231582010-05-23 20:05:16 +0000222 return m_manager.createAdapterService(serviceInterface, serviceFilter);
Marcel Offermansd665eaf2010-02-16 15:56:35 +0000223 }
Marcel Offermansa8818d52011-03-09 10:03:35 +0000224
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 Offermansd26f2bd2012-01-02 14:53:17 +0000244
Marcel Offermansfaaed472010-09-08 10:07:32 +0000245 /**
Marcel Offermans4aa032c2012-01-02 19:18:22 +0000246 * 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 Offermansfaaed472010-09-08 10:07:32 +0000255 * 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 Offermanse9c13d92010-07-01 14:01:02 +0000260 return m_manager.createResourceAdapterService(resourceFilter, propagate, callbackInstance, callbackChanged);
Marcel Offermansd665eaf2010-02-16 15:56:35 +0000261 }
Marcel Offermansfaaed472010-09-08 10:07:32 +0000262
263 /**
264 * Creates a new resource adapter service.
265 *
266 * @return the resource adapter service
267 */
Marcel Offermansd26f2bd2012-01-02 14:53:17 +0000268 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 Offermansfaaed472010-09-08 10:07:32 +0000277 public Component createResourceAdapter(String resourceFilter, Object propagateCallbackInstance, String propagateCallbackMethod, Object callbackInstance, String callbackChanged) {
Marcel Offermansd26f2bd2012-01-02 14:53:17 +0000278 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 Offermans26081d32010-07-12 12:43:42 +0000288 }
289
Marcel Offermansfaaed472010-09-08 10:07:32 +0000290 /**
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 Rop13dd63d2010-05-23 21:58:28 +0000296 return m_manager.createBundleAdapterService(bundleStateMask, bundleFilter, propagate);
Marcel Offermans61a81142010-04-02 15:16:50 +0000297 }
Marcel Offermans80eeafe2009-12-01 22:12:26 +0000298
Marcel Offermansfaaed472010-09-08 10:07:32 +0000299 /**
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 Rop3e100372010-05-24 12:43:44 +0000305 return m_manager.createFactoryConfigurationAdapterService(factoryPid, update, propagate);
Pierre De Ropef94c882010-04-17 18:23:35 +0000306 }
307
Marcel Offermansfaaed472010-09-08 10:07:32 +0000308 /**
309 * Creates a new factory configuration adapter service.
310 *
311 * @return the factory configuration adapter service
312 */
Marcel Offermans07095832011-11-16 06:28:10 +0000313 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 Offermansa962bc92009-11-21 17:59:33 +0000315 }
Marcel Offermansa962bc92009-11-21 17:59:33 +0000316}