Class RulesBuilder

java.lang.Object
org.cojen.boxtin.RulesBuilder

public final class RulesBuilder extends Object
Is used to build up a set of access rules, which can then be built into a usable Rules instance.
  • Constructor Details

    • RulesBuilder

      public RulesBuilder()
      Construct an instance which uses the boot module layer for discovering modules, packages, and classes.
    • RulesBuilder

      public RulesBuilder(ModuleLayer layer)
      Construct an instance which uses the given module layer for discovering modules, packages, and classes.
  • Method Details

    • moduleLayer

      public ModuleLayer moduleLayer()
      Returns the ModuleLayer used by this builder.
    • applyRules

      public RulesBuilder applyRules(RulesApplier applier)
      Applies all the rules from the given applier to this builder.
      Returns:
      this
    • applyDenyRules

      public RulesBuilder applyDenyRules(RulesApplier applier)
      Applies only the deny rules from the given applier to this builder.
      Returns:
      this
    • applyAllowRules

      public RulesBuilder applyAllowRules(RulesApplier applier)
      Applies only the allow rules from the given applier to this builder.
      Returns:
      this
    • denyAll

      public RulesBuilder denyAll()
      Deny access to all packages, superseding all previous rules. This action is recursive, denying access to all packages, classes, constructors, etc.
      Returns:
      this
    • allowAll

      public RulesBuilder allowAll()
      Allow access to all packages, superseding all previous rules. This action is recursive, allowing access to all packages, classes, constructors, etc.
      Returns:
      this
    • forModule

      public RulesBuilder.ModuleScope forModule(String name)
      Define specific rules against the given module, which can supersede all previous rules.
      Parameters:
      name - fully qualified module name
      Throws:
      IllegalArgumentException - if the module isn't found
    • forModule

      public RulesBuilder.ModuleScope forModule(String name, String minVersion, String maxVersion)
      Define specific rules against the given module, which can supersede all previous rules.
      Parameters:
      name - fully qualified module name
      minVersion - optional minimum module version number to support (inclusive)
      maxVersion - optional maximum module version number to support (exclusive)
      Throws:
      IllegalArgumentException - if the module isn't found, or if the version is out of bounds, or if the min/max versions provided aren't parseable
    • validate

      public RulesBuilder validate()
      Validates that all classes are loadable, and that all class members are found. An exception is thrown if validation fails.
      Returns:
      this
      Throws:
      NullPointerException - if layer is null
      IllegalStateException - if validation fails
    • validate

      public RulesBuilder validate(Consumer<String> reporter)
      Validates that all classes are loadable, and that all class members are found. An exception is thrown if validation fails.
      Parameters:
      reporter - pass non-null for reporting multiple validation failures
      Returns:
      this
      Throws:
      NullPointerException - if layer is null
      IllegalStateException - if validation fails
    • build

      public Rules build()
      Returns an immutable set of rules based on what's been defined so far.
      Throws:
      IllegalStateException - if a package is defined in multiple modules