org.springframework.core.ParameterNameDiscoverer Java Examples

The following examples show how to use org.springframework.core.ParameterNameDiscoverer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractReflectiveMBeanInfoAssembler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create parameter info for the given method.
 * <p>The default implementation returns an empty array of {@code MBeanParameterInfo}.
 * @param method the {@code Method} to get the parameter information for
 * @param beanKey the key associated with the MBean in the beans map
 * of the {@code MBeanExporter}
 * @return the {@code MBeanParameterInfo} array
 */
protected MBeanParameterInfo[] getOperationParameters(Method method, String beanKey) {
	ParameterNameDiscoverer paramNameDiscoverer = getParameterNameDiscoverer();
	String[] paramNames = (paramNameDiscoverer != null ? paramNameDiscoverer.getParameterNames(method) : null);
	if (paramNames == null) {
		return new MBeanParameterInfo[0];
	}

	MBeanParameterInfo[] info = new MBeanParameterInfo[paramNames.length];
	Class<?>[] typeParameters = method.getParameterTypes();
	for (int i = 0; i < info.length; i++) {
		info[i] = new MBeanParameterInfo(paramNames[i], typeParameters[i].getName(), paramNames[i]);
	}

	return info;
}
 
Example #2
Source File: AbstractReflectiveMBeanInfoAssembler.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Create parameter info for the given method.
 * <p>The default implementation returns an empty array of {@code MBeanParameterInfo}.
 * @param method the {@code Method} to get the parameter information for
 * @param beanKey the key associated with the MBean in the beans map
 * of the {@code MBeanExporter}
 * @return the {@code MBeanParameterInfo} array
 */
protected MBeanParameterInfo[] getOperationParameters(Method method, String beanKey) {
	ParameterNameDiscoverer paramNameDiscoverer = getParameterNameDiscoverer();
	String[] paramNames = (paramNameDiscoverer != null ? paramNameDiscoverer.getParameterNames(method) : null);
	if (paramNames == null) {
		return new MBeanParameterInfo[0];
	}

	MBeanParameterInfo[] info = new MBeanParameterInfo[paramNames.length];
	Class<?>[] typeParameters = method.getParameterTypes();
	for (int i = 0; i < info.length; i++) {
		info[i] = new MBeanParameterInfo(paramNames[i], typeParameters[i].getName(), paramNames[i]);
	}

	return info;
}
 
Example #3
Source File: AbstractReflectiveMBeanInfoAssembler.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Create parameter info for the given method.
 * <p>The default implementation returns an empty array of {@code MBeanParameterInfo}.
 * @param method the {@code Method} to get the parameter information for
 * @param beanKey the key associated with the MBean in the beans map
 * of the {@code MBeanExporter}
 * @return the {@code MBeanParameterInfo} array
 */
protected MBeanParameterInfo[] getOperationParameters(Method method, String beanKey) {
	ParameterNameDiscoverer paramNameDiscoverer = getParameterNameDiscoverer();
	String[] paramNames = (paramNameDiscoverer != null ? paramNameDiscoverer.getParameterNames(method) : null);
	if (paramNames == null) {
		return new MBeanParameterInfo[0];
	}

	MBeanParameterInfo[] info = new MBeanParameterInfo[paramNames.length];
	Class<?>[] typeParameters = method.getParameterTypes();
	for (int i = 0; i < info.length; i++) {
		info[i] = new MBeanParameterInfo(paramNames[i], typeParameters[i].getName(), paramNames[i]);
	}

	return info;
}
 
Example #4
Source File: AbstractReflectiveMBeanInfoAssembler.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Create parameter info for the given method.
 * <p>The default implementation returns an empty array of {@code MBeanParameterInfo}.
 * @param method the {@code Method} to get the parameter information for
 * @param beanKey the key associated with the MBean in the beans map
 * of the {@code MBeanExporter}
 * @return the {@code MBeanParameterInfo} array
 */
