本文整理汇总了Java中gnu.classpath.VMStackWalker.getClassContext方法的典型用法代码示例。如果您正苦于以下问题:Java VMStackWalker.getClassContext方法的具体用法?Java VMStackWalker.getClassContext怎么用?Java VMStackWalker.getClassContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnu.classpath.VMStackWalker
的用法示例。
在下文中一共展示了VMStackWalker.getClassContext方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClassContext
import gnu.classpath.VMStackWalker; //导入方法依赖的package包/类
/**
* Get a list of all the classes currently executing methods on the Java
* stack. getClassContext()[0] is the currently executing method (ie. the
* class that CALLED getClassContext, not SecurityManager).
*
* @return an array of classes on the Java execution stack
*/
protected Class[] getClassContext()
{
Class[] stack1 = VMStackWalker.getClassContext();
Class[] stack2 = new Class[stack1.length - 1];
System.arraycopy(stack1, 1, stack2, 0, stack1.length - 1);
return stack2;
}
示例2: forName
import gnu.classpath.VMStackWalker; //导入方法依赖的package包/类
/**
* Load the class with the given name. This method tries to use the context
* class loader first. If this fails, it searches for the suitable class
* loader in the caller stack trace. This method is a central point where all
* requests to find a class by name are delegated.
*/
static Class forName(String className)
{
try
{
return Class.forName(className, true,
Thread.currentThread().getContextClassLoader());
}
catch (ClassNotFoundException nex)
{
/**
* Returns the first user defined class loader on the call stack, or
* null when no non-null class loader was found.
*/
Class[] ctx = VMStackWalker.getClassContext();
for (int i = 0; i < ctx.length; i++)
{
// Since we live in a class loaded by the bootstrap
// class loader, getClassLoader is safe to call without
// needing to be wrapped in a privileged action.
ClassLoader cl = ctx[i].getClassLoader();
try
{
if (cl != null)
return Class.forName(className, true, cl);
}
catch (ClassNotFoundException nex2)
{
// Try next.
}
}
}
return null;
}
示例3: forName
import gnu.classpath.VMStackWalker; //导入方法依赖的package包/类
/**
* Load the class with the given name. This method tries to use the context
* class loader first. If this fails, it searches for the suitable class
* loader in the caller stack trace. This method is a central point where all
* requests to find a class by name are delegated.
*/
public static Class forName(String className) throws ClassNotFoundException
{
try
{
return Class.forName(className, true,
Thread.currentThread().getContextClassLoader());
}
catch (ClassNotFoundException nex)
{
/**
* Returns the first user defined class loader on the call stack, or
* null when no non-null class loader was found.
*/
Class[] ctx = VMStackWalker.getClassContext();
for (int i = 0; i < ctx.length; i++)
{
// Since we live in a class loaded by the bootstrap
// class loader, getClassLoader is safe to call without
// needing to be wrapped in a privileged action.
ClassLoader cl = ctx[i].getClassLoader();
try
{
if (cl != null)
return Class.forName(className, true, cl);
}
catch (ClassNotFoundException nex2)
{
// Try next.
}
}
}
throw new ClassNotFoundException(className);
}
示例4: getCallerClass
import gnu.classpath.VMStackWalker; //导入方法依赖的package包/类
/**
* A stack-walking wrapper method used by the JSR 166 RI.
*/
public static Class getCallerClass(int depth)
{
return VMStackWalker.getClassContext()[depth];
}
示例5: getCallerClass
import gnu.classpath.VMStackWalker; //导入方法依赖的package包/类
/**
* A stack-walking wrapper method used by the JSR 166 RI.
*/
public static Class getCallerClass(int depth)
{
return VMStackWalker.getClassContext()[depth];
}
示例6: callerClassLoader
import gnu.classpath.VMStackWalker; //导入方法依赖的package包/类
/**
* This method must be included, as it is used by System.load(),
* System.loadLibrary(). The reference implementation of this method uses
* the getStackClassLoader() method. Returns the ClassLoader of the method
* that called the caller. i.e. A.x() calls B.y() calls callerClassLoader(),
* A's ClassLoader will be returned. Returns null for the bootstrap
* ClassLoader.
*
* @return a ClassLoader or null for the bootstrap ClassLoader
*/
static ClassLoader callerClassLoader() {
Class[] classes = VMStackWalker.getClassContext();
return classes[2].getClassLoader();
}