There's a good discussion of this as a JEXL improvement at https://issues.apache.org/jira/browse/JEXL-140.
The guy who requested this proposed a solution that puts the burden on the JEXL programmer. It creates a String only to get the String class, which is only used to look up the desired class.
${''.class.forName('person').howYouDoing()}
...assuming that "person" is in the default package. This can be used to call static constructors for classes like Pattern for which there is no public constructor:
${''.class.forName('java.util.regex.Pattern').compile('\\d{2}-(\\w{3})-\\d{2}')}
By the way, the JEXL developers suggested subclassing JexlContext
to always return any class which exists. This is more elegant than requiring your template writers do the ''.class.forName()
hack, but since you didn't want to modify your MapContext
, it might not satisfy your question. It also pollutes your context with all classes.