1/*
2 * Copyright (c) 2001, 2004, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 *
26 */
27
28import java.net.MalformedURLException;
29import java.net.URL;
30import java.net.URLClassLoader;
31import java.util.ArrayList;
32import java.util.Collections;
33import java.util.List;
34
35import java.rmi.server.RMIClassLoader;
36import java.rmi.server.RMIClassLoaderSpi;
37
38/**
39 * TestProvider2 extends TestProvider with very similar behavior, but
40 * with its own static fields, to allow a test to distinguish between
41 * an installed TestProvider2 being used, or a property-specified
42 * TestProvider being used.
43 */
44public class TestProvider2 extends TestProvider {
45
46    public static final Class loadClassReturn =
47        (new Object() { }).getClass();
48    public static final Class loadProxyClassReturn =
49        (new Object() { }).getClass();
50    public static final ClassLoader getClassLoaderReturn =
51        URLClassLoader.newInstance(new URL[0]);
52    public static final String getClassAnnotationReturn = new String();
53
54    public static List invocations =
55        Collections.synchronizedList(new ArrayList(1));
56
57    public TestProvider2() {
58        System.err.println("TestProvider2()");
59    }
60
61    public Class loadClass(String codebase, String name,
62                           ClassLoader defaultLoader)
63        throws MalformedURLException, ClassNotFoundException
64    {
65        invocations.add(new Invocation(loadClassMethod,
66            new Object[] { codebase, name, defaultLoader }));
67
68        return loadClassReturn;
69    }
70
71    public Class loadProxyClass(String codebase, String[] interfaces,
72                                ClassLoader defaultLoader)
73        throws MalformedURLException, ClassNotFoundException
74    {
75        invocations.add(new Invocation(loadProxyClassMethod,
76            new Object[] { codebase, interfaces, defaultLoader }));
77
78        return loadProxyClassReturn;
79    }
80
81    public ClassLoader getClassLoader(String codebase)
82        throws MalformedURLException
83    {
84        invocations.add(new Invocation(
85            getClassLoaderMethod, new Object[] { codebase }));
86
87        return getClassLoaderReturn;
88    }
89
90    public String getClassAnnotation(Class<?> cl) {
91        invocations.add(new Invocation(
92            getClassAnnotationMethod, new Object[] { cl }));
93
94        return getClassAnnotationReturn;
95    }
96}
97