Package io.inversion

Class Rule<R extends Rule>

  • All Implemented Interfaces:
    java.lang.Comparable<R>
    Direct Known Subclasses:
    AclRule, Action, Collection, Db, Endpoint

    public abstract class Rule<R extends Rule>
    extends java.lang.Object
    implements java.lang.Comparable<R>
    Matches against an HTTP method and URL path to determine if the object should be included when processing the associated Request.

    Matching relies heavily on variablized Path matching via Path.matches(String)

    • Field Detail

      • ALL_METHODS

        public static final java.util.SortedSet<java.lang.String> ALL_METHODS
      • log

        protected final transient org.slf4j.Logger log
      • includeMatchers

        protected final java.util.List<Rule.RuleMatcher> includeMatchers
        Method/path combinations that would cause this Rule to be included in the relevant processing.
      • excludeMatchers

        protected final java.util.List<Rule.RuleMatcher> excludeMatchers
        Method/path combinations that would cause this Rule to be excluded from the relevant processing.
      • configMap

        protected final transient io.inversion.json.JSMap configMap
        JSNode is used because it implements a case insensitive map without modifying the keys
      • name

        protected java.lang.String name
        The name used for configuration and debug purposes.
      • order

        protected int order
        Rules are always processed in sequence sorted by ascending order.
      • includeOn

        protected java.lang.String includeOn
        An optional querystring that will be applied to every request processed. This is useful to force specific params on different endpoints/actions etc.
      • excludeOn

        protected java.lang.String excludeOn
      • description

        protected java.lang.String description
      • params

        protected java.util.List<Param> params
    • Constructor Detail

      • Rule

        public Rule()
    • Method Detail

      • afterWiringComplete

        public void afterWiringComplete​(io.inversion.context.Context context)
      • checkLazyConfig

        protected void checkLazyConfig()
      • doLazyConfig

        protected void doLazyConfig()
      • getDefaultIncludeMatchers

        protected java.util.List<Rule.RuleMatcher> getDefaultIncludeMatchers()
        Designed to allow subclasses to provide a default match behavior of no configuration was provided by the developer.
        Returns:
        the default include match "*","*"
      • matches

        public boolean matches​(java.lang.String method,
                               java.lang.String path)
        Check if the http method and path match this Rule.
        Parameters:
        method - the HTTP method to match
        path - the concrete path to match
        Returns:
        true if the http method and path are included and not excluded
      • matches

        public boolean matches​(java.lang.String method,
                               io.inversion.utils.Path path)
        Check if the http method and path match this Rule.
        Parameters:
        method - the HTTP method to match
        path - the concrete path to match
        Returns:
        true if the http method and path are included and not excluded
      • match

        public io.inversion.utils.Path match​(java.lang.String method,
                                             io.inversion.utils.Path path)
        Find the first ordered Path that satisfies this method/path match.
        Parameters:
        method - the HTTP method to match
        path - the concrete path to match
        Returns:
        the first includeMatchers path to match when method also matches, null if no matches or excluded
      • match

        public io.inversion.utils.Path match​(java.lang.String method,
                                             io.inversion.utils.Path path,
                                             boolean bidirectional)
      • getAllIncludeMethods

        public java.util.List<java.lang.String> getAllIncludeMethods()
      • getAllIncludePaths

        public java.util.List<io.inversion.utils.Path> getAllIncludePaths()
      • getAllExcludePaths

        public java.util.List<io.inversion.utils.Path> getAllExcludePaths()
      • getIncludeMatchers

        public java.util.List<Rule.RuleMatcher> getIncludeMatchers()
      • withIncludeOn

        public R withIncludeOn​(java.lang.String... specs)
      • withExcludeOn

        public R withExcludeOn​(Rule.RuleMatcher matcher)
        Don't select this Rule when RuleMatcher matches
        Parameters:
        matcher - the method/path combo to exclude
        Returns:
        this
      • withExcludeOn

        public R withExcludeOn​(java.lang.String... specs)
      • getExcludeMatchers

        public java.util.List<Rule.RuleMatcher> getExcludeMatchers()
      • getName

        public java.lang.String getName()
      • withName

        public R withName​(java.lang.String name)
      • withDescription

        public Rule withDescription​(java.lang.String description)
      • getDescription

        public java.lang.String getDescription()
      • getOrder

        public int getOrder()
      • withOrder

        public R withOrder​(int order)
      • compareTo

        public int compareTo​(Rule a)
        Specified by:
        compareTo in interface java.lang.Comparable<R extends Rule>
      • getParams

        public java.util.List<Param> getParams()
      • withParams

        public R withParams​(java.util.List<Param> params)
      • withParam

        public R withParam​(Param param)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object