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