KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > equinox > internal > jsp > jasper > Activator


1 /*******************************************************************************
2  * Copyright (c) 2006-2007 Cognos Incorporated, IBM Corporation and others
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Cognos Incorporated - initial API and implementation
10  * IBM Corporation - bug fixes and enhancements
11  *******************************************************************************/

12 package org.eclipse.equinox.internal.jsp.jasper;
13
14 import org.osgi.framework.Bundle;
15 import org.osgi.framework.BundleActivator;
16 import org.osgi.framework.BundleContext;
17 import org.osgi.framework.ServiceReference;
18 import org.osgi.service.packageadmin.PackageAdmin;
19 import org.osgi.util.tracker.ServiceTracker;
20 import org.osgi.util.tracker.ServiceTrackerCustomizer;
21
22 public class Activator implements BundleActivator, ServiceTrackerCustomizer {
23
24     private ServiceTracker packageAdminTracker;
25     private static PackageAdmin packageAdmin;
26     private BundleContext context;
27
28     public void start(BundleContext context) throws Exception JavaDoc {
29         this.context = context;
30         packageAdminTracker = new ServiceTracker(context, PackageAdmin.class.getName(), this);
31         packageAdminTracker.open();
32     }
33
34     public void stop(BundleContext context) throws Exception JavaDoc {
35         packageAdminTracker.close();
36         packageAdminTracker = null;
37         this.context = null;
38     }
39
40     public Object JavaDoc addingService(ServiceReference reference) {
41         synchronized (Activator.class) {
42             packageAdmin = (PackageAdmin) context.getService(reference);
43         }
44         return packageAdmin;
45     }
46
47     public void modifiedService(ServiceReference reference, Object JavaDoc service) {
48     }
49
50     public void removedService(ServiceReference reference, Object JavaDoc service) {
51         synchronized (Activator.class) {
52             context.ungetService(reference);
53             packageAdmin = null;
54         }
55     }
56
57     public static synchronized Bundle getBundle(Class JavaDoc clazz) {
58         if (packageAdmin == null)
59             throw new IllegalStateException JavaDoc("Not started"); //$NON-NLS-1$
60

61         return packageAdmin.getBundle(clazz);
62     }
63     
64     public static Bundle[] getFragments(Bundle bundle) {
65         if (packageAdmin == null)
66             throw new IllegalStateException JavaDoc("Not started"); //$NON-NLS-1$
67

68         return packageAdmin.getFragments(bundle);
69     }
70 }
71
Popular Tags