Java Code Examples for org.springframework.expression.MethodExecutor#execute()

The following examples show how to use org.springframework.expression.MethodExecutor#execute() . 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: Spr7538Tests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Ignore @Test
public void repro() throws Exception {
	AlwaysTrueReleaseStrategy target = new AlwaysTrueReleaseStrategy();
	BeanFactoryTypeConverter converter = new BeanFactoryTypeConverter();

	StandardEvaluationContext context = new StandardEvaluationContext();
	context.setTypeConverter(converter);

	List<Foo> arguments = new ArrayList<>();

	// !!!! With the below line commented you'll get NPE. Uncomment and everything is OK!
	//arguments.add(new Foo());

	List<TypeDescriptor> paramDescriptors = new ArrayList<>();
	Method method = AlwaysTrueReleaseStrategy.class.getMethod("checkCompleteness", List.class);
	paramDescriptors.add(new TypeDescriptor(new MethodParameter(method, 0)));


	List<TypeDescriptor> argumentTypes = new ArrayList<>();
	argumentTypes.add(TypeDescriptor.forObject(arguments));
	ReflectiveMethodResolver resolver = new ReflectiveMethodResolver();
	MethodExecutor executor = resolver.resolve(context, target, "checkCompleteness", argumentTypes);

	Object result = executor.execute(context, target, arguments);
	System.out.println("Result: " + result);
}
 
Example 2
Source File: Spr7538Tests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Ignore @Test
public void repro() throws Exception {
	AlwaysTrueReleaseStrategy target = new AlwaysTrueReleaseStrategy();
	BeanFactoryTypeConverter converter = new BeanFactoryTypeConverter();

	StandardEvaluationContext context = new StandardEvaluationContext();
	context.setTypeConverter(converter);

	List<Foo> arguments = new ArrayList<>();

	// !!!! With the below line commented you'll get NPE. Uncomment and everything is OK!
	//arguments.add(new Foo());

	List<TypeDescriptor> paramDescriptors = new ArrayList<>();
	Method method = AlwaysTrueReleaseStrategy.class.getMethod("checkCompleteness", List.class);
	paramDescriptors.add(new TypeDescriptor(new MethodParameter(method, 0)));


	List<TypeDescriptor> argumentTypes = new ArrayList<>();
	argumentTypes.add(TypeDescriptor.forObject(arguments));
	ReflectiveMethodResolver resolver = new ReflectiveMethodResolver();
	MethodExecutor executor = resolver.resolve(context, target, "checkCompleteness", argumentTypes);

	Object result = executor.execute(context, target, arguments);
	System.out.println("Result: " + result);
}
 
Example 3
Source File: Spr7538Tests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Ignore @Test
public void repro() throws Exception {
	AlwaysTrueReleaseStrategy target = new AlwaysTrueReleaseStrategy();
	BeanFactoryTypeConverter converter = new BeanFactoryTypeConverter();

	StandardEvaluationContext context = new StandardEvaluationContext();
	context.setTypeConverter(converter);

	List<Foo> arguments = new ArrayList<Foo>();

	// !!!! With the below line commented you'll get NPE. Uncomment and everything is OK!
	//arguments.add(new Foo());

	List<TypeDescriptor> paramDescriptors = new ArrayList<TypeDescriptor>();
	Method method = AlwaysTrueReleaseStrategy.class.getMethod("checkCompleteness", List.class);
	paramDescriptors.add(new TypeDescriptor(new MethodParameter(method, 0)));


	List<TypeDescriptor> argumentTypes = new ArrayList<TypeDescriptor>();
	argumentTypes.add(TypeDescriptor.forObject(arguments));
	ReflectiveMethodResolver resolver = new ReflectiveMethodResolver();
	MethodExecutor executor = resolver.resolve(context, target, "checkCompleteness", argumentTypes);

	Object result = executor.execute(context, target, arguments);
	System.out.println("Result: " + result);
}
 
