1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.osgi.mock;
17
18 import java.net.URL;
19 import java.util.Dictionary;
20 import java.util.Enumeration;
21
22 import org.osgi.framework.BundleContext;
23
24 /**
25 * Mock Bundle that allows the entry to return on future calls.
26 *
27 * @author Adrian Colyer
28 *
29 */
30 public class EntryLookupControllingMockBundle extends MockBundle {
31
32 protected Enumeration nextFindResult = null;
33
34 protected URL nextEntryResult = null;
35
36 public EntryLookupControllingMockBundle(Dictionary headers) {
37 super(headers);
38 }
39
40 public void setResultsToReturnOnNextCallToFindEntries(String[] findResult) {
41 if (findResult == null) {
42 findResult = new String[0];
43 }
44 this.nextFindResult = createEnumerationOver(findResult);
45 }
46
47 public Enumeration findEntries(String path, String filePattern, boolean recurse) {
48 if (this.nextFindResult == null) {
49 return super.findEntries(path, filePattern, recurse);
50 }
51 else {
52 Enumeration ret = this.nextFindResult;
53 this.nextFindResult = null;
54 return ret;
55 }
56 }
57
58 public void setEntryReturnOnNextCallToGetEntry(URL entry) {
59 this.nextEntryResult = entry;
60 }
61
62 public URL getEntry(String name) {
63 if (this.nextEntryResult != null) {
64 URL result = this.nextEntryResult;
65 this.nextEntryResult = null;
66 return result;
67 }
68 else {
69 return super.getEntry(name);
70 }
71 }
72
73 public URL getResource(String name) {
74 return getEntry(name);
75 }
76
77
78 public BundleContext getContext() {
79 return super.getContext();
80 }
81
82 protected Enumeration createEnumerationOver(String[] entries) {
83 return new ArrayEnumerator(entries);
84 }
85 }