MemberSelectorListMemberAccessPolicy.MemberSelector (FreeMarker 2.3.35 API)
Description: declaration: package: freemarker.ext.beans, class: MemberSelectorListMemberAccessPolicy, class: MemberSelector

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 Object
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

  Constructors
  Constructor
  Description
  `MemberSelector​(Class<?> upperBoundType, 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​(Class<?> upperBoundType, 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​(Class<?> upperBoundType, 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.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Constructor<?>`
  `getConstructor()`
  Maybe `null`; set if the selector matches constructors similar to the returned one.
  `Field`
  `getField()`
  Maybe `null`; set if the selector matches fields similar to the returned one.
  `Method`
  `getMethod()`
  Maybe `null`; set if the selector matches methods similar to the returned one.
  `Class<?>`
  `getUpperBoundType()`
  Not `null`.
  `static boolean`
  `isIgnoredLine​(String line)`
  A line is ignored if it's blank or a comment.
  `static MemberSelectorListMemberAccessPolicy.MemberSelector`
  `parse​(String memberSelectorString, ClassLoader classLoader)`
  Parses a member selector that was specified with a string.
  `static List<MemberSelectorListMemberAccessPolicy.MemberSelector>`
  `parse​(Collection<String> memberSelectors, boolean ignoreMissingClassOrMember, 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)`.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### MemberSelector

    public MemberSelector​(Class<?> upperBoundType, 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. When methods are matched, only the name and the parameter types matter.

  - ### MemberSelector

    public MemberSelector​(Class<?> upperBoundType, 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. When constructors are matched, only the parameter types matter.

  - ### MemberSelector

    public MemberSelector​(Class<?> upperBoundType, 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. When fields are matched, only the name matters.

- ## Method Details

  - ### getUpperBoundType

    public Class<?> getUpperBoundType()
    Not `null`.

  - ### getMethod

    public Method getMethod()
    Maybe `null`; set if the selector matches methods similar to the returned one.

  - ### getConstructor

    public Constructor<?> getConstructor()
    Maybe `null`; set if the selector matches constructors similar to the returned one.

  - ### getField

    public Field getField()
    Maybe `null`; set if the selector matches fields similar to the returned one.

  - ### parse

    public static MemberSelectorListMemberAccessPolicy.MemberSelector parse​(String memberSelectorString, ClassLoader classLoader) throws ClassNotFoundException, NoSuchMethodException, 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 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.
    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, NoSuchFieldException
    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)`.
    Parameters:
      `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.
    Throws:
      `ClassNotFoundException`
      `NoSuchMethodException`
      `NoSuchFieldException`

  - ### isIgnoredLine

    public static boolean isIgnoredLine​(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).