本文整理汇总了Java中org.apache.commons.lang3.ClassUtils.getAllInterfaces方法的典型用法代码示例。如果您正苦于以下问题:Java ClassUtils.getAllInterfaces方法的具体用法?Java ClassUtils.getAllInterfaces怎么用?Java ClassUtils.getAllInterfaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.ClassUtils
的用法示例。
在下文中一共展示了ClassUtils.getAllInterfaces方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAnnotatedPublicMethods
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
* 找出所有标注了该annotation的公共方法(含父类的公共函数),循环其接口.
*
* 暂未支持Spring风格Annotation继承Annotation
*
* 另,如果子类重载父类的公共函数,父类函数上的annotation不会继承,只有接口上的annotation会被继承.
*/
public static <T extends Annotation> Set<Method> getAnnotatedPublicMethods(Class<?> clazz, Class<T> annotation) {
// 已递归到Objebt.class, 停止递归
if (Object.class.equals(clazz)) {
return Collections.emptySet();
}
List<Class<?>> ifcs = ClassUtils.getAllInterfaces(clazz);
Set<Method> annotatedMethods = new HashSet<Method>();
// 遍历当前类的所有公共方法
Method[] methods = clazz.getMethods();
for (Method method : methods) {
// 如果当前方法有标注,或定义了该方法的所有接口有标注
if (method.getAnnotation(annotation) != null || searchOnInterfaces(method, annotation, ifcs)) {
annotatedMethods.add(method);
}
}
return annotatedMethods;
}
示例2: isOfType
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
public static <T extends Model> boolean isOfType(Class<T> modelClass, String fqn) {
if (modelClass == null)
return false;
Class<T> clazz = getModelInterface(modelClass);
if (clazz != null && clazz.getName().equals(fqn))
return true;
List<Class<?>> interfaces = ClassUtils.getAllInterfaces(modelClass);
if (interfaces != null && !interfaces.isEmpty()) {
for (Class<?> interf : interfaces) {
if (interf.getName().equals(fqn))
return true;
}
}
return false;
}
示例3: scanForExampleModels
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
protected void scanForExampleModels(Object o) {
List<Class<?>> classesToScan = ClassUtils.getAllInterfaces(o.getClass());
classesToScan.add(o.getClass());
for (Class<?> scanMe : classesToScan) {
for (Method m : scanMe.getMethods()) {
ExampleModel exampleModel = m.getAnnotation(ExampleModel.class);
if (exampleModel != null) {
if (!isStatic(m.getModifiers()) || !isPublic(m.getModifiers())) {
throw new IllegalArgumentException(
"@ExampleModel annotation may only be applied to public static method, not " + m);
}
Class modelClass = m.getReturnType();
modelClassToExampleFactoryMethods.put(modelClass, m);
}
}
}
}
示例4: getSimpleInterfaceName
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
private static String getSimpleInterfaceName(Class<?> basicImplClass) {
List<Class<?>> list = ClassUtils.getAllInterfaces(basicImplClass);
for (Class interfaceImplemented : list) {
if (!interfaceImplemented.getSimpleName().equals("LoadAcceptor"))
return interfaceImplemented.getSimpleName();
}
return "LoadAcceptor";
}
示例5: createSyncronized
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
* enables Webdriver usage of the same from different threads (handles locks internally). This locks an already in use instance.
* <p/>
* <i>Difference to <tt>ThreadGuard</tt>:</i> It does not forbid usage of a single webdriver by different threads.
* <p/>
* based on {@link org.openqa.selenium.support.ThreadGuard}
*/
public static WebDriver createSyncronized(WebDriver webDriver) {
ClassLoader classLoader = webDriver.getClass().getClassLoader();
List<Class<?>> interfaces = ClassUtils.getAllInterfaces(webDriver.getClass());
InvocationHandler invocationHandler = new SynchronizedWebDriverInvocationHandler(webDriver);
return (WebDriver) Proxy.newProxyInstance(classLoader,
interfaces.toArray(new Class[interfaces.size()]),
invocationHandler);
}
示例6: getAllInterfaces
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
* 递归返回本类及所有基类继承的接口,及接口继承的接口,比Spring中的相同实现完整
*/
public static List<Class<?>> getAllInterfaces(final Class<?> cls) {
return ClassUtils.getAllInterfaces(cls);
}
示例7: createLocking
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
* adds capability to lock your webDriver instance, suitable for concurrent usage
* <p/>
* <pre>
* LockingWebDriver lockingDriver = ConcurrentWebDriverFactory.createLocking(webDriver);
*
* // blocking any other locking request
* lockingDriver.lock();
*
* lockingDriver.get("http://www.lgohlke.de");
*
* lockingDriver.unlock();
* </pre>
*/
public static LockingWebDriver createLocking(WebDriver webDriver) {
ClassLoader classLoader = webDriver.getClass().getClassLoader();
List<Class<?>> interfaces = ClassUtils.getAllInterfaces(webDriver.getClass());
interfaces.add(LockingWebDriver.class);
InvocationHandler invocationHandler = new LockingWebDriverInvocationHandler(webDriver);
return (LockingWebDriver) Proxy.newProxyInstance(classLoader,
interfaces.toArray(new Class[interfaces.size()]),
invocationHandler);
}
示例8: isSubclass
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
* <p>
* isSubclass
* </p>
*
* @param superclass
* a {@link java.lang.reflect.Type} object.
* @param subclass
* a {@link java.lang.reflect.Type} object.
* @return a boolean.
*/
public static boolean isSubclass(Type superclass, Type subclass) {
List<Class<?>> superclasses = ClassUtils.getAllSuperclasses((Class<?>) subclass);
List<Class<?>> interfaces = ClassUtils.getAllInterfaces((Class<?>) subclass);
if (superclasses.contains(superclass) || interfaces.contains(superclass)) {
return true;
}
return false;
}