本文整理匯總了Java中org.apache.commons.lang3.reflect.MethodUtils.invokeMethod方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodUtils.invokeMethod方法的具體用法?Java MethodUtils.invokeMethod怎麽用?Java MethodUtils.invokeMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang3.reflect.MethodUtils
的用法示例。
在下文中一共展示了MethodUtils.invokeMethod方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: applyRemoversToOriginal
import org.apache.commons.lang3.reflect.MethodUtils; //導入方法依賴的package包/類
private T applyRemoversToOriginal(T original, Mutant<T> mutant) {
try {
T modifiedOriginal = (T) MethodUtils.invokeMethod(original, "duplicate");
List<Mutant<T>> list = Arrays.asList(new Mutant<>(modifiedOriginal, ""));
for (MutantRemover mutantRemover : mutant.getRemoversApplied()) {
list = mutantRemover.removeMutants(list);
}
if (list.size() != 1) {
throw new RuntimeException("Applying the MutantRemovers used for a "
+ "mutant on the original schema did not produce only 1 "
+ "schema (expected: 1, actual: " + list.size() + ")");
}
return list.get(0).getMutatedArtefact();
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
throw new RuntimeException("Unable to execute the 'duplicate' "
+ "method in a class that appears to have an accessible "
+ "duplicate method to call", ex);
}
}
示例2: getLogger
import org.apache.commons.lang3.reflect.MethodUtils; //導入方法依賴的package包/類
/**
* Gets the logger.
*
* @param name the name
* @return the logger
*/
public Jdk14LoggerAccessor getLogger(String name) {
try {
Object logger = MethodUtils.invokeMethod(getTarget(), "getLogger", name);
if (logger == null) {
throw new NullPointerException(
getTarget().getClass().getName() + "#getLogger(\"" + name + "\") returned null");
}
Jdk14LoggerAccessor accessor = new Jdk14LoggerAccessor();
accessor.setTarget(logger);
accessor.setApplication(getApplication());
return accessor;
} catch (Exception e) {
logger.error("{}#getLogger('{}') failed", getTarget().getClass().getName(), name, e);
}
return null;
}
示例3: getHandlers
import org.apache.commons.lang3.reflect.MethodUtils; //導入方法依賴的package包/類
/**
* Gets the handlers.
*
* @return the handlers
*/
public List<LogDestination> getHandlers() {
List<LogDestination> handlerAccessors = new ArrayList<>();
try {
Object[] handlers = (Object[]) MethodUtils.invokeMethod(getTarget(), "getHandlers");
for (int h = 0; h < handlers.length; h++) {
Object handler = handlers[h];
Jdk14HandlerAccessor handlerAccessor = wrapHandler(handler, h);
if (handlerAccessor != null) {
handlerAccessors.add(handlerAccessor);
}
}
} catch (Exception e) {
logger.error("{}#handlers inaccessible", getTarget().getClass().getName(), e);
}
return handlerAccessors;
}
示例4: getSiftedAppenders
import org.apache.commons.lang3.reflect.MethodUtils; //導入方法依賴的package包/類
/**
* Gets the sifted appenders.
*
* @param appender the appender
* @return the sifted appenders
* @throws Exception the exception
*/
@SuppressWarnings("unchecked")
private List<Object> getSiftedAppenders(Object appender) throws Exception {
if ("org.apache.juli.logging.ch.qos.logback.classic.sift.SiftingAppender"
.equals(appender.getClass().getName())) {
Object tracker = MethodUtils.invokeMethod(appender, "getAppenderTracker");
if (tracker != null) {
try {
return (List<Object>) MethodUtils.invokeMethod(tracker, "allComponents");
} catch (final NoSuchMethodException e) {
// XXX Legacy 1.0.x and lower support for logback
logger.trace("", e);
return (List<Object>) MethodUtils.invokeMethod(tracker, "valueList");
}
}
return new ArrayList<>();
}
return null;
}
示例5: getLevel
import org.apache.commons.lang3.reflect.MethodUtils; //導入方法依賴的package包/類
/**
* Gets the level.
*
* @return the level
*/
public String getLevel() {
try {
Object level = null;
Object target = getTarget();
while (level == null && target != null) {
level = getLevelInternal(target);
target = MethodUtils.invokeMethod(target, "getParent");
}
if (level == null && isJuliRoot()) {
return "INFO";
}
return (String) MethodUtils.invokeMethod(level, "getName");
} catch (Exception e) {
logger.error("{}#getLevel() failed", getTarget().getClass().getName(), e);
}
return null;
}
示例6: getAppender
import org.apache.commons.lang3.reflect.MethodUtils; //導入方法依賴的package包/類
/**
* Returns the appender of this logger with the given name.
*
* @param name the name of the appender to return
* @return the appender with the given name, or null if no such appender exists for this logger
*/
public TomcatSlf4jLogbackAppenderAccessor getAppender(String name) {
try {
Object appender = MethodUtils.invokeMethod(getTarget(), "getAppender", name);
if (appender == null) {
List<TomcatSlf4jLogbackAppenderAccessor> appenders = getAppenders();
for (TomcatSlf4jLogbackAppenderAccessor wrappedAppender : appenders) {
if (wrappedAppender.getIndex().equals(name)) {
return wrappedAppender;
}
}
}
return wrapAppender(appender);
} catch (Exception e) {
logger.error("{}#getAppender() failed", getTarget().getClass().getName(), e);
}
return null;
}
示例7: getSiftedAppenders
import org.apache.commons.lang3.reflect.MethodUtils; //導入方法依賴的package包/類
/**
* Gets the sifted appenders.
*
* @param appender the appender
* @return the sifted appenders
* @throws Exception the exception
*/
@SuppressWarnings("unchecked")
private List<Object> getSiftedAppenders(Object appender) throws Exception {
if ("ch.qos.logback.classic.sift.SiftingAppender".equals(appender.getClass().getName())) {
Object tracker = MethodUtils.invokeMethod(appender, "getAppenderTracker");
if (tracker != null) {
try {
return (List<Object>) MethodUtils.invokeMethod(tracker, "allComponents");
} catch (final NoSuchMethodException e) {
// XXX Legacy 1.0.x and lower support for logback
logger.trace("", e);
return (List<Object>) MethodUtils.invokeMethod(tracker, "valueList");
}
}
return new ArrayList<>();
}
return null;
}
示例8: getDataForSqlWrite
import org.apache.commons.lang3.reflect.MethodUtils; //導入方法依賴的package包/類
/**
* some column data need special procession, eg. jsonb, hstore, etc.
*
* @param fieldAccessor
* @param entity
* @param propertyValue
* @return
*/
public static Object getDataForSqlWrite(FieldAccessor fieldAccessor, Object entity, Object propertyValue) {
Column columnAnno = fieldAccessor.getPropertyAnnotation(Column.class);
if ((columnAnno != null && !columnAnno.nullable()) && fieldAccessor.getPropertyType() == String.class && propertyValue == null) {
return "";
}
if (propertyValue == null) {
return null;
}
if (fieldAccessor.getPropertyAnnotation(Jsonb.class) != null) {
try {
Class<?> pgObjectCls = Class.forName("org.postgresql.util.PGobject");
String jsonText = JSON.toJSONString(propertyValue);
Object pgObject = pgObjectCls.newInstance();
// TODO: cache this method call or direct use PGobject by injection
MethodUtils.invokeMethod(pgObject, "setType", "text");
MethodUtils.invokeMethod(pgObject, "setValue", jsonText);
return pgObject;
} catch (Exception e) {
throw new JdbcRuntimeException(e);
}
}
// may need more annotation processor
return propertyValue;
}
示例9: sendMessage
import org.apache.commons.lang3.reflect.MethodUtils; //導入方法依賴的package包/類
public static Object sendMessage(String extensionID, String message, Object... args)
{
ExtensionWrapper ext = SW.get().getExtensionManager().getExtensions().get(extensionID);
if(!ext.isActivated())
{
return null;
}
try
{
return MethodUtils.invokeMethod(ext.getExtension(), message, args);
}
catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e2)
{
e2.printStackTrace();
}
return null;
}
示例10: compensatoryTransfer
import org.apache.commons.lang3.reflect.MethodUtils; //導入方法依賴的package包/類
/**
* 執行補償
*
* @param transactionRecover 補償信息
*/
@SuppressWarnings("unchecked")
private void compensatoryTransfer(TransactionRecover transactionRecover) {
if (Objects.nonNull(transactionRecover)) {
final TransactionInvocation transactionInvocation = transactionRecover.getTransactionInvocation();
if (Objects.nonNull(transactionInvocation)) {
final Class clazz = transactionInvocation.getTargetClazz();
final String method = transactionInvocation.getMethod();
final Object[] argumentValues = transactionInvocation.getArgumentValues();
final Class[] argumentTypes = transactionInvocation.getArgumentTypes();
final Object bean = SpringBeanUtils.getInstance().getBean(clazz);
try {
CompensationLocal.getInstance().setCompensationId(CommonConstant.COMPENSATE_ID);
MethodUtils.invokeMethod(bean, method, argumentValues, argumentTypes);
//通知tm自身已經完成提交 //刪除本地信息
final Boolean success = txManagerMessageService.completeCommitTxTransaction(transactionRecover.getGroupId(),
transactionRecover.getTaskId(), TransactionStatusEnum.COMMIT.getCode());
if (success) {
transactionRecoverRepository.remove(transactionRecover.getId());
}
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
LogUtil.error(LOGGER, "補償方法反射調用失敗!{}", e::getMessage);
}
}
}
}
示例11: executeCoordinator
import org.apache.commons.lang3.reflect.MethodUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private void executeCoordinator(TccInvocation tccInvocation) throws Exception {
if (Objects.nonNull(tccInvocation)) {
final Class clazz = tccInvocation.getTargetClass();
final String method = tccInvocation.getMethodName();
final Object[] args = tccInvocation.getArgs();
final Class[] parameterTypes = tccInvocation.getParameterTypes();
final Object bean = SpringBeanUtils.getInstance().getBean(clazz);
MethodUtils.invokeMethod(bean, method, args, parameterTypes);
LogUtil.debug(LOGGER, "執行本地協調事務:{}", () -> tccInvocation.getTargetClass()
+ ":" + tccInvocation.getMethodName());
}
}
示例12: executeParticipantMethod
import org.apache.commons.lang3.reflect.MethodUtils; //導入方法依賴的package包/類
private void executeParticipantMethod(TccInvocation tccInvocation) throws Exception {
if (Objects.nonNull(tccInvocation)) {
final Class clazz = tccInvocation.getTargetClass();
final String method = tccInvocation.getMethodName();
final Object[] args = tccInvocation.getArgs();
final Class[] parameterTypes = tccInvocation.getParameterTypes();
final Object bean = SpringBeanUtils.getInstance().getBean(clazz);
LogUtil.debug(LOGGER, "開始執行:{}", () -> clazz.getName() + " ;" + method);
MethodUtils.invokeMethod(bean, method, args, parameterTypes);
}
}
示例13: executeParticipantMethod
import org.apache.commons.lang3.reflect.MethodUtils; //導入方法依賴的package包/類
private void executeParticipantMethod(TccInvocation tccInvocation) throws Exception {
if (Objects.nonNull(tccInvocation)) {
final Class clazz = tccInvocation.getTargetClass();
final String method = tccInvocation.getMethodName();
final Object[] args = tccInvocation.getArgs();
final Class[] parameterTypes = tccInvocation.getParameterTypes();
final Object bean = SpringBeanUtils.getInstance().getBean(clazz);
MethodUtils.invokeMethod(bean, method, args, parameterTypes);
}
}
示例14: executeLocalTransaction
import org.apache.commons.lang3.reflect.MethodUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private void executeLocalTransaction(MythInvocation mythInvocation) throws Exception {
if (Objects.nonNull(mythInvocation)) {
final Class clazz = mythInvocation.getTargetClass();
final String method = mythInvocation.getMethodName();
final Object[] args = mythInvocation.getArgs();
final Class[] parameterTypes = mythInvocation.getParameterTypes();
final Object bean = SpringBeanUtils.getInstance().getBean(clazz);
MethodUtils.invokeMethod(bean, method, args, parameterTypes);
LogUtil.debug(LOGGER, "Myth執行本地協調事務:{}", () -> mythInvocation.getTargetClass()
+ ":" + mythInvocation.getMethodName());
}
}
示例15: invokeMethod
import org.apache.commons.lang3.reflect.MethodUtils; //導入方法依賴的package包/類
public static Object invokeMethod(Object target, String name, Object... args) {
try {
return MethodUtils.invokeMethod(target, name, args);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new SpongeException(e);
}
}