private URL findResource(String resource) {
   ModuleWiring searchWiring = generation.getRevision().getWiring();
   if (searchWiring != null) {
     if ((generation.getRevision().getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
       List<ModuleWire> hostWires =
           searchWiring.getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
       searchWiring = null;
       Long lowestHost = Long.MAX_VALUE;
       if (hostWires != null) {
         // search for the host with the highest ID
         for (ModuleWire hostWire : hostWires) {
           Long hostID = hostWire.getProvider().getRevisions().getModule().getId();
           if (hostID.compareTo(lowestHost) <= 0) {
             lowestHost = hostID;
             searchWiring = hostWire.getProviderWiring();
           }
         }
       }
     }
   }
   if (searchWiring != null) {
     int lastSlash = resource.lastIndexOf('/');
     String path = lastSlash > 0 ? resource.substring(0, lastSlash) : "/"; // $NON-NLS-1$
     String fileName = lastSlash != -1 ? resource.substring(lastSlash + 1) : resource;
     List<URL> result = searchWiring.findEntries(path, fileName, 0);
     return (result == null || result.isEmpty()) ? null : result.get(0);
   }
   // search the raw bundle file for the generation
   return generation.getEntry(resource);
 }
  @Override
  public Map<X509Certificate, List<X509Certificate>> getSignerCertificates(int signersType) {
    SignedContentFactory factory = equinoxContainer.getSignedContentFactory();
    if (factory == null) {
      return Collections.emptyMap();
    }

    try {
      SignerInfo[] infos = signerInfos;
      if (infos == null) {
        SignedContent signedContent = factory.getSignedContent(this);
        infos = signedContent.getSignerInfos();
        signerInfos = infos;
      }
      if (infos.length == 0) return Collections.emptyMap();
      Map<X509Certificate, List<X509Certificate>> results =
          new HashMap<X509Certificate, List<X509Certificate>>(infos.length);
      for (int i = 0; i < infos.length; i++) {
        if (signersType == SIGNERS_TRUSTED && !infos[i].isTrusted()) continue;
        Certificate[] certs = infos[i].getCertificateChain();
        if (certs == null || certs.length == 0) continue;
        List<X509Certificate> certChain = new ArrayList<X509Certificate>();
        for (int j = 0; j < certs.length; j++) certChain.add((X509Certificate) certs[j]);
        results.put((X509Certificate) certs[0], certChain);
      }
      return results;
    } catch (Exception e) {
      return Collections.emptyMap();
    }
  }
 /*
  * Maps an already mapped library name to additional library file extensions.
  * This is needed on platforms like AIX where .a and .so can be used as library file
  * extensions, but System.mapLibraryName only returns a single string.
  */
 public String[] mapLibraryNames(String mappedLibName) {
   int extIndex = mappedLibName.lastIndexOf('.');
   List<String> LIB_EXTENSIONS =
       generation.getBundleInfo().getStorage().getConfiguration().LIB_EXTENSIONS;
   if (LIB_EXTENSIONS.isEmpty() || extIndex < 0) return EMPTY_STRINGS;
   String libNameBase = mappedLibName.substring(0, extIndex);
   String[] results = new String[LIB_EXTENSIONS.size()];
   for (int i = 0; i < results.length; i++) results[i] = libNameBase + LIB_EXTENSIONS.get(i);
   return results;
 }
 private String[] buildNLVariants(String nl) {
   List<String> result = new ArrayList<String>();
   while (nl.length() > 0) {
     result.add(nl);
     int i = nl.lastIndexOf('_');
     nl = (i < 0) ? "" : nl.substring(0, i); // $NON-NLS-1$
   }
   result.add(""); // $NON-NLS-1$
   return result.toArray(new String[result.size()]);
 }
 List<Generation> getGenerations() {
   List<Generation> result = new ArrayList<Generation>();
   ModuleRevision current = getModule().getCurrentRevision();
   result.add((Generation) current.getRevisionInfo());
   ModuleWiring wiring = current.getWiring();
   if (wiring != null) {
     List<ModuleWire> hostWires = wiring.getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
     if (hostWires != null) {
       for (ModuleWire hostWire : hostWires) {
         result.add((Generation) hostWire.getRequirer().getRevisionInfo());
       }
     }
   }
   return result;
 }
 void removeInitListeners() {
   BundleContext context = createBundleContext(false);
   for (FrameworkListener initListener : initListeners) {
     context.removeFrameworkListener(initListener);
   }
   initListeners.clear();
 }
 private String findBundleNativeCode(String libname, String mappedName, String[] altMappedNames) {
   String path = null;
   if (debug.DEBUG_LOADER) Debug.println("  mapped library name: " + mappedName); // $NON-NLS-1$
   List<String> nativePaths = getNativePaths();
   if (nativePaths.isEmpty()) {
     return null;
   }
   path = findNativePath(nativePaths, mappedName);
   if (path == null) {
     for (int i = 0; i < altMappedNames.length && path == null; i++)
       path = findNativePath(nativePaths, altMappedNames[i]);
   }
   if (path == null) {
     if (debug.DEBUG_LOADER)
       Debug.println("  library does not exist: " + mappedName); // $NON-NLS-1$
     path = findNativePath(nativePaths, libname);
   }
   if (debug.DEBUG_LOADER) Debug.println("  returning library: " + path); // $NON-NLS-1$
   return path;
 }
 public void init(FrameworkListener... listeners) throws BundleException {
   if (listeners != null) {
     if (getEquinoxContainer().getConfiguration().getDebug().DEBUG_SYSTEM_BUNDLE) {
       Debug.println(
           "Initializing framework with framework listeners: " + listeners); // $NON-NLS-1$
     }
     initListeners.addAll(Arrays.asList(listeners));
   } else {
     if (getEquinoxContainer().getConfiguration().getDebug().DEBUG_SYSTEM_BUNDLE) {
       Debug.println("Initializing framework with framework no listeners"); // $NON-NLS-1$
     }
   }
   try {
     ((SystemModule) getModule()).init();
   } finally {
     if (!initListeners.isEmpty()) {
       getEquinoxContainer().getEventPublisher().flushFrameworkEvents();
       removeInitListeners();
     }
   }
 }
  private List<String> getNativePaths() {
    ModuleRevision revision = generation.getRevision();
    ModuleWiring wiring = revision.getWiring();
    if (wiring == null) {
      // unresolved?  should not be possible
      return Collections.emptyList();
    }
    if ((revision.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
      List<ModuleWire> hosts = wiring.getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
      if (hosts == null) {
        // unresolved or invalid?  should not be possible
        return Collections.emptyList();
      }
      if (!hosts.isEmpty()) {
        // just use the first host wiring
        wiring = hosts.get(0).getProviderWiring();
      }
    }

    List<ModuleWire> nativeCode = wiring.getRequiredModuleWires(NativeNamespace.NATIVE_NAMESPACE);
    if (nativeCode.isEmpty()) {
      return Collections.emptyList();
    }

    // just taking the first paths for the revision, we sorted correctly when transforming to the
    // requirement
    for (ModuleWire moduleWire : nativeCode) {
      if (moduleWire.getRequirement().getRevision().equals(revision)) {
        @SuppressWarnings("unchecked")
        List<String> result =
            (List<String>)
                nativeCode
                    .get(0)
                    .getRequirement()
                    .getAttributes()
                    .get(REQUIREMENT_NATIVE_PATHS_ATTRIBUTE);
        if (result != null) return result;
        // this must be a multi-clause Bundle-NativeCode header, need to check for the correct one
        // in the index
        try {
          FilterImpl filter =
              FilterImpl.newInstance(
                  moduleWire
                      .getRequirement()
                      .getDirectives()
                      .get(NativeNamespace.REQUIREMENT_FILTER_DIRECTIVE));
          int index = -1;
          Map<String, Object> capabilityAttrs = moduleWire.getCapability().getAttributes();
          for (FilterImpl child : filter.getChildren()) {
            index++;
            if (child.matches(capabilityAttrs)) {
              break;
            }
          }
          if (index != -1) {
            @SuppressWarnings("unchecked")
            List<String> indexResult =
                (List<String>)
                    nativeCode
                        .get(0)
                        .getRequirement()
                        .getAttributes()
                        .get(REQUIREMENT_NATIVE_PATHS_ATTRIBUTE + '.' + index);
            if (indexResult != null) return indexResult;
          }
        } catch (InvalidSyntaxException e) {
          throw new RuntimeException(e);
        }
      }
    }
    return Collections.emptyList();
  }