committed by
Christoph Strobl
parent
0671862ed8
commit
e9901e7df8
@@ -102,7 +102,7 @@ class EvaluationContextExtensionInformation {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this extension provides {@link ExpressionDependencies.ExpressionDependency}.
|
||||
* Return {@literal true} if this extension provides {@link ExpressionDependencies.ExpressionDependency}.
|
||||
*
|
||||
* @param dependency the expression dependency.
|
||||
* @return {@literal true} if {@link ExpressionDependencies.ExpressionDependency} is provided by this root object or
|
||||
@@ -159,7 +159,7 @@ class EvaluationContextExtensionInformation {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this extension provides {@link ExpressionDependencies.ExpressionDependency}.
|
||||
* Return {@literal true} if this extension provides {@link ExpressionDependencies.ExpressionDependency}.
|
||||
*
|
||||
* @param dependency the expression dependency.
|
||||
* @return {@literal true} if {@link ExpressionDependencies.ExpressionDependency} is provided by this root object.
|
||||
|
||||
@@ -34,12 +34,12 @@ public interface EvaluationContextProvider {
|
||||
* A simple default {@link EvaluationContextProvider} returning a {@link StandardEvaluationContext} with the given
|
||||
* root object.
|
||||
*/
|
||||
static EvaluationContextProvider DEFAULT = rootObject -> rootObject == null //
|
||||
EvaluationContextProvider DEFAULT = rootObject -> rootObject == null //
|
||||
? new StandardEvaluationContext() //
|
||||
: new StandardEvaluationContext(rootObject);
|
||||
|
||||
/**
|
||||
* Returns an {@link EvaluationContext} built using the given parameter values.
|
||||
* Return a {@link EvaluationContext} built using the given parameter values.
|
||||
*
|
||||
* @param rootObject the root object to set in the {@link EvaluationContext}.
|
||||
* @return
|
||||
@@ -47,10 +47,10 @@ public interface EvaluationContextProvider {
|
||||
EvaluationContext getEvaluationContext(Object rootObject);
|
||||
|
||||
/**
|
||||
* Returns a tailored {@link EvaluationContext} built using the given parameter values and considering
|
||||
* {@link ExpressionDependencies.ExpressionDependency expression dependencies}. The returned {@link EvaluationContext}
|
||||
* may contain a reduced visibility of methods and properties/fields according to the required
|
||||
* {@link ExpressionDependencies.ExpressionDependency expression dependencies}.
|
||||
* Return a tailored {@link EvaluationContext} built using the given parameter values and considering
|
||||
* {@link ExpressionDependencies expression dependencies}. The returned {@link EvaluationContext} may contain a
|
||||
* reduced visibility of methods and properties/fields according to the required {@link ExpressionDependencies
|
||||
* expression dependencies}.
|
||||
*
|
||||
* @param rootObject the root object to set in the {@link EvaluationContext}.
|
||||
* @param dependencies the requested expression dependencies to be available.
|
||||
|
||||
@@ -179,21 +179,21 @@ public class ExpressionDependencies implements Streamable<ExpressionDependencies
|
||||
/**
|
||||
* Create a new {@link ExpressionDependency} for a method.
|
||||
*
|
||||
* @param symbol the method name.
|
||||
* @return
|
||||
* @param methodName the method name.
|
||||
* @return a method dependency on {@code methodName}.
|
||||
*/
|
||||
public static ExpressionDependency forMethod(String symbol) {
|
||||
return new ExpressionDependency(DependencyType.METHOD, symbol, 0);
|
||||
public static ExpressionDependency forMethod(String methodName) {
|
||||
return new ExpressionDependency(DependencyType.METHOD, methodName, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link ExpressionDependency} for a property or field.
|
||||
*
|
||||
* @param symbol the property/field name.
|
||||
* @return
|
||||
* @param fieldOrPropertyName the property/field name.
|
||||
* @return a method dependency on {@code fieldOrPropertyName}.
|
||||
*/
|
||||
public static ExpressionDependency forPropertyOrField(String symbol) {
|
||||
return new ExpressionDependency(DependencyType.PROPERTY, symbol, 0);
|
||||
public static ExpressionDependency forPropertyOrField(String fieldOrPropertyName) {
|
||||
return new ExpressionDependency(DependencyType.PROPERTY, fieldOrPropertyName, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -59,13 +59,14 @@ import org.springframework.util.Assert;
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @author Jens Schauder
|
||||
* @author Mark Paluch
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ExtensionAwareEvaluationContextProvider implements EvaluationContextProvider {
|
||||
|
||||
private final Map<Class<?>, EvaluationContextExtensionInformation> extensionInformationCache = new ConcurrentHashMap<>();
|
||||
|
||||
private final Lazy<? extends Collection<? extends ExtensionIdAware>> extensions;
|
||||
|
||||
private ListableBeanFactory beanFactory;
|
||||
|
||||
ExtensionAwareEvaluationContextProvider() {
|
||||
@@ -80,7 +81,7 @@ public class ExtensionAwareEvaluationContextProvider implements EvaluationContex
|
||||
*/
|
||||
public ExtensionAwareEvaluationContextProvider(ListableBeanFactory beanFactory) {
|
||||
|
||||
this(Lazy.of(() -> getExtensionsFrom(beanFactory)));
|
||||
this(Lazy.of(() -> beanFactory.getBeansOfType(ExtensionIdAware.class, true, false).values()));
|
||||
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
@@ -142,12 +143,12 @@ public class ExtensionAwareEvaluationContextProvider implements EvaluationContex
|
||||
return this.extensions.get();
|
||||
}
|
||||
|
||||
Collection<? extends EvaluationContextExtension> getExtensions(
|
||||
private Collection<? extends EvaluationContextExtension> getExtensions(
|
||||
Predicate<EvaluationContextExtensionInformation> extensionFilter) {
|
||||
|
||||
Collection<EvaluationContextExtension> extensionsToUse = new ArrayList<>();
|
||||
|
||||
for (ExtensionIdAware candidate : this.extensions.get()) {
|
||||
for (ExtensionIdAware candidate : getExtensions()) {
|
||||
|
||||
if (candidate instanceof EvaluationContextExtension) {
|
||||
|
||||
@@ -161,16 +162,6 @@ public class ExtensionAwareEvaluationContextProvider implements EvaluationContex
|
||||
return extensionsToUse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up all {@link ExtensionIdAware} instances from the given {@link ListableBeanFactory}.
|
||||
*
|
||||
* @param beanFactory must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
private static Collection<? extends ExtensionIdAware> getExtensionsFrom(ListableBeanFactory beanFactory) {
|
||||
return beanFactory.getBeansOfType(ExtensionIdAware.class, true, false).values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up the {@link EvaluationContextExtensionInformation} for the given {@link EvaluationContextExtension} from
|
||||
* the cache or creates a new one and caches that for later lookup.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2020 the original author or authors.
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,7 +28,7 @@ import org.springframework.expression.EvaluationContext;
|
||||
public interface ReactiveEvaluationContextProvider extends EvaluationContextProvider {
|
||||
|
||||
/**
|
||||
* Returns an {@link EvaluationContext} built using the given parameter values.
|
||||
* Return a {@link EvaluationContext} built using the given parameter values.
|
||||
*
|
||||
* @param rootObject the root object to set in the {@link EvaluationContext}.
|
||||
* @return a mono that emits exactly one {@link EvaluationContext}.
|
||||
@@ -36,10 +36,10 @@ public interface ReactiveEvaluationContextProvider extends EvaluationContextProv
|
||||
Mono<? extends EvaluationContext> getEvaluationContextLater(Object rootObject);
|
||||
|
||||
/**
|
||||
* Returns a tailored {@link EvaluationContext} built using the given parameter values and considering
|
||||
* {@link ExpressionDependencies.ExpressionDependency expression dependencies}. The returned {@link EvaluationContext}
|
||||
* may contain a reduced visibility of methods and properties/fields according to the required
|
||||
* {@link ExpressionDependencies.ExpressionDependency expression dependencies}.
|
||||
* Return a tailored {@link EvaluationContext} built using the given parameter values and considering
|
||||
* {@link ExpressionDependencies expression dependencies}. The returned {@link EvaluationContext} may contain a
|
||||
* reduced visibility of methods and properties/fields according to the required {@link ExpressionDependencies
|
||||
* expression dependencies}.
|
||||
*
|
||||
* @param rootObject the root object to set in the {@link EvaluationContext}.
|
||||
* @param dependencies the requested expression dependencies to be available.
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.lang.Nullable;
|
||||
public interface EvaluationContextExtension extends ExtensionIdAware {
|
||||
|
||||
/**
|
||||
* Returns the properties exposed by the extension.
|
||||
* Return the properties exposed by the extension.
|
||||
*
|
||||
* @return the properties
|
||||
*/
|
||||
@@ -46,7 +46,7 @@ public interface EvaluationContextExtension extends ExtensionIdAware {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the functions exposed by the extension.
|
||||
* Return the functions exposed by the extension.
|
||||
*
|
||||
* @return the functions
|
||||
*/
|
||||
@@ -55,11 +55,11 @@ public interface EvaluationContextExtension extends ExtensionIdAware {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root object to be exposed by the extension. It's strongly recommended to declare the most concrete type
|
||||
* Return the root object to be exposed by the extension. It's strongly recommended to declare the most concrete type
|
||||
* possible as return type of the implementation method. This will allow us to obtain the necessary metadata once and
|
||||
* not for every evaluation.
|
||||
*
|
||||
* @return
|
||||
* @return the root object to be exposed by the extension.
|
||||
*/
|
||||
@Nullable
|
||||
default Object getRootObject() {
|
||||
|
||||
@@ -26,8 +26,8 @@ package org.springframework.data.spel.spi;
|
||||
public interface ExtensionIdAware {
|
||||
|
||||
/**
|
||||
* Returns the identifier of the extension. The id can be leveraged by users to fully qualify property lookups and
|
||||
* thus overcome ambiguities in case multiple extensions expose properties with the same name.
|
||||
* Return the identifier of the extension. The id can be leveraged by users to fully qualify property lookups and thus
|
||||
* overcome ambiguities in case multiple extensions expose properties with the same name.
|
||||
*
|
||||
* @return the extension id, must not be {@literal null}.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2020 the original author or authors.
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,9 +35,9 @@ import org.springframework.expression.EvaluationContext;
|
||||
public interface ReactiveEvaluationContextExtension extends ExtensionIdAware {
|
||||
|
||||
/**
|
||||
* Returns the {@link EvaluationContextExtension} to be consumed during the actual execution. It's strongly
|
||||
* recommended to declare the most concrete type possible as return type of the implementation method. This will allow
|
||||
* us to obtain the necessary metadata once and not for every evaluation.
|
||||
* Return the {@link EvaluationContextExtension} to be consumed during the actual execution. It's strongly recommended
|
||||
* to declare the most concrete type possible as return type of the implementation method. This will allow us to
|
||||
* obtain the necessary metadata once and not for every evaluation.
|
||||
*
|
||||
* @return the resolved {@link EvaluationContextExtension}. Publishers emitting no value will be skipped.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user