dsdp/tm/tcf_0_3_x/org.eclipse.tm.tcf.core/activator/org/eclipse/tm/internal/tcf/Activator.java
changeset 84 7f7234222666
equal deleted inserted replaced
83:eb76ac5926e9 84:7f7234222666
       
     1 package org.eclipse.tm.internal.tcf;
       
     2 
       
     3 import org.osgi.framework.Bundle;
       
     4 import org.osgi.framework.BundleActivator;
       
     5 import org.osgi.framework.BundleContext;
       
     6 import org.osgi.service.packageadmin.PackageAdmin;
       
     7 import org.osgi.util.tracker.ServiceTracker;
       
     8 
       
     9 public class Activator implements  BundleActivator {
       
    10     
       
    11     private static final String TCF_INTEGRATION_BUNDLE_ID = "org.eclipse.tm.tcf";
       
    12 
       
    13     public void start(BundleContext context) throws Exception {
       
    14         /*
       
    15          * Activate TCF Eclipse integration bundle "org.eclipse.tm.tcf".
       
    16          * It must be activated explicitly, because default activation through
       
    17          * class loading may never happen - most client don't need classes from that bundle.
       
    18          */
       
    19         ServiceTracker tracker = new ServiceTracker(context, PackageAdmin.class.getName(), null);
       
    20         tracker.open();
       
    21         Bundle[] bundles = ((PackageAdmin)tracker.getService()).getBundles(TCF_INTEGRATION_BUNDLE_ID, null);
       
    22         int cnt = 0;
       
    23         if (bundles != null) {
       
    24             for (Bundle bundle : bundles) {
       
    25                 if ((bundle.getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
       
    26                     bundle.start(Bundle.START_TRANSIENT);
       
    27                     cnt++;
       
    28                 }
       
    29             }
       
    30         }
       
    31         if (cnt != 1) throw new Exception("Invalid or missing bundle: " + TCF_INTEGRATION_BUNDLE_ID);
       
    32     }
       
    33 
       
    34     public void stop(BundleContext context) throws Exception {
       
    35     }
       
    36 }