01: /*
02: * Copyright (C) 2005 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 07. March 2005 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.core.util;
13:
14: /**
15: * ClassLoader that refers to another ClassLoader, allowing a single instance to be passed around the codebase that
16: * can later have its destination changed.
17: *
18: * @author Joe Walnes
19: * @author Jörg Schaible
20: * @since 1.1.1
21: */
22: public class ClassLoaderReference extends ClassLoader {
23:
24: private transient ClassLoader reference;
25:
26: public ClassLoaderReference(ClassLoader reference) {
27: this .reference = reference;
28: }
29:
30: public Class loadClass(String name) throws ClassNotFoundException {
31: return reference.loadClass(name);
32: }
33:
34: public ClassLoader getReference() {
35: return reference;
36: }
37:
38: public void setReference(ClassLoader reference) {
39: this .reference = reference;
40: }
41:
42: private Object writeReplace() {
43: return new Replacement();
44: }
45:
46: static class Replacement {
47:
48: private Object readResolve() {
49: return new ClassLoaderReference(new CompositeClassLoader());
50: }
51:
52: };
53: }
|