本文整理汇总了Java中org.apache.commons.lang3.reflect.MethodUtils.getAccessibleMethod方法的典型用法代码示例。如果您正苦于以下问题:Java MethodUtils.getAccessibleMethod方法的具体用法?Java MethodUtils.getAccessibleMethod怎么用?Java MethodUtils.getAccessibleMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.reflect.MethodUtils
的用法示例。
在下文中一共展示了MethodUtils.getAccessibleMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findAnnotation
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
/**
* 获得运行的annotaion.
*
* <h3>代码流程:</h3>
*
* <blockquote>
* <ol>
* <li>先基于 {@link org.aspectj.lang.reflect.MethodSignature},获得其 method,然后继续这个method 调用
* {@link org.springframework.core.annotation.AnnotationUtils#findAnnotation(Method, Class)}解析</li>
* <li>如果第一步找不到相应的annotation,那么会通过 {@link org.aspectj.lang.JoinPoint#getTarget()} 构建target method,并解析</li>
* </ol>
* </blockquote>
*
* @param <T>
* the generic type
* @param joinPoint
* the join point
* @param annotationClass
* the annotation class
* @return the annotation
*/
public static <T extends Annotation> T findAnnotation(JoinPoint joinPoint,Class<T> annotationClass){
Validate.notNull(joinPoint, "joinPoint can't be null!");
Validate.notNull(annotationClass, "annotationClass can't be null!");
//---------------------------------------------------------------
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
Method method = methodSignature.getMethod();
T annotation = AnnotationUtils.findAnnotation(method, annotationClass);
if (null != annotation){
return annotation;
}
//---------------------------------------------------------------
Method targetMethod = MethodUtils
.getAccessibleMethod(joinPoint.getTarget().getClass(), method.getName(), method.getParameterTypes());
annotation = AnnotationUtils.findAnnotation(targetMethod, annotationClass);
if (null != annotation){
return annotation;
}
return null;
}
示例2: LogbackFactoryAccessor
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
/**
* Attempts to initialize a Logback logger factory via the given class loader.
*
* @param cl the ClassLoader to use when fetching the factory
* @throws ClassNotFoundException the class not found exception
* @throws IllegalAccessException the illegal access exception
* @throws InvocationTargetException the invocation target exception
*/
public LogbackFactoryAccessor(ClassLoader cl)
throws ClassNotFoundException, IllegalAccessException, InvocationTargetException {
// Get the singleton SLF4J binding, which may or may not be Logback, depending on the binding.
Class<?> clazz = cl.loadClass("org.slf4j.impl.StaticLoggerBinder");
Method getSingleton = MethodUtils.getAccessibleMethod(clazz, "getSingleton", new Class[0]);
Object singleton = getSingleton.invoke(null);
Method getLoggerFactory =
MethodUtils.getAccessibleMethod(clazz, "getLoggerFactory", new Class[0]);
Object loggerFactory = getLoggerFactory.invoke(singleton);
// Check if the binding is indeed Logback
Class<?> loggerFactoryClass = cl.loadClass("ch.qos.logback.classic.LoggerContext");
if (!loggerFactoryClass.isInstance(loggerFactory)) {
throw new RuntimeException("The singleton SLF4J binding was not Logback");
}
setTarget(loggerFactory);
}
示例3: getAppenders
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
/**
* Returns a list of wrappers for all Logback appenders that have an associated logger.
*
* @return a list of {@link LogbackAppenderAccessor}s representing all appenders that are in use
*/
@SuppressWarnings("unchecked")
public List<LogbackAppenderAccessor> getAppenders() {
List<LogbackAppenderAccessor> appenders = new ArrayList<>();
try {
Class<? extends Object> clazz = getTarget().getClass();
Method getLoggerList = MethodUtils.getAccessibleMethod(clazz, "getLoggerList", new Class[0]);
List<Object> loggers = (List<Object>) getLoggerList.invoke(getTarget());
for (Object logger : loggers) {
LogbackLoggerAccessor accessor = new LogbackLoggerAccessor();
accessor.setTarget(logger);
accessor.setApplication(getApplication());
appenders.addAll(accessor.getAppenders());
}
} catch (Exception e) {
logger.error("{}.getLoggerList() failed", getTarget(), e);
}
return appenders;
}
示例4: getAppenders
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
/**
* Gets the appenders.
*
* @return the appenders
*/
@SuppressWarnings("unchecked")
public List<Log4JAppenderAccessor> getAppenders() {
List<Log4JAppenderAccessor> appenders = new ArrayList<>();
try {
appenders.addAll(getRootLogger().getAppenders());
Class<?> clazz = (Class<?>) getTarget();
Method getCurrentLoggers =
MethodUtils.getAccessibleMethod(clazz, "getCurrentLoggers", new Class[0]);
for (Object currentLogger : Collections
.list((Enumeration<Object>) getCurrentLoggers.invoke(null))) {
Log4JLoggerAccessor accessor = new Log4JLoggerAccessor();
accessor.setTarget(currentLogger);
accessor.setApplication(getApplication());
appenders.addAll(accessor.getAppenders());
}
} catch (Exception e) {
logger.error("{}#getCurrentLoggers() failed", getTarget().getClass().getName(), e);
}
return appenders;
}
示例5: TomcatSlf4jLogbackFactoryAccessor
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
/**
* Attempts to initialize a TomcatSlf4jLogback logger factory via the given class loader.
*
* @param cl the ClassLoader to use when fetching the factory
* @throws ClassNotFoundException the class not found exception
* @throws IllegalAccessException the illegal access exception
* @throws InvocationTargetException the invocation target exception
*/
public TomcatSlf4jLogbackFactoryAccessor(ClassLoader cl)
throws ClassNotFoundException, IllegalAccessException, InvocationTargetException {
// Get the singleton SLF4J binding, which may or may not be Logback, depending on the binding.
Class<?> clazz = cl.loadClass("org.apache.juli.logging.org.slf4j.impl.StaticLoggerBinder");
Method getSingleton = MethodUtils.getAccessibleMethod(clazz, "getSingleton", new Class[0]);
Object singleton = getSingleton.invoke(null);
Method getLoggerFactory =
MethodUtils.getAccessibleMethod(clazz, "getLoggerFactory", new Class[0]);
Object loggerFactory = getLoggerFactory.invoke(singleton);
// Check if the binding is indeed Logback
Class<?> loggerFactoryClass =
cl.loadClass("org.apache.juli.logging.ch.qos.logback.classic.LoggerContext");
if (!loggerFactoryClass.isInstance(loggerFactory)) {
throw new RuntimeException("The singleton SLF4J binding was not Logback");
}
setTarget(loggerFactory);
}
示例6: getAppenders
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
/**
* Returns a list of wrappers for all TomcatSlf4jLogback appenders that have an associated logger.
*
* @return a list of {@link TomcatSlf4jLogbackAppenderAccessor}s representing all appenders that
* are in use
*/
@SuppressWarnings("unchecked")
public List<TomcatSlf4jLogbackAppenderAccessor> getAppenders() {
List<TomcatSlf4jLogbackAppenderAccessor> appenders = new ArrayList<>();
try {
Class<? extends Object> clazz = getTarget().getClass();
Method getLoggerList = MethodUtils.getAccessibleMethod(clazz, "getLoggerList", new Class[0]);
List<Object> loggers = (List<Object>) getLoggerList.invoke(getTarget());
for (Object logger : loggers) {
TomcatSlf4jLogbackLoggerAccessor accessor = new TomcatSlf4jLogbackLoggerAccessor();
accessor.setTarget(logger);
accessor.setApplication(getApplication());
appenders.addAll(accessor.getAppenders());
}
} catch (Exception e) {
logger.error("{}.getLoggerList() failed", getTarget(), e);
}
return appenders;
}
示例7: convertFromStringUnresolved
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
protected Object convertFromStringUnresolved(Class parameterClass, String paramValueStr) {
try {
Constructor constructor = ConstructorUtils.getAccessibleConstructor(parameterClass, String.class);
if (constructor != null) {
return constructor.newInstance(paramValueStr);
} else {
Method valueOf = MethodUtils.getAccessibleMethod(parameterClass, "valueOf", String.class);
if (valueOf != null) {
return valueOf.invoke(null, paramValueStr);
}
}
} catch (ReflectiveOperationException e) {
throw new ReportingException(
String.format("Could not instantiate object with class [%s] from [%s] string.",
parameterClass.getCanonicalName(),
paramValueStr));
}
return paramValueStr;
}
示例8: getInvokeValue
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
static <T> String getInvokeValue(T t, String methodName) {
try {
Method method = MethodUtils.getAccessibleMethod(t.getClass(),
methodName);
String text = TransformUtils.toString(method.invoke(t));
return text;
} catch (Exception e) {
return null;
}
}
示例9: getCron
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
/**
* 获取cron表达式
*
* @author nan.li
* @param jobClazz
* @return
*/
private String getCron(Class<Job> jobClazz)
{
Method method = MethodUtils.getAccessibleMethod(jobClazz, "execute", JobExecutionContext.class);
if (method != null)
{
if (method.isAnnotationPresent(Scheduled.class))
{
Scheduled scheduled = method.getAnnotation(Scheduled.class);
String cron = scheduled.cron();
return cron;
}
}
return null;
}
示例10: mockSessionManager
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
protected Object mockSessionManager(ClassLoader classLoader) throws ReflectiveOperationException {
Class<?> managerClass = Class.forName(getManagerInterfaceName(), false, classLoader);
Object mockManager = Mockito.mock(managerClass);
Method loggerHolderMethod =
MethodUtils.getAccessibleMethod(managerClass, getManagerGetLoggerHolderMethodName());
Class<?> loggerHolderClass = loggerHolderMethod.getReturnType();
Object mockLoggerHolder = mockLoggerHolder(loggerHolderClass);
Mockito.when(loggerHolderMethod.invoke(mockManager)).thenReturn(mockLoggerHolder);
return mockManager;
}
示例11: Jdk14ManagerAccessor
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
/**
* Instantiates a new jdk14 manager accessor.
*
* @param cl the cl
* @throws ClassNotFoundException the class not found exception
* @throws IllegalAccessException the illegal access exception
* @throws InvocationTargetException the invocation target exception
*/
public Jdk14ManagerAccessor(ClassLoader cl)
throws ClassNotFoundException, IllegalAccessException, InvocationTargetException {
Class<?> clazz = cl.loadClass("java.util.logging.LogManager");
Method getManager = MethodUtils.getAccessibleMethod(clazz, "getLogManager", new Class[0]);
Object manager = getManager.invoke(null);
if (manager == null) {
throw new NullPointerException(clazz.getName() + ".getLogManager() returned null");
}
setTarget(manager);
}
示例12: setLevel
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
/**
* Sets the level.
*
* @param newLevelStr the new level
*/
public void setLevel(String newLevelStr) {
try {
Class<?> levelClass =
getTarget().getClass().getClassLoader().loadClass("java.util.logging.Level");
Method parse = MethodUtils.getAccessibleMethod(levelClass, "parse", String.class);
Object newLevel = parse.invoke(null, newLevelStr);
MethodUtils.invokeMethod(getTarget(), "setLevel", newLevel);
} catch (Exception e) {
logger.error("{}#setLevel('{}') failed", getTarget().getClass().getName(), newLevelStr, e);
}
}
示例13: Log4JManagerAccessor
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
/**
* Instantiates a new log4 j manager accessor.
*
* @param cl the cl
* @throws ClassNotFoundException the class not found exception
*/
public Log4JManagerAccessor(ClassLoader cl) throws ClassNotFoundException {
Class<?> clazz = cl.loadClass("org.apache.log4j.LogManager");
Method exists = MethodUtils.getAccessibleMethod(clazz, "exists", new Class[] {String.class});
if (exists == null) {
throw new RuntimeException("The LogManager is part of the slf4j bridge.");
}
setTarget(clazz);
}
示例14: configure
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
@Override
protected X configure(final X repository) {
Method setter = MethodUtils.getAccessibleMethod(repository.getClass(),
RESOURCE_INJECTOR_SETTER,
ResourceInjector.class);
if (setter != null) {
try {
setter.invoke(repository, new CdiResourceInjector(getBeanManager()));
} catch (ReflectiveOperationException e) {
throw new CreationException(e);
}
}
return repository;
}
示例15: hasDuplicateMethod
import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
private boolean hasDuplicateMethod(Class c) {
return MethodUtils.getAccessibleMethod(c, "duplicate") != null;
}