Example 4
Source File: SpelReproTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void varargsAndPrimitives_SPR8174() throws Exception {
	EvaluationContext emptyEvalContext = new StandardEvaluationContext();
	List<TypeDescriptor> args = new ArrayList<>();

	args.add(TypeDescriptor.forObject(34L));
	ReflectionUtil<Integer> ru = new ReflectionUtil<>();
	MethodExecutor me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "methodToCall", args);

	args.set(0, TypeDescriptor.forObject(23));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, 45);

	args.set(0, TypeDescriptor.forObject(23f));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, 45f);

	args.set(0, TypeDescriptor.forObject(23d));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, 23d);

	args.set(0, TypeDescriptor.forObject((short) 23));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, (short) 23);

	args.set(0, TypeDescriptor.forObject(23L));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, 23L);

	args.set(0, TypeDescriptor.forObject((char) 65));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, (char) 65);

	args.set(0, TypeDescriptor.forObject((byte) 23));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, (byte) 23);

	args.set(0, TypeDescriptor.forObject(true));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, true);

	// trickier:
	args.set(0, TypeDescriptor.forObject(12));
	args.add(TypeDescriptor.forObject(23f));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "bar", args);
	me.execute(emptyEvalContext, ru, 12, 23f);
}
 
Example 5
Source File: SpelReproTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void varargsAndPrimitives_SPR8174() throws Exception {
	EvaluationContext emptyEvalContext = new StandardEvaluationContext();
	List<TypeDescriptor> args = new ArrayList<>();

	args.add(TypeDescriptor.forObject(34L));
	ReflectionUtil<Integer> ru = new ReflectionUtil<>();
	MethodExecutor me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "methodToCall", args);

	args.set(0, TypeDescriptor.forObject(23));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, 45);

	args.set(0, TypeDescriptor.forObject(23f));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, 45f);

	args.set(0, TypeDescriptor.forObject(23d));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, 23d);

	args.set(0, TypeDescriptor.forObject((short) 23));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, (short) 23);

	args.set(0, TypeDescriptor.forObject(23L));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, 23L);

	args.set(0, TypeDescriptor.forObject((char) 65));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, (char) 65);

	args.set(0, TypeDescriptor.forObject((byte) 23));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, (byte) 23);

	args.set(0, TypeDescriptor.forObject(true));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, true);

	// trickier:
	args.set(0, TypeDescriptor.forObject(12));
	args.add(TypeDescriptor.forObject(23f));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "bar", args);
	me.execute(emptyEvalContext, ru, 12, 23f);
}
 
Example 6
Source File: SpelReproTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void varargsAndPrimitives_SPR8174() throws Exception {
	EvaluationContext emptyEvalContext = new StandardEvaluationContext();
	List<TypeDescriptor> args = new ArrayList<TypeDescriptor>();

	args.add(TypeDescriptor.forObject(34L));
	ReflectionUtil<Integer> ru = new ReflectionUtil<Integer>();
	MethodExecutor me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "methodToCall", args);

	args.set(0, TypeDescriptor.forObject(23));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, 45);

	args.set(0, TypeDescriptor.forObject(23f));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, 45f);

	args.set(0, TypeDescriptor.forObject(23d));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, 23d);

	args.set(0, TypeDescriptor.forObject((short) 23));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, (short) 23);

	args.set(0, TypeDescriptor.forObject(23L));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, 23L);

	args.set(0, TypeDescriptor.forObject((char) 65));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, (char) 65);

	args.set(0, TypeDescriptor.forObject((byte) 23));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, (byte) 23);

	args.set(0, TypeDescriptor.forObject(true));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "foo", args);
	me.execute(emptyEvalContext, ru, true);

	// trickier:
	args.set(0, TypeDescriptor.forObject(12));
	args.add(TypeDescriptor.forObject(23f));
	me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "bar", args);
	me.execute(emptyEvalContext, ru, 12, 23f);
}