1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.uruma.rcp.core;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.osgi.framework.Bundle;
22 import org.osgi.framework.ServiceFactory;
23 import org.osgi.framework.ServiceRegistration;
24 import org.seasar.uruma.rcp.UrumaService;
25
26
27
28
29
30
31 public class UrumaServiceFactory implements ServiceFactory {
32 protected static final Map<String, UrumaService> serviceMap = new HashMap<String, UrumaService>();
33
34 UrumaServiceFactory() {
35
36 }
37
38
39
40
41
42 public Object getService(final Bundle bundle,
43 final ServiceRegistration registration) {
44 String symbolicName = bundle.getSymbolicName();
45 UrumaService service = serviceMap.get(symbolicName);
46 if (service == null) {
47 service = new UrumaServiceImpl(bundle);
48 serviceMap.put(symbolicName, service);
49 }
50 return service;
51 }
52
53
54
55
56
57 public void ungetService(final Bundle bundle,
58 final ServiceRegistration registration, final Object service) {
59 String symbolicName = bundle.getSymbolicName();
60 UrumaServiceImpl urumaService = (UrumaServiceImpl) serviceMap
61 .get(symbolicName);
62 if (urumaService != null) {
63 urumaService.destroy();
64 serviceMap.remove(symbolicName);
65 }
66 }
67 }