本文整理匯總了Java中org.apache.commons.beanutils.MethodUtils.getAccessibleMethod方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodUtils.getAccessibleMethod方法的具體用法?Java MethodUtils.getAccessibleMethod怎麽用?Java MethodUtils.getAccessibleMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.beanutils.MethodUtils
的用法示例。
在下文中一共展示了MethodUtils.getAccessibleMethod方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: LogbackFactoryAccessor
import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
/**
* Attempts to initialize a Logback logger factory via the given class loader.
*
* @param cl the ClassLoader to use when fetching the factory
*/
public LogbackFactoryAccessor(ClassLoader cl) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, 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 m1 = MethodUtils.getAccessibleMethod(clazz, "getSingleton", new Class[]{});
Object singleton = m1.invoke(null, null);
Method m = MethodUtils.getAccessibleMethod(clazz, "getLoggerFactory", new Class[]{});
Object loggerFactory = m.invoke(singleton, null);
// 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);
}
示例2: getLogger
import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
/**
* Returns the Logback logger with a given name.
*
* @return the Logger with the given name
*/
public LogbackLoggerAccessor getLogger(String name) {
try {
Class clazz = getTarget().getClass();
Method m = MethodUtils.getAccessibleMethod(clazz, "getLogger", new Class[] {String.class});
Object logger = m.invoke(getTarget(), new Object[] {name});
if (logger == null) {
throw new NullPointerException(getTarget() + ".getLogger(\"" + name + "\") returned null");
}
LogbackLoggerAccessor accessor = new LogbackLoggerAccessor();
accessor.setTarget(logger);
accessor.setApplication(getApplication());
return accessor;
} catch (Exception e) {
log.error(getTarget() + ".getLogger(\"" + name + "\") failed", e);
}
return null;
}
示例3: getAppenders
import org.apache.commons.beanutils.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
*/
public List getAppenders() {
List appenders = new ArrayList();
try {
Class clazz = getTarget().getClass();
Method m = MethodUtils.getAccessibleMethod(clazz, "getLoggerList", new Class[]{});
List loggers = (List) m.invoke(getTarget(), null);
Iterator it = loggers.iterator();
while (it.hasNext()) {
LogbackLoggerAccessor accessor = new LogbackLoggerAccessor();
accessor.setTarget(it.next());
accessor.setApplication(getApplication());
appenders.addAll(accessor.getAppenders());
}
} catch (Exception e) {
log.error(getTarget() + ".getLoggerList() failed", e);
}
return appenders;
}
示例4: getRootLogger
import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
public Log4JLoggerAccessor getRootLogger() {
try {
Class clazz = (Class) getTarget();
Method m = MethodUtils.getAccessibleMethod(clazz, "getRootLogger", new Class[]{});
Object logger = m.invoke(null, null);
if (logger == null) {
throw new NullPointerException(getTarget().getClass().getName() + "#getRootLogger() returned null");
}
Log4JLoggerAccessor accessor = new Log4JLoggerAccessor();
accessor.setTarget(logger);
accessor.setApplication(getApplication());
return accessor;
} catch (Exception e) {
log.error(getTarget().getClass().getName() + "#getRootLogger() failed", e);
}
return null;
}
示例5: getLogger
import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
public Log4JLoggerAccessor getLogger(String name) {
try {
Class clazz = (Class) getTarget();
Method m = MethodUtils.getAccessibleMethod(clazz, "getLogger", new Class[] {String.class});
Object logger = m.invoke(null, new Object[] {name});
if (logger == null) {
throw new NullPointerException(getTarget().getClass().getName() + "#getLogger(\"" + name + "\") returned null");
}
Log4JLoggerAccessor accessor = new Log4JLoggerAccessor();
accessor.setTarget(logger);
accessor.setApplication(getApplication());
return accessor;
} catch (Exception e) {
log.error(getTarget().getClass().getName() + "#getLogger(\"" + name + "\") failed", e);
}
return null;
}
示例6: setTestName
import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
protected void setTestName(final Object test, final Method testMethod) throws Exception {
String name = testMethod == null ? "" : testMethod.getName();
final Method setNameMethod = MethodUtils.getAccessibleMethod(test.getClass(), "setName",
new Class[]{String.class});
if (setNameMethod != null) {
setNameMethod.invoke(test, name);
}
}
示例7: setTestName
import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
protected void setTestName(final Object test, final Method testMethod) throws Exception {
String name = testMethod == null ? "" : testMethod.getName();
final Method setNameMethod = MethodUtils.getAccessibleMethod(test.getClass(), "setName", new Class[]{String.class});
if (setNameMethod != null) {
setNameMethod.invoke(test, name);
}
}
示例8: testBeanClass
import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
@Override
public boolean testBeanClass(Class<?> klass, Object[] constructorArgs) {
this.setFailureReason(null);
Object bean = InstantiationUtils.safeNewInstance(klass, constructorArgs);
if (bean instanceof Serializable) {
InjectionUtils.injectValues(bean, valueGeneratorFactory, false);
Serializable sBean = (Serializable)bean;
Serializable sBeanReconstituted = null;
byte[] serializedObj;
try {
serializedObj = SerializationUtils.serialize(sBean);
sBeanReconstituted = SerializationUtils.deserialize(serializedObj);
} catch (Throwable e) {
this.setFailureReason("Error serializing bean that implements serializable");
throw new BeanTesterException("Error serializing bean that implements serializable", e)
.addContextValue("class", klass.getName());
}
/*
* An equals() test is only valid if the bean isn't relying on Object.equals().
*/
Method equalsMethod = MethodUtils.getAccessibleMethod(klass, "equals", Object.class);
if ( !equalsMethod.getDeclaringClass().equals(Object.class) && !sBean.equals(sBeanReconstituted)) {
this.setFailureReason("Bean implements serializable, but the reconstituted bean doesn't equal it's original");
throw new BeanTesterException("Bean implements serializable, but the reconstituted bean doesn't equal it's original")
.addContextValue("class", klass.getName());
}
}
return true;
}
示例9: isPk
import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
public <T> boolean isPk(ManagedType<T> mt, SingularAttribute<? super T, ?> attr) {
try {
Method m = MethodUtils.getAccessibleMethod(mt.getJavaType(), "get" + WordUtils.capitalize(attr.getName()), (Class<?>) null);
if (m != null && m.getAnnotation(Id.class) != null) {
return true;
}
Field field = mt.getJavaType().getField(attr.getName());
return field.getAnnotation(Id.class) != null;
} catch (Exception e) {
return false;
}
}
示例10: Jdk14ManagerAccessor
import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
public Jdk14ManagerAccessor(ClassLoader cl) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Class clazz = cl.loadClass("java.util.logging.LogManager");
Method getManager = MethodUtils.getAccessibleMethod(clazz, "getLogManager", new Class[]{});
Object manager = getManager.invoke(null, null);
if (manager == null) {
throw new NullPointerException(clazz.getName() + ".getLogManager() returned null");
}
setTarget(manager);
}
示例11: setLevel
import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
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, new Object[] {newLevelStr});
MethodUtils.invokeMethod(getTarget(), "setLevel", newLevel);
} catch (Exception e) {
log.error(getTarget().getClass().getName() + "#setLevel(\"" + newLevelStr + "\") failed", e);
}
}
示例12: Log4JManagerAccessor
import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
public Log4JManagerAccessor(ClassLoader cl) throws ClassNotFoundException {
Class clazz = cl.loadClass("org.apache.log4j.LogManager");
Method m = MethodUtils.getAccessibleMethod(clazz, "exists", new Class[] {String.class});
if (m == null) {
throw new RuntimeException("The LogManager is part of the slf4j bridge.");
}
setTarget(clazz);
}
示例13: register
import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
@Override
public synchronized void register(String topic, EventHandler eventHandler) {
final Method eventHandlerMethod = MethodUtils.getAccessibleMethod(eventHandler.getClass(), "handleEvent", Event.class);
final AnnotatedObserver ao = new AnnotatedObserver(eventHandler, eventHandlerMethod);
ao.setTopic(topic);
final Collection<AnnotatedObserver> topicObservers = getOrCreateObserversForTopic(topic);
topicObservers.add(ao);
}
示例14: getReadMethod
import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
/**
* <p>Return an accessible property getter method for this property,
* if there is one; otherwise return <code>null</code>.</p>
*
* @param clazz The class of the read method will be invoked on
* @param descriptor Property descriptor to return a getter for
* @return The read method
*/
Method getReadMethod(Class clazz, PropertyInfo descriptor) {
return (MethodUtils.getAccessibleMethod(clazz, descriptor.getReadMethodName(), EMPTY_CLASS_PARAMETERS));
}
示例15: getWriteMethod
import org.apache.commons.beanutils.MethodUtils; //導入方法依賴的package包/類
/**
* <p>Return an accessible property setter method for this property,
* if there is one; otherwise return <code>null</code>.</p>
*
* @param clazz The class of the read method will be invoked on
* @param descriptor Property descriptor to return a setter for
* @return The write method
*/
Method getWriteMethod(Class clazz, PropertyInfo descriptor) {
return (MethodUtils.getAccessibleMethod(clazz, descriptor.getWriteMethodName(),
new Class[]{descriptor.getWriteType()}));
}