本文整理匯總了Java中java.security.ProtectionDomain.getClassLoader方法的典型用法代碼示例。如果您正苦於以下問題:Java ProtectionDomain.getClassLoader方法的具體用法?Java ProtectionDomain.getClassLoader怎麽用?Java ProtectionDomain.getClassLoader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.security.ProtectionDomain
的用法示例。
在下文中一共展示了ProtectionDomain.getClassLoader方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: cleanProtectionDomainWhichCameFromModuleClassLoader
import java.security.ProtectionDomain; //導入方法依賴的package包/類
/**
* 清理來自URLClassLoader.acc.ProtectionDomain[]中,來自上一個ModuleClassLoader的ProtectionDomain
* 這樣寫好蛋疼,而且還有不兼容的風險,從JDK6+都必須要這樣清理,但我找不出更好的辦法。
* 在重置沙箱時,遇到MgrModule模塊無法正確卸載類的情況,主要的原因是在於URLClassLoader.acc.ProtectionDomain[]中包含了上一個ModuleClassLoader的引用
* 所以必須要在這裏清理掉,否則隨著重置次數的增加,類會越累積越多
*/
private void cleanProtectionDomainWhichCameFromModuleClassLoader() {
// got ProtectionDomain[] from URLClassLoader's acc
final AccessControlContext acc = unCaughtGetClassDeclaredJavaFieldValue(URLClassLoader.class, "acc", this);
final ProtectionDomain[] protectionDomainArray = unCaughtInvokeMethod(
unCaughtGetClassDeclaredJavaMethod(AccessControlContext.class, "getContext"),
acc
);
// remove ProtectionDomain which loader is ModuleClassLoader
final Set<ProtectionDomain> cleanProtectionDomainSet = new LinkedHashSet<ProtectionDomain>();
if (ArrayUtils.isNotEmpty(protectionDomainArray)) {
for (final ProtectionDomain protectionDomain : protectionDomainArray) {
if (protectionDomain.getClassLoader() == null
|| !StringUtils.equals(ModuleClassLoader.class.getName(), protectionDomain.getClassLoader().getClass().getName())) {
cleanProtectionDomainSet.add(protectionDomain);
}
}
}
// rewrite acc
final AccessControlContext newAcc = new AccessControlContext(cleanProtectionDomainSet.toArray(new ProtectionDomain[]{}));
unCaughtSetClassDeclaredJavaFieldValue(URLClassLoader.class, "acc", this, newAcc);
}
示例2: loadJar
import java.security.ProtectionDomain; //導入方法依賴的package包/類
/**
* Loads specified JAR.
*
* @param jarFileInfo
* @throws IOException
*/
private void loadJar(JarFileInfo jarFileInfo) throws IOException {
lstJarFile.add(jarFileInfo);
try {
Enumeration<JarEntry> en = jarFileInfo.jarFile.entries();
final String EXT_JAR = ".jar";
while (en.hasMoreElements()) {
JarEntry je = en.nextElement();
if (je.isDirectory()) {
continue;
}
String s = je.getName().toLowerCase(); // JarEntry name
if (s.lastIndexOf(EXT_JAR) == s.length() - EXT_JAR.length()) {
JarEntryInfo inf = new JarEntryInfo(jarFileInfo, je);
File fileTemp = createTempFile(inf);
logInfo(LogArea.JAR, "Loading inner JAR %s from temp file %s",
inf.jarEntry, getFilename4Log(fileTemp));
// Construct ProtectionDomain for this inner JAR:
URL url = fileTemp.toURI().toURL();
ProtectionDomain pdParent = jarFileInfo.pd;
// 'csParent' is never null: top JAR has it, JCL creates it for child JAR:
CodeSource csParent = pdParent.getCodeSource();
Certificate[] certParent = csParent.getCertificates();
CodeSource csChild = (certParent == null ? new CodeSource(url, csParent.getCodeSigners())
: new CodeSource(url, certParent));
ProtectionDomain pdChild = new ProtectionDomain(csChild,
pdParent.getPermissions(), pdParent.getClassLoader(), pdParent.getPrincipals());
loadJar(new JarFileInfo(
new JarFile(fileTemp), inf.getName(), jarFileInfo, pdChild, fileTemp));
}
}
} catch (JarClassLoaderException e) {
throw new RuntimeException(
"ERROR on loading inner JAR: " + e.getMessageAll());
}
}