org.springframework.expression.MethodExecutor Java Examples
The following examples show how to use
org.springframework.expression.MethodExecutor.
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: MethodReference.java From spring-analysis-note with MIT License | 6 votes |
@Nullable private MethodExecutor getCachedExecutor(EvaluationContext evaluationContext, Object value, @Nullable TypeDescriptor target, List<TypeDescriptor> argumentTypes) { List<MethodResolver> methodResolvers = evaluationContext.getMethodResolvers(); if (methodResolvers.size() != 1 || !(methodResolvers.get(0) instanceof ReflectiveMethodResolver)) { // Not a default ReflectiveMethodResolver - don't know whether caching is valid return null; } CachedMethodExecutor executorToCheck = this.cachedExecutor; if (executorToCheck != null && executorToCheck.isSuitable(value, target, argumentTypes)) { return executorToCheck.get(); } this.cachedExecutor = null; return null; }
Example #2
Source File: SpelReproTests.java From java-technology-stack with MIT License | 6 votes |
/** * Test whether {@link ReflectiveMethodResolver} handles Widening Primitive Conversion. That's passing an 'int' to a * method accepting 'long' is ok. */ @Test public void wideningPrimitiveConversion_SPR8224() throws Exception { class WideningPrimitiveConversion { public int getX(long i) { return 10; } } final Integer INTEGER_VALUE = Integer.valueOf(7); WideningPrimitiveConversion target = new WideningPrimitiveConversion(); EvaluationContext emptyEvalContext = new StandardEvaluationContext(); List<TypeDescriptor> args = new ArrayList<>(); args.add(TypeDescriptor.forObject(INTEGER_VALUE)); MethodExecutor me = new ReflectiveMethodResolver(true).resolve(emptyEvalContext, target, "getX", args); final int actual = (Integer) me.execute(emptyEvalContext, target, INTEGER_VALUE).getValue(); final int compiler = target.getX(INTEGER_VALUE); assertEquals(compiler, actual); }
Example #3
Source File: Spr7538Tests.java From java-technology-stack with MIT License | 6 votes |
@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 #4
Source File: MethodReference.java From lams with GNU General Public License v2.0 | 6 votes |
private MethodExecutor getCachedExecutor(EvaluationContext evaluationContext, Object value, TypeDescriptor target, List<TypeDescriptor> argumentTypes) { List<MethodResolver> methodResolvers = evaluationContext.getMethodResolvers(); if (methodResolvers == null || methodResolvers.size() != 1 || !(methodResolvers.get(0) instanceof ReflectiveMethodResolver)) { // Not a default ReflectiveMethodResolver - don't know whether caching is valid return null; } CachedMethodExecutor executorToCheck = this.cachedExecutor; if (executorToCheck != null && executorToCheck.isSuitable(value, target, argumentTypes)) { return executorToCheck.get(); } this.cachedExecutor = null; return null; }
Example #5
Source File: MethodReference.java From lams with GNU General Public License v2.0 | 6 votes |
private MethodExecutor findAccessorForMethod(String name, List<TypeDescriptor> argumentTypes, Object targetObject, EvaluationContext evaluationContext) throws SpelEvaluationException { List<MethodResolver> methodResolvers = evaluationContext.getMethodResolvers(); if (methodResolvers != null) { for (MethodResolver methodResolver : methodResolvers) { try { MethodExecutor methodExecutor = methodResolver.resolve( evaluationContext, targetObject, name, argumentTypes); if (methodExecutor != null) { return methodExecutor; } } catch (AccessException ex) { throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.PROBLEM_LOCATING_METHOD, name, targetObject.getClass()); } } } throw new SpelEvaluationException(getStartPosition(), SpelMessage.METHOD_NOT_FOUND, FormatHelper.formatMethodForMessage(name, argumentTypes), FormatHelper.formatClassNameForMessage( targetObject instanceof Class ? ((Class<?>) targetObject) : targetObject.getClass())); }
Example #6
Source File: MethodReference.java From java-technology-stack with MIT License | 6 votes |
@Nullable private MethodExecutor getCachedExecutor(EvaluationContext evaluationContext, Object value, @Nullable TypeDescriptor target, List<TypeDescriptor> argumentTypes) { List<MethodResolver> methodResolvers = evaluationContext.getMethodResolvers(); if (methodResolvers.size() != 1 || !(methodResolvers.get(0) instanceof ReflectiveMethodResolver)) { // Not a default ReflectiveMethodResolver - don't know whether caching is valid return null; } CachedMethodExecutor executorToCheck = this.cachedExecutor; if (executorToCheck != null && executorToCheck.isSuitable(value, target, argumentTypes)) { return executorToCheck.get(); } this.cachedExecutor = null; return null; }
Example #7
Source File: Spr7538Tests.java From spring-analysis-note with MIT License | 6 votes |
@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 #8
Source File: MethodReference.java From spring4-understanding with Apache License 2.0 | 6 votes |
private MethodExecutor getCachedExecutor(EvaluationContext evaluationContext, Object value, TypeDescriptor target, List<TypeDescriptor> argumentTypes) { List<MethodResolver> methodResolvers = evaluationContext.getMethodResolvers(); if (methodResolvers == null || methodResolvers.size() != 1 || !(methodResolvers.get(0) instanceof ReflectiveMethodResolver)) { // Not a default ReflectiveMethodResolver - don't know whether caching is valid return null; } CachedMethodExecutor executorToCheck = this.cachedExecutor; if (executorToCheck != null && executorToCheck.isSuitable(value, target, argumentTypes)) { return executorToCheck.get(); } this.cachedExecutor = null; return null; }
Example #9
Source File: SpelReproTests.java From spring-analysis-note with MIT License | 6 votes |
/** * Test whether {@link ReflectiveMethodResolver} handles Widening Primitive Conversion. That's passing an 'int' to a * method accepting 'long' is ok. */ @Test public void wideningPrimitiveConversion_SPR8224() throws Exception { class WideningPrimitiveConversion { public int getX(long i) { return 10; } } final Integer INTEGER_VALUE = Integer.valueOf(7); WideningPrimitiveConversion target = new WideningPrimitiveConversion(); EvaluationContext emptyEvalContext = new StandardEvaluationContext(); List<TypeDescriptor> args = new ArrayList<>(); args.add(TypeDescriptor.forObject(INTEGER_VALUE)); MethodExecutor me = new ReflectiveMethodResolver(true).resolve(emptyEvalContext, target, "getX", args); final int actual = (Integer) me.execute(emptyEvalContext, target, INTEGER_VALUE).getValue(); final int compiler = target.getX(INTEGER_VALUE); assertEquals(compiler, actual); }
Example #10
Source File: MethodReference.java From spring4-understanding with Apache License 2.0 | 6 votes |
private MethodExecutor findAccessorForMethod(String name, List<TypeDescriptor> argumentTypes, Object targetObject, EvaluationContext evaluationContext) throws SpelEvaluationException { List<MethodResolver> methodResolvers = evaluationContext.getMethodResolvers(); if (methodResolvers != null) { for (MethodResolver methodResolver : methodResolvers) { try { MethodExecutor methodExecutor = methodResolver.resolve( evaluationContext, targetObject, name, argumentTypes); if (methodExecutor != null) { return methodExecutor; } } catch (AccessException ex) { throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.PROBLEM_LOCATING_METHOD, name, targetObject.getClass()); } } } throw new SpelEvaluationException(getStartPosition(), SpelMessage.METHOD_NOT_FOUND, FormatHelper.formatMethodForMessage(name, argumentTypes), FormatHelper.formatClassNameForMessage( targetObject instanceof Class ? ((Class<?>) targetObject) : targetObject.getClass())); }
Example #11
Source File: SpelReproTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Test whether {@link ReflectiveMethodResolver} handles Widening Primitive Conversion. That's passing an 'int' to a * method accepting 'long' is ok. */ @Test public void wideningPrimitiveConversion_8224() throws Exception { class WideningPrimitiveConversion { public int getX(long i) { return 10; } } final Integer INTEGER_VALUE = Integer.valueOf(7); WideningPrimitiveConversion target = new WideningPrimitiveConversion(); EvaluationContext emptyEvalContext = new StandardEvaluationContext(); List<TypeDescriptor> args = new ArrayList<TypeDescriptor>(); args.add(TypeDescriptor.forObject(INTEGER_VALUE)); MethodExecutor me = new ReflectiveMethodResolver(true).resolve(emptyEvalContext, target, "getX", args); final int actual = (Integer) me.execute(emptyEvalContext, target, INTEGER_VALUE).getValue(); final int compiler = target.getX(INTEGER_VALUE); assertEquals(compiler, actual); }
Example #12
Source File: Spr7538Tests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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 #13
Source File: SpelTaskEvaluator.java From piper with Apache License 2.0 | 6 votes |
private SpelTaskEvaluator(Builder aBuilder) { Map<String,MethodExecutor> map = new HashMap<> (); map.put("boolean", new Cast<>(Boolean.class)); map.put("byte", new Cast<>(Byte.class)); map.put("char", new Cast<>(Character.class)); map.put("short", new Cast<>(Short.class)); map.put("int", new Cast<>(Integer.class)); map.put("long", new Cast<>(Long.class)); map.put("float", new Cast<>(Float.class)); map.put("double", new Cast<>(Double.class)); map.put("systemProperty", new SystemProperty()); map.put("range", new Range()); map.put("join", new Join()); map.put("concat", new Concat()); map.put("flatten", new Flatten()); map.put("uuid", new Uuid()); map.put("stringf", new StringFormat()); map.put("sort", new Sort()); map.put("timestamp", new Timestamp()); map.put("now", new Now()); map.put("dateFormat", new DateFormat()); map.put("config", new Config(aBuilder.environment)); map.putAll(aBuilder.methodExecutors); methodExecutors = Collections.unmodifiableMap(map); }
Example #14
Source File: MethodReference.java From spring4-understanding with Apache License 2.0 | 5 votes |
public CachedMethodExecutor(MethodExecutor methodExecutor, Class<?> staticClass, TypeDescriptor target, List<TypeDescriptor> argumentTypes) { this.methodExecutor = methodExecutor; this.staticClass = staticClass; this.target = target; this.argumentTypes = argumentTypes; }
Example #15
Source File: ScenariosForSpringSecurity.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List<TypeDescriptor> arguments) throws AccessException { if (name.equals("hasRole")) { return new HasRoleExecutor(context.getTypeConverter()); } return null; }
Example #16
Source File: MethodReference.java From lams with GNU General Public License v2.0 | 5 votes |
public CachedMethodExecutor(MethodExecutor methodExecutor, Class<?> staticClass, TypeDescriptor target, List<TypeDescriptor> argumentTypes) { this.methodExecutor = methodExecutor; this.staticClass = staticClass; this.target = target; this.argumentTypes = argumentTypes; }
Example #17
Source File: RestrictedMethodResolver.java From scheduling with GNU Affero General Public License v3.0 | 5 votes |
@Override public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List<TypeDescriptor> argumentTypes) throws AccessException { if (unAuthorizedMethods.contains(name)) { throw new AccessException("Unauthorized method: " + name); } return super.resolve(context, targetObject, name, argumentTypes); }
Example #18
Source File: ScenariosForSpringSecurity.java From java-technology-stack with MIT License | 5 votes |
@Override public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List<TypeDescriptor> arguments) throws AccessException { if (name.equals("hasRole")) { return new HasRoleExecutor(context.getTypeConverter()); } return null; }
Example #19
Source File: MethodReference.java From spring-analysis-note with MIT License | 5 votes |
private MethodExecutor findAccessorForMethod(List<TypeDescriptor> argumentTypes, Object targetObject, EvaluationContext evaluationContext) throws SpelEvaluationException { AccessException accessException = null; List<MethodResolver> methodResolvers = evaluationContext.getMethodResolvers(); for (MethodResolver methodResolver : methodResolvers) { try { MethodExecutor methodExecutor = methodResolver.resolve( evaluationContext, targetObject, this.name, argumentTypes); if (methodExecutor != null) { return methodExecutor; } } catch (AccessException ex) { accessException = ex; break; } } String method = FormatHelper.formatMethodForMessage(this.name, argumentTypes); String className = FormatHelper.formatClassNameForMessage( targetObject instanceof Class ? ((Class<?>) targetObject) : targetObject.getClass()); if (accessException != null) { throw new SpelEvaluationException( getStartPosition(), accessException, SpelMessage.PROBLEM_LOCATING_METHOD, method, className); } else { throw new SpelEvaluationException(getStartPosition(), SpelMessage.METHOD_NOT_FOUND, method, className); } }
Example #20
Source File: DataBindingMethodResolver.java From java-technology-stack with MIT License | 5 votes |
@Override @Nullable public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List<TypeDescriptor> argumentTypes) throws AccessException { if (targetObject instanceof Class) { throw new IllegalArgumentException("DataBindingMethodResolver does not support Class targets"); } return super.resolve(context, targetObject, name, argumentTypes); }
Example #21
Source File: MethodReference.java From spring-analysis-note with MIT License | 5 votes |
public CachedMethodExecutor(MethodExecutor methodExecutor, @Nullable Class<?> staticClass, @Nullable TypeDescriptor target, List<TypeDescriptor> argumentTypes) { this.methodExecutor = methodExecutor; this.staticClass = staticClass; this.target = target; this.argumentTypes = argumentTypes; }
Example #22
Source File: MethodReference.java From java-technology-stack with MIT License | 5 votes |
public CachedMethodExecutor(MethodExecutor methodExecutor, @Nullable Class<?> staticClass, @Nullable TypeDescriptor target, List<TypeDescriptor> argumentTypes) { this.methodExecutor = methodExecutor; this.staticClass = staticClass; this.target = target; this.argumentTypes = argumentTypes; }
Example #23
Source File: MethodReference.java From java-technology-stack with MIT License | 5 votes |
private MethodExecutor findAccessorForMethod(List<TypeDescriptor> argumentTypes, Object targetObject, EvaluationContext evaluationContext) throws SpelEvaluationException { AccessException accessException = null; List<MethodResolver> methodResolvers = evaluationContext.getMethodResolvers(); for (MethodResolver methodResolver : methodResolvers) { try { MethodExecutor methodExecutor = methodResolver.resolve( evaluationContext, targetObject, this.name, argumentTypes); if (methodExecutor != null) { return methodExecutor; } } catch (AccessException ex) { accessException = ex; break; } } String method = FormatHelper.formatMethodForMessage(this.name, argumentTypes); String className = FormatHelper.formatClassNameForMessage( targetObject instanceof Class ? ((Class<?>) targetObject) : targetObject.getClass()); if (accessException != null) { throw new SpelEvaluationException( getStartPosition(), accessException, SpelMessage.PROBLEM_LOCATING_METHOD, method, className); } else { throw new SpelEvaluationException(getStartPosition(), SpelMessage.METHOD_NOT_FOUND, method, className); } }
Example #24
Source File: ScenariosForSpringSecurity.java From spring-analysis-note with MIT License | 5 votes |
@Override public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List<TypeDescriptor> arguments) throws AccessException { if (name.equals("hasRole")) { return new HasRoleExecutor(context.getTypeConverter()); } return null; }
Example #25
Source File: DataBindingMethodResolver.java From spring-analysis-note with MIT License | 5 votes |
@Override @Nullable public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List<TypeDescriptor> argumentTypes) throws AccessException { if (targetObject instanceof Class) { throw new IllegalArgumentException("DataBindingMethodResolver does not support Class targets"); } return super.resolve(context, targetObject, name, argumentTypes); }
Example #26
Source File: MethodInvocationTests.java From spring-analysis-note with MIT License | 4 votes |
@Override public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List<TypeDescriptor> argumentTypes) throws AccessException { throw new UnsupportedOperationException(); }
Example #27
Source File: SpelTaskEvaluator.java From piper with Apache License 2.0 | 4 votes |
public Builder methodExecutor (String aMethodName, MethodExecutor aMethodExecutor) { methodExecutors.put(aMethodName, aMethodExecutor); return this; }
Example #28
Source File: MethodReference.java From spring-analysis-note with MIT License | 4 votes |
public MethodExecutor get() { return this.methodExecutor; }
Example #29
Source File: SpelReproTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@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); }
Example #30
Source File: EvaluationTests.java From spring-analysis-note with MIT License | 4 votes |
@Override public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List<TypeDescriptor> argumentTypes) throws AccessException { return null; }