An implementation of narrow that always attempts to load stub classes
from the class loader before dynamically generating a stub class.
338732
@Override
    @FFDCIgnore(BAD_OPERATION.class)
    public Object narrow(Object narrowFrom, @SuppressWarnings("rawtypes") Class narrowTo) throws ClassCastException {
        if (narrowFrom == null) {
            return null;
        }

        if (narrowTo.isInstance(narrowFrom)) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                Tr.debug(tc, "object is already an instance");
            return narrowFrom;
        }

        if (!!!(narrowFrom instanceof ObjectImpl))
            throw new ClassCastException(narrowTo.getName());

        if (IDLEntity.class.isAssignableFrom(narrowTo))
            return super.narrow(narrowFrom, narrowTo);

        Class<?> stubClass = loadStubClass(narrowTo);
        if (stubClass == null) {
            // The stub class could not be loaded.  Fallback to the default
            // implementation to allow it to dynamically generate one.
            return super.narrow(narrowFrom, narrowTo);
        }

        Object stubObject;
        try {
            stubObject = stubClass.newInstance();
        } catch (Throwable t) {
            // This will fail if the stub class is "invalid" (missing default
            // constructor, non-public default constructor, logic in the
            // constructor that throws, etc.).
            ClassCastException e = new ClassCastException(narrowTo.getName());
            e.initCause(t);
            throw e;
        }

        // This will fail if the loaded class does not actually extend Stub.
        Stub stub = (Stub) stubObject;

        try {
            stub._set_delegate(((ObjectImpl) narrowFrom)._get_delegate());
        } catch (org.omg.CORBA.BAD_OPERATION e) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                Tr.debug(tc, "unable to copy delegate", e);
        }

        // This will fail if the loaded stub class does not implement the
        // interface. For example, narrow was called with one version of the
        // interface, but the context class loader loaded a stub that
        // implemented a different version of the interface.
        return narrowTo.cast(stub);
    }
253112
protected boolean narrowAccept(Class<?> narrow, Class<?> source) {
    return narrow == null || narrow.equals(source);
  }
1028377
private GroovyClassLoader initGroovyLoader() {
        return (GroovyClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                if (parentLoader instanceof GroovyClassLoader) {
                    return new ScriptClassLoader((GroovyClassLoader) parentLoader);
                } else {
                    return new ScriptClassLoader(parentLoader, config);
                }
            }
        });
    }
1205273
public void classLoaderInit(DynamicClassLoader loader)
  {
    EnvLoaderListener listener = _listenerRef.get();
    
    if (listener != null)
      listener.classLoaderInit(loader);
  }
1372284
def get_stub(source, generic=False):
    
    generator = StubGenerator(source, generic=generic)
    stub = generator.generate_stub()
    return stub
433209
def utils(opts, whitelist=None, context=None, proxy=proxy):
    '''
    
    '''
    return LazyLoader(
        _module_dirs(opts, 'utils', ext_type_dirs='utils_dirs'),
        opts,
        tag='utils',
        whitelist=whitelist,
        pack={'__context__': context, '__proxy__': proxy or {}},
    )
869854
def stub_with_erb(filename, hsh={})
      return if ::ServiceMock.disable_stubs
      yield self if block_given?
      template = File.open(filename, 'rb') { |file| file.read }
      erb_content = ERB.new(template).result(data_binding(hsh))
      stub(erb_content)
    end
437832
def create_dataclass_loader(cls, registry, field_getters):
    """"""
    fields = cls.__dataclass_fields__
    item_loaders = map(registry, map(attrgetter('type'), fields.values()))
    getters = map(field_getters.__getitem__, fields)
    loaders = list(starmap(compose, zip(item_loaders, getters)))

    def dloader(obj):
        return cls(*(g(obj) for g in loaders))

    return dloader
641665
private Map<PluginClassLoaderDef, ClassLoader> build(Collection<PluginClassLoaderDef> defs, ClassloaderBuilder builder) {
    Map<PluginClassLoaderDef, ClassLoader> result = new HashMap<>();
    Map<String, ClassLoader> classloadersByBasePluginKey = builder.build();
    for (PluginClassLoaderDef def : defs) {
      ClassLoader classloader = classloadersByBasePluginKey.get(def.getBasePluginKey());
      if (classloader == null) {
        throw new IllegalStateException(String.format("Fail to create classloader for plugin [%s]", def.getBasePluginKey()));
      }
      result.put(def, classloader);
    }
    return result;
  }
