Package com.osohq.oso
Class Polar
java.lang.Object
com.osohq.oso.Polar
- Direct Known Subclasses:
Oso
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Clear the rules from the KB, but maintain all registered classes and calls.void
Deprecated.void
Load Polar policy files.void
loadFilesFromResources
(String... filenames) Load Polar policy files from resources.void
Load a Polar string into the KB (without filename).void
Load a Polar string into the KB (with filename).static void
Query for a predicate.Query for a predicate, optionally accepting expressions in the result.Query for a predicate, applying bindings and optionally accepting the expression type as a result.Query for a predicate, parsing it first.Query for a predicate, parsing it first and optionally accepting an expression.Query for a predicate, parsing it first and applying bindingsQuery for a predicate, parsing it first, applying bindings and optionally accepting an expression.Query for a rule.Query for a rule.boolean
queryRuleOnce
(String rule, Object... args) Query for a rule, and check if it has any results.void
registerClass
(Class<?> cls) Register a Java class with Polar.void
registerClass
(Class<?> cls, String name) Register a Java class with Polar using an alias.void
registerConstant
(Object value, String name) Registers `value` as a Polar constant variable called `name`.void
repl()
Start the Polar REPL.void
Load the given files and start the Polar REPL.
-
Field Details
-
host
-
-
Constructor Details
-
Polar
- Throws:
Exceptions.OsoException
-
-
Method Details
-
clearRules
Clear the rules from the KB, but maintain all registered classes and calls.- Throws:
Exceptions.OsoException
-
loadFiles
Load Polar policy files. File contents are loaded into a String and saved here, so changes to a file made after a call to loadFiles will not be recognized.- Throws:
Exceptions.PolarFileExtensionError
- On incorrect file extension.Exceptions.PolarFileNotFoundError
- On nonexistent file.Exceptions.InlineQueryFailedError
- On a failed inline query.IOException
- If unable to open or read the file.Exceptions.OsoException
-
loadFilesFromResources
Load Polar policy files from resources. File contents are loaded into a String and saved here, so changes to a file made after a call to loadFiles will not be recognized.- Throws:
Exceptions.PolarFileExtensionError
- On incorrect file extension.Exceptions.PolarFileNotFoundError
- On nonexistent file.Exceptions.InlineQueryFailedError
- On a failed inline query.IOException
- If unable to open or read the file.Exceptions.OsoException
-
loadFile
Deprecated.loadFile(String)
has been deprecated in favor ofloadFiles(String[])
as of the 0.20 release. Please see changelog for migration instructions: https://docs.osohq.com/project/changelogs/2021-09-15.htmlLoad a Polar policy file. File contents are loaded into a String and saved here, so changes to the file made after a call to loadFile will not be recognized.- Throws:
Exceptions.PolarFileExtensionError
- On incorrect file extension.Exceptions.PolarFileNotFoundError
- On nonexistent file.Exceptions.InlineQueryFailedError
- On a failed inline query.IOException
- If unable to open or read the file.Exceptions.OsoException
-
loadStr
Load a Polar string into the KB (with filename).- Parameters:
str
- Polar string to be loaded.filename
- Name of the source file.- Throws:
Exceptions.InlineQueryFailedError
- On a failed inline query.Exceptions.OsoException
-
loadStr
Load a Polar string into the KB (without filename).- Parameters:
str
- Polar string to be loaded.- Throws:
Exceptions.InlineQueryFailedError
- On a failed inline query.Exceptions.OsoException
-
query
Query for a predicate, parsing it first.- Throws:
Exceptions.OsoException
-
query
Query for a predicate, parsing it first and optionally accepting an expression.- Throws:
Exceptions.OsoException
-
query
Query for a predicate, parsing it first and applying bindings- Throws:
Exceptions.OsoException
-
query
public Query query(String query, Map<String, Object> bindings, boolean acceptExpression) throws Exceptions.OsoExceptionQuery for a predicate, parsing it first, applying bindings and optionally accepting an expression.- Throws:
Exceptions.OsoException
-
query
Query for a predicate.- Throws:
Exceptions.OsoException
-
query
Query for a predicate, optionally accepting expressions in the result.- Throws:
Exceptions.OsoException
-
query
public Query query(Predicate query, Map<String, Object> bindings, boolean acceptExpression) throws Exceptions.OsoExceptionQuery for a predicate, applying bindings and optionally accepting the expression type as a result.- Parameters:
acceptExpression
- Set to true to accept an Expression as a result from the VM.- Throws:
Exceptions.OsoException
-
queryRule
Query for a rule.- Parameters:
rule
- Rule name, e.g. "f" for rule "f(x)".args
- Variable list of rule arguments.- Throws:
Exceptions.OsoException
-
queryRule
public Query queryRule(String rule, Map<String, Object> bindings, Object... args) throws Exceptions.OsoExceptionQuery for a rule.- Parameters:
rule
- Rule name, e.g. "f" for rule "f(x)".args
- Variable list of rule arguments.- Throws:
Exceptions.OsoException
-
queryRuleOnce
Query for a rule, and check if it has any results. Returns true if there are results, and false if not.- Parameters:
rule
- Rule name, e.g. "f" for rule "f(x)".args
- Variable list of rule arguments.- Throws:
Exceptions.OsoException
-
repl
Start the Polar REPL.- Throws:
Exceptions.OsoException
IOException
-
repl
Load the given files and start the Polar REPL.- Throws:
Exceptions.OsoException
IOException
-
main
- Throws:
Exceptions.OsoException
IOException
-
registerClass
public void registerClass(Class<?> cls) throws Exceptions.DuplicateClassAliasError, Exceptions.OsoException Register a Java class with Polar. -
registerClass
public void registerClass(Class<?> cls, String name) throws Exceptions.DuplicateClassAliasError, Exceptions.OsoException Register a Java class with Polar using an alias. -
registerConstant
Registers `value` as a Polar constant variable called `name`.- Throws:
Exceptions.OsoException
-
loadFile(String)
has been deprecated in favor ofloadFiles(String[])
as of the 0.20 release.