1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.slf4j.test_osgi;
26
27 import java.util.ArrayList;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.Properties;
31
32 import org.apache.felix.framework.Felix;
33 import org.apache.felix.framework.util.FelixConstants;
34 import org.apache.felix.framework.util.StringMap;
35 import org.apache.felix.main.AutoProcessor;
36 import org.osgi.framework.Bundle;
37 import org.osgi.framework.BundleContext;
38 import org.osgi.framework.BundleException;
39 import org.osgi.framework.Constants;
40
41
42
43
44
45
46
47 public class FelixHost {
48
49 private Felix felix = null;
50
51 Properties otherProps = new Properties();
52
53 final FrameworkErrorListener frameworkErrorListener;
54 final CheckingBundleListener myBundleListener;
55
56 public FelixHost(FrameworkErrorListener frameworkErrorListener,
57 CheckingBundleListener myBundleListener) {
58 this.frameworkErrorListener = frameworkErrorListener;
59 this.myBundleListener = myBundleListener;
60 }
61
62 public void doLaunch() {
63
64 Map configMap = new StringMap(false);
65
66
67
68
69 configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES,
70 "org.osgi.framework; version=1.3.0,"
71 + "org.osgi.service.packageadmin; version=1.2.0,"
72 + "org.osgi.service.startlevel; version=1.0.0,"
73 + "org.osgi.service.url; version=1.0.0");
74
75 configMap.put(Constants.FRAMEWORK_STORAGE_CLEAN,
76 Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
77
78
79
80
81 try {
82
83
84 List list = new ArrayList();
85
86
87 configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
88 "org.xml.sax, org.xml.sax.helpers, javax.xml.parsers, javax.naming");
89 configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);
90 configMap.put("felix.log.level", "4");
91
92
93
94 felix = new Felix(configMap);
95 felix.init();
96
97
98
99 otherProps.put(AutoProcessor.AUTO_DEPLOY_DIR_PROPERY,
100 AutoProcessor.AUTO_DEPLOY_DIR_VALUE);
101 otherProps.put(AutoProcessor.AUTO_DEPLOY_ACTION_PROPERY,
102 AutoProcessor.AUTO_DEPLOY_START_VALUE + ","
103 + AutoProcessor.AUTO_DEPLOY_INSTALL_VALUE);
104
105 BundleContext felixBudleContext = felix.getBundleContext();
106
107 AutoProcessor.process(otherProps, felixBudleContext);
108
109 felixBudleContext.addFrameworkListener(frameworkErrorListener);
110 felixBudleContext.addBundleListener(myBundleListener);
111
112 felix.start();
113 System.out.println("felix started");
114
115 } catch (Exception ex) {
116 ex.printStackTrace();
117 }
118 }
119
120 public void stop() throws BundleException {
121 felix.stop();
122 }
123
124 public Bundle[] getInstalledBundles() {
125
126
127 return null;
128 }
129 }