570874
private ClassLoader makeAggregatedClassLoader(ClassLoader globalClassLoader) {
      // use an ordered set to deduplicate them
      Set<ClassLoader> classLoaders = new LinkedHashSet<>(6);

      // add the cache manager's CL
      if (globalClassLoader != null) {
         classLoaders.add(globalClassLoader);
      }

      // add Infinispan's CL
      classLoaders.add(AggregatedClassLoader.class.getClassLoader());

      // add Hibernate Search's CL
      classLoaders.add(ClassLoaderService.class.getClassLoader());

      // add this module's CL
      classLoaders.add(getClass().getClassLoader());

      // add the TCCL
      try {
         ClassLoader tccl = Thread.currentThread().getContextClassLoader();
         if (tccl != null) {
            classLoaders.add(tccl);
         }
      } catch (Exception e) {
         // ignored
      }

      // add the system CL
      try {
         ClassLoader syscl = ClassLoader.getSystemClassLoader();
         if (syscl != null) {
            classLoaders.add(syscl);
         }

      } catch (Exception e) {
         // ignored
      }

      return new AggregatedClassLoader(classLoaders);
   }
120156
def stub(self, obj, attr=None):
        '''
        
        '''
        s = stub(obj, attr)
        if s not in self._stubs:
            self._stubs.append(s)
        return s
193872
static Class<?> findClassFromClassLoaders(final String className, final Iterable<ClassLoader> classLoaders)
        throws ClassNotFoundException, IllegalArgumentException {
        // Precondition checks
        assert className != null && className.length() > 0 : "Class Name must be specified";
        assert classLoaders != null : "ClassLoaders as search path must be specified";

        // Find the class by searching through the CLs in order
        Class<?> clazz = null;
        for (final ClassLoader cl : classLoaders) {
            try {
                clazz = Class.forName(className, false, cl);
                if (log.isLoggable(Level.FINER)) {
                    log.finer("Found requested class " + clazz.getName() + " from ClassLoader "
                        + clazz.getClassLoader());
                }
            } catch (final ClassNotFoundException cnfe) {
                // Ignore here, try the next
            }

        }
        // If we haven't got a class yet, now we need to show we've got CNFE
        if (clazz == null) {
            throw new ClassNotFoundException("Could not find requested class \"" + className
                + "\" in any of the associated ClassLoaders: " + classLoaders);
        }

        // Return
        return clazz;
    }
1172059
private static <T> Optional<T> loadFirst(final Class<T> service) {
        return of(ServiceLoader.load(service).iterator()).filter(Iterator::hasNext).map(Iterator::next);
    }
1099333
function buildCommonCompiler(name, deps, opts) {
    return deps.map(function (res) {
        var compiler = opts.browserify(R.mixin(cleanOpts(opts), {
            deps: depsStream(Rx.Observable.fromArray([].concat(res.externals, res.requires)).distinct(R.prop("id")))
        }));

        R.each(compiler.external.bind(compiler), R.uniq(R.pluck("id", res.externals)));
        R.each(compiler.require.bind(compiler), R.uniq(R.pluck("id", res.requires)));

        return { name: name, compiler: compiler };
    }).single();
}
589352
private Class<?> loadClass(final ClassLoader lastLoader, final String className) {
        // XXX: this is overly complicated
        Class<?> clazz;
        if (lastLoader != null) {
            try {
                clazz = lastLoader.loadClass(className);
                if (clazz != null) {
                    return clazz;
                }
            } catch (final Throwable ignore) {
                // Ignore exception.
            }
        }
        try {
            clazz = LoaderUtil.loadClass(className);
        } catch (final ClassNotFoundException | NoClassDefFoundError e) {
            return loadClass(className);
        } catch (final SecurityException e) {
            return null;
        }
        return clazz;
    }
146257
protected ClassLoader initClassLoader(String baseDirPath)
			throws MalformedURLException {
		File webAppClasses = new File(baseDirPath + WEB_INF_CLASSES_DIR_PATH);
		File[] webAppLibs = new File(baseDirPath + WEB_INF_LIB_DIR_PATH)
				.listFiles(new FilenameFilter() {
					public boolean accept(File dir, String name) {
						return name.endsWith(JAR_FILE_EXTENSION);
					}
				});

		int length = webAppLibs != null ? webAppLibs.length + 1 : 1;
		URL[] urls = new URL[length];

		urls[0] = webAppClasses.toURI().toURL();

		for (int i = 1; i < length; i++) {
			urls[i] = webAppLibs[i - 1].toURI().toURL();
		}

		ClassLoader webAppClassLoader = new JawrBundleProcessorCustomClassLoader(
				urls, getClass().getClassLoader());

		Thread.currentThread().setContextClassLoader(webAppClassLoader);
		return webAppClassLoader;
	}
116857
public static ClassResolver weakCachingConcurrentResolver(ClassLoader classLoader) {
        return new CachingClassResolver(
                new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
                new WeakReferenceMap<String, Class<?>>(
                        PlatformDependent.<String, Reference<Class<?>>>newConcurrentHashMap()));
    }