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