Package: StubBundleContext

StubBundleContext

nameinstructionbranchcomplexitylinemethod
StubBundleContext()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
StubBundleContext(StubBundle)
M: 104 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 23 C: 0
0%
M: 1 C: 0
0%
addBundleListener(BundleListener)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
addDataFile(String, File)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
addFilter(Filter[])
M: 24 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
addFilter(String, Filter)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
addFrameworkListener(FrameworkListener)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
addInstalledBundle(StubBundle[])
M: 33 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
addProperty(String, String)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
addServiceListener(ServiceListener)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
addServiceListener(ServiceListener, String)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
createFilter(String)
M: 40 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
createServiceReference(String[], Object, StubServiceRegistration)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
createServiceRegistration(String[], Dictionary)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getAllServiceReferences(String, String)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getBundle()
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getBundle(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getBundle(long)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getBundleListeners()
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getBundles()
M: 21 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getContextBundle()
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getDataFile(String)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getFilter(String)
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getFrameworkListeners()
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getProperty(String)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getService(ServiceReference)
M: 23 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getServiceListeners()
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getServiceReference(Class)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getServiceReference(String)
M: 33 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
getServiceReferences(Class, String)
M: 37 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
getServiceReferences(String, String)
M: 63 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
getServiceRegistrations()
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
installBundle(String)
M: 61 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
installBundle(String, InputStream)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
matchesClass(String, String[])
M: 28 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
registerService(Class, Object, Dictionary)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
registerService(String, Object, Dictionary)
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
registerService(String[], Object, Dictionary)
M: 44 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
removeBundleListener(BundleListener)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
removeFrameworkListener(FrameworkListener)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
removeRegisteredService(ServiceRegistration[])
M: 37 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
removeServiceListener(ServiceListener)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
serviceUnregistered(ServiceReference)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
ungetService(ServiceReference)
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2008, 2010 VMware Inc.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * VMware Inc. - initial contribution
10: *******************************************************************************/
11:
12: package org.eclipse.virgo.test.stubs.framework;
13:
14: import static org.eclipse.virgo.test.stubs.internal.Assert.assertNotNull;
15: import static org.eclipse.virgo.test.stubs.internal.Duplicator.shallowCopy;
16:
17: import java.io.File;
18: import java.io.InputStream;
19: import java.util.ArrayList;
20: import java.util.Arrays;
21: import java.util.Collection;
22: import java.util.Dictionary;
23: import java.util.HashMap;
24: import java.util.List;
25: import java.util.Map;
26:
27: import org.osgi.framework.Bundle;
28: import org.osgi.framework.BundleContext;
29: import org.osgi.framework.BundleException;
30: import org.osgi.framework.BundleListener;
31: import org.osgi.framework.Constants;
32: import org.osgi.framework.Filter;
33: import org.osgi.framework.FrameworkListener;
34: import org.osgi.framework.InvalidSyntaxException;
35: import org.osgi.framework.ServiceListener;
36: import org.osgi.framework.ServiceReference;
37: import org.osgi.framework.ServiceRegistration;
38: import org.osgi.framework.Version;
39:
40: import org.eclipse.virgo.test.stubs.support.TrueFilter;
41:
42: /**
43: * A stub testing implementation of {@link BundleContext} as defined in section 6.1.6 of the OSGi Service Platform Core
44: * Specification.
45: * <p />
46: *
47: * <strong>Concurrent Semantics</strong><br />
48: *
49: * Threadsafe
50: *
51: */
52: public final class StubBundleContext implements BundleContext {
53:
54: private final StubBundle bundle;
55:
56: private final Object bundleMonitor = new Object();
57:
58: private final List<BundleListener> bundleListeners = new ArrayList<BundleListener>();
59:
60: private final Object bundleListenersMonitor = new Object();
61:
62: private final List<FrameworkListener> frameworkListeners = new ArrayList<FrameworkListener>();
63:
64: private final Object frameworkListenersMonitor = new Object();
65:
66: private final List<ServiceListener> serviceListeners = new ArrayList<ServiceListener>();
67:
68: private final Object serviceListenersMonitor = new Object();
69:
70: private volatile long installedBundleId = Long.valueOf(2);
71:
72: private final Map<Long, StubBundle> installedBundles = new HashMap<Long, StubBundle>();
73:
74: private final Object installedBundlesMonitor = new Object();
75:
76: private final List<StubServiceRegistration<Object>> serviceRegistrations = new ArrayList<StubServiceRegistration<Object>>();
77:
78: private final Map<StubServiceReference<Object>, Object> services = new HashMap<StubServiceReference<Object>, Object>();
79:
80: private final Object servicesMonitor = new Object();
81:
82: private final Map<String, File> dataFiles = new HashMap<String, File>();
83:
84: private final Object dataFilesMonitor = new Object();
85:
86: private final Map<String, String> properties = new HashMap<String, String>();
87:
88: private final Object propertiesMonitor = new Object();
89:
90: private final Map<String, Filter> filters = new HashMap<String, Filter>();
91:
92: private final Object filtersMonitor = new Object();
93:
94: /**
95: * Creates a new {@link StubBundleContext} and sets its initial state
96: */
97: public StubBundleContext() {
98: this(new StubBundle());
99: }
100:
101: /**
102: * Creates a new {@link StubBundleContext} and sets its initial state
103: *
104: * @param bundle The context bundle
105: */
106: public StubBundleContext(StubBundle bundle) {
107: assertNotNull(bundle, "bundle");
108: this.bundle = bundle;
109: }
110:
111: /**
112: * {@inheritDoc}
113: */
114: public void addBundleListener(BundleListener listener) {
115: synchronized (this.bundleListenersMonitor) {
116: this.bundleListeners.add(listener);
117: }
118: }
119:
120: /**
121: * {@inheritDoc}
122: */
123: public void addFrameworkListener(FrameworkListener listener) {
124: synchronized (this.frameworkListenersMonitor) {
125: this.frameworkListeners.add(listener);
126: }
127: }
128:
129: /**
130: * {@inheritDoc}
131: */
132: public void addServiceListener(ServiceListener listener) {
133: try {
134: addServiceListener(listener, null);
135: } catch (InvalidSyntaxException e) {
136: // In theory this exception can never be thrown
137: }
138: }
139:
140: /**
141: * {@inheritDoc}
142: */
143: public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException {
144: synchronized (this.serviceListenersMonitor) {
145: this.serviceListeners.add(listener);
146: }
147: }
148:
149: /**
150: * {@inheritDoc}
151: */
152: public Filter createFilter(String filter) throws InvalidSyntaxException {
153: synchronized (this.filtersMonitor) {
154:• if (filter == null) {
155: throw new NullPointerException();
156: }
157:• if (!this.filters.containsKey(filter)) {
158: throw new InvalidSyntaxException(String.format(
159: "You must first add a filter mapping for '%s' with the addFilter(String, Filter) method", filter), filter);
160: }
161: return this.filters.get(filter);
162: }
163: }
164:
165: /**
166: * Adds a mapping from a filter string to a {@link Filter} for all subsequent calls to {@link #createFilter(String)}
167: *
168: * @param filterString The filterString to map from
169: * @param filter The {@link Filter} to map to
170: * @return <code>this</code> instance of the {@link StubBundleContext}
171: */
172: public StubBundleContext addFilter(String filterString, Filter filter) {
173: synchronized (this.filtersMonitor) {
174: this.filters.put(filterString, filter);
175: return this;
176: }
177: }
178:
179: /**
180: * Adds filters for all subsequent calls to {@link #createFilter(String)}
181: *
182: * @param filters The {@link Filter}s to add
183: * @return <code>this</code> instance of the {@link StubBundleContext}
184: */
185: public StubBundleContext addFilter(Filter... filters) {
186:• for (Filter filter : filters) {
187: addFilter(filter.toString(), filter);
188: }
189: return this;
190: }
191:
192: /**
193: * {@inheritDoc}
194: */
195: public ServiceReference<?>[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
196: return getServiceReferences(clazz, filter);
197: }
198:
199: /**
200: * {@inheritDoc}
201: */
202: public Bundle getBundle() {
203: synchronized (this.bundleMonitor) {
204: return this.bundle;
205: }
206: }
207:
208: /**
209: * {@inheritDoc}
210: */
211: public Bundle getBundle(long id) {
212: synchronized (this.installedBundlesMonitor) {
213: return this.installedBundles.get(id);
214: }
215: }
216:
217: /**
218: * {@inheritDoc}
219: */
220: public Bundle[] getBundles() {
221: synchronized (this.installedBundlesMonitor) {
222: return this.installedBundles.values().toArray(new Bundle[this.installedBundles.values().size()]);
223: }
224: }
225:
226: /**
227: * Adds a collection of {@link Bundle}s to this {@link BundleContext} to be returned for all subsequent calls to
228: * {@link #getBundle(long)} or {@link #getBundles()}.
229: *
230: * @param bundles The bundles to add
231: * @return <code>this</code> instance of the {@link StubBundleContext}
232: */
233: public StubBundleContext addInstalledBundle(StubBundle... bundles) {
234: synchronized (this.installedBundlesMonitor) {
235:• for (StubBundle bundle : bundles) {
236: this.installedBundles.put(bundle.getBundleId(), bundle);
237: }
238: return this;
239: }
240: }
241:
242: /**
243: * {@inheritDoc}
244: */
245: public File getDataFile(String filename) {
246: synchronized (this.dataFilesMonitor) {
247: return this.dataFiles.get(filename);
248: }
249: }
250:
251: /**
252: * Adds a mapping from a filename to a {@link File} for all subsequent calls to {@link #getDataFile(String)}.
253: *
254: * @param filename The filename to map from
255: * @param file The {@link File} to map to
256: * @return <code>this</code> instance of the {@link StubBundleContext}
257: */
258: public StubBundleContext addDataFile(String filename, File file) {
259: synchronized (this.dataFilesMonitor) {
260: this.dataFiles.put(filename, file);
261: return this;
262: }
263: }
264:
265: /**
266: * {@inheritDoc}
267: */
268: public String getProperty(String key) {
269: synchronized (this.propertiesMonitor) {
270: return this.properties.get(key);
271: }
272: }
273:
274: /**
275: * Adds a mapping from a key to a value for all subsequent calls to {@link #getProperty(String)}.
276: *
277: * @param key The key to map from
278: * @param value The value to map to
279: * @return <code>this</code> instance of the {@link StubBundleContext}
280: */
281: public StubBundleContext addProperty(String key, String value) {
282: synchronized (this.propertiesMonitor) {
283: this.properties.put(key, value);
284: return this;
285: }
286: }
287:
288: /**
289: * {@inheritDoc}
290: */
291: @SuppressWarnings("unchecked")
292: public <S> S getService(ServiceReference<S> reference) {
293: synchronized (this.servicesMonitor) {
294:• if (serviceUnregistered(reference)) {
295: return null;
296: }
297:
298: return (S) this.services.get(reference);
299: }
300: }
301:
302: /**
303: * {@inheritDoc}
304: */
305: public ServiceReference<?> getServiceReference(String clazz) {
306: ServiceReference<?>[] serviceReferences = null;
307: try {
308: serviceReferences = getServiceReferences(clazz, null);
309: } catch (InvalidSyntaxException e) {
310: // In theory this exception can never be thrown
311: }
312:
313:• if (serviceReferences == null) {
314: return null;
315:• } else if (serviceReferences.length == 1) {
316: return serviceReferences[0];
317: } else {
318: Arrays.sort(serviceReferences);
319: return serviceReferences[serviceReferences.length - 1];
320: }
321: }
322:
323: /**
324: * {@inheritDoc}
325: */
326: public ServiceReference<?>[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
327: synchronized (this.servicesMonitor) {
328: List<ServiceReference<?>> candidateReferences = new ArrayList<ServiceReference<?>>();
329:
330: Filter f = getFilter(filter);
331:• for (ServiceReference<?> serviceReference : this.services.keySet()) {
332: String[] objectClasses = (String[]) serviceReference.getProperty(Constants.OBJECTCLASS);
333:• if (f.match(serviceReference) && matchesClass(clazz, objectClasses)) {
334: candidateReferences.add(serviceReference);
335: }
336: }
337:
338:• if (candidateReferences.isEmpty()) {
339: return null;
340: } else {
341: return candidateReferences.toArray(new ServiceReference[candidateReferences.size()]);
342: }
343: }
344: }
345:
346: private Filter getFilter(String filter) throws InvalidSyntaxException {
347:• if (filter == null) {
348: return new TrueFilter();
349: } else {
350: return createFilter(filter);
351: }
352: }
353:
354: private boolean matchesClass(String clazz, String[] objectClasses) {
355:• if (clazz == null) {
356: return true;
357: }
358:
359:• for (String objectClass : objectClasses) {
360:• if (clazz.equals(objectClass)) {
361: return true;
362: }
363: }
364:
365: return false;
366: }
367:
368: /**
369: * {@inheritDoc}
370: */
371: public Bundle installBundle(String location) throws BundleException {
372: StubBundle bundle = new StubBundle(this.installedBundleId++, location, Version.emptyVersion, location);
373:• bundle.setState(Bundle.INSTALLED);
374: return bundle;
375: }
376:
377: /**
378: * {@inheritDoc}
379: */
380: public Bundle installBundle(String location, InputStream input) throws BundleException {
381: return installBundle(location);
382: }
383:
384: /**
385: * {@inheritDoc}
386: */
387: public ServiceRegistration<?> registerService(String[] clazzes, Object service, Dictionary<String, ?> properties) {
388: StubServiceRegistration<Object> serviceRegistration = createServiceRegistration(clazzes, properties);
389: StubServiceReference<Object> serviceReference = createServiceReference(clazzes, service, serviceRegistration);
390:
391: synchronized (this.servicesMonitor) {
392: this.serviceRegistrations.add(serviceRegistration);
393: this.services.put(serviceReference, service);
394: }
395:
396: return serviceRegistration;
397: }
398:
399: private StubServiceRegistration<Object> createServiceRegistration(String[] clazzes, Dictionary<String, ?> properties) {
400: StubServiceRegistration<Object> serviceRegistration = new StubServiceRegistration<Object>(this, clazzes);
401: serviceRegistration.setProperties(properties);
402: return serviceRegistration;
403: }
404:
405: private <S> StubServiceReference<S> createServiceReference(String[] clazzes, Object service, StubServiceRegistration<S> serviceRegistration) {
406: StubServiceReference<S> serviceReference = new StubServiceReference<S>(serviceRegistration);
407: serviceRegistration.setServiceReference(serviceReference);
408: return serviceReference;
409: }
410:
411: /**
412: * {@inheritDoc}
413: */
414: public ServiceRegistration<?> registerService(String clazz, Object service, Dictionary<String, ?> properties) {
415: return registerService(new String[] { clazz }, service, properties);
416: }
417:
418: /**
419: * Gets the collection of {@link ServiceRegistration}s for this {@link BundleContext}
420: *
421: * @return The collection of {@link ServiceRegistration}s
422: */
423: public List<StubServiceRegistration<Object>> getServiceRegistrations() {
424: synchronized (this.servicesMonitor) {
425: return shallowCopy(this.serviceRegistrations);
426: }
427: }
428:
429: /**
430: * Removes a collection of {@link ServiceRegistration}s from this {@link StubBundleContext} to be returned for all
431: * subsequent calls to {@link #getServiceReference(String)} and {@link #getServiceReferences(String, String)}.
432: *
433: * @param serviceRegistrations The service registrations to remove
434: * @return <code>this</code> instance of the {@link StubBundleContext}
435: */
436: public StubBundleContext removeRegisteredService(ServiceRegistration<?>... serviceRegistrations) {
437: synchronized (this.servicesMonitor) {
438: this.serviceRegistrations.removeAll(Arrays.asList(serviceRegistrations));
439:• for (ServiceRegistration<?> registration: serviceRegistrations) {
440: this.services.remove(registration.getReference());
441: }
442: return this;
443: }
444: }
445:
446: /**
447: * {@inheritDoc}
448: */
449: public void removeBundleListener(BundleListener listener) {
450: synchronized (this.bundleListenersMonitor) {
451: this.bundleListeners.remove(listener);
452: }
453: }
454:
455: /**
456: * {@inheritDoc}
457: */
458: public void removeFrameworkListener(FrameworkListener listener) {
459: synchronized (this.frameworkListenersMonitor) {
460: this.frameworkListeners.remove(listener);
461: }
462: }
463:
464: /**
465: * {@inheritDoc}
466: */
467: public void removeServiceListener(ServiceListener listener) {
468: synchronized (this.serviceListenersMonitor) {
469: this.serviceListeners.remove(listener);
470: }
471: }
472:
473: /**
474: * Gets the collection of {@link FrameworkListener}s for this {@link BundleContext}
475: *
476: * @return The collection of {@link BundleListener}s
477: */
478: public List<FrameworkListener> getFrameworkListeners() {
479: synchronized (this.frameworkListenersMonitor) {
480: return shallowCopy(this.frameworkListeners);
481: }
482: }
483:
484: /**
485: * Gets the collection of {@link BundleListener}s for this {@link BundleContext}
486: *
487: * @return The collection of {@link BundleListener}s
488: */
489: public List<BundleListener> getBundleListeners() {
490: synchronized (this.bundleListenersMonitor) {
491: return shallowCopy(this.bundleListeners);
492: }
493: }
494:
495: /**
496: * Gets the collection of {@link ServiceListener}s for this {@link BundleContext}
497: *
498: * @return The collection of {@link ServiceListener}s
499: */
500: public List<ServiceListener> getServiceListeners() {
501: synchronized (this.serviceListenersMonitor) {
502: return shallowCopy(this.serviceListeners);
503: }
504: }
505:
506: /**
507: * {@inheritDoc}
508: */
509: public boolean ungetService(ServiceReference<?> reference) {
510:• return !serviceUnregistered(reference);
511: }
512:
513: /**
514: * @return Returns the context bundle for this {@link BundleContext}
515: */
516: public StubBundle getContextBundle() {
517: synchronized (this.bundleMonitor) {
518: return this.bundle;
519: }
520: }
521:
522: private boolean serviceUnregistered(ServiceReference<?> reference) {
523: return ((StubServiceReference<?>) reference).getServiceRegistration().getUnregistered();
524: }
525:
526: /**
527: * {@inheritDoc}
528: */
529: @SuppressWarnings("unchecked")
530: public <S> ServiceRegistration<S> registerService(Class<S> clazz, S service, Dictionary<String, ?> properties) {
531: return (ServiceRegistration<S>) registerService(clazz.getName(), service, properties);
532: }
533:
534: /**
535: * {@inheritDoc}
536: */
537: @SuppressWarnings("unchecked")
538: public <S> ServiceReference<S> getServiceReference(Class<S> clazz) {
539: return (ServiceReference<S>) getServiceReference(clazz.getName());
540: }
541:
542: /**
543: * {@inheritDoc}
544: */
545: @SuppressWarnings("unchecked")
546: public <S> Collection<ServiceReference<S>> getServiceReferences(Class<S> clazz, String filter) throws InvalidSyntaxException {
547: Collection<ServiceReference<S>> references = new ArrayList<ServiceReference<S>>();
548: ServiceReference<S>[] matchingReferences = (ServiceReference<S>[]) getServiceReferences(clazz.getName(), filter);
549:• if (matchingReferences != null) {
550:• for (ServiceReference<S> reference : matchingReferences) {
551: references.add(reference);
552: }
553: }
554: return references;
555: }
556:
557: /**
558: * {@inheritDoc}
559: */
560: public Bundle getBundle(String location) {
561: return null;
562: }
563: }