Pierre De Rop | ddce586 | 2009-12-04 22:16:48 +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 | */ |
Marcel Offermans | 8b93efa | 2010-07-02 18:27:21 +0000 | [diff] [blame] | 19 | package org.apache.felix.dm; |
Pierre De Rop | ddce586 | 2009-12-04 22:16:48 +0000 | [diff] [blame] | 20 | |
Pierre De Rop | ddce586 | 2009-12-04 22:16:48 +0000 | [diff] [blame] | 21 | import org.osgi.framework.ServiceReference; |
| 22 | |
| 23 | /** |
| 24 | * Service dependency that can track an OSGi service. |
| 25 | * |
| 26 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 27 | */ |
Marcel Offermans | faaed47 | 2010-09-08 10:07:32 +0000 | [diff] [blame] | 28 | public interface ServiceDependency extends Dependency, ComponentDependencyDeclaration { |
Pierre De Rop | ddce586 | 2009-12-04 22:16:48 +0000 | [diff] [blame] | 29 | /** |
| 30 | * Sets the name of the service that should be tracked. |
| 31 | * |
| 32 | * @param serviceName the name of the service |
| 33 | * @return this service dependency |
| 34 | */ |
Marcel Offermans | a564b3a | 2010-03-20 20:19:15 +0000 | [diff] [blame] | 35 | public ServiceDependency setService(Class serviceName); |
Pierre De Rop | ddce586 | 2009-12-04 22:16:48 +0000 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Sets the name of the service that should be tracked. You can either specify |
| 39 | * only the name, or the name and a filter. In the latter case, the filter is used |
| 40 | * to track the service and should only return services of the type that was specified |
| 41 | * in the name. To make sure of this, the filter is actually extended internally to |
| 42 | * filter on the correct name. |
| 43 | * |
| 44 | * @param serviceName the name of the service |
| 45 | * @param serviceFilter the filter condition |
| 46 | * @return this service dependency |
| 47 | */ |
Marcel Offermans | a564b3a | 2010-03-20 20:19:15 +0000 | [diff] [blame] | 48 | public ServiceDependency setService(Class serviceName, String serviceFilter); |
Marcel Offermans | a83c25a | 2009-12-22 13:38:38 +0000 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * Sets the filter for the services that should be tracked. Any service object |
| 52 | * matching the filter will be returned, without any additional filter on the |
| 53 | * class. |
| 54 | * |
| 55 | * @param serviceFilter the filter condition |
| 56 | * @return this service dependency |
| 57 | */ |
Marcel Offermans | a564b3a | 2010-03-20 20:19:15 +0000 | [diff] [blame] | 58 | public ServiceDependency setService(String serviceFilter); |
Pierre De Rop | ddce586 | 2009-12-04 22:16:48 +0000 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * Sets the name of the service that should be tracked. You can either specify |
| 62 | * only the name, or the name and a reference. In the latter case, the service reference |
| 63 | * is used to track the service and should only return services of the type that was |
| 64 | * specified in the name. |
| 65 | * |
| 66 | * @param serviceName the name of the service |
| 67 | * @param serviceReference the service reference to track |
| 68 | * @return this service dependency |
| 69 | */ |
Marcel Offermans | a564b3a | 2010-03-20 20:19:15 +0000 | [diff] [blame] | 70 | public ServiceDependency setService(Class serviceName, ServiceReference serviceReference); |
Pierre De Rop | ddce586 | 2009-12-04 22:16:48 +0000 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * Sets the default implementation for this service dependency. You can use this to supply |
| 74 | * your own implementation that will be used instead of a Null Object when the dependency is |
| 75 | * not available. This is also convenient if the service dependency is not an interface |
| 76 | * (which would cause the Null Object creation to fail) but a class. |
| 77 | * |
| 78 | * @param implementation the instance to use or the class to instantiate if you want to lazily |
| 79 | * instantiate this implementation |
| 80 | * @return this service dependency |
| 81 | */ |
Marcel Offermans | a564b3a | 2010-03-20 20:19:15 +0000 | [diff] [blame] | 82 | public ServiceDependency setDefaultImplementation(Object implementation); |
Pierre De Rop | ddce586 | 2009-12-04 22:16:48 +0000 | [diff] [blame] | 83 | |
| 84 | /** |
| 85 | * Sets the required flag which determines if this service is required or not. |
| 86 | * |
| 87 | * @param required the required flag |
| 88 | * @return this service dependency |
| 89 | */ |
Marcel Offermans | a564b3a | 2010-03-20 20:19:15 +0000 | [diff] [blame] | 90 | public ServiceDependency setRequired(boolean required); |
Pierre De Rop | ddce586 | 2009-12-04 22:16:48 +0000 | [diff] [blame] | 91 | |
| 92 | /** |
| 93 | * Sets auto configuration for this service. Auto configuration allows the |
| 94 | * dependency to fill in any attributes in the service implementation that |
| 95 | * are of the same type as this dependency. Default is on. |
| 96 | * |
| 97 | * @param autoConfig the value of auto config |
| 98 | * @return this service dependency |
| 99 | */ |
Marcel Offermans | a564b3a | 2010-03-20 20:19:15 +0000 | [diff] [blame] | 100 | public ServiceDependency setAutoConfig(boolean autoConfig); |
Pierre De Rop | ddce586 | 2009-12-04 22:16:48 +0000 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Sets auto configuration for this service. Auto configuration allows the |
| 104 | * dependency to fill in the attribute in the service implementation that |
| 105 | * has the same type and instance name. |
| 106 | * |
| 107 | * @param instanceName the name of attribute to auto config |
| 108 | * @return this service dependency |
| 109 | */ |
Marcel Offermans | a564b3a | 2010-03-20 20:19:15 +0000 | [diff] [blame] | 110 | public ServiceDependency setAutoConfig(String instanceName); |
Pierre De Rop | ddce586 | 2009-12-04 22:16:48 +0000 | [diff] [blame] | 111 | |
| 112 | /** |
| 113 | * Sets the callbacks for this service. These callbacks can be used as hooks whenever a |
| 114 | * dependency is added or removed. When you specify callbacks, the auto configuration |
| 115 | * feature is automatically turned off, because we're assuming you don't need it in this |
| 116 | * case. |
| 117 | * |
| 118 | * @param added the method to call when a service was added |
| 119 | * @param removed the method to call when a service was removed |
| 120 | * @return this service dependency |
| 121 | */ |
Marcel Offermans | a564b3a | 2010-03-20 20:19:15 +0000 | [diff] [blame] | 122 | public ServiceDependency setCallbacks(String added, String removed); |
Pierre De Rop | ddce586 | 2009-12-04 22:16:48 +0000 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * Sets the callbacks for this service. These callbacks can be used as hooks whenever a |
| 126 | * dependency is added, changed or removed. When you specify callbacks, the auto |
| 127 | * configuration feature is automatically turned off, because we're assuming you don't |
| 128 | * need it in this case. |
| 129 | * |
| 130 | * @param added the method to call when a service was added |
| 131 | * @param changed the method to call when a service was changed |
| 132 | * @param removed the method to call when a service was removed |
| 133 | * @return this service dependency |
| 134 | */ |
Marcel Offermans | a564b3a | 2010-03-20 20:19:15 +0000 | [diff] [blame] | 135 | public ServiceDependency setCallbacks(String added, String changed, String removed); |
Pierre De Rop | ddce586 | 2009-12-04 22:16:48 +0000 | [diff] [blame] | 136 | |
| 137 | /** |
| 138 | * Sets the callbacks for this service. These callbacks can be used as hooks whenever a |
Marcel Offermans | 7f0cec0 | 2011-11-04 13:39:28 +0000 | [diff] [blame] | 139 | * dependency is added, changed or removed. When you specify callbacks, the auto |
| 140 | * configuration feature is automatically turned off, because we're assuming you don't |
| 141 | * need it in this case. |
| 142 | * @param added the method to call when a service was added |
| 143 | * @param changed the method to call when a service was changed |
| 144 | * @param removed the method to call when a service was removed |
| 145 | * @param swapped the method to call when the service was swapped due to addition or |
| 146 | * removal of an aspect |
| 147 | * @return this service dependency |
| 148 | */ |
| 149 | public ServiceDependency setCallbacks(String added, String changed, String removed, String swapped); |
| 150 | |
| 151 | /** |
| 152 | * Sets the callbacks for this service. These callbacks can be used as hooks whenever a |
Pierre De Rop | ddce586 | 2009-12-04 22:16:48 +0000 | [diff] [blame] | 153 | * dependency is added or removed. They are called on the instance you provide. When you |
| 154 | * specify callbacks, the auto configuration feature is automatically turned off, because |
| 155 | * we're assuming you don't need it in this case. |
| 156 | * |
| 157 | * @param instance the instance to call the callbacks on |
| 158 | * @param added the method to call when a service was added |
| 159 | * @param removed the method to call when a service was removed |
| 160 | * @return this service dependency |
| 161 | */ |
Marcel Offermans | a564b3a | 2010-03-20 20:19:15 +0000 | [diff] [blame] | 162 | public ServiceDependency setCallbacks(Object instance, String added, String removed); |
Pierre De Rop | ddce586 | 2009-12-04 22:16:48 +0000 | [diff] [blame] | 163 | |
| 164 | /** |
| 165 | * Sets the callbacks for this service. These callbacks can be used as hooks whenever a |
| 166 | * dependency is added, changed or removed. They are called on the instance you provide. When you |
| 167 | * specify callbacks, the auto configuration feature is automatically turned off, because |
| 168 | * we're assuming you don't need it in this case. |
| 169 | * |
| 170 | * @param instance the instance to call the callbacks on |
| 171 | * @param added the method to call when a service was added |
| 172 | * @param changed the method to call when a service was changed |
| 173 | * @param removed the method to call when a service was removed |
| 174 | * @return this service dependency |
| 175 | */ |
Marcel Offermans | a564b3a | 2010-03-20 20:19:15 +0000 | [diff] [blame] | 176 | public ServiceDependency setCallbacks(Object instance, String added, String changed, String removed); |
Marcel Offermans | f9a6e4c | 2009-12-08 10:09:01 +0000 | [diff] [blame] | 177 | |
Pierre De Rop | 23514f5 | 2010-08-29 20:44:25 +0000 | [diff] [blame] | 178 | /** |
Marcel Offermans | 7f0cec0 | 2011-11-04 13:39:28 +0000 | [diff] [blame] | 179 | * Sets the callbacks for this service. These callbacks can be used as hooks whenever a |
| 180 | * dependency is added, changed or removed. When you specify callbacks, the auto |
| 181 | * configuration feature is automatically turned off, because we're assuming you don't |
| 182 | * need it in this case. |
| 183 | * @param instance the instance to call the callbacks on |
| 184 | * @param added the method to call when a service was added |
| 185 | * @param changed the method to call when a service was changed |
| 186 | * @param removed the method to call when a service was removed |
| 187 | * @param swapped the method to call when the service was swapped due to addition or |
| 188 | * removal of an aspect |
| 189 | * @return this service dependency |
| 190 | */ |
| 191 | public ServiceDependency setCallbacks(Object instance, String added, String changed, String removed, String swapped); |
| 192 | |
| 193 | /** |
Pierre De Rop | 23514f5 | 2010-08-29 20:44:25 +0000 | [diff] [blame] | 194 | * Sets propagation of the service dependency properties to the provided service properties. Any additional |
| 195 | * service properties specified directly are merged with these. |
| 196 | */ |
| 197 | public ServiceDependency setPropagate(boolean propagate); |
| 198 | |
| 199 | /** |
| 200 | * Sets an Object instance and a callback method used to propagate some properties to the provided service properties. |
| 201 | * The method will be invoked on the specified object instance and must have one of the following signatures:<p> |
| 202 | * <ul><li>Dictionary callback(ServiceReference, Object service) |
| 203 | * <li>Dictionary callback(ServiceReference) |
| 204 | * </ul> |
| 205 | * @param instance the Object instance which is used to retrieve propagated service properties |
| 206 | * @param method the method to invoke for retrieving the properties to be propagated to the service properties. |
| 207 | * @return this service dependency. |
| 208 | */ |
| 209 | public ServiceDependency setPropagate(Object instance, String method); |
| 210 | |
Marcel Offermans | cba269a | 2013-01-18 11:00:56 +0000 | [diff] [blame^] | 211 | /** |
| 212 | * Sets this dependency to be instance bound or not. |
| 213 | * |
| 214 | * @param isInstanceBound <code>true</code> if this dependency should be instance bound |
| 215 | */ |
Pierre De Rop | 23514f5 | 2010-08-29 20:44:25 +0000 | [diff] [blame] | 216 | public ServiceDependency setInstanceBound(boolean isInstanceBound); |
Pierre De Rop | ddce586 | 2009-12-04 22:16:48 +0000 | [diff] [blame] | 217 | } |