Interface DroolsVariableFactory


  • public interface DroolsVariableFactory
    Creates Variables with unique names, by adding numeric suffixes to the user-provided names. Drools executable model unfortunately doesn't enforce unique variable names, yet requires them - therefore, by unifying all access to variable creation through the factory we avoid avoiding all sorts of strange issues that are very hard to track down.
    • Method Detail

      • createVariable

        <X> org.drools.model.Variable<? extends X> createVariable​(Class<X> clz,
                                                                  String baseName)
        Declare a new Variable with a given name and no declared source. Delegates to DSL.declarationOf(Class, String).
        Type Parameters:
        X - Generic type of the variable.
        Parameters:
        clz - type of the variable. Using Object will work in all cases, but Drools will spend unnecessary amount of time looking up applicable instances of that variable, as it has to traverse instances of all types in the working memory. Therefore, it is desirable to be as specific as possible.
        baseName - name of the variable, mostly useful for debugging purposes. Will be decorated by a numeric identifier to prevent multiple variables of the same name to exist within left-hand side of a single rule.
        Returns:
        new variable declaration, not yet bound to anything
      • createVariable

        <X> org.drools.model.Variable<? extends X> createVariable​(String baseName,
                                                                  org.drools.model.DeclarationSource source)
        Declare a new Variable with a given name and a declaration source. Delegates to DSL.declarationOf(Class, String, DeclarationSource).
        Type Parameters:
        X - Generic type of the variable.
        Parameters:
        baseName - name of the variable, mostly useful for debugging purposes. Will be decorated by a numeric identifier to prevent multiple variables of the same name to exist within left-hand side of a single rule.
        source - declaration source of the variable
        Returns:
        new variable declaration, not yet bound to anything
      • createVariable

        <X> org.drools.model.Variable<? extends X> createVariable​(Class<X> clz,
                                                                  String baseName,
                                                                  org.drools.model.DeclarationSource source)
        Declare a new Variable with a given name and a declaration source. Delegates to DSL.declarationOf(Class, String, DeclarationSource).
        Type Parameters:
        X - Generic type of the variable.
        Parameters:
        clz - type of the variable. Using Object will work in all cases, but Drools will spend unnecessary amount of time looking up applicable instances of that variable, as it has to traverse instances of all types in the working memory. Therefore, it is desirable to be as specific as possible.
        baseName - name of the variable, mostly useful for debugging purposes. Will be decorated by a numeric identifier to prevent multiple variables of the same name to exist within left-hand side of a single rule.
        source - declaration source of the variable
        Returns:
        new variable declaration, not yet bound to anything