/**
   * @see org.glassfish.internal.api.ClassLoaderHierarchy#getAppLibClassLoader(String, List<URI>)
   */
  public ClassLoader getAppLibClassLoader(String application, List<URI> libURIs)
      throws MalformedURLException {

    ClassLoaderHierarchy clh = habitat.getService(ClassLoaderHierarchy.class);
    DelegatingClassLoader connectorCL = clh.getConnectorClassLoader(application);

    if (libURIs == null || libURIs.isEmpty()) {
      // Optimization: when there are no libraries, why create an empty
      // class loader in the hierarchy? Instead return the parent.
      return connectorCL;
    }

    final ClassLoader commonCL = commonCLS.getCommonClassLoader();
    DelegatingClassLoader applibCL =
        AccessController.doPrivileged(
            new PrivilegedAction<DelegatingClassLoader>() {
              public DelegatingClassLoader run() {
                return new DelegatingClassLoader(commonCL);
              }
            });

    // order of classfinders is important here :
    // connector's classfinders should be added before libraries' classfinders
    // as the delegation hierarchy is appCL->app-libsCL->connectorCL->commonCL->API-CL
    // since we are merging connector and applib classfinders to be at same level,
    // connector classfinders need to be be before applib classfinders in the horizontal
    // search path
    for (DelegatingClassLoader.ClassFinder cf : connectorCL.getDelegates()) {
      applibCL.addDelegate(cf);
    }
    addDelegates(libURIs, applibCL);

    return applibCL;
  }
Example #2
0
  // This is not mandated by the spec. It is for WSIT.
  // We will also scan any servlets/filters/listeners classes specified
  // in web.xml additionally if those classes are not resided in the wars.
  private void scanXmlDefinedClassesIfNecessary(WebBundleDescriptor webBundleDesc)
      throws IOException {

    ClassLoader commonCL = clh.getCommonClassLoader();

    for (Iterator webComponents = webBundleDesc.getWebComponentDescriptors().iterator();
        webComponents.hasNext(); ) {
      WebComponentDescriptor webCompDesc = (WebComponentDescriptor) webComponents.next();
      if (webCompDesc.isServlet()) {
        String servletName = webCompDesc.getWebComponentImplementation();
        if (isScan(servletName, commonCL)) {
          addScanClassName(servletName);
        }
      }
    }

    Vector servletFilters = webBundleDesc.getServletFilters();
    for (int i = 0; i < servletFilters.size(); i++) {
      ServletFilter filter = (ServletFilter) servletFilters.elementAt(i);
      String filterName = filter.getClassName();
      if (isScan(filterName, commonCL)) {
        addScanClassName(filter.getClassName());
      }
    }

    Vector listeners = webBundleDesc.getAppListenerDescriptors();
    for (int j = 0; j < listeners.size(); j++) {
      AppListenerDescriptor listenerDesc = (AppListenerDescriptor) listeners.elementAt(j);
      String listenerName = listenerDesc.getListener();
      if (isScan(listenerName, commonCL)) {
        addScanClassName(listenerDesc.getListener());
      }
    }
  }