Package freemarker.ext.beans
Class MemberSelectorListMemberAccessPolicy.MemberSelector
- java.lang.Object
-
- freemarker.ext.beans.MemberSelectorListMemberAccessPolicy.MemberSelector
-
- Enclosing class:
- MemberSelectorListMemberAccessPolicy
public static final class MemberSelectorListMemberAccessPolicy.MemberSelector extends java.lang.Object
A condition that matches some type members. SeeMemberSelectorListMemberAccessPolicy
documentation for more. Exactly one of these will be non-null
:getMethod()
,getConstructor()
,getField()
.- Since:
- 2.3.30
-
-
Constructor Summary
Constructors Constructor Description MemberSelector(java.lang.Class<?> upperBoundType, java.lang.reflect.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(java.lang.Class<?> upperBoundType, java.lang.reflect.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(java.lang.Class<?> upperBoundType, java.lang.reflect.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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.reflect.Constructor<?>
getConstructor()
Maybenull
; set if the selector matches constructors similar to the returned one.java.lang.reflect.Field
getField()
Maybenull
; set if the selector matches fields similar to the returned one.java.lang.reflect.Method
getMethod()
Maybenull
; set if the selector matches methods similar to the returned one.java.lang.Class<?>
getUpperBoundType()
Notnull
.static boolean
isIgnoredLine(java.lang.String line)
A line is ignored if it's blank or a comment.static MemberSelectorListMemberAccessPolicy.MemberSelector
parse(java.lang.String memberSelectorString, java.lang.ClassLoader classLoader)
Parses a member selector that was specified with a string.static java.util.List<MemberSelectorListMemberAccessPolicy.MemberSelector>
parse(java.util.Collection<java.lang.String> memberSelectors, boolean ignoreMissingClassOrMember, java.lang.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 Detail
-
MemberSelector
public MemberSelector(java.lang.Class<?> upperBoundType, java.lang.reflect.Method method)
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
public MemberSelector(java.lang.Class<?> upperBoundType, java.lang.reflect.Constructor<?> constructor)
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
public MemberSelector(java.lang.Class<?> upperBoundType, java.lang.reflect.Field field)
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 Detail
-
getUpperBoundType
public java.lang.Class<?> getUpperBoundType()
Notnull
.
-
getMethod
public java.lang.reflect.Method getMethod()
Maybenull
; set if the selector matches methods similar to the returned one.
-
getConstructor
public java.lang.reflect.Constructor<?> getConstructor()
Maybenull
; set if the selector matches constructors similar to the returned one.
-
getField
public java.lang.reflect.Field getField()
Maybenull
; set if the selector matches fields similar to the returned one.
-
parse
public static MemberSelectorListMemberAccessPolicy.MemberSelector parse(java.lang.String memberSelectorString, java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, java.lang.NoSuchFieldException
Parses 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:
java.lang.ClassNotFoundException
- If a type referred in the member selector can't be found.java.lang.NoSuchMethodException
- If the method or constructor referred in the member selector can't be found.java.lang.NoSuchFieldException
- If the field referred in the member selector can't be found.
-
parse
public static java.util.List<MemberSelectorListMemberAccessPolicy.MemberSelector> parse(java.util.Collection<java.lang.String> memberSelectors, boolean ignoreMissingClassOrMember, java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, java.lang.NoSuchFieldException
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)
.- 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:
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException
java.lang.NoSuchFieldException
-
isIgnoredLine
public static boolean isIgnoredLine(java.lang.String line)
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).
-
-