6394N/A/*
6394N/A * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
6394N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6394N/A *
6394N/A * This code is free software; you can redistribute it and/or modify it
6394N/A * under the terms of the GNU General Public License version 2 only, as
6394N/A * published by the Free Software Foundation.
6394N/A *
6394N/A * This code is distributed in the hope that it will be useful, but WITHOUT
6394N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6394N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6394N/A * version 2 for more details (a copy is included in the LICENSE file that
6394N/A * accompanied this code).
6394N/A *
6394N/A * You should have received a copy of the GNU General Public License version
6394N/A * 2 along with this work; if not, write to the Free Software Foundation,
6394N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6394N/A *
6394N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6394N/A * or visit www.oracle.com if you need additional information or have any
6394N/A * questions.
6394N/A */
6394N/Aimport java.lang.reflect.InvocationTargetException;
6394N/Aimport java.lang.reflect.Method;
6394N/Aimport java.net.URL;
6394N/Aimport java.net.URLClassLoader;
6394N/A
6394N/A/**
6394N/A * This class is loaded by a class loader that can see the resource. It creates
6394N/A * a new classloader for LoadItUp2 which cannot see the resource. So, 2 levels
6394N/A * up the call chain we have a class/classloader that can see the resource, but
6394N/A * 1 level up the class/classloader cannot.
6394N/A *
6394N/A * @author Jim Gish
6394N/A */
6394N/Apublic class LoadItUp2Invoker {
6394N/A private URLClassLoader cl;
6394N/A private String rbName;
6394N/A private Object loadItUp2;
6394N/A private Method testMethod;
6394N/A
6394N/A public void setup(URL[] urls, String rbName) throws
6394N/A ReflectiveOperationException {
6394N/A this.cl = new URLClassLoader(urls, null);
6394N/A this.rbName = rbName;
6394N/A // Using this new classloader, load the actual test class
6394N/A // which is now two levels removed from the original caller
6394N/A Class<?> loadItUp2Clazz = Class.forName("LoadItUp2", true , cl);
6394N/A this.loadItUp2 = loadItUp2Clazz.newInstance();
6394N/A this.testMethod = loadItUp2Clazz.getMethod("test", String.class);
6394N/A }
6394N/A
6394N/A public Boolean test() throws Throwable {
6394N/A try {
6394N/A return (Boolean) testMethod.invoke(loadItUp2, rbName);
6394N/A } catch (InvocationTargetException ex) {
6394N/A throw ex.getTargetException();
6394N/A }
6394N/A }
6394N/A}