1 // ========================================================================
2 // Copyright (c) 2009 Intalio, Inc.
3 // ------------------------------------------------------------------------
4 // All rights reserved. This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v1.0
6 // and Apache License v2.0 which accompanies this distribution.
7 // The Eclipse Public License is available at
8 // http://www.eclipse.org/legal/epl-v10.html
9 // The Apache License v2.0 is available at
10 // http://www.opensource.org/licenses/apache2.0.php
11 // You may elect to redistribute this code under either of these licenses.
12 // Contributors:
13 // Hugues Malphettes - initial API and implementation
14 // ========================================================================
15 package org.eclipse.jetty.osgi.boot.warurl;
16
17 import java.util.Dictionary;
18 import java.util.Hashtable;
19
20 import org.osgi.framework.BundleActivator;
21 import org.osgi.framework.BundleContext;
22 import org.osgi.framework.ServiceRegistration;
23 import org.osgi.service.url.URLConstants;
24 import org.osgi.service.url.URLStreamHandlerService;
25
26 /**
27 * Register the factory to handle the war scheme specified by rfc66
28 * when the bundle is activated.
29 */
30 public class WarUrlActivator implements BundleActivator
31 {
32
33 private ServiceRegistration _reg;
34
35 /**
36 * Register the url stream handler factory.
37 *
38 * @param context
39 */
40 @SuppressWarnings("unchecked")
41 public void start(BundleContext context) throws Exception
42 {
43 Dictionary props = new Hashtable();
44 props.put(URLConstants.URL_HANDLER_PROTOCOL,new String[] {"war"});
45 context.registerService(URLStreamHandlerService.class.getName(),
46 new WarUrlStreamHandler(), props);
47 }
48
49 /**
50 * Remove the url stream handler. (probably not required,
51 * as osgi might shutdown every registered service
52 * by default: need test)
53 */
54 public void stop(BundleContext context) throws Exception
55 {
56 try
57 {
58 if (_reg != null)
59 {
60 _reg.unregister();
61 }
62 }
63 catch (Exception e)
64 {
65 e.printStackTrace();
66 }
67 }
68
69 }