Package freemarker.ext.beans
Class MemberSelectorListMemberAccessPolicy.MemberSelector
java.lang.Object
freemarker.ext.beans.MemberSelectorListMemberAccessPolicy.MemberSelector
- Enclosing class:
- MemberSelectorListMemberAccessPolicy
A condition that matches some type members. See
MemberSelectorListMemberAccessPolicy
documentation for more.
Exactly one of these will be non-null
:
getMethod()
, getConstructor()
, getField()
.- Since:
- 2.3.30
-
Constructor Summary
ConstructorDescriptionMemberSelector(Class<?> upperBoundType, Constructor<?> constructor)
Use if you want to match constructors similar to the specified one, in types that areinstanceof
of the specified upper bound type.MemberSelector(Class<?> upperBoundType, Field field)
Use if you want to match fields similar to the specified one, in types that areinstanceof
of the specified upper bound type.MemberSelector(Class<?> upperBoundType, Method method)
Use if you want to match methods similar to the specified one, in types that areinstanceof
of the specified upper bound type. -
Method Summary
Modifier and TypeMethodDescriptionConstructor<?>
Maybenull
; set if the selector matches constructors similar to the returned one.getField()
Maybenull
; set if the selector matches fields similar to the returned one.Maybenull
; set if the selector matches methods similar to the returned one.Class<?>
Notnull
.static boolean
isIgnoredLine(String line)
A line is ignored if it's blank or a comment.parse(String memberSelectorString, ClassLoader classLoader)
Parses a member selector that was specified with a string.parse(Collection<String> memberSelectors, boolean ignoreMissingClassOrMember, ClassLoader classLoader)
Convenience method to parse all member selectors in the collection (seeparse(String, ClassLoader)
), while also filtering out blank and comment lines; seeparse(String, ClassLoader)
, andisIgnoredLine(String)
.
-
Constructor Details
-
MemberSelector
Use if you want to match methods similar to the specified one, in types that areinstanceof
of the specified upper bound type. When methods are matched, only the name and the parameter types matter. -
MemberSelector
Use if you want to match constructors similar to the specified one, in types that areinstanceof
of the specified upper bound type. When constructors are matched, only the parameter types matter. -
MemberSelector
Use if you want to match fields similar to the specified one, in types that areinstanceof
of the specified upper bound type. When fields are matched, only the name matters.
-
-
Method Details
-
getUpperBoundType
Notnull
. -
getMethod
Maybenull
; set if the selector matches methods similar to the returned one. -
getConstructor
Maybenull
; set if the selector matches constructors similar to the returned one. -
getField
Maybenull
; set if the selector matches fields similar to the returned one. -
parse
public static MemberSelectorListMemberAccessPolicy.MemberSelector parse(String memberSelectorString, ClassLoader classLoader) throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldExceptionParses a member selector that was specified with a string.- Parameters:
classLoader
- Used to resolve class names in the member selectors. Generally you want to pick a class that belongs to you application (not to a 3rd party library, like FreeMarker), and then callClass.getClassLoader()
on that. Note that the resolution of the classes is not lazy, and so theClassLoader
won't be stored after this method returns.memberSelectorString
- Describes the member (method, constructor, field) which you want to whitelist. Starts with the full qualified name of the member, likecom.example.MyClass.myMember
. Unless it's a field, the name is followed by comma separated list of the parameter types inside parentheses, like incom.example.MyClass.myMember(java.lang.String, boolean)
. The parameter type names must be also full qualified names, except primitive type names. Array types must be indicated with one or more[]
-s after the type name. Varargs arguments shouldn't be marked with...
, but with[]
. In the member name, likecom.example.MyClass.myMember
, the class refers to the so called "upper bound class". Regarding that and inheritance rules see the class level documentation.- Throws:
ClassNotFoundException
- If a type referred in the member selector can't be found.NoSuchMethodException
- If the method or constructor referred in the member selector can't be found.NoSuchFieldException
- If the field referred in the member selector can't be found.
-
parse
public static List<MemberSelectorListMemberAccessPolicy.MemberSelector> parse(Collection<String> memberSelectors, boolean ignoreMissingClassOrMember, ClassLoader classLoader) throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldExceptionConvenience method to parse all member selectors in the collection (seeparse(String, ClassLoader)
), while also filtering out blank and comment lines; seeparse(String, ClassLoader)
, andisIgnoredLine(String)
.- Parameters:
ignoreMissingClassOrMember
- Iftrue
, members selectors that throw exceptions because the referred type or member can't be found will be silently ignored. Iftrue
, same exceptions will be just thrown by this method.- Throws:
ClassNotFoundException
NoSuchMethodException
NoSuchFieldException
-
isIgnoredLine
A line is ignored if it's blank or a comment. A line is be blank if it doesn't contain non-whitespace character. A line is a comment if it starts with#
, or//
(ignoring any amount of preceding whitespace).
-