1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.acme.osgi;
20
21 import java.util.Dictionary;
22 import java.util.Hashtable;
23
24 import javax.servlet.ServletContextEvent;
25 import javax.servlet.ServletContextListener;
26
27 import org.eclipse.jetty.server.Server;
28 import org.eclipse.jetty.server.handler.ContextHandler;
29 import org.osgi.framework.Bundle;
30 import org.osgi.framework.BundleActivator;
31 import org.osgi.framework.BundleContext;
32 import org.osgi.framework.BundleException;
33 import org.osgi.framework.FrameworkUtil;
34 import org.osgi.framework.ServiceRegistration;
35 import org.osgi.util.tracker.BundleTracker;
36
37
38
39
40
41
42 public class Activator implements BundleActivator
43 {
44
45
46
47
48
49 public void start(final BundleContext context) throws Exception
50 {
51 ContextHandler ch = new ContextHandler();
52 ch.addEventListener(new ServletContextListener ()
53 {
54 public void contextInitialized(ServletContextEvent sce)
55 {
56 System.err.println("Context is initialized");
57 }
58
59 public void contextDestroyed(ServletContextEvent sce)
60 {
61 System.err.println("CONTEXT IS DESTROYED!");
62 }
63 });
64 Dictionary props = new Hashtable();
65 props.put("contextPath","/acme");
66 props.put("Jetty-ContextFilePath", "acme.xml");
67 context.registerService(ContextHandler.class.getName(),ch,props);
68 }
69
70
71
72
73
74
75
76 public void stop(BundleContext context) throws Exception
77 {
78 }
79 }