private ModuleClassLoader getModuleClassLoader(boolean logResolveError) {
   ResolutionReport report = resolve();
   if (logResolveError && !Module.RESOLVED_SET.contains(module.getState())) {
     String reportMessage = report.getResolutionReportMessage(module.getCurrentRevision());
     equinoxContainer
         .getEventPublisher()
         .publishFrameworkEvent(
             FrameworkEvent.ERROR,
             this,
             new BundleException(reportMessage, BundleException.RESOLVE_ERROR));
   }
   return AccessController.doPrivileged(
       new PrivilegedAction<ModuleClassLoader>() {
         @Override
         public ModuleClassLoader run() {
           ModuleWiring wiring = getModule().getCurrentRevision().getWiring();
           if (wiring != null) {
             ModuleLoader moduleLoader = wiring.getModuleLoader();
             if (moduleLoader instanceof BundleLoader) {
               return ((BundleLoader) moduleLoader).getModuleClassLoader();
             }
           }
           return null;
         }
       });
 }
 @Override
 public boolean hasPermission(Object permission) {
   Generation current = (Generation) module.getCurrentRevision().getRevisionInfo();
   ProtectionDomain domain = current.getDomain();
   if (domain != null) {
     if (permission instanceof Permission) {
       SecurityManager sm = System.getSecurityManager();
       if (sm instanceof EquinoxSecurityManager) {
         /*
          * If the FrameworkSecurityManager is active, we need to do checks the "right" way.
          * We can exploit our knowledge that the security context of FrameworkSecurityManager
          * is an AccessControlContext to invoke it properly with the ProtectionDomain.
          */
         AccessControlContext acc = new AccessControlContext(new ProtectionDomain[] {domain});
         try {
           sm.checkPermission((Permission) permission, acc);
           return true;
         } catch (Exception e) {
           return false;
         }
       }
       return domain.implies((Permission) permission);
     }
     return false;
   }
   return true;
 }
  @Override
  public URL getResource(String name) {
    try {
      equinoxContainer.checkAdminPermission(this, AdminPermission.RESOURCE);
    } catch (SecurityException e) {
      return null;
    }
    checkValid();
    if (isFragment()) {
      return null;
    }

    ModuleClassLoader classLoader = getModuleClassLoader(false);
    if (classLoader != null) {
      return classLoader.getResource(name);
    }

    return new ClasspathManager((Generation) module.getCurrentRevision().getRevisionInfo(), null)
        .findLocalResource(name);
  }
 @Override
 public Enumeration<URL> getResources(String name) throws IOException {
   try {
     equinoxContainer.checkAdminPermission(this, AdminPermission.RESOURCE);
   } catch (SecurityException e) {
     return null;
   }
   checkValid();
   if (isFragment()) {
     return null;
   }
   ModuleClassLoader classLoader = getModuleClassLoader(false);
   Enumeration<URL> result = null;
   if (classLoader != null) {
     result = classLoader.getResources(name);
   } else {
     result =
         new ClasspathManager((Generation) module.getCurrentRevision().getRevisionInfo(), null)
             .findLocalResources(name);
   }
   return result != null && result.hasMoreElements() ? result : null;
 }
 @Override
 public File getDataFile(String filename) {
   checkValid();
   Generation current = (Generation) module.getCurrentRevision().getRevisionInfo();
   return current.getBundleInfo().getDataFile(filename);
 }
  @SuppressWarnings("unchecked")
  private <A> A adapt0(Class<A> adapterType) {
    if (AccessControlContext.class.equals(adapterType)) {
      Generation current = (Generation) module.getCurrentRevision().getRevisionInfo();
      ProtectionDomain domain = current.getDomain();
      return (A)
          (domain == null ? null : new AccessControlContext(new ProtectionDomain[] {domain}));
    }

    if (BundleContext.class.equals(adapterType)) {
      try {
        return (A) getBundleContext();
      } catch (SecurityException e) {
        return null;
      }
    }

    if (BundleRevision.class.equals(adapterType)) {
      if (module.getState().equals(State.UNINSTALLED)) {
        return null;
      }
      return (A) module.getCurrentRevision();
    }

    if (BundleRevisions.class.equals(adapterType)) {
      return (A) module.getRevisions();
    }

    if (BundleStartLevel.class.equals(adapterType)) {
      return (A) module;
    }

    if (BundleWiring.class.equals(adapterType)) {
      if (module.getState().equals(State.UNINSTALLED)) {
        return null;
      }
      ModuleRevision revision = module.getCurrentRevision();
      if (revision == null) {
        return null;
      }
      return (A) revision.getWiring();
    }

    if (BundleDTO.class.equals(adapterType)) {
      // Unfortunately we need to lock here to make sure the BSN and version
      // are consistent in case of updates
      readLock();
      try {
        return (A) DTOBuilder.newBundleDTO(this);
      } finally {
        readUnlock();
      }
    }

    if (BundleStartLevelDTO.class.equals(adapterType)) {
      if (module.getState().equals(State.UNINSTALLED)) {
        return null;
      }
      return (A) DTOBuilder.newBundleStartLevelDTO(this, module);
    }

    if (BundleRevisionDTO.class.equals(adapterType)) {
      if (module.getState().equals(State.UNINSTALLED)) {
        return null;
      }
      return (A) DTOBuilder.newBundleRevisionDTO(module.getCurrentRevision());
    }

    if (BundleRevisionDTO[].class.equals(adapterType)) {
      if (module.getState().equals(State.UNINSTALLED)) {
        return null;
      }
      // No need to lock the database here since the ModuleRevisions object does the
      // proper locking for us.
      return (A) DTOBuilder.newArrayBundleRevisionDTO(module.getRevisions());
    }

    if (BundleWiringDTO.class.equals(adapterType)) {
      if (module.getState().equals(State.UNINSTALLED)) {
        return null;
      }
      readLock();
      try {
        return (A) DTOBuilder.newBundleWiringDTO(module.getCurrentRevision());
      } finally {
        readUnlock();
      }
    }

    if (BundleWiringDTO[].class.equals(adapterType)) {
      if (module.getState().equals(State.UNINSTALLED)) {
        return null;
      }
      readLock();
      try {
        return (A) DTOBuilder.newArrayBundleWiringDTO(module.getRevisions());
      } finally {
        readUnlock();
      }
    }

    if (ServiceReferenceDTO[].class.equals(adapterType)) {
      if (module.getState().equals(State.UNINSTALLED)) {
        return null;
      }
      BundleContextImpl current = getBundleContextImpl();
      ServiceReference<?>[] references =
          (current == null)
              ? null
              : equinoxContainer.getServiceRegistry().getRegisteredServices(current);
      return (A) DTOBuilder.newArrayServiceReferenceDTO(references);
    }

    if (getBundleId() == 0) {
      if (Framework.class.equals(adapterType)) {
        return (A) this;
      }

      if (FrameworkStartLevel.class.equals(adapterType)) {
        return (A) equinoxContainer.getStorage().getModuleContainer().getFrameworkStartLevel();
      }

      if (FrameworkWiring.class.equals(adapterType)) {
        return (A) equinoxContainer.getStorage().getModuleContainer().getFrameworkWiring();
      }

      if (FrameworkDTO.class.equals(adapterType)) {
        BundleContextImpl current = getBundleContextImpl();
        Map<String, String> configuration = equinoxContainer.getConfiguration().getConfiguration();
        readLock();
        try {
          return (A) DTOBuilder.newFrameworkDTO(current, configuration);
        } finally {
          readUnlock();
        }
      }

      if (FrameworkStartLevelDTO.class.equals(adapterType)) {
        return (A)
            DTOBuilder.newFrameworkStartLevelDTO(
                equinoxContainer.getStorage().getModuleContainer().getFrameworkStartLevel());
      }
    }

    // Equinox extras
    if (Module.class.equals(adapterType)) {
      return (A) module;
    }
    if (ProtectionDomain.class.equals(adapterType)) {
      Generation current = (Generation) module.getCurrentRevision().getRevisionInfo();
      return (A) current.getDomain();
    }
    return null;
  }
 @Override
 public Version getVersion() {
   return module.getCurrentRevision().getVersion();
 }
 @Override
 public String getSymbolicName() {
   return module.getCurrentRevision().getSymbolicName();
 }
 private Dictionary<String, String> privGetHeaders(String locale) {
   Generation current = (Generation) module.getCurrentRevision().getRevisionInfo();
   return current.getHeaders(locale);
 }