blob: 6b471d4b12cf3c87072e8a6d37dba35a15f7f67c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/*******************************************************************************
* Copyright (c) 2005, 2016 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.osgi.internal.loader.buddy;
import java.io.IOException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Enumeration;
import org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor;
public class SystemPolicy implements IBuddyPolicy {
public static final byte BOOT = 0;
public static final byte EXT = 1;
public static final byte APP = 2;
private static SystemPolicy[] instances = new SystemPolicy[3];
private ClassLoader classLoader;
public static SystemPolicy getInstance(final byte type) {
if (instances[type] == null) {
instances[type] = new SystemPolicy();
instances[type].classLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
@Override
public ClassLoader run() {
return createClassLoader(type);
}
});
}
return instances[type];
}
public SystemPolicy() {
//Nothing to do
}
public SystemPolicy(ClassLoader parent) {
classLoader = parent;
}
static ClassLoader createClassLoader(byte type) {
switch (type) {
case APP :
if (ClassLoader.getSystemClassLoader() != null)
return ClassLoader.getSystemClassLoader();
return EquinoxContainerAdaptor.BOOT_CLASSLOADER;
case BOOT :
return EquinoxContainerAdaptor.BOOT_CLASSLOADER;
case EXT :
if (ClassLoader.getSystemClassLoader() != null)
return ClassLoader.getSystemClassLoader().getParent();
return EquinoxContainerAdaptor.BOOT_CLASSLOADER;
}
return null;
}
@Override
public Class<?> loadClass(String name) {
try {
return classLoader.loadClass(name);
} catch (ClassNotFoundException e) {
return null;
}
}
@Override
public URL loadResource(String name) {
return classLoader.getResource(name);
}
@Override
public Enumeration<URL> loadResources(String name) {
try {
return classLoader.getResources(name);
} catch (IOException e) {
return null;
}
}
}
|