/* (non-Javadoc)
   * @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration)
   */
  @Override
  public Object getService(Bundle bundle, ServiceRegistration registration) {
    if (serviceInstance == null) {
      IRepositoryService repositoryService = null;
      IMarketService marketService = null;

      try {
        BundleContext context = CoreActivator.getDefault().getBundle().getBundleContext();

        ServiceReference serviceReference =
            context.getServiceReference(IRepositoryService.class.getName());
        if (serviceReference != null) {
          repositoryService = (IRepositoryService) context.getService(serviceReference);
          context.ungetService(serviceReference);
        }

        serviceReference = context.getServiceReference(IMarketService.class.getName());
        if (serviceReference != null) {
          marketService = (IMarketService) context.getService(serviceReference);
          context.ungetService(serviceReference);
        }

        serviceInstance = new CurrencyService(repositoryService, marketService);
        serviceInstance.startUp(null);
      } catch (Exception e) {
        CoreActivator.log("Error starting currency service", e);
      }
    }
    return serviceInstance;
  }
예제 #2
0
  public void start(BundleContext context) throws Exception {

    // simplistic way of achieving the WebContainer as service
    ServiceReference<WebContainer> serviceReference =
        context.getServiceReference(WebContainer.class);

    while (serviceReference == null) {
      serviceReference = context.getServiceReference(WebContainer.class);
    }

    WebContainer service = (WebContainer) context.getService(serviceReference);

    Collection<ServiceReference<HttpContext>> serviceReferences =
        context.getServiceReferences(HttpContext.class, "(httpContext.id=shared)");

    if (serviceReferences.size() > 1) {
      throw new RuntimeException("should only be one http shared context");
    }

    HttpContext httpContext = context.getService(serviceReferences.iterator().next());

    Dictionary<String, String> props;

    props = new Hashtable<String, String>();
    props.put("pattern", ".*");
    props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "shared");

    service.registerFilter(new ServletFilter(), new String[] {"/*"}, null, props, httpContext);
  }
예제 #3
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  private void getServices() {
    try {
      BundleContext bundleContext =
          FrameworkUtil.getBundle(VehicleViewForm.class).getBundleContext();

      ServiceReference vehicleServiceReference =
          bundleContext.getServiceReference(VehicleService.class.getName());
      vehicleService = VehicleService.class.cast(bundleContext.getService(vehicleServiceReference));

      ServiceReference supplierServiceReference =
          bundleContext.getServiceReference(SupplierService.class.getName());
      supplierService =
          SupplierService.class.cast(bundleContext.getService(supplierServiceReference));

      ServiceReference tireTypeServiceReference =
          bundleContext.getServiceReference(TireTypeService.class.getName());
      tireTypeService =
          TireTypeService.class.cast(bundleContext.getService(tireTypeServiceReference));

      ServiceReference tireStatusServiceReference =
          bundleContext.getServiceReference(TireStatusService.class.getName());
      tireStatusService =
          TireStatusService.class.cast(bundleContext.getService(tireStatusServiceReference));

    } catch (Exception e) {
      e.getMessage();
    }
  }