protected MBeanParameterInfo[] getOperationParameters(Method method, String beanKey) {
	ParameterNameDiscoverer paramNameDiscoverer = getParameterNameDiscoverer();
	String[] paramNames = (paramNameDiscoverer != null ? paramNameDiscoverer.getParameterNames(method) : null);
	if (paramNames == null) {
		return new MBeanParameterInfo[0];
	}

	MBeanParameterInfo[] info = new MBeanParameterInfo[paramNames.length];
	Class<?>[] typeParameters = method.getParameterTypes();
	for (int i = 0; i < info.length; i++) {
		info[i] = new MBeanParameterInfo(paramNames[i], typeParameters[i].getName(), paramNames[i]);
	}

	return info;
}
 
Example #5
Source File: MethodBasedSpelExpression.java    From ddal with Apache License 2.0 6 votes vote down vote up
/**
 * DefaultParameterNameDiscoverer is supported spring 4.0
 * @return
 */
private String[] getParameterNames(Method method) {
    if (notSupportParameterNameDiscoverer) {
        return null;
    } else {
        try {
            ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();// only support
            // from spring4
            String[] strs = parameterNameDiscoverer.getParameterNames(method);
            if (strs == null) {
                notSupportParameterNameDiscoverer = true;
            }
            return strs;
        } catch (NoClassDefFoundError e) {
            notSupportParameterNameDiscoverer = true;
            return null;
        }
    }
}
 
Example #6
Source File: AbstractAspectJAdvice.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a ParameterNameDiscoverer to be used for argument binding.
 * <p>The default implementation creates a {@link DefaultParameterNameDiscoverer}
 * and adds a specifically configured {@link AspectJAdviceParameterNameDiscoverer}.
 */
protected ParameterNameDiscoverer createParameterNameDiscoverer() {
	// We need to discover them, or if that fails, guess,
	// and if we can't guess with 100% accuracy, fail.
	DefaultParameterNameDiscoverer discoverer = new DefaultParameterNameDiscoverer();
	AspectJAdviceParameterNameDiscoverer adviceParameterNameDiscoverer =
			new AspectJAdviceParameterNameDiscoverer(this.pointcut.getExpression());
	adviceParameterNameDiscoverer.setReturningName(this.returningName);
	adviceParameterNameDiscoverer.setThrowingName(this.throwingName);
	// Last in chain, so if we're called and we fail, that's bad...
	adviceParameterNameDiscoverer.setRaiseExceptions(true);
	discoverer.addDiscoverer(adviceParameterNameDiscoverer);
	return discoverer;
}
 
Example #7
Source File: AbstractAspectJAdvice.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create a ParameterNameDiscoverer to be used for argument binding.
 * <p>The default implementation creates a {@link DefaultParameterNameDiscoverer}
 * and adds a specifically configured {@link AspectJAdviceParameterNameDiscoverer}.
 */
protected ParameterNameDiscoverer createParameterNameDiscoverer() {
	// We need to discover them, or if that fails, guess,
	// and if we can't guess with 100% accuracy, fail.
	DefaultParameterNameDiscoverer discoverer = new DefaultParameterNameDiscoverer();
	AspectJAdviceParameterNameDiscoverer adviceParameterNameDiscoverer =
			new AspectJAdviceParameterNameDiscoverer(this.pointcut.getExpression());
	adviceParameterNameDiscoverer.setReturningName(this.returningName);
	adviceParameterNameDiscoverer.setThrowingName(this.throwingName);
	// Last in chain, so if we're called and we fail, that's bad...
	adviceParameterNameDiscoverer.setRaiseExceptions(true);
	discoverer.addDiscoverer(adviceParameterNameDiscoverer);
	return discoverer;
}
 
Example #8
Source File: ExpressionEvaluator.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
LazyParamAwareEvaluationContext(Object rootObject, ParameterNameDiscoverer paramDiscoverer, Method method,
		Object[] args, Class<?> targetClass, Map<String, Method> methodCache) {
	super(rootObject);
	this.paramDiscoverer = paramDiscoverer;
	this.method = method;
	this.args = args;
	this.targetClass = targetClass;
	this.methodCache = methodCache;
}
 
