/** * Returns the root delegate object that is not a {@link Delegator} in the delegation chain * that is assignable to the given type. */ @SuppressWarnings("unchecked") public static <T, V> V getDelegate(T object, Class<V> type) { Object result = object; // Keep searching while the result is still instance of Delegator while (result != null && result instanceof Delegator) { result = ((Delegator<T>) result).getDelegate(); // Terminate the search if result is not a Delegator and assignable to the given type if (result != null && !(result instanceof Delegator) && type.isAssignableFrom(result.getClass())) { break; } } if (result == null || !type.isAssignableFrom(result.getClass())) { throw new IllegalArgumentException("No object in the delegation chain is of type " + type); } return (V) result; }
/** * Returns the root delegate object that is not a {@link Delegator} in the delegation chain * that is assignable to the given type. */ @SuppressWarnings("unchecked") public static <T, V> V getDelegate(T object, Class<V> type) { Object result = object; // Keep searching while the result is still instance of Delegator while (result != null && result instanceof Delegator) { result = ((Delegator<T>) result).getDelegate(); // Terminate the search if result is not a Delegator and assignable to the given type if (result != null && !(result instanceof Delegator) && type.isAssignableFrom(result.getClass())) { break; } } if (result == null || !type.isAssignableFrom(result.getClass())) { throw new IllegalArgumentException("No object in the delegation chain is of type " + type); } return (V) result; }
/** * Finds a ClassLoader along the ClassLoader hierarchy that the ClassLoader class matches the given name. * This method recognize usage of {@link Delegator} on ClassLoader and will try to match with * the object returned by {@link Delegator#getDelegate()} for the ClassLoader of the given type. * * @return the ClassLoader found or {@code null} if no such ClassLoader exists. */ @Nullable public static ClassLoader findByName(@Nullable ClassLoader classLoader, String classLoaderName) { ClassLoader result = classLoader; while (result != null) { if (result instanceof Delegator) { Object delegate = ((Delegator) result).getDelegate(); if (delegate != null && delegate instanceof ClassLoader) { result = (ClassLoader) delegate; } } if (result.getClass().getName().equals(classLoaderName)) { break; } result = result.getParent(); } return result; }
/** * Finds a ClassLoader along the ClassLoader hierarchy that the ClassLoader class matches the given name. * This method recognize usage of {@link Delegator} on ClassLoader and will try to match with * the object returned by {@link Delegator#getDelegate()} for the ClassLoader of the given type. * * @return the ClassLoader found or {@code null} if no such ClassLoader exists. */ @Nullable public static ClassLoader findByName(@Nullable ClassLoader classLoader, String classLoaderName) { ClassLoader result = classLoader; while (result != null) { if (result instanceof Delegator) { Object delegate = ((Delegator) result).getDelegate(); if (delegate != null && delegate instanceof ClassLoader) { result = (ClassLoader) delegate; } } if (result.getClass().getName().equals(classLoaderName)) { break; } result = result.getParent(); } return result; }
Object delegate = ((Delegator) cl).getDelegate(); if (delegate != null && delegate instanceof ClassLoader) {
Object delegate = ((Delegator) cl).getDelegate(); if (delegate != null && delegate instanceof ClassLoader) { queue.add((ClassLoader) delegate);
Object delegate = ((Delegator) cl).getDelegate(); if (delegate != null && delegate instanceof ClassLoader) { queue.add((ClassLoader) delegate);
Object delegate = ((Delegator) cl).getDelegate(); if (delegate != null && delegate instanceof ClassLoader) {