예제 #4
0
  public void start(BundleContext context) throws Exception {
    ServiceReference messageManager = context.getServiceReference(MessageManager.class.getName());
    mgr = (MessageManager) context.getService(messageManager);
    ServiceReference azureuCore = context.getServiceReference(AzureusCore.class.getName());
    core = (AzureusCore) context.getService(azureuCore);

    //        ServiceReference gmRef = context.getServiceReference(GlobalManager.class.getName());
    //        gm = (GlobalManager) context.getService(gmRef);

    ServiceReference dlmgrRef = context.getServiceReference(DownloadManager.class.getName());
    dlmgr = (DownloadManager) context.getService(dlmgrRef);

    initialize();
  }
  public synchronized MavenResolver getMavenResolver() throws RuntimeException {
    if (mavenResolver == null) {
      BundleContext context = CoreRuntimePlugin.getInstance().getBundle().getBundleContext();
      ServiceReference<ManagedService> managedServiceRef =
          context.getServiceReference(ManagedService.class);
      if (managedServiceRef != null) {
        String repositories = "";
        NexusServerBean customServer = getCustomNexusServer();
        if (customServer != null) {
          // custom nexus server should use snapshot repository
          repositories = customServer.getRepositoryUrl() + NexusConstants.SNAPSHOTS + ",";
        }
        final NexusServerBean officailServer = getLibrariesNexusServer();
        repositories = repositories + officailServer.getRepositoryUrl();

        ManagedService managedService = context.getService(managedServiceRef);
        Dictionary<String, String> props = new Hashtable<String, String>();
        props.put(
            ServiceConstants.PID + '.' + ServiceConstants.PROPERTY_REPOSITORIES, repositories);

        // get the setting file same as M2E preference in M2eUserSettingForTalendLoginTask.
        String settingsFile = MavenPlugin.getMavenConfiguration().getUserSettingsFile();
        if (settingsFile != null && new File(settingsFile).exists()) {
          props.put(
              ServiceConstants.PID + '.' + ServiceConstants.PROPERTY_SETTINGS_FILE, settingsFile);
        }

        try {
          managedService.updated(props);
        } catch (ConfigurationException e) {
          throw new RuntimeException("Failed to modifiy the service properties"); // $NON-NLS-1$
        }
      } else {
        throw new RuntimeException(
            "Failed to load the service :"
                + ManagedService.class.getCanonicalName()); // $NON-NLS-1$
      }

      ServiceReference<org.ops4j.pax.url.mvn.MavenResolver> mavenResolverService =
          context.getServiceReference(org.ops4j.pax.url.mvn.MavenResolver.class);
      if (mavenResolverService != null) {
        mavenResolver = context.getService(mavenResolverService);
      } else {
        throw new RuntimeException("Unable to acquire org.ops4j.pax.url.mvn.MavenResolver");
      }
    }

    return mavenResolver;
  }
  /**
   * Returns the prefix for all persistently stored properties of the account with the specified id.
   *
   * @param bundleContext a currently valid bundle context.
   * @param accountID the AccountID of the account whose properties we're looking for.
   * @param sourcePackageName a String containing the package name of the concrete factory class
   *     that extends us.
   * @return a String indicating the ConfigurationService property name prefix under which all
   *     account properties are stored or null if no account corresponding to the specified id was
   *     found.
   */
  public static String findAccountPrefix(
      BundleContext bundleContext, AccountID accountID, String sourcePackageName) {
    ServiceReference confReference =
        bundleContext.getServiceReference(ConfigurationService.class.getName());
    ConfigurationService configurationService =
        (ConfigurationService) bundleContext.getService(confReference);

    // first retrieve all accounts that we've registered
    List<String> storedAccounts =
        configurationService.getPropertyNamesByPrefix(sourcePackageName, true);

    // find an account with the corresponding id.
    for (String accountRootPropertyName : storedAccounts) {
      // unregister the account in the configuration service.
      // all the properties must have been registered in the following
      // hierarchy:
      // net.java.sip.communicator.impl.protocol.PROTO_NAME.ACC_ID.PROP_NAME
      String accountUID =
          configurationService.getString(
              accountRootPropertyName // node id
                  + "."
                  + ACCOUNT_UID); // propname

      if (accountID.getAccountUniqueID().equals(accountUID)) {
        return accountRootPropertyName;
      }
    }
    return null;
  }
  public void start() throws IOException {
    if (httpService != null || httpServiceReference != null)
      throw new IllegalStateException("Server has already been started.");

    httpServiceReference = context.getServiceReference(HttpService.class.getName());

    if (httpServiceReference != null) {
      httpService = (HttpService) context.getService(httpServiceReference);

      if (httpService == null) throw new IOException("Unable to access Http Service");
    } else {
      throw new IOException("Unable to access Http Service");
    }

    for (Iterator i = registrations.keySet().iterator(); i.hasNext(); ) {
      String prefix = (String) i.next();
      IHandler handler = (IHandler) registrations.get(prefix);
      try {
        httpService.registerServlet(
            globalPrefix + "/" + prefix, new HandlerServletAdapter(handler), null, null);
      } catch (Exception e) {
        throw new IOException(e.getMessage());
      }
    }
  }
 private static final IBundleScanService lookupBundleScanner(BundleContext ctx) {
   ServiceReference svcRef = ctx.getServiceReference(IBundleScanService.class);
   if (svcRef == null) {
     throw new ServiceException("Unable to lookup IBundleScanService");
   }
   return IBundleScanService.class.cast(ctx.getService(svcRef));
 }
  @Override
  public void start(BundleContext context) throws Exception {
    LOG.info("Starting Bundle");

    // Get our name.
    String myName = context.getBundle().getSymbolicName();

    // Find reference.
    ServiceReference<HelloService> ref = context.getServiceReference(HelloService.class);
    if (ref != null) {
      try {
        // Print service properties.
        String props = getServiceProperties(ref);
        LOG.info(
            "Calling HelloService#sayHello('{}') Published by {}. Props:\n{}",
            myName,
            ref.getBundle().getSymbolicName(),
            props);
        // Get the service
        HelloService service = context.getService(ref);
        if (service != null) {
          service.sayHello(myName);
        }
      } finally {
        // Release reference
        context.ungetService(ref);
      }
    }
  }
  @Before
  public void areWeReady() {
    assertNotNull(bc);
    boolean debugit = false;
    Bundle b[] = bc.getBundles();
    for (Bundle element : b) {
      int state = element.getState();
      if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
        log.debug("Bundle:" + element.getSymbolicName() + " state:" + stateToString(state));
        debugit = true;
      }
    }
    if (debugit) {
      log.debug("Do some debugging because some bundle is " + "unresolved");
    }

    // Assert if true, if false we are good to go!
    assertFalse(debugit);

    ServiceReference r = bc.getServiceReference(IForwardingRulesManager.class.getName());
    if (r != null) {
      this.manager = (IForwardingRulesManager) bc.getService(r);
    }
    // If StatisticsManager is null, cannot run tests.
    assertNotNull(this.manager);
  }