Example #9
Source File: ParameterNameResolverTest.java    From eclair with Apache License 2.0 5 votes vote down vote up
@Test
public void tryToResolveNull() {
    // given
    ParameterNameDiscoverer discoverer = mock(ParameterNameDiscoverer.class);
    when(discoverer.getParameterNames(eq(method))).thenReturn(null);
    parameterNameResolver.setParameterNameDiscoverer(discoverer);
    // when
    List<String> parameterNames = parameterNameResolver.tryToResolve(method);
    // then
    assertThat(parameterNames, hasSize(2));
    assertThat(parameterNames.get(0), nullValue());
    assertThat(parameterNames.get(1), nullValue());
}
 
Example #10
Source File: HandlerMethodInvoker.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public HandlerMethodInvoker(HandlerMethodResolver methodResolver, WebBindingInitializer bindingInitializer,
		SessionAttributeStore sessionAttributeStore, ParameterNameDiscoverer parameterNameDiscoverer,
		WebArgumentResolver[] customArgumentResolvers, HttpMessageConverter<?>[] messageConverters) {

	this.methodResolver = methodResolver;
	this.bindingInitializer = bindingInitializer;
	this.sessionAttributeStore = sessionAttributeStore;
	this.parameterNameDiscoverer = parameterNameDiscoverer;
	this.customArgumentResolvers = customArgumentResolvers;
	this.messageConverters = messageConverters;
}
 
Example #11
Source File: MethodBasedEvaluationContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public MethodBasedEvaluationContext(Object rootObject, Method method, Object[] arguments,
		ParameterNameDiscoverer parameterNameDiscoverer) {

	super(rootObject);
	this.method = method;
	this.arguments = arguments;
	this.parameterNameDiscoverer = parameterNameDiscoverer;
}
 
Example #12
Source File: MethodBasedEvaluationContext.java    From java-technology-stack with MIT License 5 votes vote down vote up
public MethodBasedEvaluationContext(Object rootObject, Method method, Object[] arguments,
		ParameterNameDiscoverer parameterNameDiscoverer) {

	super(rootObject);
	this.method = method;
	this.arguments = arguments;
	this.parameterNameDiscoverer = parameterNameDiscoverer;
}
 
Example #13
Source File: DubboRouteScanner.java    From bird-java with MIT License 5 votes vote down vote up
/**
 * 获取方法参数名与类型的Map
 *
 * @param method method
 * @return map
 */
private Map<String, String> getParameterMap(Method method) {
    Map<String, String> map = new LinkedHashMap<>();

    ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
    String[] parameterNames = parameterNameDiscoverer.getParameterNames(method);
    Class<?>[] parameterTypes = method.getParameterTypes();
    if (parameterNames != null && ArrayUtils.isNotEmpty(parameterTypes) && parameterNames.length == parameterTypes.length) {
        for (int i = 0, len = parameterNames.length; i < len; i++) {
            map.put(parameterNames[i], parameterTypes[i].getName());
        }
    }
    return map;
}
 
Example #14
Source File: MethodBasedEvaluationContext.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public MethodBasedEvaluationContext(Object rootObject, Method method, Object[] arguments,
		ParameterNameDiscoverer parameterNameDiscoverer) {

	super(rootObject);
	this.method = method;
	this.arguments = arguments;
	this.parameterNameDiscoverer = parameterNameDiscoverer;
}
 
Example #15
Source File: AbstractAspectJAdvice.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create a ParameterNameDiscoverer to be used for argument binding.
 * <p>The default implementation creates a {@link DefaultParameterNameDiscoverer}
 * and adds a specifically configured {@link AspectJAdviceParameterNameDiscoverer}.
 */
protected ParameterNameDiscoverer createParameterNameDiscoverer() {
	// We need to discover them, or if that fails, guess,
	// and if we can't guess with 100% accuracy, fail.
	DefaultParameterNameDiscoverer discoverer = new DefaultParameterNameDiscoverer();
	AspectJAdviceParameterNameDiscoverer adviceParameterNameDiscoverer =
			new AspectJAdviceParameterNameDiscoverer(this.pointcut.getExpression());
	adviceParameterNameDiscoverer.setReturningName(this.returningName);
	adviceParameterNameDiscoverer.setThrowingName(this.throwingName);
	// Last in chain, so if we're called and we fail, that's bad...
	adviceParameterNameDiscoverer.setRaiseExceptions(true);
	discoverer.addDiscoverer(adviceParameterNameDiscoverer);
	return discoverer;
}
 
