Interface DSLKnowledgeProvider

All Known Implementing Classes:
DSLClassProvider, DSLJarProvider, DSLSourceProvider

public interface DSLKnowledgeProvider
An interface for creating and integrating Domain-Specific Language (DSL) implementations with the rule engine. Implementations can utilize any DSL format, ranging from plain text to database storage. When an implementation is available on the classpath, developers can use it through the RuntimeContext.importRules(String, Object) method.

Implementations are expected to create a new RuleSetBuilder from the provided RuntimeContext, append new rules, and finally invoke the RuleSetBuilder.build() method.

If an implementation requires or relies on specific configuration options, the authors of the implementation should read them via the RuntimeContext.get(String) method. The configuration options should be documented so that developers can set those options via the corresponding RuntimeContext.set(String, Object) method prior to importing the rules.

  • Method Details

    • getName

      String getName()
      Returns the name of the DSL knowledge provider.
      Returns:
      the name of the provider
    • appendTo

      default <C extends RuntimeContext<C>> void appendTo(RuntimeContext<C> context, Object source) throws IOException
      Appends the provided rule source to the specified RuleSetBuilder instance.

      If the implementation requires or relies on specific configuration entries, they should be set via the FluentEnvironment.set(String, Object) method.

      This method is the preferred approach for integrating external rule sources. Unlike the deprecated create(KnowledgeService, TypeResolver, URL...) method and its variants, this method enables appending sources directly to both Knowledge and RuleSession rule set instances.

      Type Parameters:
      C - The type of the context for the builder.
      Parameters:
      context - The RuntimeContext instance to which the rule source(s) will be appended.
      source - The rule source to be appended to the target builder. The source can be in various formats, depending on the implementation (e.g., a String representing rule definitions, a File with rule definitions, a URL, etc.).
      Throws:
      IOException - If an I/O error occurs while processing the source.
      IllegalArgumentException - If the source format is unrecognized or cannot be processed.
    • create

      @Deprecated default Knowledge create(KnowledgeService service, URL... resources) throws IOException
      Deprecated.
      Use the appendTo(RuntimeContext, Object) method instead.
      Creates a new Knowledge from the provided resources. This method has been deprecated since version 4.0.0 in favor of using the new appendTo(RuntimeContext, Object) method for applying external resources. To ensure backward compatibility, this method (and other similar pre-4.0.0 methods) now attempts to automatically adopt the new approach. However, depending on the implementation, compatibility might not be fully guaranteed.
      Parameters:
      service - the Knowledge service.
      resources - the remote or local resources to apply.
      Returns:
      a new Knowledge instance.
      Throws:
      IOException - if an error occurs while reading the data sources.
    • create

      @Deprecated default Knowledge create(KnowledgeService service, TypeResolver typeResolver, URL... resources) throws IOException
      Deprecated.
      Use the appendTo(RuntimeContext, Object) method instead.
      Creates a new Knowledge from the provided resources. This method has been deprecated since version 4.0.0 in favor of using the new appendTo(RuntimeContext, Object) method for applying external resources. To ensure backward compatibility, this method (and other similar pre-4.0.0 methods) now attempts to automatically adopt the new approach. However, depending on the implementation, compatibility might not be fully guaranteed.
      Parameters:
      resources - remote or local resources to apply
      typeResolver - TypeResolver to use.
      service - Knowledge service.
      Returns:
      new Knowledge instance
      Throws:
      IOException - if an error occurs when reading the data sources.
    • create

      @Deprecated default Knowledge create(KnowledgeService service, InputStream... streams) throws IOException
      Deprecated.
      Use the appendTo(RuntimeContext, Object) method instead.
      Creates a new Knowledge from the provided resources. This method has been deprecated since version 4.0.0 in favor of using the new appendTo(RuntimeContext, Object) method for applying external resources. To ensure backward compatibility, this method (and other similar pre-4.0.0 methods) now attempts to automatically adopt the new approach. However, depending on the implementation, compatibility might not be fully guaranteed.
      Parameters:
      streams - remote or local resources to apply
      service - Knowledge service.
      Returns:
      new Knowledge instance
      Throws:
      IOException - if an error occurs when reading the data sources.
      See Also:
    • create

      @Deprecated default Knowledge create(KnowledgeService service, TypeResolver resolver, File... files) throws IOException
      Deprecated.
      Use the appendTo(RuntimeContext, Object) method instead.
      Creates a new Knowledge from the provided resources. This method has been deprecated since version 4.0.0 in favor of using the new appendTo(RuntimeContext, Object) method for applying external resources. To ensure backward compatibility, this method (and other similar pre-4.0.0 methods) now attempts to automatically adopt the new approach. However, depending on the implementation, compatibility might not be fully guaranteed.
      Parameters:
      files - file resources
      service - Knowledge service.
      resolver - Type resolver
      Returns:
      new Knowledge instance
      Throws:
      IOException - if an error occurs when reading the data sources.
    • create

      @Deprecated default Knowledge create(KnowledgeService service, File... files) throws IOException
      Deprecated.
      Use the appendTo(RuntimeContext, Object) method instead.
      Creates a new Knowledge from the provided resources. This method has been deprecated since version 4.0.0 in favor of using the new appendTo(RuntimeContext, Object) method for applying external resources. To ensure backward compatibility, this method (and other similar pre-4.0.0 methods) now attempts to automatically adopt the new approach. However, depending on the implementation, compatibility might not be fully guaranteed.
      Parameters:
      files - file resources
      service - Knowledge service.
      Returns:
      new Knowledge instance
      Throws:
      IOException - if an error occurs when reading the data sources.
    • create

      @Deprecated default Knowledge create(KnowledgeService service, TypeResolver typeResolver, InputStream... streams) throws IOException
      Deprecated.
      Use the appendTo(RuntimeContext, Object) method instead.
      Creates a new Knowledge from the provided resources. This method has been deprecated since version 4.0.0 in favor of using the new appendTo(RuntimeContext, Object) method for applying external resources. To ensure backward compatibility, this method (and other similar pre-4.0.0 methods) now attempts to automatically adopt the new approach. However, depending on the implementation, compatibility might not be fully guaranteed.
      Parameters:
      streams - remote or local resources to apply
      service - Knowledge service.
      typeResolver - TypeResolver to use.
      Returns:
      new Knowledge instance
      Throws:
      IOException - if an error occurs when reading the data sources.
    • create

      @Deprecated default Knowledge create(KnowledgeService service, Reader... streams) throws IOException
      Deprecated.
      Use the appendTo(RuntimeContext, Object) method instead.
      Creates a new Knowledge from the provided resources. This method has been deprecated since version 4.0.0 in favor of using the new appendTo(RuntimeContext, Object) method for applying external resources. To ensure backward compatibility, this method (and other similar pre-4.0.0 methods) now attempts to automatically adopt the new approach. However, depending on the implementation, compatibility might not be fully guaranteed.
      Parameters:
      streams - remote or local resources to apply
      service - Knowledge service.
      Returns:
      new Knowledge instance
      Throws:
      IOException - if resources can not be read
      UnsupportedOperationException - if this method is not supported by the implementation
      See Also:
    • create

      @Deprecated default Knowledge create(KnowledgeService service, TypeResolver typeResolver, Reader... streams) throws IOException
      Deprecated.
      Use the appendTo(RuntimeContext, Object) method instead.
      Creates a new Knowledge from the provided resources. This method has been deprecated since version 4.0.0 in favor of using the new appendTo(RuntimeContext, Object) method for applying external resources. To ensure backward compatibility, this method (and other similar pre-4.0.0 methods) now attempts to automatically adopt the new approach. However, depending on the implementation, compatibility might not be fully guaranteed.
      Parameters:
      streams - The remote or local resources to apply.
      service - The Knowledge service.
      typeResolver - The TypeResolver to use.
      Returns:
      A new instance of Knowledge.
      Throws:
      IOException - If the resources cannot be read.
      UnsupportedOperationException - If this method is not supported by the implementation.
    • load

      static DSLKnowledgeProvider load(String dsl)
      Loads a specific DSL (Domain-Specific Language) knowledge provider based on the provided identifier.
      Parameters:
      dsl - The identifier for the DSL provider to load.
      Returns:
      The DSLKnowledgeProvider implementation matching the given identifier.
      Throws:
      NullPointerException - if the dsl argument is null.
      IllegalStateException - if no or multiple providers were found for the specified DSL identifier.
    • load

      static DSLKnowledgeProvider load(Class<? extends DSLKnowledgeProvider> dsl)
      Attempts to load and instantiate a DSLKnowledgeProvider implementation.
      Parameters:
      dsl - The Class object corresponding to the DSL implementation class. This class must implement the DSLKnowledgeProvider interface and have a public no-argument constructor. Must not be null.
      Returns:
      An instance of the specified DSLKnowledgeProvider implementation.
      Throws:
      IllegalStateException - If the instantiation of the DSL class instance fails for any reason, including if the input parameter is null.