blob: 49955d4e95e5569f4fad3f21e74a69eedf4c4fd2 [file] [log] [blame]
Vladimir Markoc5798bf2016-12-09 10:20:54 +00001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17public class DelegatingLoader extends DefiningLoader {
18 private DefiningLoader defining_loader;
19
20 public DelegatingLoader(ClassLoader parent, DefiningLoader defining_loader) {
21 super(parent);
22 this.defining_loader = defining_loader;
23 }
24
25 public void resetDefiningLoader(DefiningLoader defining_loader) {
26 this.defining_loader = defining_loader;
27 }
28
29 protected Class<?> findClass(String name) throws ClassNotFoundException
30 {
31 if (name.equals("Test")) {
32 throw new Error("Unexpected DelegatingLoader.findClass(\"Test\")");
33 }
34 return super.findClass(name);
35 }
36
37 protected Class<?> loadClass(String name, boolean resolve)
38 throws ClassNotFoundException
39 {
40 if (name.equals("Test")) {
41 return defining_loader.loadClass(name, resolve);
42 }
43 return super.loadClass(name, resolve);
44 }
45}