Print
Custom Variable Resolvers

MVEL supports use of custom variable resolvers for integrating into third-party frameworks and systems which may have a more efficient and direct way of accessing variables (or properties).

The facilities to extend this functionality are located in the package: org.mvel.integration. * with a set of default implementations in: org.mvel.integration.impl. *

The integration of external resolves consists of two interfaces, the VariableResolverFactory and the VariableResolver. As you may or may not gather, the VariableResolverFactory is responsible for obtaining and returning a VariableResolver which in turn allows reading and writing to external variables.

The org.mvel.integration.VariableResolverFactory interface

The VariableResolverFactory exists as part of a chain, with the root factory always consisting of either the default internal LocalVariableResolverFactory or the factory provided to the MVEL runtime.

Chaining of the factories is an essential part of how MVEL efficiently, and internally, maintains (and allows to be maintained externally) locality-of-reference. Put simply, there is always one factory per scope, and factories created as part of sub-scopes are destroyed when the scopes are destroyed, which allows for locality-of-reference rules to be maintained both inside and outside, and indeed across MVEL expressions within a particular implementation.

In many ways, factory chaining in MVEL is a analogue to Java Classloader Hierarchy, but with variable scopes instead of class definitions.

Since all this can be difficult to get your head around, and for the most part, the chaining of factories is a completely internal activity within MVEL, we provide you with a simple base implementation of the VariableResolverFactory which implements all the baseline behaviors required for well-behaved chains. The class is: org.mvel.integration.impl.BaseVariableResolverFactory .

The JavaDoc for the VariableResolverFactory is here.

Powered by Atlassian Confluence