本文整理匯總了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;
}