Example #16
Source File: MethodBasedEvaluationContext.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public MethodBasedEvaluationContext(Object rootObject, Method method, Object[] args,
		ParameterNameDiscoverer paramDiscoverer) {

	super(rootObject);
	this.method = method;
	this.args = args;
	this.paramDiscoverer = paramDiscoverer;
}
 
Example #17
Source File: AbstractAspectJAdvice.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create a ParameterNameDiscoverer to be used for argument binding.
 * <p>The default implementation creates a {@link DefaultParameterNameDiscoverer}
 * and adds a specifically configured {@link AspectJAdviceParameterNameDiscoverer}.
 */
protected ParameterNameDiscoverer createParameterNameDiscoverer() {
	// We need to discover them, or if that fails, guess,
	// and if we can't guess with 100% accuracy, fail.
	DefaultParameterNameDiscoverer discoverer = new DefaultParameterNameDiscoverer();
	AspectJAdviceParameterNameDiscoverer adviceParameterNameDiscoverer =
			new AspectJAdviceParameterNameDiscoverer(this.pointcut.getExpression());
	adviceParameterNameDiscoverer.setReturningName(this.returningName);
	adviceParameterNameDiscoverer.setThrowingName(this.throwingName);
	// Last in chain, so if we're called and we fail, that's bad...
	adviceParameterNameDiscoverer.setRaiseExceptions(true);
	discoverer.addDiscoverer(adviceParameterNameDiscoverer);
	return discoverer;
}
 
Example #18
Source File: HandlerMethodInvoker.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public HandlerMethodInvoker(HandlerMethodResolver methodResolver, WebBindingInitializer bindingInitializer,
		SessionAttributeStore sessionAttributeStore, ParameterNameDiscoverer parameterNameDiscoverer,
		WebArgumentResolver[] customArgumentResolvers, HttpMessageConverter<?>[] messageConverters) {

	this.methodResolver = methodResolver;
	this.bindingInitializer = bindingInitializer;
	this.sessionAttributeStore = sessionAttributeStore;
	this.parameterNameDiscoverer = parameterNameDiscoverer;
	this.customArgumentResolvers = customArgumentResolvers;
	this.messageConverters = messageConverters;
}
 
Example #19
Source File: RequestParamMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	resolver = new RequestParamMethodArgumentResolver(null, true);

	ParameterNameDiscoverer paramNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();

	Method method = getClass().getMethod("params", String.class, String[].class,
			Map.class, MultipartFile.class, List.class, MultipartFile[].class,
			Part.class, List.class, Part[].class, Map.class,
			String.class, MultipartFile.class, List.class, Part.class,
			MultipartFile.class, String.class, String.class, Optional.class);

	paramNamedDefaultValueString = new SynthesizingMethodParameter(method, 0);
	paramNamedStringArray = new SynthesizingMethodParameter(method, 1);
	paramNamedMap = new SynthesizingMethodParameter(method, 2);
	paramMultipartFile = new SynthesizingMethodParameter(method, 3);
	paramMultipartFileList = new SynthesizingMethodParameter(method, 4);
	paramMultipartFileArray = new SynthesizingMethodParameter(method, 5);
	paramPart = new SynthesizingMethodParameter(method, 6);
	paramPartList  = new SynthesizingMethodParameter(method, 7);
	paramPartArray  = new SynthesizingMethodParameter(method, 8);
	paramMap = new SynthesizingMethodParameter(method, 9);
	paramStringNotAnnot = new SynthesizingMethodParameter(method, 10);
	paramStringNotAnnot.initParameterNameDiscovery(paramNameDiscoverer);
	paramMultipartFileNotAnnot = new SynthesizingMethodParameter(method, 11);
	paramMultipartFileNotAnnot.initParameterNameDiscovery(paramNameDiscoverer);
	paramMultipartFileListNotAnnot = new SynthesizingMethodParameter(method, 12);
	paramMultipartFileListNotAnnot.initParameterNameDiscovery(paramNameDiscoverer);
	paramPartNotAnnot = new SynthesizingMethodParameter(method, 13);
	paramPartNotAnnot.initParameterNameDiscovery(paramNameDiscoverer);
	paramRequestPartAnnot = new SynthesizingMethodParameter(method, 14);
	paramRequired = new SynthesizingMethodParameter(method, 15);
	paramNotRequired = new SynthesizingMethodParameter(method, 16);
	paramOptional = new SynthesizingMethodParameter(method, 17);

	request = new MockHttpServletRequest();
	webRequest = new ServletWebRequest(request, new MockHttpServletResponse());
}
 
