Felix Meschberger | 3f9e4da | 2009-08-17 07:52:39 +0000 | [diff] [blame] | 1 | /* |
Felix Meschberger | 642b48e | 2007-04-11 18:14:28 +0000 | [diff] [blame] | 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 |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 9 | * |
Felix Meschberger | 642b48e | 2007-04-11 18:14:28 +0000 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 11 | * |
Felix Meschberger | 642b48e | 2007-04-11 18:14:28 +0000 | [diff] [blame] | 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. |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 18 | */ |
| 19 | package org.apache.felix.cm; |
| 20 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 21 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 22 | import java.io.File; |
| 23 | import java.io.InputStream; |
Felix Meschberger | 63e7ab1 | 2012-07-02 14:10:43 +0000 | [diff] [blame] | 24 | import java.util.Collection; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 25 | import java.util.Dictionary; |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 26 | import java.util.Properties; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 27 | |
| 28 | import org.osgi.framework.Bundle; |
| 29 | import org.osgi.framework.BundleContext; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 30 | import org.osgi.framework.BundleListener; |
| 31 | import org.osgi.framework.Filter; |
| 32 | import org.osgi.framework.FrameworkListener; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 33 | import org.osgi.framework.ServiceListener; |
| 34 | import org.osgi.framework.ServiceReference; |
| 35 | import org.osgi.framework.ServiceRegistration; |
| 36 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 37 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 38 | /** |
Felix Meschberger | 6b086e7 | 2007-07-03 09:49:39 +0000 | [diff] [blame] | 39 | * The <code>MockBundleContext</code> is a dummy implementation of the |
| 40 | * <code>BundleContext</code> interface. No methods are implemented here, that |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 41 | * is all methods have no effect and return <code>null</code> if a return value |
| 42 | * is specified. |
Felix Meschberger | 6b086e7 | 2007-07-03 09:49:39 +0000 | [diff] [blame] | 43 | * <p> |
| 44 | * Extensions may overwrite methods as see fit. |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 45 | */ |
| 46 | public class MockBundleContext implements BundleContext |
| 47 | { |
| 48 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 49 | private final Properties properties = new Properties(); |
| 50 | |
| 51 | |
| 52 | public void setProperty( String name, String value ) |
| 53 | { |
| 54 | if ( value == null ) |
| 55 | { |
| 56 | properties.remove( name ); |
| 57 | } |
| 58 | else |
| 59 | { |
| 60 | properties.setProperty( name, value ); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | |
| 65 | /* |
| 66 | * (non-Javadoc) |
| 67 | * @see |
| 68 | * org.osgi.framework.BundleContext#addBundleListener(org.osgi.framework |
| 69 | * .BundleListener) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 70 | */ |
| 71 | public void addBundleListener( BundleListener arg0 ) |
| 72 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 76 | /* |
| 77 | * (non-Javadoc) |
| 78 | * @see |
| 79 | * org.osgi.framework.BundleContext#addFrameworkListener(org.osgi.framework |
| 80 | * .FrameworkListener) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 81 | */ |
| 82 | public void addFrameworkListener( FrameworkListener arg0 ) |
| 83 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 87 | /* |
| 88 | * (non-Javadoc) |
| 89 | * @see |
| 90 | * org.osgi.framework.BundleContext#addServiceListener(org.osgi.framework |
| 91 | * .ServiceListener) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 92 | */ |
| 93 | public void addServiceListener( ServiceListener arg0 ) |
| 94 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 98 | /* |
| 99 | * (non-Javadoc) |
| 100 | * @see |
| 101 | * org.osgi.framework.BundleContext#addServiceListener(org.osgi.framework |
| 102 | * .ServiceListener, java.lang.String) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 103 | */ |
Felix Meschberger | f6e2a53 | 2012-07-05 12:24:15 +0000 | [diff] [blame] | 104 | public void addServiceListener( ServiceListener arg0, String arg1 ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 105 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 109 | /* |
| 110 | * (non-Javadoc) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 111 | * @see org.osgi.framework.BundleContext#createFilter(java.lang.String) |
| 112 | */ |
Felix Meschberger | f6e2a53 | 2012-07-05 12:24:15 +0000 | [diff] [blame] | 113 | public Filter createFilter( String arg0 ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 114 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 115 | return null; |
| 116 | } |
| 117 | |
| 118 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 119 | /* |
| 120 | * (non-Javadoc) |
| 121 | * @see |
| 122 | * org.osgi.framework.BundleContext#getAllServiceReferences(java.lang.String |
| 123 | * , java.lang.String) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 124 | */ |
Felix Meschberger | f6e2a53 | 2012-07-05 12:24:15 +0000 | [diff] [blame] | 125 | public ServiceReference[] getAllServiceReferences( String arg0, String arg1 ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 126 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 127 | return null; |
| 128 | } |
| 129 | |
| 130 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 131 | /* |
| 132 | * (non-Javadoc) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 133 | * @see org.osgi.framework.BundleContext#getBundle() |
| 134 | */ |
| 135 | public Bundle getBundle() |
| 136 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 137 | return null; |
| 138 | } |
| 139 | |
| 140 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 141 | /* |
| 142 | * (non-Javadoc) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 143 | * @see org.osgi.framework.BundleContext#getBundle(long) |
| 144 | */ |
| 145 | public Bundle getBundle( long arg0 ) |
| 146 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 147 | return null; |
| 148 | } |
| 149 | |
| 150 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 151 | /* |
| 152 | * (non-Javadoc) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 153 | * @see org.osgi.framework.BundleContext#getBundles() |
| 154 | */ |
| 155 | public Bundle[] getBundles() |
| 156 | { |
Felix Meschberger | 3f9e4da | 2009-08-17 07:52:39 +0000 | [diff] [blame] | 157 | return new Bundle[0]; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 161 | /* |
| 162 | * (non-Javadoc) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 163 | * @see org.osgi.framework.BundleContext#getDataFile(java.lang.String) |
| 164 | */ |
| 165 | public File getDataFile( String arg0 ) |
| 166 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 167 | return null; |
| 168 | } |
| 169 | |
| 170 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 171 | /* |
| 172 | * (non-Javadoc) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 173 | * @see org.osgi.framework.BundleContext#getProperty(java.lang.String) |
| 174 | */ |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 175 | public String getProperty( String name ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 176 | { |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 177 | return properties.getProperty( name ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 181 | /* |
| 182 | * (non-Javadoc) |
| 183 | * @seeorg.osgi.framework.BundleContext#getService(org.osgi.framework. |
| 184 | * ServiceReference) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 185 | */ |
Felix Meschberger | 63e7ab1 | 2012-07-02 14:10:43 +0000 | [diff] [blame] | 186 | public <S> S getService( ServiceReference<S> reference ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 187 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 188 | return null; |
| 189 | } |
| 190 | |
| 191 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 192 | /* |
| 193 | * (non-Javadoc) |
| 194 | * @see |
| 195 | * org.osgi.framework.BundleContext#getServiceReference(java.lang.String) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 196 | */ |
| 197 | public ServiceReference getServiceReference( String arg0 ) |
| 198 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 199 | return null; |
| 200 | } |
| 201 | |
| 202 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 203 | /* |
| 204 | * (non-Javadoc) |
| 205 | * @see |
| 206 | * org.osgi.framework.BundleContext#getServiceReferences(java.lang.String, |
| 207 | * java.lang.String) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 208 | */ |
Felix Meschberger | f6e2a53 | 2012-07-05 12:24:15 +0000 | [diff] [blame] | 209 | public ServiceReference[] getServiceReferences( String arg0, String arg1 ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 210 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 211 | return null; |
| 212 | } |
| 213 | |
| 214 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 215 | /* |
| 216 | * (non-Javadoc) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 217 | * @see org.osgi.framework.BundleContext#installBundle(java.lang.String) |
| 218 | */ |
Felix Meschberger | f6e2a53 | 2012-07-05 12:24:15 +0000 | [diff] [blame] | 219 | public Bundle installBundle( String arg0 ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 220 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 221 | return null; |
| 222 | } |
| 223 | |
| 224 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 225 | /* |
| 226 | * (non-Javadoc) |
| 227 | * @see org.osgi.framework.BundleContext#installBundle(java.lang.String, |
| 228 | * java.io.InputStream) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 229 | */ |
Felix Meschberger | f6e2a53 | 2012-07-05 12:24:15 +0000 | [diff] [blame] | 230 | public Bundle installBundle( String arg0, InputStream arg1 ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 231 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 232 | return null; |
| 233 | } |
| 234 | |
| 235 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 236 | /* |
| 237 | * (non-Javadoc) |
| 238 | * @see org.osgi.framework.BundleContext#registerService(java.lang.String[], |
| 239 | * java.lang.Object, java.util.Dictionary) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 240 | */ |
Felix Meschberger | 63e7ab1 | 2012-07-02 14:10:43 +0000 | [diff] [blame] | 241 | public ServiceRegistration<?> registerService( String[] clazzes, Object service, Dictionary<String, ?> properties ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 242 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 243 | return null; |
| 244 | } |
| 245 | |
| 246 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 247 | /* |
| 248 | * (non-Javadoc) |
| 249 | * @see org.osgi.framework.BundleContext#registerService(java.lang.String, |
| 250 | * java.lang.Object, java.util.Dictionary) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 251 | */ |
Felix Meschberger | 63e7ab1 | 2012-07-02 14:10:43 +0000 | [diff] [blame] | 252 | public ServiceRegistration<?> registerService( String clazz, Object service, Dictionary<String, ?> properties ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 253 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 254 | return null; |
| 255 | } |
| 256 | |
| 257 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 258 | /* |
| 259 | * (non-Javadoc) |
| 260 | * @see |
| 261 | * org.osgi.framework.BundleContext#removeBundleListener(org.osgi.framework |
| 262 | * .BundleListener) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 263 | */ |
| 264 | public void removeBundleListener( BundleListener arg0 ) |
| 265 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 269 | /* |
| 270 | * (non-Javadoc) |
| 271 | * @see |
| 272 | * org.osgi.framework.BundleContext#removeFrameworkListener(org.osgi.framework |
| 273 | * .FrameworkListener) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 274 | */ |
| 275 | public void removeFrameworkListener( FrameworkListener arg0 ) |
| 276 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 280 | /* |
| 281 | * (non-Javadoc) |
| 282 | * @see |
| 283 | * org.osgi.framework.BundleContext#removeServiceListener(org.osgi.framework |
| 284 | * .ServiceListener) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 285 | */ |
| 286 | public void removeServiceListener( ServiceListener arg0 ) |
| 287 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | |
Felix Meschberger | 1311eb3 | 2009-01-28 07:13:49 +0000 | [diff] [blame] | 291 | /* |
| 292 | * (non-Javadoc) |
| 293 | * @seeorg.osgi.framework.BundleContext#ungetService(org.osgi.framework. |
| 294 | * ServiceReference) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 295 | */ |
Felix Meschberger | 63e7ab1 | 2012-07-02 14:10:43 +0000 | [diff] [blame] | 296 | public boolean ungetService( ServiceReference<?> reference ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 297 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 298 | return false; |
| 299 | } |
Felix Meschberger | 63e7ab1 | 2012-07-02 14:10:43 +0000 | [diff] [blame] | 300 | |
| 301 | |
| 302 | public <S> ServiceRegistration<S> registerService( Class<S> clazz, S service, Dictionary<String, ?> properties ) |
| 303 | { |
Felix Meschberger | 63e7ab1 | 2012-07-02 14:10:43 +0000 | [diff] [blame] | 304 | return null; |
| 305 | } |
| 306 | |
| 307 | |
| 308 | public <S> ServiceReference<S> getServiceReference( Class<S> clazz ) |
| 309 | { |
Felix Meschberger | 63e7ab1 | 2012-07-02 14:10:43 +0000 | [diff] [blame] | 310 | return null; |
| 311 | } |
| 312 | |
| 313 | |
| 314 | public <S> Collection<ServiceReference<S>> getServiceReferences( Class<S> clazz, String filter ) |
Felix Meschberger | 63e7ab1 | 2012-07-02 14:10:43 +0000 | [diff] [blame] | 315 | { |
Felix Meschberger | 63e7ab1 | 2012-07-02 14:10:43 +0000 | [diff] [blame] | 316 | return null; |
| 317 | } |
| 318 | |
| 319 | |
| 320 | public Bundle getBundle( String location ) |
| 321 | { |
Felix Meschberger | 63e7ab1 | 2012-07-02 14:10:43 +0000 | [diff] [blame] | 322 | return null; |
| 323 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 324 | } |