Package: StubBundle

StubBundle

nameinstructionbranchcomplexitylinemethod
StubBundle()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
StubBundle(Long, String, Version, String)
M: 161 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 37 C: 0
0%
M: 1 C: 0
0%
StubBundle(String, Version)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
adapt(Class)
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%
addEntry(String, URL)
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%
addEntryPaths(String, Enumeration)
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%
addHeader(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%
addLoadClass(String, Class)
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%
addPermission(Object, boolean)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
addRegisteredService(StubServiceReference)
M: 18 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
addResource(String, URL)
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%
addResources(String, Enumeration)
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%
addServiceInUse(StubServiceReference)
M: 23 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
compareTo(Bundle)
M: 43 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
equals(Object)
M: 29 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
findEntries(String, String, boolean)
M: 21 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getBundleContext()
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%
getBundleId()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDataFile(String)
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%
getEntry(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%
getEntryPaths(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%
getHeaders()
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%
getHeaders(String)
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%
getLastModified()
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%
getLocation()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getRegisteredServices()
M: 27 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getResource(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%
getResources(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%
getServicesInUse()
M: 27 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getSignerCertificates(int)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getState()
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%
getSymbolicName()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getVersion()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
hasPermission(Object)
M: 26 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
hashCode()
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
loadClass(String)
M: 34 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
setBundleContext(StubBundleContext)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
setFindEntriesDelegate(FindEntriesDelegate)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setLastModified(long)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setLocalizedHeaders(Dictionary)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setState(int)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setUpdateDelegate(UpdateDelegate)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
start()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
start(int)
M: 184 C: 0
0%
M: 26 C: 0
0%
M: 14 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
startBundleIfNeeded(int)
M: 6 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
stop()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
stop(int)
M: 188 C: 0
0%
M: 22 C: 0
0%
M: 12 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
stopBundleIfNeeded(int)
M: 12 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
toString()
M: 26 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
uninstall()
M: 63 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
update()
M: 81 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
update(InputStream)
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%

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.IOException;
19: import java.io.InputStream;
20: import java.net.URL;
21: import java.security.cert.X509Certificate;
22: import java.util.ArrayList;
23: import java.util.Dictionary;
24: import java.util.Enumeration;
25: import java.util.HashMap;
26: import java.util.Hashtable;
27: import java.util.List;
28: import java.util.Map;
29:
30: import org.osgi.framework.Bundle;
31: import org.osgi.framework.BundleContext;
32: import org.osgi.framework.BundleException;
33: import org.osgi.framework.ServiceReference;
34: import org.osgi.framework.Version;
35:
36: /**
37: * A stub testing implementation of {@link Bundle} as defined in section 6.1.4 of the OSGi Service Platform Core
38: * Specification.
39: * <p />
40: *
41: * <strong>Concurrent Semantics</strong><br />
42: *
43: * Threadsafe
44: *
45: */
46: public final class StubBundle implements Bundle {
47:
48: private static final Long DEFAULT_BUNDLE_ID = Long.valueOf(1);
49:
50: private static final String DEFAULT_SYMBOLIC_NAME = "org.eclipse.virgo.test.stubs.testbundle";
51:
52: private static final Version DEFAULT_VERSION = Version.emptyVersion;
53:
54: private static final String DEFAULT_LOCATION = "/";
55:
56: private final Long bundleId;
57:
58: private final String symbolicName;
59:
60: private final Version version;
61:
62: private final String location;
63:
64: private volatile int state;
65:
66: private final Object stateMonitor = new Object();
67:
68: private volatile long lastModified;
69:
70: private final Object lastModifiedMonitor = new Object();
71:
72: private volatile StubBundleContext bundleContext;
73:
74: private final Object bundleContextMonitor = new Object();
75:
76: private volatile Dictionary<String, String> headers = new Hashtable<String, String>();
77:
78: private final Object headersMonitor = new Object();
79:
80: private volatile Dictionary<String, String> localizedHeaders = new Hashtable<String, String>();
81:
82: private final Object localizedHeadersMonitor = new Object();
83:
84: private final Map<String, Class<?>> loadClasses = new HashMap<String, Class<?>>();
85:
86: private final Object loadClassesMonitor = new Object();
87:
88: private final Map<String, URL> entries = new HashMap<String, URL>();
89:
90: private final Object entriesMonitor = new Object();
91:
92: private final Map<String, Enumeration<String>> entryPaths = new HashMap<String, Enumeration<String>>();
93:
94: private final Object entryPathsMonitor = new Object();
95:
96: private final Map<Object, Boolean> permissions = new HashMap<Object, Boolean>();
97:
98: private final Object permissionsMonitor = new Object();
99:
100: private final Map<String, URL> resource = new HashMap<String, URL>();
101:
102: private final Object resourceMonitor = new Object();
103:
104: private final Map<String, Enumeration<URL>> resources = new HashMap<String, Enumeration<URL>>();
105:
106: private final Object resourcesMonitor = new Object();
107:
108: private volatile FindEntriesDelegate findEntriesDelegate;
109:
110: private final Object findEntriesMonitor = new Object();
111:
112: private final List<StubServiceReference<Object>> registeredServices = new ArrayList<StubServiceReference<Object>>();
113:
114: private final Object registeredServicesMonitor = new Object();
115:
116: private final List<StubServiceReference<Object>> servicesInUse = new ArrayList<StubServiceReference<Object>>();
117:
118: private final Object servicesInUseMonitor = new Object();
119:
120: private volatile UpdateDelegate updateDelegate;
121:
122: private final Object updateDelegateMonitor = new Object();
123:
124: /**
125: * Creates a new {@link StubServiceRegistration} and sets its initial state. This constructor sets
126: * <code>bundleId</code> to <code>1</code>, <code>symbolicName</code> to
127: * <code>org.eclipse.virgo.test.stubs.testbundle</code>, <code>version</code> to <code>0.0.0</code>, and
128: * <code>location</code> to <code>/</code>.
129: */
130: public StubBundle() {
131: this(DEFAULT_SYMBOLIC_NAME, DEFAULT_VERSION);
132: }
133:
134: /**
135: * Creates a new {@link StubServiceRegistration} and sets its initial state. This constructor sets
136: * <code>bundleId</code> to <code>1</code> and <code>location</code> to <code>/</code>.
137: *
138: * @param symbolicName The symbolic name of this bundle
139: * @param version The version of this bundle
140: */
141: public StubBundle(String symbolicName, Version version) {
142: this(DEFAULT_BUNDLE_ID, symbolicName, version, DEFAULT_LOCATION);
143: }
144:
145: /**
146: * Creates a new {@link StubBundle} and sets its initial state
147: *
148: * @param bundleId The id of this bundle
149: * @param symbolicName The symbolic name of this bundle
150: * @param version The version of this bundle
151: * @param location The location of this bundle
152: */
153: public StubBundle(Long bundleId, String symbolicName, Version version, String location) {
154: assertNotNull(bundleId, "bundleId");
155: assertNotNull(symbolicName, "symbolicName");
156: assertNotNull(version, "version");
157: assertNotNull(location, "location");
158:
159: this.bundleId = bundleId;
160: this.symbolicName = symbolicName;
161: this.version = version;
162: this.location = location;
163: this.bundleContext = new StubBundleContext(this);
164: this.state = STARTING;
165: }
166:
167: /**
168: * {@inheritDoc}
169: */
170: public Enumeration<URL> findEntries(String path, String filePattern, boolean recurse) {
171: synchronized (this.findEntriesMonitor) {
172:• if (this.findEntriesDelegate != null) {
173: return this.findEntriesDelegate.findEntries(path, filePattern, recurse);
174: }
175: return null;
176: }
177: }
178:
179: /**
180: * Sets the {@link FindEntriesDelegate} to use for all subsequent calls to
181: * {@link #findEntries(String, String, boolean)}.
182: *
183: * @param delegate the delegate to use
184: *
185: * @return <code>this</code> instance of the {@link StubBundle}
186: */
187: public StubBundle setFindEntriesDelegate(FindEntriesDelegate delegate) {
188: synchronized (this.findEntriesMonitor) {
189: this.findEntriesDelegate = delegate;
190: return this;
191: }
192: }
193:
194: /**
195: * {@inheritDoc}
196: */
197: public BundleContext getBundleContext() {
198: synchronized (this.bundleContextMonitor) {
199: return this.bundleContext;
200: }
201: }
202:
203: /**
204: * Sets the {@link BundleContext} to return for all subsequent calls to {@link #getBundleContext()}.
205: *
206: * @param bundleContext The @{link BundleContext} to return
207: *
208: * @return <code>this</code> instance of the {@link StubBundle}
209: */
210: public StubBundle setBundleContext(StubBundleContext bundleContext) {
211: assertNotNull(bundleContext, "bundleContext");
212: synchronized (bundleContextMonitor) {
213: this.bundleContext = bundleContext;
214: return this;
215: }
216: }
217:
218: /**
219: * {@inheritDoc}
220: */
221: public long getBundleId() {
222: return this.bundleId;
223: }
224:
225: /**
226: * {@inheritDoc}
227: */
228: public URL getEntry(String path) {
229: synchronized (this.entriesMonitor) {
230: return this.entries.get(path);
231: }
232: }
233:
234: /**
235: * Adds a mapping from a path to a {@link URL} for all subsequent calls to {@link #getEntry(String)}.
236: *
237: * @param path The path to map from
238: * @param url The {@link URL} to map to
239: * @return <code>this</code> instance of the {@link StubBundle}
240: */
241: public StubBundle addEntry(String path, URL url) {
242: synchronized (this.entriesMonitor) {
243: this.entries.put(path, url);
244: return this;
245: }
246: }
247:
248: /**
249: * {@inheritDoc}
250: */
251: public Enumeration<String> getEntryPaths(String path) {
252: synchronized (this.entryPathsMonitor) {
253: return this.entryPaths.get(path);
254: }
255: }
256:
257: /**
258: * Adds a mapping from a path to a {@link Enumeration} for all subsequent calls to {@link #getEntryPaths(String)}.
259: *
260: * @param path The path to map from
261: * @param paths The {@link Enumeration} to map to
262: * @return <code>this</code> instance of the {@link StubBundle}
263: */
264: public StubBundle addEntryPaths(String path, Enumeration<String> paths) {
265: synchronized (this.entryPathsMonitor) {
266: this.entryPaths.put(path, paths);
267: return this;
268: }
269: }
270:
271: /**
272: * {@inheritDoc}
273: */
274: public Dictionary<String, String> getHeaders() {
275: synchronized (this.headersMonitor) {
276: return shallowCopy(this.headers);
277: }
278: }
279:
280: /**
281: * Adds a header mapping for all subsequent calls to {@link #getHeaders()}.
282: *
283: * @param key The key to map from
284: * @param value The value to map to
285: *
286: * @return <code>this</code> instance of the {@link StubBundle}
287: */
288: public StubBundle addHeader(String key, String value) {
289: synchronized (this.headersMonitor) {
290: this.headers.put(key, value);
291: return this;
292: }
293: }
294:
295: /**
296: * {@inheritDoc}
297: */
298: public Dictionary<String, String> getHeaders(String locale) {
299: synchronized (this.localizedHeadersMonitor) {
300: return shallowCopy(this.localizedHeaders);
301: }
302: }
303:
304: /**
305: * Sets the localized headers to return for all subsequent calls to {@link #getHeaders(String)}.
306: *
307: * @param dictionary The headers to return
308: *
309: * @return <code>this</code> instance of the {@link StubBundle}
310: */
311: public StubBundle setLocalizedHeaders(Dictionary<String, String> dictionary) {
312: synchronized (this.localizedHeadersMonitor) {
313: this.localizedHeaders = dictionary;
314: return this;
315: }
316: }
317:
318: /**
319: * {@inheritDoc}
320: */
321: public long getLastModified() {
322: synchronized (this.lastModifiedMonitor) {
323: return this.lastModified;
324: }
325: }
326:
327: /**
328: * Sets the last modified date to return for all subsequent calls to {@link #getLastModified()}. A call to any other
329: * modifying method will update this.
330: *
331: * @param lastModified The new last modified date
332: * @return <code>this</code> instance of the {@link StubBundle}
333: */
334: public StubBundle setLastModified(long lastModified) {
335: synchronized (this.lastModifiedMonitor) {
336: this.lastModified = lastModified;
337: return this;
338: }
339: }
340:
341: /**
342: * {@inheritDoc}
343: */
344: public String getLocation() {
345: return this.location;
346: }
347:
348: /**
349: * {@inheritDoc}
350: */
351: public ServiceReference<?>[] getRegisteredServices() {
352: synchronized (this.registeredServicesMonitor) {
353:• if (this.registeredServices.isEmpty()) {
354: return null;
355: }
356: return this.registeredServices.toArray(new ServiceReference[this.registeredServices.size()]);
357: }
358: }
359:
360: /**
361: * Adds a {@link ServiceReference} for all subsequent calls to {@link #getRegisteredServices()}.
362: *
363: * @param serviceReference The {@link ServiceReference}
364: * @return <code>this</code> instance of the {@link StubBundle}
365: */
366: public StubBundle addRegisteredService(StubServiceReference<Object> serviceReference) {
367: synchronized (this.registeredServicesMonitor) {
368: serviceReference.setBundle(this);
369: this.registeredServices.add(serviceReference);
370: return this;
371: }
372: }
373:
374: /**
375: * {@inheritDoc}
376: */
377: public URL getResource(String name) {
378: synchronized (this.resourceMonitor) {
379: return this.resource.get(name);
380: }
381: }
382:
383: /**
384: * Adds a mapping from a name to a {@link URL} for all subsequent calls to {@link #getResource(String)}.
385: *
386: * @param name The name to map from
387: * @param url The {@link URL} to map to
388: * @return <code>this</code> instance of the {@link StubBundle}
389: */
390: public StubBundle addResource(String name, URL url) {
391: synchronized (this.resourceMonitor) {
392: this.resource.put(name, url);
393: return this;
394: }
395: }
396:
397: /**
398: * {@inheritDoc}
399: */
400: public Enumeration<URL> getResources(String name) throws IOException {
401: synchronized (this.resourcesMonitor) {
402: return this.resources.get(name);
403: }
404: }
405:
406: /**
407: * Adds a mapping from a name to a {@link Enumeration} for all subsequent calls to {@link #getResources(String)}.
408: *
409: * @param name The name to map from
410: * @param resources The {@link Enumeration} to map to
411: * @return <code>this</code> instance of the {@link StubBundle}
412: */
413: public StubBundle addResources(String name, Enumeration<URL> resources) {
414: synchronized (this.resourcesMonitor) {
415: this.resources.put(name, resources);
416: return this;
417: }
418: }
419:
420: /**
421: * {@inheritDoc}
422: */
423: public ServiceReference<?>[] getServicesInUse() {
424: synchronized (this.servicesInUseMonitor) {
425:• if (this.servicesInUse.isEmpty()) {
426: return null;
427: }
428: return this.servicesInUse.toArray(new ServiceReference[this.servicesInUse.size()]);
429: }
430: }
431:
432: /**
433: * Adds a {@link ServiceReference} for all subsequent calls to {@link #getServicesInUse()}.
434: *
435: * @param serviceReference The {@link ServiceReference}
436: * @return <code>this</code> instance of the {@link StubBundle}
437: */
438: public StubBundle addServiceInUse(StubServiceReference<Object> serviceReference) {
439: synchronized (this.servicesInUseMonitor) {
440: serviceReference.addUsingBundles(this);
441: this.servicesInUse.add(serviceReference);
442: return this;
443: }
444: }
445:
446: /**
447: * {@inheritDoc}
448: */
449: public int getState() {
450: synchronized (this.stateMonitor) {
451: return this.state;
452: }
453: }
454:
455: /**
456: * Sets the state to return for all subsequent calls to {@link #getState()}. A call to any state modifying method
457: * will change this value.
458: *
459: * @param state The state to return
460: *
461: * @return <code>this</code> instance of the {@link StubBundle}
462: */
463: public StubBundle setState(int state) {
464: synchronized (this.stateMonitor) {
465: this.state = state;
466: return this;
467: }
468: }
469:
470: /**
471: * {@inheritDoc}
472: */
473: public String getSymbolicName() {
474: return this.symbolicName;
475: }
476:
477: /**
478: * {@inheritDoc}
479: */
480: public Version getVersion() {
481: return this.version;
482: }
483:
484: /**
485: * {@inheritDoc}
486: */
487: public boolean hasPermission(Object permission) {
488: synchronized (this.permissionsMonitor) {
489:• if (this.permissions.containsKey(permission)) {
490: return this.permissions.get(permission);
491: }
492: return true;
493: }
494: }
495:
496: /**
497: * Adds a mapping from a permission to a {@link Boolean} of whether that permission is valid for all subsequent
498: * calls to {@link #hasPermission(Object)}.
499: *
500: * @param permission the permission to add
501: * @param hasPermission whether this permission is valid
502: * @return <code>this</code> instance of the {@link StubBundle}
503: */
504: public StubBundle addPermission(Object permission, boolean hasPermission) {
505: synchronized (this.permissionsMonitor) {
506: this.permissions.put(permission, hasPermission);
507: return this;
508: }
509: }
510:
511: /**
512: * {@inheritDoc}
513: */
514: public Class<?> loadClass(String name) throws ClassNotFoundException {
515: synchronized (this.loadClassesMonitor) {
516:• if (this.loadClasses.containsKey(name)) {
517: return this.loadClasses.get(name);
518: }
519: throw new ClassNotFoundException("'" + name + "' cannot be loaded");
520: }
521: }
522:
523: /**
524: * Adds a mapping from a class name to a {@link Class} for all subsequent calls to {@link #loadClass(String)}.
525: *
526: * @param name The name of the class to map from
527: * @param clazz The class to map to
528: * @return <code>this</code> instance of the {@link StubBundle}
529: */
530: public StubBundle addLoadClass(String name, Class<?> clazz) {
531: synchronized (this.loadClassesMonitor) {
532: this.loadClasses.put(name, clazz);
533: return this;
534: }
535: }
536:
537: /**
538: * {@inheritDoc}
539: */
540: public void start() throws BundleException {
541: start(0);
542: }
543:
544: /**
545: * {@inheritDoc}
546: */
547: public void start(int options) throws BundleException {
548: synchronized (this.stateMonitor) {
549:• if (this.getState() == ACTIVE) {
550: return;
551: }
552:• setState(RESOLVED);
553:• setState(STARTING);
554:• setState(ACTIVE);
555: }
556: }
557:
558: /**
559: * {@inheritDoc}
560: */
561: public void stop() throws BundleException {
562: stop(0);
563: }
564:
565: /**
566: * {@inheritDoc}
567: */
568: public void stop(int options) throws BundleException {
569: synchronized (this.stateMonitor) {
570:• if (this.getState() != ACTIVE) {
571: return;
572: }
573:
574:• setState(STOPPING);
575: synchronized (this.registeredServicesMonitor) {
576:• for (StubServiceReference<Object> serviceReference : this.registeredServices) {
577: serviceReference.setBundle(null);
578: }
579: this.registeredServices.clear();
580: }
581:
582: synchronized (this.servicesInUseMonitor) {
583:• for (StubServiceReference<Object> serviceReference : this.servicesInUse) {
584: serviceReference.removeUsingBundles(this);
585: }
586: this.servicesInUse.clear();
587: }
588:
589:• setState(RESOLVED);
590: }
591: }
592:
593: /**
594: * {@inheritDoc}
595: */
596: public void uninstall() throws BundleException {
597: synchronized (this.stateMonitor) {
598: int initialState = getState();
599: stopBundleIfNeeded(initialState);
600:• setState(UNINSTALLED);
601: }
602: }
603:
604: /**
605: * {@inheritDoc}
606: */
607: public void update() throws BundleException {
608: synchronized (this.updateDelegateMonitor) {
609: synchronized (this.stateMonitor) {
610: int initialState = getState();
611: stopBundleIfNeeded(initialState);
612:
613:• if (this.updateDelegate != null) {
614: this.updateDelegate.update(this);
615: }
616:
617:• setState(INSTALLED);
618: startBundleIfNeeded(initialState);
619: }
620: }
621: }
622:
623: /**
624: * {@inheritDoc}
625: */
626: public void update(InputStream in) throws BundleException {
627: update();
628: }
629:
630: /**
631: * Sets the {@link UpdateDelegate} to use for all subsequent calls to {@link #update()} or
632: * {@link #update(InputStream)}.
633: *
634: * @param delegate the delegate to use
635: *
636: * @return <code>this</code> instance of the {@link StubBundle}
637: */
638: public StubBundle setUpdateDelegate(UpdateDelegate delegate) {
639: synchronized (this.updateDelegateMonitor) {
640: this.updateDelegate = delegate;
641: return this;
642: }
643: }
644:
645: /**
646: * {@inheritDoc}
647: */
648: @Override
649: public int hashCode() {
650: final int prime = 31;
651: int result = 1;
652: result = prime * result + bundleId.hashCode();
653: return result;
654: }
655:
656: /**
657: * {@inheritDoc}
658: */
659: @Override
660: public boolean equals(Object obj) {
661:• if (this == obj) {
662: return true;
663: }
664:• if (obj == null) {
665: return false;
666: }
667:• if (getClass() != obj.getClass()) {
668: return false;
669: }
670: StubBundle other = (StubBundle) obj;
671:• if (!bundleId.equals(other.bundleId)) {
672: return false;
673: }
674: return true;
675: }
676:
677: /**
678: * {@inheritDoc}
679: */
680: @Override
681: public String toString() {
682: return String.format("id: %d, symbolic name: %s, version: %s, state: %d", this.bundleId, this.symbolicName, this.version, this.state);
683: }
684:
685: private void startBundleIfNeeded(int initialState) throws BundleException {
686:• if (initialState == ACTIVE) {
687: this.start();
688: }
689: }
690:
691: private void stopBundleIfNeeded(int initialState) throws BundleException {
692:• if (initialState == Bundle.ACTIVE || initialState == Bundle.STARTING || initialState == Bundle.STOPPING) {
693: this.stop();
694: }
695: }
696:
697: /**
698: * {@inheritDoc}
699: */
700: public int compareTo(Bundle o) {
701: int bundleIdCompare = Long.valueOf(o.getBundleId()).compareTo(this.bundleId);
702:• if (bundleIdCompare != 0) {
703: return bundleIdCompare;
704: }
705: int symbolicNameCompare = o.getSymbolicName().compareTo(this.symbolicName);
706:• if (symbolicNameCompare != 0) {
707: return symbolicNameCompare;
708: }
709: int bundleVersionCompare = o.getVersion().compareTo(this.version);
710:• if (bundleVersionCompare != 0) {
711: return bundleVersionCompare;
712: }
713: int bundleLocationCompare = o.getLocation().compareTo(this.location);
714:• if (bundleLocationCompare != 0) {
715: return bundleLocationCompare;
716: }
717: return 0;
718: }
719:
720: /**
721: * {@inheritDoc}
722: */
723: public Map<X509Certificate, List<X509Certificate>> getSignerCertificates(int signersType) {
724: return new HashMap<X509Certificate, List<X509Certificate>>();
725: }
726:
727: /**
728: * {@inheritDoc}
729: */
730: public <A> A adapt(Class<A> type) {
731: return null;
732: }
733:
734: /**
735: * {@inheritDoc}
736: */
737: public File getDataFile(String filename) {
738: return null;
739: }
740:
741: }