当前位置: 首页>>代码示例>>Java>>正文


Java ReflectionUtils.invokeMethod方法代码示例

本文整理汇总了Java中org.springframework.util.ReflectionUtils.invokeMethod方法的典型用法代码示例。如果您正苦于以下问题:Java ReflectionUtils.invokeMethod方法的具体用法?Java ReflectionUtils.invokeMethod怎么用?Java ReflectionUtils.invokeMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.util.ReflectionUtils的用法示例。


在下文中一共展示了ReflectionUtils.invokeMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: invoke

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Object invoke(MethodInvocation invocation) throws Throwable {
	Class<?>[] groups = determineValidationGroups(invocation);
	if (forExecutablesMethod != null) {
		Object executableValidator = ReflectionUtils.invokeMethod(forExecutablesMethod, this.validator);
		Set<ConstraintViolation<?>> result = (Set<ConstraintViolation<?>>)
				ReflectionUtils.invokeMethod(validateParametersMethod, executableValidator,
						invocation.getThis(), invocation.getMethod(), invocation.getArguments(), groups);
		if (!result.isEmpty()) {
			throw new ConstraintViolationException(result);
		}
		Object returnValue = invocation.proceed();
		result = (Set<ConstraintViolation<?>>)
				ReflectionUtils.invokeMethod(validateReturnValueMethod, executableValidator,
						invocation.getThis(), invocation.getMethod(), returnValue, groups);
		if (!result.isEmpty()) {
			throw new ConstraintViolationException(result);
		}
		return returnValue;
	}
	else {
		return HibernateValidatorDelegate.invokeWithinValidation(invocation, this.validator, groups);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:MethodValidationInterceptor.java

示例2: invoke

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
 * 关于这个方法,还发现了一个很神奇的现象。。。
 * 当我调试时,偶尔会发现微信会收到消息,消息内容是被代理的对象的toString(),这就奇怪了,从哪里来的呢?
 * 而且不调试时没这个问题。。。仔细分析发现,应该就是和调试时调试器会调用对象的toString方法导致的
 * 因为调用了代理对象的toString,进入这个拦截器,只要进入这个拦截器,最终就会调用send。因为toString()最终返回string,故会发出那个消息。。。
 * 又一次被调试时toString坑了。添加方法过滤解决此问题。
 *
 * @param invocation
 * @return
 * @throws Throwable
 */
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable {
    if (ReflectionUtils.isObjectMethod(invocation.getMethod())) {
        return ReflectionUtils.invokeMethod(invocation.getMethod(), invocation.getThis(), invocation.getArguments());
    }
    WxRequest wxRequest = WxWebUtils.getWxRequestFromRequest();
    wxAsyncMessageTemplate.send(wxRequest, () -> {
        try {
            return invocation.proceed();
        } catch (Throwable e) {
            throw new WxApiException(e.getMessage(), e);
        }
    });
    return null;
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:27,代码来源:WxAsyncMethodInterceptor.java

示例3: invokeMethod

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private static Object invokeMethod(final Object target, final Class<?> targetClass, String methodName, Object[] args) {
	Class<?>[] types = null;
	if (ObjectUtils.isEmpty(args)) {
		types = new Class[0];
	}
	else {
		types = new Class[args.length];
		for (int objectIndex = 0; objectIndex < args.length; objectIndex++) {
			types[objectIndex] = args[objectIndex].getClass();
		}
	}

	Method method = ReflectionUtils.findMethod(targetClass, methodName, types);
	ReflectionUtils.makeAccessible(method);
	return ReflectionUtils.invokeMethod(method, target, args);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:17,代码来源:TestUtils.java

示例4: getAuthor

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private Object getAuthor(Event event) {
    if (event == null) {
        return null;
    }
    Class<? extends Event> clazz = event.getClass();
    Method method;
    if (!userAccessors.containsKey(clazz)) {
        method = ReflectionUtils.findMethod(clazz, "getUser");
        if (method == null) {
            method = ReflectionUtils.findMethod(clazz, "getAuthor");
        }
        userAccessors.put(clazz, method);
    } else {
        method = userAccessors.get(clazz);
    }
    if (method != null) {
        Object result = ReflectionUtils.invokeMethod(method, event);
        if (result instanceof User) {
            return result;
        }
    }
    return null;
}
 
开发者ID:GoldRenard,项目名称:JuniperBotJ,代码行数:24,代码来源:SourceResolverServiceImpl.java

示例5: copyPropertiesToBean

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
 * Copy the properties of the supplied {@link Annotation} to the supplied target bean.
 * Any properties defined in {@code excludedProperties} will not be copied.
 * <p>A specified value resolver may resolve placeholders in property values, for example.
 * @param ann the annotation to copy from
 * @param bean the bean instance to copy to
 * @param valueResolver a resolve to post-process String property values (may be {@code null})
 * @param excludedProperties the names of excluded properties, if any
 * @see org.springframework.beans.BeanWrapper
 */
public static void copyPropertiesToBean(Annotation ann, Object bean, StringValueResolver valueResolver, String... excludedProperties) {
	Set<String> excluded =  new HashSet<String>(Arrays.asList(excludedProperties));
	Method[] annotationProperties = ann.annotationType().getDeclaredMethods();
	BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(bean);
	for (Method annotationProperty : annotationProperties) {
		String propertyName = annotationProperty.getName();
		if ((!excluded.contains(propertyName)) && bw.isWritableProperty(propertyName)) {
			Object value = ReflectionUtils.invokeMethod(annotationProperty, ann);
			if (valueResolver != null && value instanceof String) {
				value = valueResolver.resolveStringValue((String) value);
			}
			bw.setPropertyValue(propertyName, value);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:AnnotationBeanUtils.java

示例6: execute

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
 * This implementation applies the passed-in job data map as bean property
 * values, and delegates to {@code executeInternal} afterwards.
 * @see #executeInternal
 */
@Override
public final void execute(JobExecutionContext context) throws JobExecutionException {
	try {
		// Reflectively adapting to differences between Quartz 1.x and Quartz 2.0...
		Scheduler scheduler = (Scheduler) ReflectionUtils.invokeMethod(getSchedulerMethod, context);
		Map<?, ?> mergedJobDataMap = (Map<?, ?>) ReflectionUtils.invokeMethod(getMergedJobDataMapMethod, context);

		BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
		MutablePropertyValues pvs = new MutablePropertyValues();
		pvs.addPropertyValues(scheduler.getContext());
		pvs.addPropertyValues(mergedJobDataMap);
		bw.setPropertyValues(pvs, true);
	}
	catch (SchedulerException ex) {
		throw new JobExecutionException(ex);
	}
	executeInternal(context);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:QuartzJobBean.java

示例7: createJobInstance

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
 * Create an instance of the specified job class.
 * <p>Can be overridden to post-process the job instance.
 * @param bundle the TriggerFiredBundle from which the JobDetail
 * and other info relating to the trigger firing can be obtained
 * @return the job instance
 * @throws Exception if job instantiation failed
 */
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
	// Reflectively adapting to differences between Quartz 1.x and Quartz 2.0...
	Method getJobDetail = bundle.getClass().getMethod("getJobDetail");
	Object jobDetail = ReflectionUtils.invokeMethod(getJobDetail, bundle);
	Method getJobClass = jobDetail.getClass().getMethod("getJobClass");
	Class<?> jobClass = (Class<?>) ReflectionUtils.invokeMethod(getJobClass, jobDetail);
	return jobClass.newInstance();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:AdaptableJobFactory.java

示例8: callMethod

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T callMethod(String name, Object target, Object[] args, Class<?>[] argsTypes) throws Exception {
	Class<?> clazz = target.getClass();
	Method method = ReflectionUtils.findMethod(clazz, name, argsTypes);

	if (method == null)
		throw new IllegalArgumentException("Cannot find method '" + method + "' in the class hierarchy of "
				+ target.getClass());
	method.setAccessible(true);
	return (T) ReflectionUtils.invokeMethod(method, target, args);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-dashboard,代码行数:12,代码来源:TestUtils.java

示例9: setUp

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
  //as PropertySourcesProcessor has some static states, so we must manually clear its state
  ReflectionUtils.invokeMethod(PROPERTY_SOURCES_PROCESSOR_CLEAR, null);
  //as ConfigService is singleton, so we must manually clear its container
  ReflectionUtils.invokeMethod(CONFIG_SERVICE_RESET, null);
  MockInjector.reset();
  MockInjector.setInstance(ConfigManager.class, new MockConfigManager());
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:10,代码来源:AbstractSpringIntegrationTest.java

示例10: SpringSessionContext

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
 * Create a new SpringSessionContext for the given Hibernate SessionFactory.
 * @param sessionFactory the SessionFactory to provide current Sessions for
 */
public SpringSessionContext(SessionFactoryImplementor sessionFactory) {
	this.sessionFactory = sessionFactory;
	try {
		Object jtaPlatform = sessionFactory.getServiceRegistry().getService(ConfigurableJtaPlatform.jtaPlatformClass);
		Method rtmMethod = ConfigurableJtaPlatform.jtaPlatformClass.getMethod("retrieveTransactionManager");
		Object transactionManager = ReflectionUtils.invokeMethod(rtmMethod, jtaPlatform);
		if (transactionManager != null) {
			this.jtaSessionContext = new SpringJtaSessionContext(sessionFactory);
		}
	}
	catch (Exception ex) {
		throw new IllegalStateException("Could not introspect Hibernate JtaPlatform for SpringJtaSessionContext", ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:SpringSessionContext.java

示例11: findJobDetail

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private JobDetail findJobDetail(Trigger trigger) {
	if (trigger instanceof JobDetailAwareTrigger) {
		return ((JobDetailAwareTrigger) trigger).getJobDetail();
	}
	else {
		try {
			Map<?, ?> jobDataMap =
					(Map<?, ?>) ReflectionUtils.invokeMethod(Trigger.class.getMethod("getJobDataMap"), trigger);
			return (JobDetail) jobDataMap.remove(JobDetailAwareTrigger.JOB_DETAIL_KEY);
		}
		catch (NoSuchMethodException ex) {
			throw new IllegalStateException("Inconsistent Quartz API: " + ex);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:SchedulerAccessor.java

示例12: updateProperty

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public static void updateProperty(String key, Object value) {
  ReflectionUtils.invokeMethod(updatePropertyMethod, null, key, value);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:4,代码来源:Utils.java

示例13: checkNewConnectionHolder

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private boolean checkNewConnectionHolder(Object transaction){
    Method method=ReflectionUtils.findMethod(transaction.getClass(), "isNewConnectionHolder");
    method.setAccessible(true);
    Object invokeResult=null!=method?ReflectionUtils.invokeMethod(method,transaction):null;
    return null!=invokeResult&&invokeResult instanceof Boolean&&(Boolean)invokeResult;
}
 
开发者ID:zhangkewei,项目名称:dubbo-transaction,代码行数:7,代码来源:DubboTransactionDataSourceTransactonManager.java

示例14: start

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public BundleContext start() {
	framework = BeanUtils.instantiateClass(CONSTRUCTOR, monitor);
	ReflectionUtils.invokeMethod(LAUNCH, framework, 0);
	return (BundleContext) ReflectionUtils.invokeMethod(GET_BUNDLE_CONTEXT, framework);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:6,代码来源:KnopflerfishPlatform.java

示例15: getTestMethodName

import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public String getTestMethodName() {
	return (String) ReflectionUtils.invokeMethod(GET_TEST_METHOD_NAME, instance);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:4,代码来源:ReflectionOsgiHolder.java


注:本文中的org.springframework.util.ReflectionUtils.invokeMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。