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,
56 CheckingBundleListener myBundleListener) {
57 this.frameworkErrorListener = frameworkErrorListener;
58 this.myBundleListener = myBundleListener;
59 }
60
61 public void doLaunch() {
62
63 StringMap configMap = new StringMap(false);
64
65
66
67
68 configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES,
69 "org.osgi.framework; version=1.3.0,"
70 + "org.osgi.service.packageadmin; version=1.2.0,"
71 + "org.osgi.service.startlevel; version=1.0.0,"
72 + "org.osgi.service.url; version=1.0.0");
73
74 configMap.put(Constants.FRAMEWORK_STORAGE_CLEAN,
75 Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
76
77
78
79
80 try {
81
82
83 List<Object> list = new ArrayList<Object>();
84
85
86 configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
87 "org.xml.sax, org.xml.sax.helpers, javax.xml.parsers, javax.naming");
88 configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);
89 configMap.put("felix.log.level", "4");
90
91
92
93 felix = new Felix(configMap);
94 felix.init();
95
96
97
98 otherProps.put(AutoProcessor.AUTO_DEPLOY_DIR_PROPERY,
99 AutoProcessor.AUTO_DEPLOY_DIR_VALUE);
100 otherProps.put(AutoProcessor.AUTO_DEPLOY_ACTION_PROPERY,
101 AutoProcessor.AUTO_DEPLOY_START_VALUE + ","
102 + AutoProcessor.AUTO_DEPLOY_INSTALL_VALUE);
103
104 BundleContext felixBudleContext = felix.getBundleContext();
105
106 AutoProcessor.process(otherProps, felixBudleContext);
107
108 felixBudleContext.addFrameworkListener(frameworkErrorListener);
109 felixBudleContext.addBundleListener(myBundleListener);
110
111 felix.start();
112 System.out.println("felix started");
113
114 } catch (Exception ex) {
115 ex.printStackTrace();
116 }
117 }
118
119 public void stop() throws BundleException {
120 felix.stop();
121 }
122
123 public Bundle[] getInstalledBundles() {
124
125
126 return null;
127 }
128 }