Class Copperlace
- All Implemented Interfaces:
AutoCloseable
Copperlace compiles a config once and owns the resulting native
ruleset until close() is called. Use this class when rendering more
than one rule, or when rendering the same rule multiple times, so the config
does not need to be parsed and compiled for each render.
Instances are AutoCloseable; callers should prefer
try-with-resources.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Releases the underlying native ruleset handle.static CopperlaceLoads and compiles a configuration file into a reusable renderer.static CopperlaceLoads and compiles a configuration file into a reusable renderer.static CopperlacefromFileWithProcessors(String path, Map<String, CopperlaceProcessor> processors) Loads and compiles a configuration file into a reusable renderer with custom processors.static CopperlacefromFileWithProcessors(Path path, Map<String, CopperlaceProcessor> processors) Loads and compiles a configuration file into a reusable renderer with custom processors.static CopperlacefromString(String config) Compiles a configuration string into a reusable renderer.static CopperlacefromStringWithProcessors(String config, Map<String, CopperlaceProcessor> processors) Compiles a configuration string into a reusable renderer with custom processors.Renders a named rule from the loaded config.Renders a named rule from the loaded config with initial context values.static StringrenderFile(String path, String rule) Renders one rule from a configuration file.static StringRenders one rule from a configuration file with initial context values.static StringrenderFile(Path path, String rule) Renders one rule from a configuration file.static StringRenders one rule from a configuration file with initial context values.static StringrenderFileInferred(String path, String rule) Renders one rule from a configuration file as text, returning formatted JSON for object-valued rules.static StringRenders one rule from a configuration file with initial context, returning formatted JSON for object-valued rules.static StringrenderFileInferred(Path path, String rule) Renders one rule from a configuration file as text, returning formatted JSON for object-valued rules.static StringRenders one rule from a configuration file with initial context, returning formatted JSON for object-valued rules.static StringrenderFileStructuredJson(String path, String rule) Renders one structured rule from a configuration file as formatted JSON text.static StringrenderFileStructuredJson(String path, String rule, boolean formatJson) Renders one structured rule from a configuration file as JSON text.static StringRenders one structured rule from a configuration file as formatted JSON text with initial context values.static StringRenders one structured rule from a configuration file as JSON text with initial context values.static StringrenderFileStructuredJson(Path path, String rule) Renders one structured rule from a configuration file as formatted JSON text.static StringrenderFileStructuredJson(Path path, String rule, boolean formatJson) Renders one structured rule from a configuration file as JSON text.static StringRenders one structured rule from a configuration file as formatted JSON text with initial context values.static StringRenders one structured rule from a configuration file as JSON text with initial context values.static StringrenderFileWithProcessors(String path, String rule, Map<String, CopperlaceProcessor> processors) Renders one rule from a configuration file with custom processors.static StringrenderFileWithProcessors(String path, String rule, Map<String, String> context, Map<String, CopperlaceProcessor> processors) Renders one rule from a configuration file with custom processors and initial context values.static StringrenderFileWithProcessors(Path path, String rule, Map<String, CopperlaceProcessor> processors) Renders one rule from a configuration file with custom processors.static StringrenderFileWithProcessors(Path path, String rule, Map<String, String> context, Map<String, CopperlaceProcessor> processors) Renders one rule from a configuration file with custom processors and initial context values.renderInferred(String rule) Renders a named rule as text, returning formatted JSON for object-valued rules.renderInferred(String rule, Map<String, String> context) Renders a named rule with initial context, returning formatted JSON for object-valued rules.static StringrenderString(String config, String rule) Renders one rule from a configuration string.static StringRenders one rule from a configuration string with initial context values.static StringrenderStringInferred(String config, String rule) Renders one rule from a configuration string as text, returning formatted JSON for object-valued rules.static StringRenders one rule from a configuration string with initial context, returning formatted JSON for object-valued rules.static StringrenderStringStructuredJson(String config, String rule) Renders one structured rule from a configuration string as formatted JSON text.static StringrenderStringStructuredJson(String config, String rule, boolean formatJson) Renders one structured rule from a configuration string as JSON text.static StringRenders one structured rule from a configuration string as formatted JSON text with initial context values.static StringrenderStringStructuredJson(String config, String rule, Map<String, String> context, boolean formatJson) Renders one structured rule from a configuration string as JSON text with initial context values.static StringrenderStringWithProcessors(String config, String rule, Map<String, CopperlaceProcessor> processors) Renders one rule from a configuration string with custom processors.static StringrenderStringWithProcessors(String config, String rule, Map<String, String> context, Map<String, CopperlaceProcessor> processors) Renders one rule from a configuration string with custom processors and initial context values.renderStructuredJson(String rule) Renders a named structured rule from the loaded config as formatted JSON text.renderStructuredJson(String rule, boolean formatJson) Renders a named structured rule from the loaded config as JSON text.renderStructuredJson(String rule, Map<String, String> context) Renders a named structured rule from the loaded config as formatted JSON text with initial context values.renderStructuredJson(String rule, Map<String, String> context, boolean formatJson) Renders a named structured rule from the loaded config as JSON text with initial context values.
-
Method Details
-
fromString
Compiles a configuration string into a reusable renderer.- Parameters:
config- configuration text containing Copperlace rules- Returns:
- a renderer backed by a native Copperlace ruleset
- Throws:
IllegalArgumentException- ifconfigis blankCopperlaceException- if the config cannot be parsed or compiled
-
fromStringWithProcessors
public static Copperlace fromStringWithProcessors(String config, Map<String, CopperlaceProcessor> processors) Compiles a configuration string into a reusable renderer with custom processors.- Parameters:
config- configuration text containing Copperlace rulesprocessors- custom processor callbacks keyed by processor name- Returns:
- a renderer backed by a native Copperlace ruleset
- Throws:
NullPointerException- ifprocessors, a processor name, or a processor is nullIllegalArgumentException- ifconfigis blankCopperlaceException- if the config cannot be parsed or compiled
-
fromFile
Loads and compiles a configuration file into a reusable renderer.- Parameters:
path- path to the configuration file- Returns:
- a renderer backed by a native Copperlace ruleset
- Throws:
NullPointerException- ifpathis nullCopperlaceException- if the file cannot be loaded, parsed, or compiled
-
fromFileWithProcessors
public static Copperlace fromFileWithProcessors(Path path, Map<String, CopperlaceProcessor> processors) Loads and compiles a configuration file into a reusable renderer with custom processors.- Parameters:
path- path to the configuration fileprocessors- custom processor callbacks keyed by processor name- Returns:
- a renderer backed by a native Copperlace ruleset
- Throws:
NullPointerException- ifpath,processors, a processor name, or a processor is nullCopperlaceException- if the file cannot be loaded, parsed, or compiled
-
fromFile
Loads and compiles a configuration file into a reusable renderer.- Parameters:
path- path to the configuration file- Returns:
- a renderer backed by a native Copperlace ruleset
- Throws:
IllegalArgumentException- ifpathis blankCopperlaceException- if the file cannot be loaded, parsed, or compiled
-
fromFileWithProcessors
public static Copperlace fromFileWithProcessors(String path, Map<String, CopperlaceProcessor> processors) Loads and compiles a configuration file into a reusable renderer with custom processors.- Parameters:
path- path to the configuration fileprocessors- custom processor callbacks keyed by processor name- Returns:
- a renderer backed by a native Copperlace ruleset
- Throws:
NullPointerException- ifprocessors, a processor name, or a processor is nullIllegalArgumentException- ifpathis blankCopperlaceException- if the file cannot be loaded, parsed, or compiled
-
renderString
Renders one rule from a configuration string.This convenience method compiles the config, renders one rule, and releases the native ruleset. Use
fromString(String)for repeated renders from the same config.- Parameters:
config- configuration text containing Copperlace rulesrule- name of the rule to render- Returns:
- rendered text for
rule - Throws:
IllegalArgumentException- ifconfigorruleis blankCopperlaceException- if parsing, compilation, or rendering fails
-
renderStringWithProcessors
public static String renderStringWithProcessors(String config, String rule, Map<String, CopperlaceProcessor> processors) Renders one rule from a configuration string with custom processors.- Parameters:
config- configuration text containing Copperlace rulesrule- name of the rule to renderprocessors- custom processor callbacks keyed by processor name- Returns:
- rendered text for
rule - Throws:
NullPointerException- ifprocessors, a processor name, or a processor is nullIllegalArgumentException- ifconfigorruleis blankCopperlaceException- if parsing, compilation, or rendering fails
-
renderStringWithProcessors
public static String renderStringWithProcessors(String config, String rule, Map<String, String> context, Map<String, CopperlaceProcessor> processors) Renders one rule from a configuration string with custom processors and initial context values.- Parameters:
config- configuration text containing Copperlace rulesrule- name of the rule to rendercontext- initial render context valuesprocessors- custom processor callbacks keyed by processor name- Returns:
- rendered text for
rule - Throws:
NullPointerException- ifcontext,processors, a key, value, processor name, or processor is nullIllegalArgumentException- ifconfigorruleis blankCopperlaceException- if parsing, compilation, or rendering fails
-
renderString
Renders one rule from a configuration string with initial context values.This convenience method compiles the config, renders one rule, and releases the native ruleset. Use
fromString(String)for repeated renders from the same config.- Parameters:
config- configuration text containing Copperlace rulesrule- name of the rule to rendercontext- initial render context values- Returns:
- rendered text for
rule - Throws:
NullPointerException- ifcontext, a context key, or a context value is nullIllegalArgumentException- ifconfigorruleis blankCopperlaceException- if parsing, compilation, or rendering fails
-
renderStringInferred
Renders one rule from a configuration string as text, returning formatted JSON for object-valued rules.- Parameters:
config- configuration text containing Copperlace rulesrule- name of the rule to render- Returns:
- rendered text, or formatted JSON for an object-valued rule
- Throws:
IllegalArgumentException- ifconfigorruleis blankCopperlaceException- if parsing, compilation, or rendering fails
-
renderStringInferred
Renders one rule from a configuration string with initial context, returning formatted JSON for object-valued rules.- Parameters:
config- configuration text containing Copperlace rulesrule- name of the rule to rendercontext- initial render context values- Returns:
- rendered text, or formatted JSON for an object-valued rule
- Throws:
NullPointerException- ifcontext, a context key, or a context value is nullIllegalArgumentException- ifconfigorruleis blankCopperlaceException- if parsing, compilation, or rendering fails
-
renderStringStructuredJson
Renders one structured rule from a configuration string as formatted JSON text.- Parameters:
config- configuration text containing Copperlace rulesrule- name of the structured rule to render- Returns:
- formatted JSON for
rule - Throws:
IllegalArgumentException- ifconfigorruleis blankCopperlaceException- if parsing, compilation, or rendering fails
-
renderStringStructuredJson
Renders one structured rule from a configuration string as JSON text.- Parameters:
config- configuration text containing Copperlace rulesrule- name of the structured rule to renderformatJson- true to format JSON with tabs, false for compact JSON- Returns:
- JSON for
rule - Throws:
IllegalArgumentException- ifconfigorruleis blankCopperlaceException- if parsing, compilation, or rendering fails
-
renderStringStructuredJson
public static String renderStringStructuredJson(String config, String rule, Map<String, String> context) Renders one structured rule from a configuration string as formatted JSON text with initial context values.- Parameters:
config- configuration text containing Copperlace rulesrule- name of the structured rule to rendercontext- initial render context values- Returns:
- formatted JSON for
rule - Throws:
NullPointerException- ifcontext, a context key, or a context value is nullIllegalArgumentException- ifconfigorruleis blankCopperlaceException- if parsing, compilation, or rendering fails
-
renderStringStructuredJson
public static String renderStringStructuredJson(String config, String rule, Map<String, String> context, boolean formatJson) Renders one structured rule from a configuration string as JSON text with initial context values.- Parameters:
config- configuration text containing Copperlace rulesrule- name of the structured rule to rendercontext- initial render context valuesformatJson- true to format JSON with tabs, false for compact JSON- Returns:
- JSON for
rule - Throws:
NullPointerException- ifcontext, a context key, or a context value is nullIllegalArgumentException- ifconfigorruleis blankCopperlaceException- if parsing, compilation, or rendering fails
-
renderFile
Renders one rule from a configuration file.This convenience method loads and compiles the file, renders one rule, and releases the native ruleset. Use
fromFile(Path)for repeated renders from the same config.- Parameters:
path- path to the configuration filerule- name of the rule to render- Returns:
- rendered text for
rule - Throws:
NullPointerException- ifpathis nullIllegalArgumentException- ifruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFileWithProcessors
public static String renderFileWithProcessors(Path path, String rule, Map<String, CopperlaceProcessor> processors) Renders one rule from a configuration file with custom processors.- Parameters:
path- path to the configuration filerule- name of the rule to renderprocessors- custom processor callbacks keyed by processor name- Returns:
- rendered text for
rule - Throws:
NullPointerException- ifpath,processors, a processor name, or a processor is nullIllegalArgumentException- ifruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFileWithProcessors
public static String renderFileWithProcessors(Path path, String rule, Map<String, String> context, Map<String, CopperlaceProcessor> processors) Renders one rule from a configuration file with custom processors and initial context values.- Parameters:
path- path to the configuration filerule- name of the rule to rendercontext- initial render context valuesprocessors- custom processor callbacks keyed by processor name- Returns:
- rendered text for
rule - Throws:
NullPointerException- ifpath,context,processors, a key, value, processor name, or processor is nullIllegalArgumentException- ifruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFile
Renders one rule from a configuration file with initial context values.This convenience method loads and compiles the file, renders one rule, and releases the native ruleset. Use
fromFile(Path)for repeated renders from the same config.- Parameters:
path- path to the configuration filerule- name of the rule to rendercontext- initial render context values- Returns:
- rendered text for
rule - Throws:
NullPointerException- ifpath,context, a context key, or a context value is nullIllegalArgumentException- ifruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFileInferred
Renders one rule from a configuration file as text, returning formatted JSON for object-valued rules.- Parameters:
path- path to the configuration filerule- name of the rule to render- Returns:
- rendered text, or formatted JSON for an object-valued rule
- Throws:
NullPointerException- ifpathis nullIllegalArgumentException- ifruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFileInferred
Renders one rule from a configuration file with initial context, returning formatted JSON for object-valued rules.- Parameters:
path- path to the configuration filerule- name of the rule to rendercontext- initial render context values- Returns:
- rendered text, or formatted JSON for an object-valued rule
- Throws:
NullPointerException- ifpath,context, a context key, or a context value is nullIllegalArgumentException- ifruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFileStructuredJson
Renders one structured rule from a configuration file as formatted JSON text.- Parameters:
path- path to the configuration filerule- name of the structured rule to render- Returns:
- formatted JSON for
rule - Throws:
NullPointerException- ifpathis nullIllegalArgumentException- ifruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFileStructuredJson
Renders one structured rule from a configuration file as JSON text.- Parameters:
path- path to the configuration filerule- name of the structured rule to renderformatJson- true to format JSON with tabs, false for compact JSON- Returns:
- JSON for
rule - Throws:
NullPointerException- ifpathis nullIllegalArgumentException- ifruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFileStructuredJson
Renders one structured rule from a configuration file as formatted JSON text with initial context values.- Parameters:
path- path to the configuration filerule- name of the structured rule to rendercontext- initial render context values- Returns:
- formatted JSON for
rule - Throws:
NullPointerException- ifpath,context, a context key, or a context value is nullIllegalArgumentException- ifruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFileStructuredJson
public static String renderFileStructuredJson(Path path, String rule, Map<String, String> context, boolean formatJson) Renders one structured rule from a configuration file as JSON text with initial context values.- Parameters:
path- path to the configuration filerule- name of the structured rule to rendercontext- initial render context valuesformatJson- true to format JSON with tabs, false for compact JSON- Returns:
- JSON for
rule - Throws:
NullPointerException- ifpath,context, a context key, or a context value is nullIllegalArgumentException- ifruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFile
Renders one rule from a configuration file.This convenience method loads and compiles the file, renders one rule, and releases the native ruleset. Use
fromFile(String)for repeated renders from the same config.- Parameters:
path- path to the configuration filerule- name of the rule to render- Returns:
- rendered text for
rule - Throws:
IllegalArgumentException- ifpathorruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFileWithProcessors
public static String renderFileWithProcessors(String path, String rule, Map<String, CopperlaceProcessor> processors) Renders one rule from a configuration file with custom processors.- Parameters:
path- path to the configuration filerule- name of the rule to renderprocessors- custom processor callbacks keyed by processor name- Returns:
- rendered text for
rule - Throws:
NullPointerException- ifprocessors, a processor name, or a processor is nullIllegalArgumentException- ifpathorruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFileWithProcessors
public static String renderFileWithProcessors(String path, String rule, Map<String, String> context, Map<String, CopperlaceProcessor> processors) Renders one rule from a configuration file with custom processors and initial context values.- Parameters:
path- path to the configuration filerule- name of the rule to rendercontext- initial render context valuesprocessors- custom processor callbacks keyed by processor name- Returns:
- rendered text for
rule - Throws:
NullPointerException- ifcontext,processors, a key, value, processor name, or processor is nullIllegalArgumentException- ifpathorruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFile
Renders one rule from a configuration file with initial context values.This convenience method loads and compiles the file, renders one rule, and releases the native ruleset. Use
fromFile(String)for repeated renders from the same config.- Parameters:
path- path to the configuration filerule- name of the rule to rendercontext- initial render context values- Returns:
- rendered text for
rule - Throws:
NullPointerException- ifcontext, a context key, or a context value is nullIllegalArgumentException- ifpathorruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFileInferred
Renders one rule from a configuration file as text, returning formatted JSON for object-valued rules.- Parameters:
path- path to the configuration filerule- name of the rule to render- Returns:
- rendered text, or formatted JSON for an object-valued rule
- Throws:
IllegalArgumentException- ifpathorruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFileInferred
Renders one rule from a configuration file with initial context, returning formatted JSON for object-valued rules.- Parameters:
path- path to the configuration filerule- name of the rule to rendercontext- initial render context values- Returns:
- rendered text, or formatted JSON for an object-valued rule
- Throws:
NullPointerException- ifcontext, a context key, or a context value is nullIllegalArgumentException- ifpathorruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFileStructuredJson
Renders one structured rule from a configuration file as formatted JSON text.- Parameters:
path- path to the configuration filerule- name of the structured rule to render- Returns:
- formatted JSON for
rule - Throws:
IllegalArgumentException- ifpathorruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFileStructuredJson
Renders one structured rule from a configuration file as JSON text.- Parameters:
path- path to the configuration filerule- name of the structured rule to renderformatJson- true to format JSON with tabs, false for compact JSON- Returns:
- JSON for
rule - Throws:
IllegalArgumentException- ifpathorruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFileStructuredJson
Renders one structured rule from a configuration file as formatted JSON text with initial context values.- Parameters:
path- path to the configuration filerule- name of the structured rule to rendercontext- initial render context values- Returns:
- formatted JSON for
rule - Throws:
NullPointerException- ifcontext, a context key, or a context value is nullIllegalArgumentException- ifpathorruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
renderFileStructuredJson
public static String renderFileStructuredJson(String path, String rule, Map<String, String> context, boolean formatJson) Renders one structured rule from a configuration file as JSON text with initial context values.- Parameters:
path- path to the configuration filerule- name of the structured rule to rendercontext- initial render context valuesformatJson- true to format JSON with tabs, false for compact JSON- Returns:
- JSON for
rule - Throws:
NullPointerException- ifcontext, a context key, or a context value is nullIllegalArgumentException- ifpathorruleis blankCopperlaceException- if loading, parsing, compilation, or rendering fails
-
render
Renders a named rule from the loaded config.Each call uses a fresh render context, so per-render bindings are consistent within one output but do not carry over to later renders.
- Parameters:
rule- name of the rule to render- Returns:
- rendered text for
rule - Throws:
IllegalArgumentException- ifruleis blankCopperlaceException- if this renderer is closed or rendering fails
-
render
Renders a named rule from the loaded config with initial context values.The provided context is scoped to this render only. Values resolve before config-defined
contextdefaults and named rules.- Parameters:
rule- name of the rule to rendercontext- initial render context values- Returns:
- rendered text for
rule - Throws:
NullPointerException- ifcontext, a context key, or a context value is nullIllegalArgumentException- ifruleis blankCopperlaceException- if this renderer is closed or rendering fails
-
renderInferred
Renders a named rule as text, returning formatted JSON for object-valued rules.- Parameters:
rule- name of the rule to render- Returns:
- rendered text, or formatted JSON for an object-valued rule
- Throws:
IllegalArgumentException- ifruleis blankCopperlaceException- if this renderer is closed or rendering fails
-
renderInferred
Renders a named rule with initial context, returning formatted JSON for object-valued rules.- Parameters:
rule- name of the rule to rendercontext- initial render context values- Returns:
- rendered text, or formatted JSON for an object-valued rule
- Throws:
NullPointerException- ifcontext, a context key, or a context value is nullIllegalArgumentException- ifruleis blankCopperlaceException- if this renderer is closed or rendering fails
-
renderStructuredJson
Renders a named structured rule from the loaded config as formatted JSON text.- Parameters:
rule- name of the structured rule to render- Returns:
- formatted JSON for
rule - Throws:
IllegalArgumentException- ifruleis blankCopperlaceException- if this renderer is closed or rendering fails
-
renderStructuredJson
Renders a named structured rule from the loaded config as JSON text.- Parameters:
rule- name of the structured rule to renderformatJson- true to format JSON with tabs, false for compact JSON- Returns:
- JSON for
rule - Throws:
IllegalArgumentException- ifruleis blankCopperlaceException- if this renderer is closed or rendering fails
-
renderStructuredJson
Renders a named structured rule from the loaded config as formatted JSON text with initial context values.- Parameters:
rule- name of the structured rule to rendercontext- initial render context values- Returns:
- formatted JSON for
rule - Throws:
NullPointerException- ifcontext, a context key, or a context value is nullIllegalArgumentException- ifruleis blankCopperlaceException- if this renderer is closed or rendering fails
-
renderStructuredJson
Renders a named structured rule from the loaded config as JSON text with initial context values.- Parameters:
rule- name of the structured rule to rendercontext- initial render context valuesformatJson- true to format JSON with tabs, false for compact JSON- Returns:
- JSON for
rule - Throws:
NullPointerException- ifcontext, a context key, or a context value is nullIllegalArgumentException- ifruleis blankCopperlaceException- if this renderer is closed or rendering fails
-
close
public void close()Releases the underlying native ruleset handle.Calling
closemore than once is allowed.- Specified by:
closein interfaceAutoCloseable
-