本文整理汇总了Java中java.rmi.server.RMIClassLoader类的典型用法代码示例。如果您正苦于以下问题:Java RMIClassLoader类的具体用法?Java RMIClassLoader怎么用?Java RMIClassLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RMIClassLoader类属于java.rmi.server包,在下文中一共展示了RMIClassLoader类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveProxyClass
import java.rmi.server.RMIClassLoader; //导入依赖的package包/类
/**
* resolveProxyClass is extended to acquire (if present) the location
* to determine the class loader to define the proxy class in.
*/
protected Class<?> resolveProxyClass(String[] interfaces)
throws IOException, ClassNotFoundException
{
/*
* Always read annotation written by MarshalOutputStream.
*/
Object annotation = readLocation();
ClassLoader defaultLoader =
skipDefaultResolveClass ? null : latestUserDefinedLoader();
String codebase = null;
if (!useCodebaseOnly && annotation instanceof String) {
codebase = (String) annotation;
}
return RMIClassLoader.loadProxyClass(codebase, interfaces,
defaultLoader);
}
示例2: resolveProxyClass
import java.rmi.server.RMIClassLoader; //导入依赖的package包/类
/**
* resolveProxyClass is extended to acquire (if present) the location
* to determine the class loader to define the proxy class in.
*/
protected Class<?> resolveProxyClass(String[] interfaces)
throws IOException, ClassNotFoundException
{
StreamChecker checker = streamChecker;
if (checker != null) {
checker.checkProxyInterfaceNames(interfaces);
}
/*
* Always read annotation written by MarshalOutputStream.
*/
Object annotation = readLocation();
ClassLoader defaultLoader =
skipDefaultResolveClass ? null : latestUserDefinedLoader();
String codebase = null;
if (!useCodebaseOnly && annotation instanceof String) {
codebase = (String) annotation;
}
return RMIClassLoader.loadProxyClass(codebase, interfaces,
defaultLoader);
}
示例3: loadClass
import java.rmi.server.RMIClassLoader; //导入依赖的package包/类
/**
* Load the class. The method uses class loaders from the call stact first. If
* this fails, the further behaviour depends on the System Property
* "java.rmi.server.useCodebaseOnly" with default value "false".
*
* <ul>
* <li>Try the current thread context class loader first.</li>
* <li>If remoteCodebase is non-null and useCodebaseOnly is "false" then call
* java.rmi.server.RMIClassLoader.loadClass (remoteCodebase, className)</li>
* <li> If remoteCodebase is null or useCodebaseOnly is true then call
* java.rmi.server.RMIClassLoader.loadClass(className)</li>
* <li>If a class is still not successfully loaded and the loader != null
* then try Class.forName(className, false, loader). </li>
* </ul>
*
* @param className the name of the class.
* @param remoteCodebase the codebase.
* @param loader the class loader.
* @return the loaded class.
*
* @throws ClassNotFoundException of the class cannot be loaded.
*/
public Class loadClass(String className, String remoteCodebase,
ClassLoader loader)
throws ClassNotFoundException
{
if (loader == null)
loader = VMStackWalker.firstNonNullClassLoader();
String p_useCodebaseOnly = System.getProperty("java.rmi.server.useCodebaseOnly");
boolean useCodebaseOnly = p_useCodebaseOnly != null
&& p_useCodebaseOnly.trim().equalsIgnoreCase("true");
if (useCodebaseOnly)
remoteCodebase = null;
try
{
return RMIClassLoader.loadClass(remoteCodebase, className, loader);
}
catch (MalformedURLException x)
{
throw new ClassNotFoundException(className, x);
}
}
示例4: loadClass
import java.rmi.server.RMIClassLoader; //导入依赖的package包/类
/**
* Load the class. The method uses class loaders from the call stact first. If
* this fails, the further behaviour depends on the System Property
* "java.rmi.server.useCodebaseOnly" with default value "false".
*
* <ul>
* <li>Try the current thread context class loader first.</li>
* <li>If remoteCodebase is non-null and useCodebaseOnly is "false" then call
* java.rmi.server.RMIClassLoader.loadClass (remoteCodebase, className)</li>
* <li> If remoteCodebase is null or useCodebaseOnly is true then call
* java.rmi.server.RMIClassLoader.loadClass(className)</li>
* <li>If a class is still not successfully loaded and the loader != null
* then try Class.forName(className, false, loader). </li>
* </ul>
*
* @param className the name of the class.
* @param remoteCodebase the codebase.
* @param loader the class loader.
* @return the loaded class.
*
* @throws ClassNotFoundException of the class cannot be loaded.
*/
public Class loadClass(String className, String remoteCodebase,
ClassLoader loader)
throws ClassNotFoundException
{
if (loader == null)
loader = VMStackWalker.firstNonNullClassLoader();
String p_useCodebaseOnly = System.getProperty("java.rmi.server.useCodebaseOnly");
boolean useCodebaseOnly = p_useCodebaseOnly != null
&& p_useCodebaseOnly.trim().equalsIgnoreCase("true");
if (useCodebaseOnly)
remoteCodebase = null;
try
{
return RMIClassLoader.loadClass(remoteCodebase, className, loader);
}
catch (MalformedURLException x)
{
throw new ClassNotFoundException(className, x);
}
}
示例5: resolveProxyClass
import java.rmi.server.RMIClassLoader; //导入依赖的package包/类
/**
* resolveProxyClass is extended to acquire (if present) the location
* to determine the class loader to define the proxy class in.
*/
protected Class resolveProxyClass(String[] interfaces)
throws IOException, ClassNotFoundException
{
/*
* Always read annotation written by MarshalOutputStream.
*/
Object annotation = readLocation();
ClassLoader defaultLoader =
skipDefaultResolveClass ? null : latestUserDefinedLoader();
String codebase = null;
if (!useCodebaseOnly && annotation instanceof String) {
codebase = (String) annotation;
}
return RMIClassLoader.loadProxyClass(codebase, interfaces,
defaultLoader);
}
示例6: getStub
import java.rmi.server.RMIClassLoader; //导入依赖的package包/类
/**
* Returns the Remote Stub for the given activatable class.
*/
public static RemoteStub getStub(ActivationDesc desc, ActivationID aid)
throws StubNotFoundException {
String cn = desc.getClassName();
String stubName = ""; //$NON-NLS-1$
try {
Class cl = RMIClassLoader.loadClass(desc.getLocation(), cn);
Class rcl = RMIUtil.getRemoteClass(cl);
stubName = rcl.getName() + "_Stub"; //$NON-NLS-1$
Class stubClass = RMIClassLoader.loadClass((String) null, stubName);
Constructor constructor = stubClass.getConstructor(new Class[] { RemoteRef.class });
RemoteStub stub = (RemoteStub) constructor.newInstance(new Object[] {
new ActivatableRef(aid, null)
});
return stub;
} catch (Exception ex) {
// rmi.68=Stub {0} not found.
throw new StubNotFoundException(Messages.getString("rmi.68", stubName), //$NON-NLS-1$ //$NON-NLS-2$
ex);
}
}
示例7: resolveClass
import java.rmi.server.RMIClassLoader; //导入依赖的package包/类
/**
* Returns the Class that corresponds to the desc argument.
*
* @param desc
* the descriptor of the needed Class
* @return the Class for the desc descriptor
*/
@SuppressWarnings("deprecation")
@Override
protected Class<?> resolveClass(ObjectStreamClass desc)
throws IOException, ClassNotFoundException {
Class<?> ret = null;
Object obj = this.readObject();
try {
ret = Class.forName(desc.getName(), true, Thread.currentThread()
.getContextClassLoader());
} catch (ClassNotFoundException e) {
if ((obj != null && obj instanceof String) && (!useCodebaseOnly)) {
ret = RMIClassLoader.loadClass((String) obj, desc.getName());
} else {
ret = RMIClassLoader.loadClass(desc.getName());
}
}
return ret;
}
示例8: LoadClassStringString
import java.rmi.server.RMIClassLoader; //导入依赖的package包/类
private void LoadClassStringString(String clase, boolean url) {
SecurityManager smOld = System.getSecurityManager();
System.setSecurityManager(new RMISecurityManager() {
public void checkPermission(Permission perm) {
}
});
try {
if (url) {
RMIClassLoader.loadClass(new URL("file://" + pathOwnClass),
clase);
} else {
RMIClassLoader.loadClass("file://" + pathOwnClass, clase);
}
} catch (Throwable e) {
fail("Failed with: " + e);
} finally {
System.setSecurityManager(smOld);
}
}
示例9: testLoadClassStringStringClassLoader006
import java.rmi.server.RMIClassLoader; //导入依赖的package包/类
public final void testLoadClassStringStringClassLoader006() {
SecurityManager smOld = System.getSecurityManager();
System.setSecurityManager(new RMISecurityManager() {
public void checkPermission(Permission perm) {
}
});
try {
RMIClassLoader
.loadClass(
"file://" + pathOwnClass,
"ar.org.fitc.test.rmi.server.testclasses.LoaderClassTest001",
null);
} catch (Throwable e) {
fail("Should not raise an exception but raised: " + e);
} finally {
System.setSecurityManager(smOld);
}
}
示例10: testLoadClassCodebaseOrder5
import java.rmi.server.RMIClassLoader; //导入依赖的package包/类
/**
* Modify the above method to test loadClass, loadClass(String, String) for
* coverage.
*/
public void testLoadClassCodebaseOrder5() throws Exception {
SecurityManager previous = System.getSecurityManager();
System.setSecurityManager(new SecurityManager() {
@Override
public void checkPermission(Permission perm) {
/*
* Override checkPermission to allow everything. Specifically,
* we want to allow the SecurityManager to be set to null at the
* end of the test and we want to allow the 'testClass.jar' file
* to be allowed to load.
*/
return;
}
});
try {
Class<?> c = RMIClassLoader.loadClass("TestClass");
fail();
} catch (ClassNotFoundException e) {
// expected
} finally {
// reset the security manager back to null state
System.setSecurityManager(previous);
}
}
示例11: resolveFallbackIfPossible
import java.rmi.server.RMIClassLoader; //导入依赖的package包/类
@Override
protected Class<?> resolveFallbackIfPossible(String className, ClassNotFoundException ex)
throws IOException, ClassNotFoundException {
// If codebaseUrl is set, try to load the class with the RMIClassLoader.
// Else, propagate the ClassNotFoundException.
if (this.codebaseUrl == null) {
throw ex;
}
return RMIClassLoader.loadClass(this.codebaseUrl, className);
}
示例12: run
import java.rmi.server.RMIClassLoader; //导入依赖的package包/类
/**
* Repeatedly load a class not found in classpath through RMIClassLoader.
* Arguments: <# reps>
*/
public long run(String[] args) throws Exception {
int reps = Integer.parseInt(args[0]);
CodeSource csrc = getClass().getProtectionDomain().getCodeSource();
String url = "jar:" + csrc.getLocation().toString() + ALTROOT;
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++)
RMIClassLoader.loadClass(url, CLASSNAME);
long time = System.currentTimeMillis() - start;
return time;
}
示例13: main
import java.rmi.server.RMIClassLoader; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
ServiceConfiguration.installServiceConfigurationFile();
System.setProperty(
"java.rmi.server.RMIClassLoaderSpi", "default");
String classname = "Foo";
URL codebaseURL = null;
try {
codebaseURL = TestLibrary.installClassInCodebase(
classname, "remote_codebase");
} catch (MalformedURLException e) {
TestLibrary.bomb(e);
}
TestLibrary.suggestSecurityManager(null);
Class fooClass = RMIClassLoader.loadClass(codebaseURL, classname);
if (!fooClass.getName().equals(classname)) {
throw new RuntimeException(
"wrong class name, expected: " + classname +
", received: " + fooClass.getName());
}
String annotation = RMIClassLoader.getClassAnnotation(fooClass);
if (!annotation.equals(codebaseURL.toString())) {
throw new RuntimeException(
"wrong class annotation, expected: " + codebaseURL.toString() +
", received: " + annotation);
}
System.err.println("TEST PASSED");
}
示例14: checkLoad
import java.rmi.server.RMIClassLoader; //导入依赖的package包/类
public void checkLoad(Proxy proxy, ClassLoader expectedLoader) {
ClassLoader proxyLoader = proxy.getClass().getClassLoader();
String proxyAnnotation =
RMIClassLoader.getClassAnnotation(proxy.getClass());
if ((proxyAnnotation == null) ||
!proxyAnnotation.equals(publicUrl.toString()))
{
TestLibrary.bomb("proxy class had incorrect annotation: " +
proxyAnnotation);
} else {
System.err.println("proxy class had correct annotation: " +
proxyAnnotation);
}
boolean proxyOk = false;
if (boomerangSemantics) {
ClassLoader ctxLoader =
Thread.currentThread().getContextClassLoader();
if (proxyLoader == ctxLoader) {
proxyOk = true;
}
} else if (proxyLoader.getClass().
getName().indexOf("sun.rmi") >= 0)
{
proxyOk = true;
}
if (proxyOk) {
System.err.println("\ncase5: proxy loaded from" +
" correct loader: " + proxyLoader);
} else {
TestLibrary.bomb("case5: proxy interface loaded from " +
"incorrect loader: " + proxyLoader);
}
}