クラス SimpleEvaluationContext
- 実装済みのインターフェース一覧:
EvaluationContext
EvaluationContext の基本的な実装で、単純な条件評価と特定のデータバインディングシナリオを対象としています。In many cases, the full extent of the SpEL language is not required and should be meaningfully restricted. Examples include but are not limited to data binding expressions, property-based filters, and others. To that effect, SimpleEvaluationContext is tailored to support only a subset of the SpEL language syntax — for example, excluding references to Java types, constructors, and bean references.
SimpleEvaluationContext を作成するときは、SpEL 式でのデータバインディングに必要なサポートレベルを選択する必要があります。
- 読み取り専用アクセスのデータバインディング
- 読み取りおよび書き込みアクセスのデータバインディング
- カスタム
PropertyAccessor(通常、反射ベースではない)、DataBindingPropertyAccessorと組み合わせる可能性
Conveniently, forReadOnlyDataBinding() enables read-only access to properties via DataBindingPropertyAccessor . Similarly, forReadWriteDataBinding() enables read and write access to properties. Alternatively, configure custom accessors via forPropertyAccessors(PropertyAccessor...), consider disabling assignment (recommended), and optionally activate method resolution and/or a type converter through the builder.
SimpleEvaluationContext は通常、デフォルトのルートオブジェクトで構成されていないことに注意してください。代わりに、一度作成され、EvaluationContext とルートオブジェクトの両方を引数として持つ定義済み Expression に対する getValue 呼び出しを通じて繰り返し使用されることを目的としています: Expression.getValue(EvaluationContext, Object)。
EvaluationContext API で定義されている変数の設定と検索のサポートに加え、SimpleEvaluationContext は関数を変数として登録および検索することもサポートします。この評価コンテキストでは関数は変数と共通の名前空間を共有するため、関数名と変数名が重複しないように注意する必要があります。
パワーと柔軟性を高めるため、特に内部構成のシナリオでは、代わりに StandardEvaluationContext の使用を検討してください。
WARNING: Although SimpleEvaluationContext restricts the SpEL language to a subset of its features, that restriction is provided on a best-effort basis and does not guarantee that evaluation of an expression is safe; SimpleEvaluationContext must not be considered safe for evaluating a SpEL expression obtained from an untrusted source. This responsibility extends to property accessors: restricting a SimpleEvaluationContext to read-only data binding governs only whether assignment to a property is permitted and does not verify that reading a property is free of side effects. See the セキュリティに関する考慮事項 and Object Design sections of the Spring Framework reference documentation, as well as the class-level documentation for ReflectivePropertyAccessor and DataBindingPropertyAccessor, for details.
Because a parsed Expression may cache accessor and executor state resolved against a particular EvaluationContext configuration, a parsed Expression must never be evaluated first against a StandardEvaluationContext (or any other, less restrictive, EvaluationContext) and later against a SimpleEvaluationContext. If the same expression string must be evaluated under both kinds of contexts, parse it into two distinct Expression instances instead. See Expression for further details on this lifecycle contract.
- 導入:
- 4.3.15
- 作成者:
- Rossen Stoyanchev, Juergen Hoeller, Sam Brannen
- 関連事項:
ネストされたクラスの概要
ネストされたクラス方法の概要
修飾子と型メソッド説明assignVariable(StringSE name, SupplierSE<TypedValue> valueSupplier) SimpleEvaluationContextは、式内での変数の割り当てをサポートしていません。forPropertyAccessors(PropertyAccessor... accessors) 指定されたPropertyAccessorデリゲートのSimpleEvaluationContextを作成します。通常は、ユースケースに固有のカスタムPropertyAccessorです (たとえば、カスタムデータ構造の属性解決用)。プロパティの逆参照も必要な場合は、DataBindingPropertyAccessorと組み合わせられる可能性があります。DataBindingPropertyAccessorを介してパブリックプロパティに読み取り専用でアクセスするSimpleEvaluationContextを作成します。DataBindingPropertyAccessorを介してパブリックプロパティへの読み取り / 書き込みアクセス用のSimpleEvaluationContextを作成します。SimpleEvaluationContextは、Bean 参照の使用をサポートしていません。指定されたIndexAccessorデリゲートがある場合はそれを返します。指定されたMethodResolverデリゲートがある場合はそれを返します。StandardOperatorOverloaderのインスタンスを返します。指定されたPropertyAccessorデリゲートがある場合はそれを返します。指定されたルートオブジェクトがあれば、それを返します。StandardTypeComparatorのインスタンスを返します。構成されたTypeConverter。SimpleEvaluationContextは型参照の使用をサポートしていません。booleanこの評価コンテキストによって評価される式内で割り当てが有効になっているかどうかを判断します。booleanDetermine if compilation is supported within expressions evaluated by this evaluation context.lookupVariable(StringSE name) この評価コンテキスト内で名前付き変数または関数を検索します。voidsetVariable(StringSE name, @Nullable ObjectSE value) この評価コンテキストの名前付き変数または関数を指定された値に設定します。クラス ObjectSE から継承されたメソッド
clone, equalsSE, finalize, getClass, hashCode, notify, notifyAll, toString, wait, waitSE, waitSEインターフェース EvaluationContext から継承されたメソッド
getConstructorResolvers
方法の詳細
getRootObject
指定されたルートオブジェクトがあれば、それを返します。- 次で指定:
- インターフェース
EvaluationContext内のgetRootObject
getPropertyAccessors
指定されたPropertyAccessorデリゲートがある場合はそれを返します。- 次で指定:
- インターフェース
EvaluationContext内のgetPropertyAccessors - 関連事項:
getIndexAccessors
指定されたIndexAccessorデリゲートがある場合はそれを返します。- 次で指定:
- インターフェース
EvaluationContext内のgetIndexAccessors - 導入:
- 6.2
- 関連事項:
getMethodResolvers
指定されたMethodResolverデリゲートがある場合はそれを返します。- 次で指定:
- インターフェース
EvaluationContext内のgetMethodResolvers - 関連事項:
getBeanResolver
SimpleEvaluationContextは、Bean 参照の使用をサポートしていません。- 次で指定:
- インターフェース
EvaluationContext内のgetBeanResolver - 戻り値:
- 常に
null
getTypeLocator
SimpleEvaluationContextは型参照の使用をサポートしていません。- 次で指定:
- インターフェース
EvaluationContext内のgetTypeLocator - 戻り値:
-
SpelEvaluationExceptionをSpelMessage.TYPE_NOT_FOUNDで発生させるTypeLocator実装
getTypeConverter
構成されたTypeConverter。デフォルトでは、これは
StandardTypeConverterです。- 次で指定:
- インターフェース
EvaluationContext内のgetTypeConverter - 関連事項:
getTypeComparator
StandardTypeComparatorのインスタンスを返します。- 次で指定:
- インターフェース
EvaluationContext内のgetTypeComparator
getOperatorOverloader
StandardOperatorOverloaderのインスタンスを返します。- 次で指定:
- インターフェース
EvaluationContext内のgetOperatorOverloader
assignVariable
SimpleEvaluationContextは、式内での変数の割り当てをサポートしていません。- 次で指定:
- インターフェース
EvaluationContext内のassignVariable - パラメーター:
name- 割り当てる変数の名前valueSupplier- 変数に割り当てられる値のサプライヤー- 戻り値:
- 割り当てられた値をラップする
TypedValue - 例外:
SpelEvaluationException-SpelMessage.VARIABLE_ASSIGNMENT_NOT_SUPPORTEDを使用する場合- 導入:
- 5.2.24
setVariable
この評価コンテキストの名前付き変数または関数を指定された値に設定します。関数は
MethodSE またはMethodHandleSE として登録できます。この評価コンテキストでは、変数と関数が共通の名前空間を共有することに注意してください。詳細については、クラスレベルのドキュメントを参照してください。
- 次で指定:
- インターフェース
EvaluationContext内のsetVariable - パラメーター:
name- 設定する変数または関数の名前value- 変数または関数に入れる値- 関連事項:
lookupVariable
この評価コンテキスト内で名前付き変数または関数を検索します。この評価コンテキストでは、変数と関数が共通の名前空間を共有することに注意してください。詳細については、クラスレベルのドキュメントを参照してください。
- 次で指定:
- インターフェース
EvaluationContext内のlookupVariable - パラメーター:
name- 検索する変数または関数の名前- 戻り値:
- 変数または関数の値、見つからない場合は
null
isAssignmentEnabled
public boolean isAssignmentEnabled()この評価コンテキストによって評価される式内で割り当てが有効になっているかどうかを判断します。このメソッドが
falseを返す場合、代入 (=)、増分 (++)、および減分 (--) 演算子は無効になります。- 次で指定:
- インターフェース
EvaluationContext内のisAssignmentEnabled - 戻り値:
- 割り当てが有効な場合は
true、そうでない場合はfalse - 導入:
- 5.3.38
- 関連事項:
isCompilationSupported
public boolean isCompilationSupported()Determine if compilation is supported within expressions evaluated by this evaluation context.By default, compilation is not supported in
SimpleEvaluationContext.- 次で指定:
- インターフェース
EvaluationContext内のisCompilationSupported - 戻り値:
trueif compilation is supported;falseotherwise- 導入:
- 7.0.9
- 関連事項:
forPropertyAccessors
指定されたPropertyAccessorデリゲートのSimpleEvaluationContextを作成します。通常は、ユースケースに固有のカスタムPropertyAccessorです (たとえば、カスタムデータ構造の属性解決用)。プロパティの逆参照も必要な場合は、DataBindingPropertyAccessorと組み合わせられる可能性があります。デフォルトでは、このファクトリメソッドを介して作成されたコンテキストによって評価される式内で割り当てが有効になっていますが、
SimpleEvaluationContext.Builder.withAssignmentDisabled()を介して割り当てを無効にすることができます。- パラメーター:
accessors- 使用するアクセサーデリゲート- 関連事項:
forReadOnlyDataBinding
DataBindingPropertyAccessorを介してパブリックプロパティに読み取り専用でアクセスするSimpleEvaluationContextを作成します。このファクトリメソッドを介して作成されたコンテキストによって評価される式内では、割り当ては無効になります。
- 関連事項:
forReadWriteDataBinding
DataBindingPropertyAccessorを介してパブリックプロパティへの読み取り / 書き込みアクセス用のSimpleEvaluationContextを作成します。デフォルトでは、このファクトリメソッドを介して作成されたコンテキストによって評価される式内で割り当てが有効になっています。割り当ては
SimpleEvaluationContext.Builder.withAssignmentDisabled()を介して無効にできますが、読み取り専用アクセスが必要な場合はforReadOnlyDataBinding()を使用することをお勧めします。- 関連事項: