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.Properties;
30
31 import org.apache.felix.framework.Felix;
32 import org.apache.felix.framework.util.FelixConstants;
33 import org.apache.felix.framework.util.StringMap;
34 import org.apache.felix.main.AutoProcessor;
35 import org.osgi.framework.Bundle;
36 import org.osgi.framework.BundleContext;
37 import org.osgi.framework.BundleException;
38 import org.osgi.framework.Constants;
39
40
41
42
43
44
45
46 public class FelixHost {
47
48 private Felix felix = null;
49
50 Properties otherProps = new Properties();
51
52 final FrameworkErrorListener frameworkErrorListener;
53 final CheckingBundleListener myBundleListener;
54
55 public FelixHost(FrameworkErrorListener frameworkErrorListener, CheckingBundleListener myBundleListener) {
56 this.frameworkErrorListener = frameworkErrorListener;
57 this.myBundleListener = myBundleListener;
58 }
59
60 public void doLaunch() {
61
62 StringMap configMap = new StringMap();
63
64
65
66
67 configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES, "org.osgi.framework; version=1.3.0," + "org.osgi.service.packageadmin; version=1.2.0,"
68 + "org.osgi.service.startlevel; version=1.0.0," + "org.osgi.service.url; version=1.0.0");
69
70 configMap.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
71
72
73
74
75 try {
76
77
78 List<Object> list = new ArrayList<>();
79
80
81 configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.xml.sax, org.xml.sax.helpers, javax.xml.parsers, javax.naming");
82 configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);
83 configMap.put("felix.log.level", "4");
84
85
86
87 felix = new Felix(configMap);
88 felix.init();
89
90
91
92 otherProps.put(AutoProcessor.AUTO_DEPLOY_DIR_PROPERTY, AutoProcessor.AUTO_DEPLOY_DIR_VALUE);
93 otherProps.put(AutoProcessor.AUTO_DEPLOY_ACTION_PROPERTY, AutoProcessor.AUTO_DEPLOY_START_VALUE + "," + AutoProcessor.AUTO_DEPLOY_INSTALL_VALUE);
94
95 BundleContext felixBudleContext = felix.getBundleContext();
96
97 AutoProcessor.process(otherProps, felixBudleContext);
98
99 felixBudleContext.addFrameworkListener(frameworkErrorListener);
100 felixBudleContext.addBundleListener(myBundleListener);
101
102 felix.start();
103 System.out.println("felix started");
104
105 } catch (Exception ex) {
106 ex.printStackTrace();
107 }
108 }
109
110 public void stop() throws BundleException {
111 felix.stop();
112 }
113
114 public Bundle[] getInstalledBundles() {
115
116
117 return null;
118 }
119 }