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