public static ClassLoader createChain(List<ClassLoader> classLoaders, Boolean createNew)
  {
    List<ClassLoader> list = new ArrayList<ClassLoader>(classLoaders.size());

    for(ClassLoader classLoader : classLoaders)
    {
      // we skip null class loaders
      if(classLoader == null)
        continue;

      // we skip null class loaders
      if(classLoader instanceof NullClassLoader)
        continue;

      // we 'flatten' the chain... no need to have a chain of a chain...
      if(classLoader instanceof ClassLoaderChain)
      {
        ClassLoaderChain classLoaderChain = (ClassLoaderChain) classLoader;
        list.addAll(classLoaderChain._classLoaders);
      }
      else
      {
        list.add(classLoader);
      }
    }

    if(list.size() == 0)
      return NullClassLoader.instance();

    // remove duplicates
    ClassLoader previous = null;
    Iterator<ClassLoader> iter = list.iterator();
    while(iter.hasNext())
    {
      ClassLoader next = iter.next();

      if(next.equals(previous))
        iter.remove();

      previous = next;
    }

    //TODO: create a new entry point, and keeping old behavior unchanged. 
    if(list.size() == 1 && !createNew)
      return list.get(0);

    return new ClassLoaderChain(list);
  }
public static ClassLoader createChain(List<ClassLoader> classLoaders, Boolean createNew)
  {
    List<ClassLoader> list = new ArrayList<ClassLoader>(classLoaders.size());

    for(ClassLoader classLoader : classLoaders)
    {
      
      if(classLoader == null)
        continue;

      
      if(classLoader instanceof NullClassLoader)
        continue;

      
      if(classLoader instanceof ClassLoaderChain)
      {
        ClassLoaderChain classLoaderChain = (ClassLoaderChain) classLoader;
        list.addAll(classLoaderChain._classLoaders);
      }
      else
      {
        list.add(classLoader);
      }
    }

    if(list.size() == 0)
      return NullClassLoader.instance();

    
    ClassLoader previous = null;
    Iterator<ClassLoader> iter = list.iterator();
    while(iter.hasNext())
    {
      ClassLoader next = iter.next();

      if(next.equals(previous))
        iter.remove();

      previous = next;
    }

    
    if(list.size() == 1 && !createNew)
      return list.get(0);

    return new ClassLoaderChain(list);
  }
public static ClassLoader createChain ( List < ClassLoader > classLoaders , Boolean createNew ) { List < ClassLoader > list = new ArrayList < ClassLoader > ( classLoaders . size ( ) ) ; for ( ClassLoader classLoader : classLoaders ) { // we skip null class loaders if ( classLoader == null ) continue ; // we skip null class loaders if ( classLoader instanceof NullClassLoader ) continue ; // we 'flatten' the chain... no need to have a chain of a chain... if ( classLoader instanceof ClassLoaderChain ) { ClassLoaderChain classLoaderChain = ( ClassLoaderChain ) classLoader ; list . addAll ( classLoaderChain . _classLoaders ) ; } else { list . add ( classLoader ) ; } } if ( list . size ( ) == 0 ) return NullClassLoader . instance ( ) ; // remove duplicates ClassLoader previous = null ; Iterator < ClassLoader > iter = list . iterator ( ) ; while ( iter . hasNext ( ) ) { ClassLoader next = iter . next ( ) ; if ( next . equals ( previous ) ) iter . remove ( ) ; previous = next ; } //TODO: create a new entry point, and keeping old behavior unchanged.  if ( list . size ( ) == 1 && ! createNew ) return list . get ( 0 ) ; return new ClassLoaderChain ( list ) ; }
Creates a chain of class loaders. Handles <code>null</code> properly.
@param classLoaders
@param createNew whether to create new instance of classloaderchain even if there is only one loader
@return a class loader (never <code>null</code>)
Creates a chain of class loaders . Handles <code > null< / code > properly .