1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.uruma.rcp.unit;
17
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.net.URL;
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.Dictionary;
24 import java.util.Enumeration;
25 import java.util.Properties;
26
27 import org.osgi.framework.Bundle;
28 import org.osgi.framework.BundleContext;
29 import org.osgi.framework.BundleException;
30 import org.osgi.framework.ServiceReference;
31
32
33
34
35
36
37 public class MockBundle implements Bundle {
38 static final String SYMBOLIC_NAME = "org.seasar.uruma.rcp.core";
39
40 protected MockBundleContext context;
41
42 public Enumeration<?> findEntries(final String path,
43 final String filePattern, final boolean recurse) {
44 URL url = getClass().getClassLoader().getResource(
45 getClass().getName() + ".class");
46 if (url != null) {
47 ArrayList<URL> entries = new ArrayList<URL>();
48 entries.add(url);
49 return Collections.enumeration(entries);
50 } else {
51 return getEmptyEnumeration();
52 }
53 }
54
55 public BundleContext getBundleContext() {
56 if (context == null) {
57 context = new MockBundleContext(this);
58 }
59 return context;
60 }
61
62 public long getBundleId() {
63 return 0;
64 }
65
66 public URL getEntry(final String path) {
67 return null;
68 }
69
70 public Enumeration<?> getEntryPaths(final String path) {
71 return getEmptyEnumeration();
72 }
73
74 public Dictionary<?, ?> getHeaders() {
75 return new Properties();
76 }
77
78 public Dictionary<?, ?> getHeaders(final String locale) {
79 return new Properties();
80 }
81
82 public long getLastModified() {
83 return 0;
84 }
85
86 public String getLocation() {
87 return null;
88 }
89
90 public ServiceReference[] getRegisteredServices() {
91 return null;
92 }
93
94 public URL getResource(final String name) {
95 return null;
96 }
97
98 public Enumeration<?> getResources(final String name) throws IOException {
99 return getEmptyEnumeration();
100 }
101
102 public ServiceReference[] getServicesInUse() {
103 return null;
104 }
105
106 public int getState() {
107 return 0;
108 }
109
110 public String getSymbolicName() {
111 return SYMBOLIC_NAME;
112 }
113
114 public boolean hasPermission(final Object permission) {
115 return true;
116 }
117
118 public Class<?> loadClass(final String name) throws ClassNotFoundException {
119 return Class.forName(name);
120 }
121
122 public void start() throws BundleException {
123
124 }
125
126 public void start(final int options) throws BundleException {
127
128 }
129
130 public void stop() throws BundleException {
131
132 }
133
134 public void stop(final int options) throws BundleException {
135
136 }
137
138 public void uninstall() throws BundleException {
139
140 }
141
142 public void update() throws BundleException {
143
144 }
145
146 public void update(final InputStream in) throws BundleException {
147
148 }
149
150 @SuppressWarnings("unchecked")
151 protected Enumeration<?> getEmptyEnumeration() {
152 return Collections.enumeration(Collections.EMPTY_LIST);
153 }
154 }