public static final class MemberSelectorListMemberAccessPolicy.MemberSelector
extends java.lang.Object
MemberSelectorListMemberAccessPolicy
documentation for more.
Exactly one of these will be non-null
:
getMethod()
, getConstructor()
, getField()
.Constructor and 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 are
instanceof 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 are
instanceof 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 are
instanceof of
the specified upper bound type. |
Modifier and Type | Method and Description |
---|---|
java.lang.reflect.Constructor<?> |
getConstructor()
Maybe
null ;
set if the selector matches constructors similar to the returned one. |
java.lang.reflect.Field |
getField()
Maybe
null ;
set if the selector matches fields similar to the returned one. |
java.lang.reflect.Method |
getMethod()
Maybe
null ;
set if the selector matches methods similar to the returned one. |
java.lang.Class<?> |
getUpperBoundType()
Not
null . |
static boolean |
isIgnoredLine(java.lang.String line)
A line is ignored if it's blank or a comment.
|
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 (see
parse(String, ClassLoader) ),
while also filtering out blank and comment lines; see parse(String, ClassLoader) ,
and isIgnoredLine(String) . |
static MemberSelectorListMemberAccessPolicy.MemberSelector |
parse(java.lang.String memberSelectorString,
java.lang.ClassLoader classLoader)
Parses a member selector that was specified with a string.
|
public MemberSelector(java.lang.Class<?> upperBoundType, java.lang.reflect.Method method)
instanceof
of
the specified upper bound type. When methods are matched, only the name and the parameter types matter.public MemberSelector(java.lang.Class<?> upperBoundType, java.lang.reflect.Constructor<?> constructor)
instanceof
of
the specified upper bound type. When constructors are matched, only the parameter types matter.public MemberSelector(java.lang.Class<?> upperBoundType, java.lang.reflect.Field field)
instanceof
of
the specified upper bound type. When fields are matched, only the name matters.public java.lang.Class<?> getUpperBoundType()
null
.public java.lang.reflect.Method getMethod()
null
;
set if the selector matches methods similar to the returned one.public java.lang.reflect.Constructor<?> getConstructor()
null
;
set if the selector matches constructors similar to the returned one.public java.lang.reflect.Field getField()
null
;
set if the selector matches fields similar to the returned one.public static MemberSelectorListMemberAccessPolicy.MemberSelector parse(java.lang.String memberSelectorString, java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, java.lang.NoSuchFieldException
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 call
Class.getClassLoader()
on that. Note that the resolution of the classes is not lazy, and so the
ClassLoader
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, like com.example.MyClass.myMember
. Unless it's a field, the
name is followed by comma separated list of the parameter types inside parentheses, like in
com.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, like com.example.MyClass.myMember
, the class refers to the so
called "upper bound class". Regarding that and inheritance rules see the class level documentation.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.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
parse(String, ClassLoader)
),
while also filtering out blank and comment lines; see parse(String, ClassLoader)
,
and isIgnoredLine(String)
.ignoreMissingClassOrMember
- If true
, members selectors that throw exceptions because the
referred type or member can't be found will be silently ignored. If true
, same exceptions
will be just thrown by this method.java.lang.ClassNotFoundException
java.lang.NoSuchMethodException
java.lang.NoSuchFieldException
public static boolean isIgnoredLine(java.lang.String line)
#
, or //
(ignoring any amount of
preceding whitespace).