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 | |
Marcel Offermans | 5be5f14 | 2011-04-26 10:47:12 +0000 | [diff] [blame] | 21 | import java.lang.ref.WeakReference; |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 22 | import java.util.ArrayList; |
| 23 | import java.util.Collections; |
Marcel Offermans | 5be5f14 | 2011-04-26 10:47:12 +0000 | [diff] [blame] | 24 | import java.util.HashSet; |
| 25 | import java.util.Iterator; |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 26 | import java.util.List; |
Marcel Offermans | 5be5f14 | 2011-04-26 10:47:12 +0000 | [diff] [blame] | 27 | import java.util.Set; |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 28 | |
Pierre De Rop | 3423158 | 2010-05-23 20:05:16 +0000 | [diff] [blame] | 29 | import org.apache.felix.dm.impl.AdapterServiceImpl; |
Pierre De Rop | 19476fe | 2010-05-23 08:13:58 +0000 | [diff] [blame] | 30 | import org.apache.felix.dm.impl.AspectServiceImpl; |
Pierre De Rop | 13dd63d | 2010-05-23 21:58:28 +0000 | [diff] [blame] | 31 | import org.apache.felix.dm.impl.BundleAdapterServiceImpl; |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 32 | import org.apache.felix.dm.impl.ComponentImpl; |
Pierre De Rop | 3e10037 | 2010-05-24 12:43:44 +0000 | [diff] [blame] | 33 | import org.apache.felix.dm.impl.FactoryConfigurationAdapterServiceImpl; |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 34 | import org.apache.felix.dm.impl.Logger; |
Pierre De Rop | 445ddec | 2010-05-23 21:05:27 +0000 | [diff] [blame] | 35 | import org.apache.felix.dm.impl.ResourceAdapterServiceImpl; |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 36 | import org.apache.felix.dm.impl.dependencies.BundleDependencyImpl; |
| 37 | import org.apache.felix.dm.impl.dependencies.ConfigurationDependencyImpl; |
| 38 | import org.apache.felix.dm.impl.dependencies.ResourceDependencyImpl; |
| 39 | import org.apache.felix.dm.impl.dependencies.ServiceDependencyImpl; |
| 40 | import org.apache.felix.dm.impl.dependencies.TemporalServiceDependencyImpl; |
Marcel Offermans | 90ba4fa | 2011-04-27 07:57:44 +0000 | [diff] [blame] | 41 | import org.apache.felix.dm.impl.index.AspectFilterIndex; |
| 42 | import org.apache.felix.dm.impl.index.MultiPropertyExactFilter; |
Xander Uiterlinden | b64a8e2 | 2012-04-03 14:42:23 +0000 | [diff] [blame] | 43 | import org.apache.felix.dm.impl.index.AdapterFilterIndex; |
Marcel Offermans | 90ba4fa | 2011-04-27 07:57:44 +0000 | [diff] [blame] | 44 | import org.apache.felix.dm.impl.index.ServiceRegistryCache; |
Pierre De Rop | a0204f5 | 2010-03-06 22:23:57 +0000 | [diff] [blame] | 45 | import org.apache.felix.dm.impl.metatype.PropertyMetaDataImpl; |
Marcel Offermans | a7dadd5 | 2011-06-22 12:10:01 +0000 | [diff] [blame] | 46 | import org.osgi.framework.Bundle; |
Marcel Offermans | b8405a5 | 2009-12-22 19:01:31 +0000 | [diff] [blame] | 47 | import org.osgi.framework.BundleContext; |
Marcel Offermans | a7dadd5 | 2011-06-22 12:10:01 +0000 | [diff] [blame] | 48 | import org.osgi.framework.BundleException; |
Marcel Offermans | 227dd71 | 2011-04-19 07:14:22 +0000 | [diff] [blame] | 49 | import org.osgi.framework.FrameworkUtil; |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 50 | |
| 51 | /** |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 52 | * The dependency manager manages all components and their dependencies. Using |
| 53 | * this API you can declare all components and their dependencies. Under normal |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 54 | * circumstances, you get passed an instance of this class through the |
| 55 | * <code>DependencyActivatorBase</code> subclass you use as your |
| 56 | * <code>BundleActivator</code>, but it is also possible to create your |
| 57 | * own instance. |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 58 | * |
| 59 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 60 | */ |
| 61 | public class DependencyManager { |
Marcel Offermans | ad76067 | 2010-03-03 15:30:01 +0000 | [diff] [blame] | 62 | public static final String ASPECT = "org.apache.felix.dependencymanager.aspect"; |
Marcel Offermans | 540daac | 2011-06-22 07:25:33 +0000 | [diff] [blame] | 63 | public static final String SERVICEREGISTRY_CACHE_INDICES = "org.apache.felix.dependencymanager.filterindex"; |
Marcel Offermans | e090607 | 2011-05-17 11:09:05 +0000 | [diff] [blame] | 64 | public static final String METHOD_CACHE_SIZE = "org.apache.felix.dependencymanager.methodcache"; |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 65 | private final BundleContext m_context; |
| 66 | private final Logger m_logger; |
Marcel Offermans | 5be5f14 | 2011-04-26 10:47:12 +0000 | [diff] [blame] | 67 | private List m_components = Collections.synchronizedList(new ArrayList()); |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 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 | 227dd71 | 2011-04-19 07:14:22 +0000 | [diff] [blame] | 82 | m_context = createContext(context); |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 83 | m_logger = logger; |
Marcel Offermans | 5be5f14 | 2011-04-26 10:47:12 +0000 | [diff] [blame] | 84 | synchronized (m_dependencyManagers) { |
| 85 | m_dependencyManagers.add(new WeakReference(this)); |
| 86 | } |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 87 | } |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 88 | |
Marcel Offermans | 227dd71 | 2011-04-19 07:14:22 +0000 | [diff] [blame] | 89 | // service registry cache |
| 90 | private static ServiceRegistryCache m_serviceRegistryCache; |
Marcel Offermans | 5be5f14 | 2011-04-26 10:47:12 +0000 | [diff] [blame] | 91 | private static final Set /* WeakReference<DependencyManager> */ m_dependencyManagers = new HashSet(); |
Marcel Offermans | 227dd71 | 2011-04-19 07:14:22 +0000 | [diff] [blame] | 92 | static { |
| 93 | String index = System.getProperty(SERVICEREGISTRY_CACHE_INDICES); |
Marcel Offermans | 227dd71 | 2011-04-19 07:14:22 +0000 | [diff] [blame] | 94 | if (index != null) { |
Marcel Offermans | a7dadd5 | 2011-06-22 12:10:01 +0000 | [diff] [blame] | 95 | Bundle bundle = FrameworkUtil.getBundle(DependencyManager.class); |
| 96 | try { |
| 97 | if (bundle.getState() != Bundle.ACTIVE) { |
| 98 | bundle.start(); |
Marcel Offermans | fd7deb0 | 2011-04-20 11:26:09 +0000 | [diff] [blame] | 99 | } |
Marcel Offermans | a7dadd5 | 2011-06-22 12:10:01 +0000 | [diff] [blame] | 100 | BundleContext bundleContext = bundle.getBundleContext(); |
| 101 | |
| 102 | m_serviceRegistryCache = new ServiceRegistryCache(bundleContext); |
| 103 | m_serviceRegistryCache.open(); // TODO close it somewhere |
| 104 | String[] props = index.split(";"); |
| 105 | for (int i = 0; i < props.length; i++) { |
| 106 | if (props[i].equals("*aspect*")) { |
| 107 | m_serviceRegistryCache.addFilterIndex(new AspectFilterIndex()); |
Marcel Offermans | cba269a | 2013-01-18 11:00:56 +0000 | [diff] [blame] | 108 | } |
| 109 | else if (props[i].equals("*adapter*")) { |
Xander Uiterlinden | b64a8e2 | 2012-04-03 14:42:23 +0000 | [diff] [blame] | 110 | m_serviceRegistryCache.addFilterIndex(new AdapterFilterIndex()); |
Marcel Offermans | a7dadd5 | 2011-06-22 12:10:01 +0000 | [diff] [blame] | 111 | } |
| 112 | else { |
| 113 | String[] propList = props[i].split(","); |
| 114 | m_serviceRegistryCache.addFilterIndex(new MultiPropertyExactFilter(propList)); |
| 115 | } |
Marcel Offermans | fd7deb0 | 2011-04-20 11:26:09 +0000 | [diff] [blame] | 116 | } |
Marcel Offermans | 227dd71 | 2011-04-19 07:14:22 +0000 | [diff] [blame] | 117 | } |
Marcel Offermans | a7dadd5 | 2011-06-22 12:10:01 +0000 | [diff] [blame] | 118 | catch (BundleException e) { |
| 119 | // if we cannot start ourselves, we cannot use the indices |
| 120 | // TODO we might want to warn people about this |
| 121 | } |
Marcel Offermans | 227dd71 | 2011-04-19 07:14:22 +0000 | [diff] [blame] | 122 | } |
Marcel Offermans | 5be5f14 | 2011-04-26 10:47:12 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | public static List getDependencyManagers() { |
| 126 | List /* DependencyManager */ result = new ArrayList(); |
| 127 | synchronized (m_dependencyManagers) { |
| 128 | Iterator iterator = m_dependencyManagers.iterator(); |
| 129 | while (iterator.hasNext()) { |
| 130 | WeakReference reference = (WeakReference) iterator.next(); |
| 131 | DependencyManager manager = (DependencyManager) reference.get(); |
| 132 | if (manager != null) { |
Marcel Offermans | c7fbf78 | 2011-05-18 14:34:33 +0000 | [diff] [blame] | 133 | try { |
| 134 | manager.getBundleContext().getBundle(); |
| 135 | result.add(manager); |
| 136 | continue; |
| 137 | } |
| 138 | catch (IllegalStateException e) { |
| 139 | } |
Marcel Offermans | 5be5f14 | 2011-04-26 10:47:12 +0000 | [diff] [blame] | 140 | } |
Marcel Offermans | c7fbf78 | 2011-05-18 14:34:33 +0000 | [diff] [blame] | 141 | iterator.remove(); |
Marcel Offermans | 5be5f14 | 2011-04-26 10:47:12 +0000 | [diff] [blame] | 142 | } |
Marcel Offermans | 227dd71 | 2011-04-19 07:14:22 +0000 | [diff] [blame] | 143 | } |
Marcel Offermans | 5be5f14 | 2011-04-26 10:47:12 +0000 | [diff] [blame] | 144 | return result; |
Marcel Offermans | 227dd71 | 2011-04-19 07:14:22 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | private BundleContext createContext(BundleContext context) { |
| 148 | if (m_serviceRegistryCache != null) { |
| 149 | // System.out.println("DM: Enabling bundle context interceptor for bundle #" + context.getBundle().getBundleId()); |
| 150 | return m_serviceRegistryCache.createBundleContextInterceptor(context); |
| 151 | } |
| 152 | else { |
| 153 | return context; |
| 154 | } |
| 155 | } |
Marcel Offermans | 5be5f14 | 2011-04-26 10:47:12 +0000 | [diff] [blame] | 156 | |
| 157 | public BundleContext getBundleContext() { |
| 158 | return m_context; |
| 159 | } |
Marcel Offermans | 227dd71 | 2011-04-19 07:14:22 +0000 | [diff] [blame] | 160 | |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 161 | /** |
| 162 | * Adds a new service to the dependency manager. After the service was added |
| 163 | * it will be started immediately. |
| 164 | * |
| 165 | * @param service the service to add |
| 166 | */ |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 167 | public void add(Component service) { |
Marcel Offermans | 5be5f14 | 2011-04-26 10:47:12 +0000 | [diff] [blame] | 168 | m_components.add(service); |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 169 | service.start(); |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Removes a service from the dependency manager. Before the service is removed |
| 174 | * it is stopped first. |
| 175 | * |
| 176 | * @param service the service to remove |
| 177 | */ |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 178 | public void remove(Component service) { |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 179 | service.stop(); |
Marcel Offermans | 5be5f14 | 2011-04-26 10:47:12 +0000 | [diff] [blame] | 180 | m_components.remove(service); |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Creates a new service. |
| 185 | * |
| 186 | * @return the new service |
| 187 | */ |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 188 | public Component createComponent() { |
| 189 | return new ComponentImpl(m_context, this, m_logger); |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Creates a new service dependency. |
| 194 | * |
| 195 | * @return the service dependency |
| 196 | */ |
| 197 | public ServiceDependency createServiceDependency() { |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 198 | return new ServiceDependencyImpl(m_context, m_logger); |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Marcel Offermans | 74363c3 | 2009-11-23 19:56:08 +0000 | [diff] [blame] | 201 | /** |
| 202 | * Creates a new temporal service dependency. |
| 203 | * |
Pierre De Rop | c3dfbb7 | 2010-05-24 13:16:35 +0000 | [diff] [blame] | 204 | * @return a new temporal service dependency |
Marcel Offermans | 74363c3 | 2009-11-23 19:56:08 +0000 | [diff] [blame] | 205 | */ |
| 206 | public TemporalServiceDependency createTemporalServiceDependency() { |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 207 | return new TemporalServiceDependencyImpl(m_context, m_logger); |
Marcel Offermans | 74363c3 | 2009-11-23 19:56:08 +0000 | [diff] [blame] | 208 | } |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 209 | |
| 210 | /** |
| 211 | * Creates a new configuration dependency. |
| 212 | * |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 213 | * @return the configuration dependency |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 214 | */ |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 215 | public ConfigurationDependency createConfigurationDependency() { |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 216 | return new ConfigurationDependencyImpl(m_context, m_logger); |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 219 | /** |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 220 | * Creates a new configuration property metadata. |
| 221 | * |
| 222 | * @return the configuration property metadata. |
Pierre De Rop | a0204f5 | 2010-03-06 22:23:57 +0000 | [diff] [blame] | 223 | */ |
| 224 | public PropertyMetaData createPropertyMetaData() { |
| 225 | return new PropertyMetaDataImpl(); |
| 226 | } |
| 227 | |
| 228 | /** |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 229 | * Creates a new bundle dependency. |
| 230 | * |
Pierre De Rop | c3dfbb7 | 2010-05-24 13:16:35 +0000 | [diff] [blame] | 231 | * @return a new BundleDependency instance. |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 232 | */ |
Marcel Offermans | d66c5ce | 2009-11-26 09:58:44 +0000 | [diff] [blame] | 233 | public BundleDependency createBundleDependency() { |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 234 | return new BundleDependencyImpl(m_context, m_logger); |
Marcel Offermans | d66c5ce | 2009-11-26 09:58:44 +0000 | [diff] [blame] | 235 | } |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 236 | |
| 237 | /** |
| 238 | * Creates a new resource dependency. |
| 239 | * |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 240 | * @return the resource dependency |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 241 | */ |
| 242 | public ResourceDependency createResourceDependency() { |
Pierre De Rop | ae4a5db | 2009-12-04 22:08:05 +0000 | [diff] [blame] | 243 | return new ResourceDependencyImpl(m_context, m_logger); |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 244 | } |
Marcel Offermans | 80eeafe | 2009-12-01 22:12:26 +0000 | [diff] [blame] | 245 | |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 246 | /** |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 247 | * Creates a new aspect. The aspect will be applied to any service that |
| 248 | * matches the specified interface and filter. For each matching service |
| 249 | * an aspect will be created based on the aspect implementation class. |
| 250 | * The aspect will be registered with the same interface and properties |
| 251 | * as the original service, plus any extra properties you supply here. |
| 252 | * It will also inherit all dependencies, and if you declare the original |
| 253 | * service as a member it will be injected. |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 254 | * |
Pierre De Rop | 19476fe | 2010-05-23 08:13:58 +0000 | [diff] [blame] | 255 | * <h3>Usage Example</h3> |
| 256 | * |
Pierre De Rop | c3dfbb7 | 2010-05-24 13:16:35 +0000 | [diff] [blame] | 257 | * <blockquote><pre> |
Marcel Offermans | a8818d5 | 2011-03-09 10:03:35 +0000 | [diff] [blame] | 258 | * manager.createAspectService(ExistingService.class, "(foo=bar)", 10, "m_service") |
| 259 | * .setImplementation(ExistingServiceAspect.class) |
| 260 | * ); |
Pierre De Rop | c3dfbb7 | 2010-05-24 13:16:35 +0000 | [diff] [blame] | 261 | * </pre></blockquote> |
Pierre De Rop | 19476fe | 2010-05-23 08:13:58 +0000 | [diff] [blame] | 262 | * |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 263 | * @param serviceInterface the service interface to apply the aspect to |
| 264 | * @param serviceFilter the filter condition to use with the service interface |
Pierre De Rop | 19476fe | 2010-05-23 08:13:58 +0000 | [diff] [blame] | 265 | * @param ranking the level used to organize the aspect chain ordering |
Marcel Offermans | a8818d5 | 2011-03-09 10:03:35 +0000 | [diff] [blame] | 266 | * @param autoConfig the aspect implementation field name where to inject original service. |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 267 | * If null, any field matching the original service will be injected. |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 268 | * @return a service that acts as a factory for generating aspects |
Marcel Offermans | 2925f17 | 2009-12-02 13:03:39 +0000 | [diff] [blame] | 269 | */ |
Marcel Offermans | a8818d5 | 2011-03-09 10:03:35 +0000 | [diff] [blame] | 270 | public Component createAspectService(Class serviceInterface, String serviceFilter, int ranking, String autoConfig) { |
Xander Uiterlinden | b64a8e2 | 2012-04-03 14:42:23 +0000 | [diff] [blame] | 271 | return new AspectServiceImpl(this, serviceInterface, serviceFilter, ranking, autoConfig, null, null, null, null); |
Marcel Offermans | a8818d5 | 2011-03-09 10:03:35 +0000 | [diff] [blame] | 272 | } |
| 273 | /** |
| 274 | * Creates a new aspect. The aspect will be applied to any service that |
| 275 | * matches the specified interface and filter. For each matching service |
| 276 | * an aspect will be created based on the aspect implementation class. |
| 277 | * The aspect will be registered with the same interface and properties |
| 278 | * as the original service, plus any extra properties you supply here. |
| 279 | * It will also inherit all dependencies, and if you declare the original |
| 280 | * service as a member it will be injected. |
| 281 | * |
| 282 | * <h3>Usage Example</h3> |
| 283 | * |
| 284 | * <blockquote><pre> |
| 285 | * manager.createAspectService(ExistingService.class, "(foo=bar)", 10) |
| 286 | * .setImplementation(ExistingServiceAspect.class) |
| 287 | * ); |
| 288 | * </pre></blockquote> |
| 289 | * |
| 290 | * @param serviceInterface the service interface to apply the aspect to |
| 291 | * @param serviceFilter the filter condition to use with the service interface |
| 292 | * @param ranking the level used to organize the aspect chain ordering |
| 293 | * @return a service that acts as a factory for generating aspects |
| 294 | */ |
| 295 | public Component createAspectService(Class serviceInterface, String serviceFilter, int ranking) { |
Xander Uiterlinden | b64a8e2 | 2012-04-03 14:42:23 +0000 | [diff] [blame] | 296 | return new AspectServiceImpl(this, serviceInterface, serviceFilter, ranking, null, null, null, null, null); |
Marcel Offermans | a8818d5 | 2011-03-09 10:03:35 +0000 | [diff] [blame] | 297 | } |
| 298 | /** |
| 299 | * Creates a new aspect. The aspect will be applied to any service that |
| 300 | * matches the specified interface and filter. For each matching service |
| 301 | * an aspect will be created based on the aspect implementation class. |
| 302 | * The aspect will be registered with the same interface and properties |
| 303 | * as the original service, plus any extra properties you supply here. |
| 304 | * It will also inherit all dependencies, and if you declare the original |
| 305 | * service as a member it will be injected. |
| 306 | * |
| 307 | * <h3>Usage Example</h3> |
| 308 | * |
| 309 | * <blockquote><pre> |
| 310 | * manager.createAspectService(ExistingService.class, "(foo=bar)", 10, "add", "change", "remove") |
| 311 | * .setImplementation(ExistingServiceAspect.class) |
| 312 | * ); |
| 313 | * </pre></blockquote> |
| 314 | * |
| 315 | * @param serviceInterface the service interface to apply the aspect to |
| 316 | * @param serviceFilter the filter condition to use with the service interface |
| 317 | * @param ranking the level used to organize the aspect chain ordering |
| 318 | * @param add name of the callback method to invoke on add |
| 319 | * @param change name of the callback method to invoke on change |
| 320 | * @param remove name of the callback method to invoke on remove |
| 321 | * @return a service that acts as a factory for generating aspects |
| 322 | */ |
| 323 | public Component createAspectService(Class serviceInterface, String serviceFilter, int ranking, String add, String change, String remove) { |
Xander Uiterlinden | b64a8e2 | 2012-04-03 14:42:23 +0000 | [diff] [blame] | 324 | return new AspectServiceImpl(this, serviceInterface, serviceFilter, ranking, null, add, change, remove, null); |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * Creates a new aspect. The aspect will be applied to any service that |
| 329 | * matches the specified interface and filter. For each matching service |
| 330 | * an aspect will be created based on the aspect implementation class. |
| 331 | * The aspect will be registered with the same interface and properties |
| 332 | * as the original service, plus any extra properties you supply here. |
| 333 | * It will also inherit all dependencies, and if you declare the original |
| 334 | * service as a member it will be injected. |
| 335 | * |
| 336 | * <h3>Usage Example</h3> |
| 337 | * |
| 338 | * <blockquote><pre> |
| 339 | * manager.createAspectService(ExistingService.class, "(foo=bar)", 10, "add", "change", "remove") |
| 340 | * .setImplementation(ExistingServiceAspect.class) |
| 341 | * ); |
| 342 | * </pre></blockquote> |
| 343 | * |
| 344 | * @param serviceInterface the service interface to apply the aspect to |
| 345 | * @param serviceFilter the filter condition to use with the service interface |
| 346 | * @param ranking the level used to organize the aspect chain ordering |
| 347 | * @param add name of the callback method to invoke on add |
| 348 | * @param change name of the callback method to invoke on change |
| 349 | * @param remove name of the callback method to invoke on remove |
| 350 | * @param swap name of the callback method to invoke on swap |
| 351 | * @return a service that acts as a factory for generating aspects |
| 352 | */ |
| 353 | public Component createAspectService(Class serviceInterface, String serviceFilter, int ranking, String add, String change, String remove, String swap) { |
| 354 | return new AspectServiceImpl(this, serviceInterface, serviceFilter, ranking, null, add, change, remove, swap); |
Marcel Offermans | 80eeafe | 2009-12-01 22:12:26 +0000 | [diff] [blame] | 355 | } |
Marcel Offermans | e9c13d9 | 2010-07-01 14:01:02 +0000 | [diff] [blame] | 356 | |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 357 | /** |
| 358 | * Creates a new adapter. The adapter will be applied to any service that |
| 359 | * matches the specified interface and filter. For each matching service |
| 360 | * an adapter will be created based on the adapter implementation class. |
| 361 | * The adapter will be registered with the specified interface and existing properties |
| 362 | * from the original service plus any extra properties you supply here. |
| 363 | * It will also inherit all dependencies, and if you declare the original |
| 364 | * service as a member it will be injected. |
| 365 | * |
Pierre De Rop | 3423158 | 2010-05-23 20:05:16 +0000 | [diff] [blame] | 366 | * <h3>Usage Example</h3> |
| 367 | * |
Pierre De Rop | c3dfbb7 | 2010-05-24 13:16:35 +0000 | [diff] [blame] | 368 | * <blockquote><pre> |
Marcel Offermans | a8818d5 | 2011-03-09 10:03:35 +0000 | [diff] [blame] | 369 | * manager.createAdapterService(AdapteeService.class, "(foo=bar)") |
| 370 | * .setInterface(AdapterService.class, new Hashtable() {{ put("extra", "property"); }}) |
| 371 | * .setImplementation(AdapterImpl.class); |
Pierre De Rop | c3dfbb7 | 2010-05-24 13:16:35 +0000 | [diff] [blame] | 372 | * </pre></blockquote> |
Marcel Offermans | a8818d5 | 2011-03-09 10:03:35 +0000 | [diff] [blame] | 373 | * |
Marcel Offermans | d665eaf | 2010-02-16 15:56:35 +0000 | [diff] [blame] | 374 | * @param serviceInterface the service interface to apply the adapter to |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 375 | * @param serviceFilter the filter condition to use with the service interface |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 376 | * @return a service that acts as a factory for generating adapters |
| 377 | */ |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 378 | public Component createAdapterService(Class serviceInterface, String serviceFilter) { |
Marcel Offermans | a8818d5 | 2011-03-09 10:03:35 +0000 | [diff] [blame] | 379 | return new AdapterServiceImpl(this, serviceInterface, serviceFilter, null, null, null, null); |
| 380 | } |
| 381 | /** |
| 382 | * Creates a new adapter. The adapter will be applied to any service that |
| 383 | * matches the specified interface and filter. For each matching service |
| 384 | * an adapter will be created based on the adapter implementation class. |
| 385 | * The adapter will be registered with the specified interface and existing properties |
| 386 | * from the original service plus any extra properties you supply here. |
| 387 | * It will also inherit all dependencies, and if you declare the original |
| 388 | * service as a member it will be injected. |
| 389 | * |
| 390 | * <h3>Usage Example</h3> |
| 391 | * |
| 392 | * <blockquote><pre> |
| 393 | * manager.createAdapterService(AdapteeService.class, "(foo=bar)", "m_service") |
| 394 | * .setInterface(AdapterService.class, new Hashtable() {{ put("extra", "property"); }}) |
| 395 | * .setImplementation(AdapterImpl.class); |
| 396 | * </pre></blockquote> |
| 397 | * |
| 398 | * @param serviceInterface the service interface to apply the adapter to |
| 399 | * @param serviceFilter the filter condition to use with the service interface |
| 400 | * @param autoConfig the name of the member to inject the service into |
| 401 | * @return a service that acts as a factory for generating adapters |
| 402 | */ |
| 403 | public Component createAdapterService(Class serviceInterface, String serviceFilter, String autoConfig) { |
| 404 | return new AdapterServiceImpl(this, serviceInterface, serviceFilter, autoConfig, null, null, null); |
| 405 | } |
| 406 | /** |
| 407 | * Creates a new adapter. The adapter will be applied to any service that |
| 408 | * matches the specified interface and filter. For each matching service |
| 409 | * an adapter will be created based on the adapter implementation class. |
| 410 | * The adapter will be registered with the specified interface and existing properties |
| 411 | * from the original service plus any extra properties you supply here. |
| 412 | * It will also inherit all dependencies, and if you declare the original |
| 413 | * service as a member it will be injected. |
| 414 | * |
| 415 | * <h3>Usage Example</h3> |
| 416 | * |
| 417 | * <blockquote><pre> |
| 418 | * manager.createAdapterService(AdapteeService.class, "(foo=bar)", "add", "change", "remove") |
| 419 | * .setInterface(AdapterService.class, new Hashtable() {{ put("extra", "property"); }}) |
| 420 | * .setImplementation(AdapterImpl.class); |
| 421 | * </pre></blockquote> |
| 422 | * |
| 423 | * @param serviceInterface the service interface to apply the adapter to |
| 424 | * @param serviceFilter the filter condition to use with the service interface |
| 425 | * @param add name of the callback method to invoke on add |
| 426 | * @param change name of the callback method to invoke on change |
| 427 | * @param remove name of the callback method to invoke on remove |
Marcel Offermans | 4aa032c | 2012-01-02 19:18:22 +0000 | [diff] [blame] | 428 | * @param swap name of the callback method to invoke on swap |
Marcel Offermans | a8818d5 | 2011-03-09 10:03:35 +0000 | [diff] [blame] | 429 | * @return a service that acts as a factory for generating adapters |
| 430 | */ |
Marcel Offermans | 4aa032c | 2012-01-02 19:18:22 +0000 | [diff] [blame] | 431 | public Component createAdapterService(Class serviceInterface, String serviceFilter, String add, String change, String remove, String swap) { |
| 432 | return new AdapterServiceImpl(this, serviceInterface, serviceFilter, null, add, change, remove, swap); |
| 433 | } |
| 434 | |
Marcel Offermans | cba269a | 2013-01-18 11:00:56 +0000 | [diff] [blame] | 435 | /** @see DependencyManager#createAdapterService(Class, String, String, String, String, String) */ |
Marcel Offermans | a8818d5 | 2011-03-09 10:03:35 +0000 | [diff] [blame] | 436 | public Component createAdapterService(Class serviceInterface, String serviceFilter, String add, String change, String remove) { |
| 437 | return new AdapterServiceImpl(this, serviceInterface, serviceFilter, null, add, change, remove); |
Marcel Offermans | 61a8114 | 2010-04-02 15:16:50 +0000 | [diff] [blame] | 438 | } |
Pierre De Rop | 3423158 | 2010-05-23 20:05:16 +0000 | [diff] [blame] | 439 | |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 440 | /** |
| 441 | * Creates a new resource adapter. The adapter will be applied to any resource that |
| 442 | * matches the specified filter condition. For each matching resource |
| 443 | * an adapter will be created based on the adapter implementation class. |
| 444 | * The adapter will be registered with the specified interface and existing properties |
| 445 | * from the original resource plus any extra properties you supply here. |
| 446 | * It will also inherit all dependencies, and if you declare the original |
| 447 | * service as a member it will be injected. |
| 448 | * |
Pierre De Rop | 445ddec | 2010-05-23 21:05:27 +0000 | [diff] [blame] | 449 | * <h3>Usage Example</h3> |
| 450 | * |
Pierre De Rop | c3dfbb7 | 2010-05-24 13:16:35 +0000 | [diff] [blame] | 451 | * <blockquote><pre> |
Pierre De Rop | 445ddec | 2010-05-23 21:05:27 +0000 | [diff] [blame] | 452 | * manager.createResourceAdapterService("(&(path=/test)(repository=TestRepository))", true) |
| 453 | * // The interface to use when registering adapter |
Pierre De Rop | c3dfbb7 | 2010-05-24 13:16:35 +0000 | [diff] [blame] | 454 | * .setInterface(AdapterService.class.getName(), new Hashtable() {{ put("foo", "bar"); }}) |
Pierre De Rop | 445ddec | 2010-05-23 21:05:27 +0000 | [diff] [blame] | 455 | * // the implementation of the adapter |
Pierre De Rop | c3dfbb7 | 2010-05-24 13:16:35 +0000 | [diff] [blame] | 456 | * .setImplementation(AdapterServiceImpl.class); |
| 457 | * </pre></blockquote> |
Pierre De Rop | 445ddec | 2010-05-23 21:05:27 +0000 | [diff] [blame] | 458 | * |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 459 | * @param resourceFilter the filter condition to use with the resource |
Marcel Offermans | d26f2bd | 2012-01-02 14:53:17 +0000 | [diff] [blame] | 460 | * @param resourcePropertiesFilter the filter condition on the resource properties to use with the resource |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 461 | * @param propagate <code>true</code> if properties from the resource should be propagated to the service |
Marcel Offermans | cba269a | 2013-01-18 11:00:56 +0000 | [diff] [blame] | 462 | * @param callbackInstance instance to invoke the callback on |
| 463 | * @param callbackChanged the name of the callback method |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 464 | * @return a service that acts as a factory for generating resource adapters |
| 465 | * @see Resource |
| 466 | */ |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 467 | public Component createResourceAdapterService(String resourceFilter, boolean propagate, Object callbackInstance, String callbackChanged) { |
Marcel Offermans | d26f2bd | 2012-01-02 14:53:17 +0000 | [diff] [blame] | 468 | return new ResourceAdapterServiceImpl(this, resourceFilter, propagate, callbackInstance, null, callbackChanged); |
| 469 | } |
| 470 | |
Marcel Offermans | cba269a | 2013-01-18 11:00:56 +0000 | [diff] [blame] | 471 | /** @see DependencyManager#createResourceAdapterService(String, boolean, Object, String) */ |
Marcel Offermans | d26f2bd | 2012-01-02 14:53:17 +0000 | [diff] [blame] | 472 | public Component createResourceAdapterService(String resourceFilter, boolean propagate, Object callbackInstance, String callbackSet, String callbackChanged) { |
| 473 | return new ResourceAdapterServiceImpl(this, resourceFilter, propagate, callbackInstance, callbackSet, callbackChanged); |
Marcel Offermans | 61a8114 | 2010-04-02 15:16:50 +0000 | [diff] [blame] | 474 | } |
Pierre De Rop | 445ddec | 2010-05-23 21:05:27 +0000 | [diff] [blame] | 475 | |
Marcel Offermans | cba269a | 2013-01-18 11:00:56 +0000 | [diff] [blame] | 476 | /** @see DependencyManager#createResourceAdapterService(String, boolean, Object, String) */ |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 477 | public Component createResourceAdapterService(String resourceFilter, Object propagateCallbackInstance, String propagateCallbackMethod, Object callbackInstance, String callbackChanged) { |
Marcel Offermans | d26f2bd | 2012-01-02 14:53:17 +0000 | [diff] [blame] | 478 | return new ResourceAdapterServiceImpl(this, resourceFilter, propagateCallbackInstance, propagateCallbackMethod, callbackInstance, null, callbackChanged); |
| 479 | } |
| 480 | |
Marcel Offermans | cba269a | 2013-01-18 11:00:56 +0000 | [diff] [blame] | 481 | /** @see DependencyManager#createResourceAdapterService(String, boolean, Object, String) */ |
Marcel Offermans | d26f2bd | 2012-01-02 14:53:17 +0000 | [diff] [blame] | 482 | public Component createResourceAdapterService(String resourceFilter, Object propagateCallbackInstance, String propagateCallbackMethod, Object callbackInstance, String callbackSet, String callbackChanged) { |
| 483 | return new ResourceAdapterServiceImpl(this, resourceFilter, propagateCallbackInstance, propagateCallbackMethod, callbackInstance, callbackSet, callbackChanged); |
Marcel Offermans | 26081d3 | 2010-07-12 12:43:42 +0000 | [diff] [blame] | 484 | } |
| 485 | |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 486 | /** |
| 487 | * Creates a new bundle adapter. The adapter will be applied to any bundle that |
| 488 | * matches the specified bundle state mask and filter condition. For each matching |
| 489 | * bundle an adapter will be created based on the adapter implementation class. |
| 490 | * The adapter will be registered with the specified interface |
| 491 | * |
| 492 | * TODO and existing properties from the original resource plus any extra properties you supply here. |
| 493 | * It will also inherit all dependencies, and if you declare the original |
| 494 | * service as a member it will be injected. |
| 495 | * |
Pierre De Rop | 13dd63d | 2010-05-23 21:58:28 +0000 | [diff] [blame] | 496 | * <h3>Usage Example</h3> |
| 497 | * |
Pierre De Rop | c3dfbb7 | 2010-05-24 13:16:35 +0000 | [diff] [blame] | 498 | * <blockquote><pre> |
Pierre De Rop | 13dd63d | 2010-05-23 21:58:28 +0000 | [diff] [blame] | 499 | * manager.createBundleAdapterService(Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE, |
| 500 | * "(Bundle-SymbolicName=org.apache.felix.dependencymanager)", |
| 501 | * true) |
| 502 | * // The interface to use when registering adapter |
Pierre De Rop | c3dfbb7 | 2010-05-24 13:16:35 +0000 | [diff] [blame] | 503 | * .setInterface(AdapterService.class.getName(), new Hashtable() {{ put("foo", "bar"); }}) |
Pierre De Rop | 13dd63d | 2010-05-23 21:58:28 +0000 | [diff] [blame] | 504 | * // the implementation of the adapter |
Pierre De Rop | c3dfbb7 | 2010-05-24 13:16:35 +0000 | [diff] [blame] | 505 | * .setImplementation(AdapterServiceImpl.class); |
| 506 | * </pre></blockquote> |
Pierre De Rop | 13dd63d | 2010-05-23 21:58:28 +0000 | [diff] [blame] | 507 | * |
Marcel Offermans | 4fd903f | 2009-12-29 09:18:05 +0000 | [diff] [blame] | 508 | * @param bundleStateMask the bundle state mask to apply |
| 509 | * @param bundleFilter the filter to apply to the bundle manifest |
Marcel Offermans | d665eaf | 2010-02-16 15:56:35 +0000 | [diff] [blame] | 510 | * @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] | 511 | * @return a service that acts as a factory for generating bundle adapters |
| 512 | */ |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 513 | public Component createBundleAdapterService(int bundleStateMask, String bundleFilter, boolean propagate) { |
Pierre De Rop | 13dd63d | 2010-05-23 21:58:28 +0000 | [diff] [blame] | 514 | return new BundleAdapterServiceImpl(this, bundleStateMask, bundleFilter, propagate); |
Marcel Offermans | 61a8114 | 2010-04-02 15:16:50 +0000 | [diff] [blame] | 515 | } |
Marcel Offermans | 80eeafe | 2009-12-01 22:12:26 +0000 | [diff] [blame] | 516 | |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 517 | /** |
Pierre De Rop | ef94c88 | 2010-04-17 18:23:35 +0000 | [diff] [blame] | 518 | * Creates a new Managed Service Factory Configuration Adapter. For each new Config Admin factory configuration matching |
| 519 | * the factoryPid, an adapter will be created based on the adapter implementation class. |
| 520 | * The adapter will be registered with the specified interface, and with the specified adapter service properties. |
| 521 | * Depending on the <code>propagate</code> parameter, every public factory configuration properties |
| 522 | * (which don't start with ".") will be propagated along with the adapter service properties. |
| 523 | * It will also inherit all dependencies. |
| 524 | * |
Pierre De Rop | 3e10037 | 2010-05-24 12:43:44 +0000 | [diff] [blame] | 525 | * <h3>Usage Example</h3> |
| 526 | * |
Pierre De Rop | c3dfbb7 | 2010-05-24 13:16:35 +0000 | [diff] [blame] | 527 | * <blockquote><pre> |
Pierre De Rop | 3e10037 | 2010-05-24 12:43:44 +0000 | [diff] [blame] | 528 | * manager.createFactoryConfigurationAdapterService("MyFactoryPid", "update", true) |
| 529 | * // The interface to use when registering adapter |
Pierre De Rop | c3dfbb7 | 2010-05-24 13:16:35 +0000 | [diff] [blame] | 530 | * .setInterface(AdapterService.class.getName(), new Hashtable() {{ put("foo", "bar"); }}) |
Pierre De Rop | 3e10037 | 2010-05-24 12:43:44 +0000 | [diff] [blame] | 531 | * // the implementation of the adapter |
| 532 | * .setImplementation(AdapterServiceImpl.class); |
Pierre De Rop | c3dfbb7 | 2010-05-24 13:16:35 +0000 | [diff] [blame] | 533 | * </pre></blockquote> |
| 534 | * |
Pierre De Rop | ef94c88 | 2010-04-17 18:23:35 +0000 | [diff] [blame] | 535 | * @param factoryPid the pid matching the factory configuration |
| 536 | * @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] | 537 | * @param propagate true if public factory configuration should be propagated to the adapter service properties |
| 538 | * @return a service that acts as a factory for generating the managed service factory configuration adapter |
| 539 | */ |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 540 | public Component createFactoryConfigurationAdapterService(String factoryPid, String update, boolean propagate) { |
Pierre De Rop | 3e10037 | 2010-05-24 12:43:44 +0000 | [diff] [blame] | 541 | return new FactoryConfigurationAdapterServiceImpl(this, factoryPid, update, propagate); |
Pierre De Rop | ef94c88 | 2010-04-17 18:23:35 +0000 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | /** |
Pierre De Rop | 3e10037 | 2010-05-24 12:43:44 +0000 | [diff] [blame] | 545 | * Creates a new Managed Service Factory Configuration Adapter with meta type support. For each new Config Admin |
| 546 | * factory configuration matching the factoryPid, an adapter will be created based on the adapter implementation |
| 547 | * class. The adapter will be registered with the specified interface, and with the specified adapter service |
| 548 | * 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] | 549 | * (which don't start with ".") will be propagated along with the adapter service properties. |
| 550 | * It will also inherit all dependencies. |
| 551 | * |
Pierre De Rop | c3dfbb7 | 2010-05-24 13:16:35 +0000 | [diff] [blame] | 552 | * <h3>Usage Example</h3> |
| 553 | * |
| 554 | * <blockquote><pre> |
| 555 | * PropertyMetaData[] propertiesMetaData = new PropertyMetaData[] { |
| 556 | * manager.createPropertyMetaData() |
| 557 | * .setCardinality(Integer.MAX_VALUE) |
| 558 | * .setType(String.class) |
| 559 | * .setHeading("English words") |
| 560 | * .setDescription("Declare here some valid english words") |
| 561 | * .setDefaults(new String[] {"hello", "world"}) |
| 562 | * .setId("words") |
| 563 | * }; |
| 564 | * |
| 565 | * manager.add(createFactoryConfigurationAdapterService("FactoryPid", |
| 566 | * "updated", |
| 567 | * true, // propagate CM settings |
| 568 | * "EnglishDictionary", |
| 569 | * "English dictionary configuration properties", |
| 570 | * null, |
| 571 | * propertiesMetaData) |
| 572 | * .setImplementation(Adapter.class)); |
| 573 | * </pre></blockquote> |
| 574 | * |
Pierre De Rop | ef94c88 | 2010-04-17 18:23:35 +0000 | [diff] [blame] | 575 | * @param factoryPid the pid matching the factory configuration |
| 576 | * @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] | 577 | * @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] | 578 | * @param heading The label used to display the tab name (or section) where the properties are displayed. |
| 579 | * Example: "Printer Service" |
| 580 | * @param desc A human readable description of the factory PID this configuration is associated with. |
| 581 | * Example: "Configuration for the PrinterService bundle" |
Pierre De Rop | 9a8ebfd | 2010-04-25 22:25:34 +0000 | [diff] [blame] | 582 | * @param localization Points to the basename of the Properties file that can localize the Meta Type informations. |
| 583 | * 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] | 584 | * be overridden by the manifest Bundle-Localization header (see core specification, in section Localization |
| 585 | * on page 68). You can specify a specific localization basename file using this parameter |
| 586 | * (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] | 587 | * @param propertiesMetaData Array of MetaData regarding configuration properties |
| 588 | * @return a service that acts as a factory for generating the managed service factory configuration adapter |
| 589 | */ |
Marcel Offermans | cba269a | 2013-01-18 11:00:56 +0000 | [diff] [blame] | 590 | public Component createFactoryConfigurationAdapterService(String factoryPid, String update, boolean propagate, String heading, String desc, String localization, PropertyMetaData[] propertiesMetaData) { |
| 591 | return new FactoryConfigurationAdapterServiceImpl(this, factoryPid, update, propagate, m_context, m_logger, heading, desc, localization, propertiesMetaData); |
Pierre De Rop | 9a8ebfd | 2010-04-25 22:25:34 +0000 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | /** |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 595 | * Returns a list of services. |
| 596 | * |
| 597 | * @return a list of services |
| 598 | */ |
Marcel Offermans | 5be5f14 | 2011-04-26 10:47:12 +0000 | [diff] [blame] | 599 | public List getComponents() { |
| 600 | return Collections.unmodifiableList(m_components); |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 601 | } |
Marcel Offermans | 0709583 | 2011-11-16 06:28:10 +0000 | [diff] [blame] | 602 | |
| 603 | /** |
| 604 | * Removes all components and their dependencies. |
| 605 | */ |
| 606 | public void clear() { |
Marcel Offermans | 8222d98 | 2013-01-15 10:11:39 +0000 | [diff] [blame] | 607 | Component[] components; |
| 608 | synchronized (m_components) { |
| 609 | components = (Component[]) m_components.toArray(new Component[m_components.size()]); |
| 610 | } |
| 611 | for (int i = components.length - 1; i >= 0; i--) { |
| 612 | Component component = (Component) components[i]; |
| 613 | remove(component); |
Marcel Offermans | 0709583 | 2011-11-16 06:28:10 +0000 | [diff] [blame] | 614 | // remove any state listeners that are still registered |
Marcel Offermans | 8222d98 | 2013-01-15 10:11:39 +0000 | [diff] [blame] | 615 | if (component instanceof ComponentImpl) { |
| 616 | ComponentImpl si = (ComponentImpl) component; |
Marcel Offermans | 0709583 | 2011-11-16 06:28:10 +0000 | [diff] [blame] | 617 | si.removeStateListeners(); |
| 618 | } |
| 619 | } |
| 620 | } |
Marcel Offermans | a962bc9 | 2009-11-21 17:59:33 +0000 | [diff] [blame] | 621 | } |