Example #20
Source File: DelegatingMethodParameter.java    From springdoc-openapi with Apache License 2.0 4 votes vote down vote up
@Override
public void initParameterNameDiscovery(ParameterNameDiscoverer parameterNameDiscoverer) {
	delegate.initParameterNameDiscovery(parameterNameDiscoverer);
}
 
Example #21
Source File: InvocableHandlerMethod.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Return the configured parameter name discoverer.
 */
public ParameterNameDiscoverer getParameterNameDiscoverer() {
	return this.parameterNameDiscoverer;
}
 
Example #22
Source File: CacheEvaluationContext.java    From java-technology-stack with MIT License 4 votes vote down vote up
CacheEvaluationContext(Object rootObject, Method method, Object[] arguments,
		ParameterNameDiscoverer parameterNameDiscoverer) {

	super(rootObject, method, arguments, parameterNameDiscoverer);
}
 
Example #23
Source File: SyncInvocableHandlerMethod.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Return the configured parameter name discoverer.
 */
public ParameterNameDiscoverer getParameterNameDiscoverer() {
	return this.delegate.getParameterNameDiscoverer();
}
 
Example #24
Source File: Application.java    From evernote-rest-webapp with Apache License 2.0 4 votes vote down vote up
/**
 * To maximize the caching feature in name discoverer, inject as a bean instead of creating every time.
 */
@Bean
public ParameterNameDiscoverer parameterNameDiscoverer() {
	return new DefaultParameterNameDiscoverer();
}
 
Example #25
Source File: InvocableHandlerMethod.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Return the configured parameter name discoverer.
 */
public ParameterNameDiscoverer getParameterNameDiscoverer() {
	return this.parameterNameDiscoverer;
}
 
Example #26
Source File: AbstractAutowireCapableBeanFactory.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Return the ParameterNameDiscoverer to use for resolving method parameter
 * names if needed.
 */
@Nullable
protected ParameterNameDiscoverer getParameterNameDiscoverer() {
	return this.parameterNameDiscoverer;
}
 
Example #27
Source File: SpelResolverConfiguration.java    From resilience4j with Apache License 2.0 4 votes vote down vote up
@Bean
public SpelResolver spelResolver(SpelExpressionParser spelExpressionParser, ParameterNameDiscoverer parameterNameDiscoverer) {
    return new SpelResolver(spelExpressionParser, parameterNameDiscoverer);
}
 
Example #28
Source File: SpelResolver.java    From resilience4j with Apache License 2.0 4 votes vote down vote up
public SpelResolver(SpelExpressionParser spelExpressionParser, ParameterNameDiscoverer parameterNameDiscoverer) {
    this.expressionParser = spelExpressionParser;
    this.parameterNameDiscoverer = parameterNameDiscoverer;
}
 
Example #29
Source File: CacheEvaluationContext.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
CacheEvaluationContext(Object rootObject, Method method, Object[] arguments,
		ParameterNameDiscoverer parameterNameDiscoverer) {

	super(rootObject, method, arguments, parameterNameDiscoverer);
}
 
Example #30
Source File: CacheEvaluationContext.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
CacheEvaluationContext(Object rootObject, Method method, Object[] args,
		ParameterNameDiscoverer paramDiscoverer) {

	super(rootObject, method, args, paramDiscoverer);
	this.unavailableVariables = new ArrayList<String>();
}