예제 #11
0
  @Before
  public void areWeReady() {
    assertNotNull(bc);
    boolean debugit = false;
    Bundle b[] = bc.getBundles();
    for (int i = 0; i < b.length; i++) {
      int state = b[i].getState();
      if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
        log.debug("Bundle:" + b[i].getSymbolicName() + " state:" + stateToString(state));
        debugit = true;
      }
    }
    if (debugit) {
      log.debug("Do some debugging because some bundle is " + "unresolved");
    }

    // Assert if true, if false we are good to go!
    assertFalse(debugit);

    // Now lets create a hosttracker for testing purpose
    ServiceReference s = bc.getServiceReference(ISwitchManager.class.getName());
    if (s != null) {
      this.switchManager = (ISwitchManager) bc.getService(s);
    }

    // If StatisticsManager is null, cannot run tests.
    assertNotNull(this.switchManager);
  }
  protected void checkRequiredBundles() {
    IProject project = getDomainClass().getFragmentRoot().getJavaProject().getProject();
    BundleContext context = FrameworkUtil.getBundle(NewAddonClassWizard.class).getBundleContext();
    ServiceReference<IBundleProjectService> ref =
        context.getServiceReference(IBundleProjectService.class);
    IBundleProjectService service = context.getService(ref);
    try {
      IBundleProjectDescription description = service.getDescription(project);
      Set<String> requiredBundles = getRequiredBundles();
      IRequiredBundleDescription[] arTmp = description.getRequiredBundles();
      List<IRequiredBundleDescription> descs = new ArrayList<IRequiredBundleDescription>();
      if (arTmp != null) {
        descs.addAll(Arrays.asList(arTmp));
      }
      for (IRequiredBundleDescription bd : descs) {
        requiredBundles.remove(bd.getName());
      }

      if (requiredBundles.size() > 0) {
        for (String b : requiredBundles) {
          descs.add(service.newRequiredBundle(b, null, false, false));
        }
        description.setRequiredBundles(descs.toArray(new IRequiredBundleDescription[0]));
        description.apply(new NullProgressMonitor());
      }
    } catch (CoreException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
예제 #13
0
 @Override
 public void undeployBundle(String bundleName) throws BundleException {
   if (bundleName == null) {
     // ignore
     return;
   }
   log.info(
       String.format(
           "Before undeploy bundle with name '%s'.\n" + "%s", bundleName, getRuntimeStatus()));
   BundleContext ctx = getBundleContext();
   ServiceReference ref = ctx.getServiceReference(PackageAdmin.class.getName());
   PackageAdmin srv = (PackageAdmin) ctx.getService(ref);
   try {
     for (Bundle b : srv.getBundles(bundleName, null)) {
       if (b != null && b.getState() == Bundle.ACTIVE) {
         Transaction tx = TransactionHelper.suspendTransaction();
         try {
           b.stop();
           b.uninstall();
         } finally {
           TransactionHelper.resumeTransaction(tx);
         }
       }
     }
   } finally {
     ctx.ungetService(ref);
   }
   log.info(String.format("Undeploy done.\n" + "%s", getRuntimeStatus()));
 }
 private HttpService getHttpService(BundleContext bundleContext) {
   ServiceReference<HttpService> ref = bundleContext.getServiceReference(HttpService.class);
   Assert.assertNotNull("Failed to get HttpService", ref);
   HttpService httpService = (HttpService) bundleContext.getService(ref);
   Assert.assertNotNull("Failed to get HttpService", httpService);
   return httpService;
 }
 /**
  * Used to get Full form of URL from the Given Short Page URL
  *
  * @param pageFullPath
  * @return {@link String}
  * @throws Exception
  */
 public static String getFullURLPath(String shortUrlPath) throws Exception {
   ResourceResolver resourceResolver = null;
   try {
     Bundle bndl = FrameworkUtil.getBundle(ResourceResolverFactory.class);
     BundleContext bundleContext = bndl.getBundleContext();
     ServiceReference ref =
         bundleContext.getServiceReference(ResourceResolverFactory.class.getName());
     ResourceResolverFactory resolverFactory =
         (ResourceResolverFactory) bundleContext.getService(ref);
     resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
     Resource resource = resourceResolver.resolve(shortUrlPath);
     if (null != resource) {
       return java.net.URLDecoder.decode(resource.getPath(), "UTF-8");
     } else {
       if (LOGGER.isDebugEnabled()) {
         LOGGER.debug("Resource doesn't exists..." + shortUrlPath);
       }
     }
   } catch (Exception e) {
     LOGGER.error(
         " Error while getting Full URL for the path :"
             + shortUrlPath
             + " and the error message is :",
         e);
   } finally {
     resourceResolver.close();
   }
   return shortUrlPath;
 }
예제 #16
0
 public static SlingRepository getSlingRepositoryFromServiceList(BundleContext bundleContext) {
   ServiceReference slingRepositoryServiceReference =
       bundleContext.getServiceReference(SlingRepository.class.getName());
   SlingRepository slingRepository =
       (SlingRepository) bundleContext.getService(slingRepositoryServiceReference);
   return slingRepository;
 }
예제 #17
0
 public static ConfigurationAdmin getConfigurationAdminService(BundleContext bundleContext) {
   ServiceReference configurationAdminServiceReference =
       bundleContext.getServiceReference(ConfigurationAdmin.class.getName());
   ConfigurationAdmin configurationAdminService =
       (ConfigurationAdmin) bundleContext.getService(configurationAdminServiceReference);
   return configurationAdminService;
 }
예제 #18
0
 @Override
 public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
   eventDispatcher =
       (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
   eventDispatcher.eventHandlerAdded(
       bundleContext.getServiceReference(INeutronFirewallAware.class.getName()), this);
 }
예제 #19
0
  @Override
  public void start(BundleContext bundleContext) throws Exception {
    context = bundleContext;

    // URL x = context.getBundle().getEntry("config.xml");
    // InputStream is = x.openStream();

    ServiceReference reference = context.getServiceReference(IAqua.class.getName());
    aqua = (IAqua) context.getService(reference);

    FileInputStream is = new FileInputStream(new File(getBaseDir(), "config.xml"));
    config = new XmlConfig(MXml.loadXml(is).getDocumentElement());
    config.setString("_path", getBaseDir().getAbsolutePath());
    is.close();

    // init directories to publish
    IConfig cp = aqua.getConfig().getConfig("deploy");
    contentDir = cp.getExtracted("content") + "/" + getId();
    templateDir = cp.getExtracted("templates") + "/" + getId();

    getConfiguration().setProperty("_contentdir", contentDir);
    getConfiguration().setProperty("_templatedir", templateDir);

    // publish
    publish();

    // load resources
    loadResources();

    jmx = new JmxAquaModule(this);
    Activator.getAqua().getJmxManager().register(jmx);
  }
  @Test
  public void testRepositoryService() throws Exception {

    Repository repo = getRepository();
    MavenCoordinates coordinates =
        MavenCoordinates.parse("org.apache.felix:org.apache.felix.eventadmin:1.2.6");
    Requirement req = XRequirementBuilder.createArtifactRequirement(coordinates);
    assertNotNull("Requirement not null", req);

    Collection<Capability> caps = repo.findProviders(Collections.singleton(req)).get(req);
    assertEquals("Capability not null", 1, caps.size());

    XIdentityCapability xcap = (XIdentityCapability) caps.iterator().next();
    assertEquals("org.apache.felix.eventadmin", xcap.getSymbolicName());
    InputStream content = ((XResource) xcap.getResource()).getContent();
    try {
      Bundle bundle = context.installBundle(xcap.getSymbolicName(), content);
      try {
        bundle.start();
        Assert.assertEquals(Bundle.ACTIVE, bundle.getState());
        ServiceReference sref = context.getServiceReference("org.osgi.service.event.EventAdmin");
        assertNotNull("EventAdmin service not null", sref);
      } finally {
        bundle.uninstall();
      }
    } finally {
      content.close();
    }
  }
예제 #21
0
  @Before
  public void areWeReady() {
    assertNotNull(bc);
    boolean debugit = false;
    Bundle b[] = bc.getBundles();
    for (int i = 0; i < b.length; i++) {
      int state = b[i].getState();
      if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
        System.out.println(">>> " + b[i].getSymbolicName() + " " + stateToString(state));
        log.debug("Bundle:" + b[i].getSymbolicName() + " state:" + stateToString(state));
        debugit = true;
      }
    }

    if (debugit) {
      log.debug("Do some debugging because some bundle is unresolved");
    }

    // Assert if true, if false we are good to go!
    assertFalse(debugit);

    ServiceReference r = bc.getServiceReference(IAffinityManager.class.getName());

    if (r != null) {
      this.manager = (IAffinityManager) bc.getService(r);
    }

    // If AffinityManager is null, cannot run tests.
    assertNotNull(this.manager);
  }
예제 #22
0
  /**
   * This will try and find a resource of the given name using the bundle from which was originally
   * loaded the given class so as to try and detect if it is jarred. If <code>clazz</code> hasn't
   * been loaded from a bundle class loader, we'll resort to the default class loader mechanism.
   * This will only return <code>null</code> in the case where the resource at <code>resourcePath
   * </code> cannot be located at all.
   *
   * @param clazz Class which class loader will be used to try and locate the resource.
   * @param resourcePath Path of the resource we seek, relative to the class.
   * @return The URL of the resource as we could locate it.
   * @throws IOException This will be thrown if we fail to convert bundle-scheme URIs into
   *     file-scheme URIs.
   */
  public static URL getResourceURL(Class<?> clazz, String resourcePath) throws IOException {
    BundleContext context = AcceleoCommonPlugin.getDefault().getContext();
    ServiceReference packageAdminReference =
        context.getServiceReference(PackageAdmin.class.getName());
    PackageAdmin packageAdmin = null;
    if (packageAdminReference != null) {
      packageAdmin = (PackageAdmin) context.getService(packageAdminReference);
    }

    URL resourceURL = null;
    if (packageAdmin != null) {
      Bundle bundle = packageAdmin.getBundle(clazz);
      if (bundle != null) {
        final String pathSeparator = "/"; // $NON-NLS-1$
        // We found the appropriate bundle. We'll now try and determine whether the emtl is jarred
        resourceURL = getBundleResourceURL(bundle, pathSeparator, resourcePath);
      }
    }
    /*
     * We couldn't locate either the bundle which loaded the class or the resource. Resort to the class
     * loader and return null if it cannot locate the resource either.
     */
    if (resourceURL == null) {
      resourceURL = clazz.getResource(resourcePath);
    }

    if (packageAdminReference != null) {
      context.ungetService(packageAdminReference);
    }
    return resourceURL;
  }
예제 #23
0
 static Object getService(String name) {
   ServiceReference reference = context.getServiceReference(name);
   if (reference == null) return null;
   Object result = context.getService(reference);
   context.ungetService(reference);
   return result;
 }
 /** Get a ServiceReference within the given timeout. */
 protected ServiceReference getServiceReference(String clazz, long timeout)
     throws BundleException {
   int fraction = 200;
   timeout = timeout / fraction;
   BundleContext systemContext = getSystemContext();
   ServiceReference sref = systemContext.getServiceReference(clazz);
   while (sref == null && 0 < timeout--) {
     try {
       Thread.sleep(fraction);
     } catch (InterruptedException e) {
       // ignore
     }
     sref = systemContext.getServiceReference(clazz);
   }
   return sref;
 }
예제 #25
0
  @Override
  public void start(BundleContext context) throws Exception {
    bundleContext = context;

    this.tracker =
        new ServiceTracker(context, HttpService.class.getName(), null) {

          @Override
          public Object addingService(ServiceReference ref) {
            Object service = super.addingService(ref);
            serviceAdded((HttpService) service);
            return service;
          }

          @Override
          public void removedService(ServiceReference ref, Object service) {
            serviceRemoved((HttpService) service);
            super.removedService(ref, service);
          }
        };
    this.tracker.open();
    httpService = context.getServiceReference(HttpService.class.getName());
    if (httpService != null) {
      HttpService service = (HttpService) context.getService(httpService);
      serviceAdded(service);
    }
  }
예제 #26
0
  @Test
  public void testServiceContributorDiscovery() throws Exception {
    final ServiceReference sr = bundleContext.getServiceReference(SessionFactory.class.getName());
    final SessionFactoryImplementor sfi = (SessionFactoryImplementor) bundleContext.getService(sr);

    assertNotNull(sfi.getServiceRegistry().getService(SomeService.class));
  }
예제 #27
0
  // TODO - we should really make this a bundle and inject this.
  private FeaturesService getFeaturesService() throws InterruptedException {
    FeaturesService featuresService = null;
    boolean ready = false;
    long timeoutLimit = System.currentTimeMillis() + REQUIRED_BUNDLES_TIMEOUT;
    while (!ready) {
      ServiceReference<FeaturesService> featuresServiceRef =
          bundleCtx.getServiceReference(FeaturesService.class);
      try {
        if (featuresServiceRef != null) {
          featuresService = bundleCtx.getService(featuresServiceRef);
          if (featuresService != null) {
            ready = true;
          }
        }
      } catch (NullPointerException e) {
        // ignore
      }

      if (!ready) {
        if (System.currentTimeMillis() > timeoutLimit) {
          fail(
              String.format(
                  "Feature service could not be resolved within %d minutes.",
                  TimeUnit.MILLISECONDS.toMinutes(REQUIRED_BUNDLES_TIMEOUT)));
        }
        Thread.sleep(1000);
      }
    }

    return featuresService;
  }
예제 #28
0
 protected <T> T requiredService(Class<T> serviceType) {
   ServiceReference reference = bundleContext.getServiceReference(serviceType);
   if (reference == null) {
     throw new IllegalStateException("Cannot find service: " + serviceType.getName());
   }
   return (T) bundleContext.getService(reference);
 }
  /**
   * Get the <tt>AccountManager</tt> of the protocol.
   *
   * @return <tt>AccountManager</tt> of the protocol
   */
  private AccountManager getAccountManager() {
    BundleContext bundleContext = getBundleContext();
    ServiceReference serviceReference =
        bundleContext.getServiceReference(AccountManager.class.getName());

    return (AccountManager) bundleContext.getService(serviceReference);
  }
예제 #30
0
  private void initialize(final BundleContext context) {
    if (Debug.DEBUG_GENERAL) Debug.println("> AspectJHook.initialize() context=" + context);

    this.bundleContext = context;

    final ISupplementerRegistry supplementerRegistry = getSupplementerRegistry();
    adaptorFactory.initialize(context, supplementerRegistry);

    final ServiceReference serviceReference =
        context.getServiceReference(PackageAdmin.class.getName());
    final PackageAdmin packageAdmin = (PackageAdmin) context.getService(serviceReference);

    supplementerRegistry.setBundleContext(context);
    supplementerRegistry.setPackageAdmin(packageAdmin);
    context.addBundleListener(new SupplementBundleListener(supplementerRegistry));

    // final re-build supplementer final registry state for final installed bundles
    final Bundle[] installedBundles = context.getBundles();
    for (int i = 0; i < installedBundles.length; i++) {
      supplementerRegistry.addSupplementer(installedBundles[i], false);
    }
    for (int i = 0; i < installedBundles.length; i++) {
      supplementerRegistry.addSupplementedBundle(installedBundles[i]);
    }

    if (Debug.DEBUG_GENERAL)
      Debug.println("< AspectJHook.initialize() adaptorFactory=" + adaptorFactory);
  }