Package freemarker.ext.beans
Class DefaultMemberAccessPolicy
- java.lang.Object
-
- freemarker.ext.beans.DefaultMemberAccessPolicy
-
- All Implemented Interfaces:
MemberAccessPolicy
public final class DefaultMemberAccessPolicy extends java.lang.Object implements MemberAccessPolicy
Member access policy, used to implement default behavior that's mostly compatible with pre-2.3.30 versions, but is somewhat safer; it still can't provide safety in practice, if you allow untrusted users to edit templates! UseWhitelistMemberAccessPolicy
if you need stricter control.- Since:
- 2.3.30
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ClassMemberAccessPolicy
forClass(java.lang.Class<?> contextClass)
Returns theClassMemberAccessPolicy
that encapsulates the member access policy for a given class.static DefaultMemberAccessPolicy
getInstance(Version incompatibleImprovements)
Returns the singleton that's compatible with the given incompatible improvements version.boolean
isToStringAlwaysExposed()
If this returnstrue
, we won't invoke the probably more expensive lookup to figure out ifObject.toString()
(including its overridden variants) is exposed for a given object.
-
-
-
Method Detail
-
getInstance
public static DefaultMemberAccessPolicy getInstance(Version incompatibleImprovements)
Returns the singleton that's compatible with the given incompatible improvements version.
-
forClass
public ClassMemberAccessPolicy forClass(java.lang.Class<?> contextClass)
Description copied from interface:MemberAccessPolicy
Returns theClassMemberAccessPolicy
that encapsulates the member access policy for a given class.ClassMemberAccessPolicy
implementations need not be thread-safe. Because class introspection results are cached, and so this method is usually only called once for a given class, theClassMemberAccessPolicy
instances shouldn't be cached by the implementation of this method.- Specified by:
forClass
in interfaceMemberAccessPolicy
- Parameters:
contextClass
- The exact class of object from which members will be get in the templates.
-
isToStringAlwaysExposed
public boolean isToStringAlwaysExposed()
Description copied from interface:MemberAccessPolicy
If this returnstrue
, we won't invoke the probably more expensive lookup to figure out ifObject.toString()
(including its overridden variants) is exposed for a given object. If this returnsfalse
, then no such optimization is made. This method was introduced asObject.toString()
is called frequently, as it's used whenever an object is converted to string, like printed to the output, and it's not even a reflection-based call (we just callObject.toString()
in Java). So we try to avoid the overhead of a more generic method call.- Specified by:
isToStringAlwaysExposed
in interfaceMemberAccessPolicy
-
-