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 | |
| 21 | import java.util.ArrayList; |
| 22 | import java.util.Collections; |
Marcel Offermans | 80eeafe | 2009-12-01 22:12:26 +0000 | [diff] [blame] | 23 | import java.util.Dictionary; |
Pierre De Rop | ef94c88 | 2010-04-17 18:23:35 +0000 | [diff] [blame] | 24 | import java.util.Hashtable; |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 25 | import java.util.List; |
| 26 | |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 27 | import org.apache.felix.dm.dependencies.BundleDependency; |
| 28 | import org.apache.felix.dm.dependencies.ConfigurationDependency; |
Pierre De Rop | a0204f5 | 2010-03-06 22:23:57 +0000 | [diff] [blame] | 29 | import org.apache.felix.dm.dependencies.PropertyMetaData; |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 30 | import org.apache.felix.dm.dependencies.ResourceDependency; |
| 31 | import org.apache.felix.dm.dependencies.ServiceDependency; |
| 32 | import org.apache.felix.dm.dependencies.TemporalServiceDependency; |
Marcel Offermans | 001db05 | 2009-12-08 08:58:40 +0000 | [diff] [blame] | 33 | import org.apache.felix.dm.impl.AdapterImpl; |
Pierre De Rop | 19476fe | 2010-05-23 08:13:58 +0000 | [diff] [blame^] | 34 | import org.apache.felix.dm.impl.AspectServiceImpl; |
Marcel Offermans | 001db05 | 2009-12-08 08:58:40 +0000 | [diff] [blame] | 35 | import org.apache.felix.dm.impl.BundleAdapterImpl; |
Marcel Offermans | a6ffb99 | 2010-05-19 11:56:44 +0000 | [diff] [blame] | 36 | import org.apache.felix.dm.impl.FactoryConfigurationAdapterImpl; |
Pierre De Rop | 9a8ebfd | 2010-04-25 22:25:34 +0000 | [diff] [blame] | 37 | import org.apache.felix.dm.impl.FactoryConfigurationAdapterMetaTypeImpl; |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 38 | import org.apache.felix.dm.impl.Logger; |
Marcel Offermans | 001db05 | 2009-12-08 08:58:40 +0000 | [diff] [blame] | 39 | import org.apache.felix.dm.impl.ResourceAdapterImpl; |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 40 | import org.apache.felix.dm.impl.ServiceImpl; |
| 41 | import org.apache.felix.dm.impl.dependencies.BundleDependencyImpl; |
| 42 | import org.apache.felix.dm.impl.dependencies.ConfigurationDependencyImpl; |
| 43 | import org.apache.felix.dm.impl.dependencies.ResourceDependencyImpl; |
| 44 | import org.apache.felix.dm.impl.dependencies.ServiceDependencyImpl; |
| 45 | import org.apache.felix.dm.impl.dependencies.TemporalServiceDependencyImpl; |
Pierre De Rop | a0204f5 | 2010-03-06 22:23:57 +0000 | [diff] [blame] | 46 | import org.apache.felix.dm.impl.metatype.PropertyMetaDataImpl; |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 47 | import org.apache.felix.dm.resources.Resource; |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 48 | import org.apache.felix.dm.service.Service; |
Marcel Offermans | b8405a5 | 2009-12-22 19:01:31 +0000 | [diff] [blame] | 49 | import org.osgi.framework.BundleContext; |
Pierre De Rop | ef94c88 | 2010-04-17 18:23:35 +0000 | [diff] [blame] | 50 | import org.osgi.framework.Constants; |
| 51 | import org.osgi.service.cm.ManagedServiceFactory; |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 52 | |
| 53 | /** |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 54 | * The dependency manager manages all services and their dependencies. Using |
| 55 | * this API you can declare all services and their dependencies. Under normal |
| 56 | * circumstances, you get passed an instance of this class through the |
| 57 | * <code>DependencyActivatorBase</code> subclass you use as your |
| 58 | * <code>BundleActivator</code>, but it is also possible to create your |
| 59 | * own instance. |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 60 | * |
| 61 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 62 | */ |
| 63 | public class DependencyManager { |
Marcel Offermans | ad76067 | 2010-03-03 15:30:01 +0000 | [diff] [blame] | 64 | public static final String ASPECT = "org.apache.felix.dependencymanager.aspect"; |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 65 | private final BundleContext m_context; |
| 66 | private final Logger m_logger; |
| 67 | private List m_services = Collections.synchronizedList(new ArrayList()); |
| 68 | |
| 69 | /** |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 70 | * Creates a new dependency manager. You need to supply the |
| 71 | * <code>BundleContext</code> to be used by the dependency |
| 72 | * manager to register services and communicate with the |
| 73 | * framework. |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 74 | * |
| 75 | * @param context the bundle context |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 76 | */ |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 77 | public DependencyManager(BundleContext context) { |
| 78 | this(context, new Logger(context)); |
| 79 | } |
| 80 | |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 81 | DependencyManager(BundleContext context, Logger logger) { |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 82 | m_context = context; |
| 83 | m_logger = logger; |
| 84 | } |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 85 | |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 86 | /** |
| 87 | * Adds a new service to the dependency manager. After the service was added |
| 88 | * it will be started immediately. |
| 89 | * |
| 90 | * @param service the service to add |
| 91 | */ |
| 92 | public void add(Service service) { |
| 93 | m_services.add(service); |
| 94 | service.start(); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Removes a service from the dependency manager. Before the service is removed |
| 99 | * it is stopped first. |
| 100 | * |
| 101 | * @param service the service to remove |
| 102 | */ |
| 103 | public void remove(Service service) { |
| 104 | service.stop(); |
| 105 | m_services.remove(service); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Creates a new service. |
| 110 | * |
| 111 | * @return the new service |
| 112 | */ |
| 113 | public Service createService() { |
| 114 | return new ServiceImpl(m_context, this, m_logger); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Creates a new service dependency. |
| 119 | * |
| 120 | * @return the service dependency |
| 121 | */ |
| 122 | public ServiceDependency createServiceDependency() { |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 123 | return new ServiceDependencyImpl(m_context, m_logger); |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Marcel Offermans | 74363c3 | 2009-11-23 19:56:08 +0000 | [diff] [blame] | 126 | /** |
| 127 | * Creates a new temporal service dependency. |
| 128 | * |
| 129 | * @param timeout the max number of milliseconds to wait for a service availability. |
| 130 | * @return the service dependency |
| 131 | */ |
| 132 | public TemporalServiceDependency createTemporalServiceDependency() { |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 133 | return new TemporalServiceDependencyImpl(m_context, m_logger); |
Marcel Offermans | 74363c3 | 2009-11-23 19:56:08 +0000 | [diff] [blame] | 134 | } |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 135 | |
| 136 | /** |
| 137 | * Creates a new configuration dependency. |
| 138 | * |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 139 | * @return the configuration dependency |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 140 | */ |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 141 | public ConfigurationDependency createConfigurationDependency() { |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 142 | return new ConfigurationDependencyImpl(m_context, m_logger); |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 145 | /** |
Pierre De Rop | a0204f5 | 2010-03-06 22:23:57 +0000 | [diff] [blame] | 146 | * Creates a new configuration property MetaData. |
| 147 | * @return a new Configuration property MetaData. |
| 148 | */ |
| 149 | public PropertyMetaData createPropertyMetaData() { |
| 150 | return new PropertyMetaDataImpl(); |
| 151 | } |
| 152 | |
| 153 | /** |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 154 | * Creates a new bundle dependency. |
| 155 | * |
| 156 | * @return |
| 157 | */ |
Marcel Offermans | d66c5ce | 2009-11-26 09:58:44 +0000 | [diff] [blame] | 158 | public BundleDependency createBundleDependency() { |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 159 | return new BundleDependencyImpl(m_context, m_logger); |
Marcel Offermans | d66c5ce | 2009-11-26 09:58:44 +0000 | [diff] [blame] | 160 | } |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 161 | |
| 162 | /** |
| 163 | * Creates a new resource dependency. |
| 164 | * |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 165 | * @return the resource dependency |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 166 | */ |
| 167 | public ResourceDependency createResourceDependency() { |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 168 | return new ResourceDependencyImpl(m_context, m_logger); |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 169 | } |
Marcel Offermans | 80eeafe | 2009-12-01 22:12:26 +0000 | [diff] [blame] | 170 | |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 171 | /** |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 172 | * Creates a new aspect. The aspect will be applied to any service that |
| 173 | * matches the specified interface and filter. For each matching service |
| 174 | * an aspect will be created based on the aspect implementation class. |
| 175 | * The aspect will be registered with the same interface and properties |
| 176 | * as the original service, plus any extra properties you supply here. |
| 177 | * It will also inherit all dependencies, and if you declare the original |
| 178 | * service as a member it will be injected. |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 179 | * |
Pierre De Rop | 19476fe | 2010-05-23 08:13:58 +0000 | [diff] [blame^] | 180 | * <h3>Usage Example</h3> |
| 181 | * |
| 182 | * <blockquote> |
| 183 | * manager.createAspectService(ExistingService.class, "(foo=bar)", 10, "m_aspect") |
| 184 | * .setImplementation(ExistingServiceAspect.class) |
| 185 | * .setServiceProperties(new Hashtable() {{ put("additional", "properties"); }}) |
| 186 | * .setComposition("getComposition") |
| 187 | * .setCallbacks(new Handler(), null, "mystart", "mystop", null); |
| 188 | * <pre> |
| 189 | * </pre> |
| 190 | * </blockquote> |
| 191 | * |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 192 | * @param serviceInterface the service interface to apply the aspect to |
| 193 | * @param serviceFilter the filter condition to use with the service interface |
Pierre De Rop | 19476fe | 2010-05-23 08:13:58 +0000 | [diff] [blame^] | 194 | * @param ranking the level used to organize the aspect chain ordering |
| 195 | * @param attributeName, the aspect implementation field name where to inject original service. |
| 196 | * If null, any field matching the original service will be injected. |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 197 | * @return a service that acts as a factory for generating aspects |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 198 | */ |
Pierre De Rop | 19476fe | 2010-05-23 08:13:58 +0000 | [diff] [blame^] | 199 | public Service createAspectService(Class serviceInterface, String serviceFilter, int ranking, String attributeName) { |
| 200 | return new AspectServiceImpl(this, serviceInterface, serviceFilter, ranking, attributeName); |
Marcel Offermans | 80eeafe | 2009-12-01 22:12:26 +0000 | [diff] [blame] | 201 | } |
Pierre De Rop | 19476fe | 2010-05-23 08:13:58 +0000 | [diff] [blame^] | 202 | |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 203 | /** |
| 204 | * Creates a new adapter. The adapter will be applied to any service that |
| 205 | * matches the specified interface and filter. For each matching service |
| 206 | * an adapter will be created based on the adapter implementation class. |
| 207 | * The adapter will be registered with the specified interface and existing properties |
| 208 | * from the original service plus any extra properties you supply here. |
| 209 | * It will also inherit all dependencies, and if you declare the original |
| 210 | * service as a member it will be injected. |
| 211 | * |
Marcel Offermans | d665eaf | 2010-02-16 15:56:35 +0000 | [diff] [blame] | 212 | * @param serviceInterface the service interface to apply the adapter to |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 213 | * @param serviceFilter the filter condition to use with the service interface |
| 214 | * @param adapterInterface the interface to use when registering adapters |
| 215 | * @param adapterImplementation the implementation of the adapter |
| 216 | * @param adapterProperties additional properties to use with the adapter service registration |
| 217 | * @return a service that acts as a factory for generating adapters |
| 218 | */ |
Marcel Offermans | 61a8114 | 2010-04-02 15:16:50 +0000 | [diff] [blame] | 219 | public Service createAdapterService(Class serviceInterface, String serviceFilter, String adapterInterface, Object adapterImplementation, Dictionary adapterProperties) { |
Marcel Offermans | 001db05 | 2009-12-08 08:58:40 +0000 | [diff] [blame] | 220 | return createService() |
Marcel Offermans | 61a8114 | 2010-04-02 15:16:50 +0000 | [diff] [blame] | 221 | .setImplementation(new AdapterImpl(serviceInterface, serviceFilter, adapterImplementation, adapterInterface, adapterProperties)) |
| 222 | .add(createServiceDependency() |
| 223 | .setService(serviceInterface) |
| 224 | .setAutoConfig(false) |
| 225 | .setCallbacks("added", "removed") |
| 226 | ); |
| 227 | } |
| 228 | |
| 229 | public Service createAdapterService(Class serviceInterface, String serviceFilter, String[] adapterInterface, Object adapterImplementation, Dictionary adapterProperties) { |
| 230 | return createService() |
| 231 | .setImplementation(new AdapterImpl(serviceInterface, serviceFilter, adapterImplementation, adapterInterface, adapterProperties)) |
Marcel Offermans | 001db05 | 2009-12-08 08:58:40 +0000 | [diff] [blame] | 232 | .add(createServiceDependency() |
Marcel Offermans | 3e1998c | 2009-12-16 20:47:25 +0000 | [diff] [blame] | 233 | .setService(serviceInterface) |
Marcel Offermans | 001db05 | 2009-12-08 08:58:40 +0000 | [diff] [blame] | 234 | .setAutoConfig(false) |
| 235 | .setCallbacks("added", "removed") |
Marcel Offermans | 626260c | 2009-12-22 17:06:46 +0000 | [diff] [blame] | 236 | ); |
Marcel Offermans | 001db05 | 2009-12-08 08:58:40 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 239 | /** |
| 240 | * Creates a new resource adapter. The adapter will be applied to any resource that |
| 241 | * matches the specified filter condition. For each matching resource |
| 242 | * an adapter will be created based on the adapter implementation class. |
| 243 | * The adapter will be registered with the specified interface and existing properties |
| 244 | * from the original resource plus any extra properties you supply here. |
| 245 | * It will also inherit all dependencies, and if you declare the original |
| 246 | * service as a member it will be injected. |
| 247 | * |
| 248 | * @param resourceFilter the filter condition to use with the resource |
Marcel Offermans | 5eb38b8 | 2010-04-06 15:17:57 +0000 | [diff] [blame] | 249 | * @param adapterHandler a handler to invoke life cycle methods on for the adapter instance, or <code>null</code> |
| 250 | * if you want to invoke these methods on the instance |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 251 | * @param adapterInterface the interface to use when registering adapters |
| 252 | * @param adapterProperties additional properties to use with the adapter service registration |
| 253 | * @param adapterImplementation the implementation of the adapter |
| 254 | * @param propagate <code>true</code> if properties from the resource should be propagated to the service |
| 255 | * @return a service that acts as a factory for generating resource adapters |
| 256 | * @see Resource |
| 257 | */ |
Marcel Offermans | 5eb38b8 | 2010-04-06 15:17:57 +0000 | [diff] [blame] | 258 | public Service createResourceAdapterService(String resourceFilter, Object adapterHandler, String adapterInterface, Dictionary adapterProperties, Object adapterImplementation, boolean propagate) { |
Marcel Offermans | 001db05 | 2009-12-08 08:58:40 +0000 | [diff] [blame] | 259 | return createService() |
Marcel Offermans | 5eb38b8 | 2010-04-06 15:17:57 +0000 | [diff] [blame] | 260 | .setImplementation(new ResourceAdapterImpl(resourceFilter, adapterHandler, adapterImplementation, adapterInterface, adapterProperties, propagate)) |
Marcel Offermans | 61a8114 | 2010-04-02 15:16:50 +0000 | [diff] [blame] | 261 | .add(createResourceDependency() |
| 262 | .setFilter(resourceFilter) |
| 263 | .setAutoConfig(false) |
| 264 | .setCallbacks("added", "removed") |
| 265 | ); |
| 266 | } |
Marcel Offermans | 5eb38b8 | 2010-04-06 15:17:57 +0000 | [diff] [blame] | 267 | public Service createResourceAdapterService(String resourceFilter, Object adapterHandler, String[] adapterInterface, Dictionary adapterProperties, Object adapterImplementation, boolean propagate) { |
Marcel Offermans | 61a8114 | 2010-04-02 15:16:50 +0000 | [diff] [blame] | 268 | return createService() |
Marcel Offermans | 5eb38b8 | 2010-04-06 15:17:57 +0000 | [diff] [blame] | 269 | .setImplementation(new ResourceAdapterImpl(resourceFilter, adapterHandler, adapterImplementation, adapterInterface, adapterProperties, propagate)) |
Marcel Offermans | 001db05 | 2009-12-08 08:58:40 +0000 | [diff] [blame] | 270 | .add(createResourceDependency() |
| 271 | .setFilter(resourceFilter) |
| 272 | .setAutoConfig(false) |
| 273 | .setCallbacks("added", "removed") |
Marcel Offermans | 626260c | 2009-12-22 17:06:46 +0000 | [diff] [blame] | 274 | ); |
Marcel Offermans | 001db05 | 2009-12-08 08:58:40 +0000 | [diff] [blame] | 275 | } |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 276 | |
| 277 | /** |
| 278 | * Creates a new bundle adapter. The adapter will be applied to any bundle that |
| 279 | * matches the specified bundle state mask and filter condition. For each matching |
| 280 | * bundle an adapter will be created based on the adapter implementation class. |
| 281 | * The adapter will be registered with the specified interface |
| 282 | * |
| 283 | * TODO and existing properties from the original resource plus any extra properties you supply here. |
| 284 | * It will also inherit all dependencies, and if you declare the original |
| 285 | * service as a member it will be injected. |
| 286 | * |
| 287 | * @param bundleStateMask the bundle state mask to apply |
| 288 | * @param bundleFilter the filter to apply to the bundle manifest |
| 289 | * @param adapterImplementation the implementation of the adapter |
| 290 | * @param adapterInterface the interface to use when registering adapters |
Marcel Offermans | d665eaf | 2010-02-16 15:56:35 +0000 | [diff] [blame] | 291 | * @param adapterProperties additional properties to use with the service registration |
| 292 | * @param propagate <code>true</code> if properties from the bundle should be propagated to the service |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 293 | * @return a service that acts as a factory for generating bundle adapters |
| 294 | */ |
Marcel Offermans | d665eaf | 2010-02-16 15:56:35 +0000 | [diff] [blame] | 295 | public Service createBundleAdapterService(int bundleStateMask, String bundleFilter, Object adapterImplementation, String adapterInterface, Dictionary adapterProperties, boolean propagate) { |
Marcel Offermans | 001db05 | 2009-12-08 08:58:40 +0000 | [diff] [blame] | 296 | return createService() |
Marcel Offermans | d665eaf | 2010-02-16 15:56:35 +0000 | [diff] [blame] | 297 | .setImplementation(new BundleAdapterImpl(bundleStateMask, bundleFilter, adapterImplementation, adapterInterface, adapterProperties, propagate)) |
Marcel Offermans | 001db05 | 2009-12-08 08:58:40 +0000 | [diff] [blame] | 298 | .add(createBundleDependency() |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 299 | .setFilter(bundleFilter) |
| 300 | .setStateMask(bundleStateMask) |
Marcel Offermans | 001db05 | 2009-12-08 08:58:40 +0000 | [diff] [blame] | 301 | .setCallbacks("added", "removed") |
Marcel Offermans | 626260c | 2009-12-22 17:06:46 +0000 | [diff] [blame] | 302 | ); |
Marcel Offermans | 001db05 | 2009-12-08 08:58:40 +0000 | [diff] [blame] | 303 | } |
Marcel Offermans | 61a8114 | 2010-04-02 15:16:50 +0000 | [diff] [blame] | 304 | public Service createBundleAdapterService(int bundleStateMask, String bundleFilter, Object adapterImplementation, String[] adapterInterface, Dictionary adapterProperties, boolean propagate) { |
| 305 | return createService() |
| 306 | .setImplementation(new BundleAdapterImpl(bundleStateMask, bundleFilter, adapterImplementation, adapterInterface, adapterProperties, propagate)) |
| 307 | .add(createBundleDependency() |
| 308 | .setFilter(bundleFilter) |
| 309 | .setStateMask(bundleStateMask) |
| 310 | .setCallbacks("added", "removed") |
| 311 | ); |
| 312 | } |
Marcel Offermans | 80eeafe | 2009-12-01 22:12:26 +0000 | [diff] [blame] | 313 | |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 314 | /** |
Pierre De Rop | ef94c88 | 2010-04-17 18:23:35 +0000 | [diff] [blame] | 315 | * Creates a new Managed Service Factory Configuration Adapter. For each new Config Admin factory configuration matching |
| 316 | * the factoryPid, an adapter will be created based on the adapter implementation class. |
| 317 | * The adapter will be registered with the specified interface, and with the specified adapter service properties. |
| 318 | * Depending on the <code>propagate</code> parameter, every public factory configuration properties |
| 319 | * (which don't start with ".") will be propagated along with the adapter service properties. |
| 320 | * It will also inherit all dependencies. |
| 321 | * |
| 322 | * @param factoryPid the pid matching the factory configuration |
| 323 | * @param update the adapter method name that will be notified when the factory configuration is created/updated. |
| 324 | * @param adapterInterface the interface to use when registering adapters (can be either a String, String array) |
| 325 | * @param adapterImplementation the implementation of the adapter (can be a Class or an Object instance) |
| 326 | * @param adapterProperties additional properties to use with the service registration |
| 327 | * @param propagate true if public factory configuration should be propagated to the adapter service properties |
| 328 | * @return a service that acts as a factory for generating the managed service factory configuration adapter |
| 329 | */ |
| 330 | public Service createFactoryConfigurationAdapterService(String factoryPid, String update, Object adapterImplementation, String adapterInterface, Dictionary adapterProperties, boolean propagate) { |
| 331 | Hashtable props = new Hashtable(); |
| 332 | props.put(Constants.SERVICE_PID, factoryPid); |
| 333 | return createService() |
| 334 | .setInterface(ManagedServiceFactory.class.getName(), props) |
| 335 | .setImplementation(new FactoryConfigurationAdapterImpl(factoryPid, update, adapterImplementation, adapterInterface, adapterProperties, propagate)); |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * Creates a new Managed Service Factory Configuration Adapter. For each new Config Admin factory configuration matching |
| 340 | * the factoryPid, an adapter will be created based on the adapter implementation class. |
| 341 | * The adapter will be registered with the specified interface, and with the specified adapter service properties. |
| 342 | * Depending on the <code>propagate</code> parameter, every public factory configuration properties |
| 343 | * (which don't start with ".") will be propagated along with the adapter service properties. |
| 344 | * It will also inherit all dependencies. |
| 345 | * |
| 346 | * @param factoryPid the pid matching the factory configuration |
| 347 | * @param update the adapter method name that will be notified when the factory configuration is created/updated. |
| 348 | * @param adapterInterfaces the interfaces to use when registering adapters (can be either a String, String array) |
| 349 | * @param adapterImplementation the implementation of the adapter (can be a Class or an Object instance) |
| 350 | * @param adapterProperties additional properties to use with the service registration |
| 351 | * @param propagate true if public factory configuration should be propagated to the adapter service properties |
| 352 | * @return a service that acts as a factory for generating the managed service factory configuration adapter |
| 353 | */ |
| 354 | public Service createFactoryConfigurationAdapterService(String factoryPid, String update, Object adapterImplementation, String[] adapterInterfaces, Dictionary adapterProperties, boolean propagate) { |
| 355 | Hashtable props = new Hashtable(); |
| 356 | props.put(Constants.SERVICE_PID, factoryPid); |
| 357 | return createService() |
| 358 | .setInterface(ManagedServiceFactory.class.getName(), props) |
| 359 | .setImplementation(new FactoryConfigurationAdapterImpl(factoryPid, update, adapterImplementation, adapterInterfaces, adapterProperties, propagate)); |
| 360 | } |
| 361 | |
| 362 | /** |
Pierre De Rop | 9a8ebfd | 2010-04-25 22:25:34 +0000 | [diff] [blame] | 363 | * Creates a new Managed Service Factory Configuration Adapter with meta type support. For each new Config Admin factory configuration matching |
| 364 | * the factoryPid, an adapter will be created based on the adapter implementation class. |
| 365 | * The adapter will be registered with the specified interface, and with the specified adapter service properties. |
| 366 | * Depending on the <code>propagate</code> parameter, every public factory configuration properties |
| 367 | * (which don't start with ".") will be propagated along with the adapter service properties. |
| 368 | * It will also inherit all dependencies. |
| 369 | * |
| 370 | * @param factoryPid the pid matching the factory configuration |
| 371 | * @param update the adapter method name that will be notified when the factory configuration is created/updated. |
| 372 | * @param adapterInterfaces the interfaces to use when registering adapters (can be either a String, String array) |
| 373 | * @param adapterImplementation the implementation of the adapter (can be a Class or an Object instance) |
| 374 | * @param adapterProperties additional properties to use with the service registration |
| 375 | * @param propagate true if public factory configuration should be propagated to the adapter service properties |
| 376 | * @param heading The label used to display the tab name (or section) where the properties are displayed. Example: "Printer Service" |
| 377 | * @param desc A human readable description of the factory PID this configuration is associated with. Example: "Configuration for the PrinterService bundle" |
| 378 | * @param localization Points to the basename of the Properties file that can localize the Meta Type informations. |
| 379 | * The default localization base name for the properties is OSGI-INF/l10n/bundle, but can |
| 380 | * be overridden by the manifest Bundle-Localization header (see core specification, in section Localization on page 68). |
| 381 | * You can specify a specific localization basename file using this parameter (e.g. <code>"person"</code> |
| 382 | * will match person_du_NL.properties in the root bundle directory). |
| 383 | * @param propertiesMetaData Array of MetaData regarding configuration properties |
| 384 | * @return a service that acts as a factory for generating the managed service factory configuration adapter |
| 385 | */ |
| 386 | public Service createFactoryConfigurationAdapterService(String factoryPid, String update, Object adapterImplementation, String[] adapterInterfaces, Dictionary adapterProperties, boolean propagate, |
| 387 | String heading, String desc, String localization, PropertyMetaData[] propertiesMetaData) |
| 388 | { |
| 389 | Hashtable props = new Hashtable(); |
| 390 | props.put(Constants.SERVICE_PID, factoryPid); |
| 391 | FactoryConfigurationAdapterMetaTypeImpl impl = |
| 392 | new FactoryConfigurationAdapterMetaTypeImpl(factoryPid, update, adapterImplementation, adapterInterfaces, adapterProperties, propagate, |
| 393 | m_context, m_logger, heading, desc, localization, propertiesMetaData); |
| 394 | return createService() |
| 395 | .setInterface(ManagedServiceFactory.class.getName(), props) |
| 396 | .setImplementation(impl); |
| 397 | } |
| 398 | |
| 399 | /** |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 400 | * Returns a list of services. |
| 401 | * |
| 402 | * @return a list of services |
| 403 | */ |
| 404 | public List getServices() { |
| 405 | return Collections.unmodifiableList(m_services); |
| 406 | } |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 407 | } |