Class RuleSetFactory


  • public class RuleSetFactory
    extends Object
    RuleSetFactory is responsible for creating RuleSet instances from XML content. By default Rules will be loaded using the RulePriority.LOW priority, with Rule deprecation warnings off; the ruleset compatibility filter is active, too (see RuleSetFactoryCompatibility); if the ruleset contains rule references (e.g. for renamed or moved rules), these are ignored by default.
    • Method Detail

      • getRegisteredRuleSets

        public Iterator<RuleSet> getRegisteredRuleSets()
                                                throws RuleSetNotFoundException
        Returns an Iterator of RuleSet objects loaded from descriptions from the "categories.properties" resource for each Language with Rule support.
        Returns:
        An Iterator of RuleSet objects.
        Throws:
        RuleSetNotFoundException - if the ruleset file could not be found
      • createRuleSets

        public RuleSets createRuleSets​(List<RuleSetReferenceId> ruleSetReferenceIds)
                                throws RuleSetNotFoundException
        Create a RuleSets from a list of RuleSetReferenceIds. The currently configured ResourceLoader is used.
        Parameters:
        ruleSetReferenceIds - The List of RuleSetReferenceId of the RuleSets to create.
        Returns:
        The new RuleSets.
        Throws:
        RuleSetNotFoundException - if unable to find a resource.
      • createRuleSet

        public RuleSet createRuleSet​(RuleSetReferenceId ruleSetReferenceId)
                              throws RuleSetNotFoundException
        Create a RuleSet from a RuleSetReferenceId. Priority filtering is ignored when loading a single Rule. The currently configured ResourceLoader is used.
        Parameters:
        ruleSetReferenceId - The RuleSetReferenceId of the RuleSet to create.
        Returns:
        A new RuleSet.
        Throws:
        RuleSetNotFoundException - if unable to find a resource.
      • createRuleSetCopy

        public RuleSet createRuleSetCopy​(RuleSet original)
        Creates a copy of the given ruleset. All properties like name, description, fileName and exclude/include patterns are copied.

        Note: The rule instances are shared between the original and the new ruleset (copy-by-reference). This might lead to concurrency issues, if the original ruleset and the new ruleset are used in different threads.

        Parameters:
        original - the original rule set to copy from
        Returns:
        the copy
      • createNewRuleSet

        public RuleSet createNewRuleSet​(String name,
                                        String description,
                                        String fileName,
                                        Collection<String> excludePatterns,
                                        Collection<String> includePatterns,
                                        Collection<Rule> rules)
        Creates a new ruleset with the given metadata such as name, description, fileName, exclude/include patterns are used. The rules are taken from the given collection.

        Note: The rule instances are shared between the collection and the new ruleset (copy-by-reference). This might lead to concurrency issues, if the rules of the collection are also referenced by other rulesets and used in different threads.

        Parameters:
        name - the name of the ruleset
        description - the description
        fileName - the filename
        excludePatterns - list of exclude patterns, if any is not a valid regular expression, it will be ignored
        includePatterns - list of include patterns, if any is not a valid regular expression, it will be ignored
        rules - the collection with the rules to add to the new ruleset
        Returns:
        the new ruleset
      • createSingleRuleRuleSet

        public RuleSet createSingleRuleRuleSet​(Rule rule)
        Creates a new RuleSet containing a single rule.
        Parameters:
        rule - The rule being created
        Returns:
        The newly created RuleSet