Package com.osohq.oso
Class Polar
- java.lang.Object
-
- com.osohq.oso.Polar
-
-
Constructor Summary
Constructors Constructor Description Polar()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclearRules()Clear the rules from the KB, but maintain all registered classes and calls.voidloadFile(String filename)Deprecated.loadFile(String)has been deprecated in favor ofloadFiles(String[])as of the 0.20 release.voidloadFiles(String[] filenames)Load Polar policy files.voidloadFilesFromResources(String... filenames)Load Polar policy files from resources.voidloadStr(String str)Load a Polar string into the KB (without filename).voidloadStr(String str, String filename)Load a Polar string into the KB (with filename).static voidmain(String[] args)Queryquery(Predicate query)Query for a predicate.Queryquery(Predicate query, boolean acceptExpression)Query for a predicate, optionally accepting expressions in the result.Queryquery(Predicate query, Map<String,Object> bindings, boolean acceptExpression)Query for a predicate, applying bindings and optionally accepting the expression type as a result.Queryquery(String query)Query for a predicate, parsing it first.Queryquery(String query, boolean acceptExpression)Query for a predicate, parsing it first and optionally accepting an expression.Queryquery(String query, Map<String,Object> bindings)Query for a predicate, parsing it first and applying bindingsQueryquery(String query, Map<String,Object> bindings, boolean acceptExpression)Query for a predicate, parsing it first, applying bindings and optionally accepting an expression.QueryqueryRule(String rule, Object... args)Query for a rule.QueryqueryRule(String rule, Map<String,Object> bindings, Object... args)Query for a rule.booleanqueryRuleOnce(String rule, Object... args)Query for a rule, and check if it has any results.voidregisterClass(Class<?> cls)Register a Java class with Polar.voidregisterClass(Class<?> cls, String name)Register a Java class with Polar using an alias.voidregisterConstant(Object value, String name)Registers `value` as a Polar constant variable called `name`.voidrepl()Start the Polar REPL.voidrepl(String[] files)Load the given files and start the Polar REPL.
-
-
-
Field Detail
-
host
protected Host host
-
-
Constructor Detail
-
Polar
public Polar() throws Exceptions.OsoException- Throws:
Exceptions.OsoException
-
-
Method Detail
-
clearRules
public void clearRules() throws Exceptions.OsoExceptionClear the rules from the KB, but maintain all registered classes and calls.- Throws:
Exceptions.OsoException
-
loadFiles
public void loadFiles(String[] filenames) throws IOException, Exceptions.OsoException
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
public void loadFilesFromResources(String... filenames) throws IOException, Exceptions.OsoException
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 public void loadFile(String filename) throws IOException, Exceptions.OsoException
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
public void loadStr(String str, String filename) throws Exceptions.OsoException
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
public void loadStr(String str) throws Exceptions.OsoException
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
public Query query(String query) throws Exceptions.OsoException
Query for a predicate, parsing it first.- Throws:
Exceptions.OsoException
-
query
public Query query(String query, boolean acceptExpression) throws Exceptions.OsoException
Query for a predicate, parsing it first and optionally accepting an expression.- Throws:
Exceptions.OsoException
-
query
public Query query(String query, Map<String,Object> bindings) throws Exceptions.OsoException
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.OsoException
Query for a predicate, parsing it first, applying bindings and optionally accepting an expression.- Throws:
Exceptions.OsoException
-
query
public Query query(Predicate query) throws Exceptions.OsoException
Query for a predicate.- Throws:
Exceptions.OsoException
-
query
public Query query(Predicate query, boolean acceptExpression) throws Exceptions.OsoException
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.OsoException
Query 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
public Query queryRule(String rule, Object... args) throws Exceptions.OsoException
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.OsoException
Query for a rule.- Parameters:
rule- Rule name, e.g. "f" for rule "f(x)".args- Variable list of rule arguments.- Throws:
Exceptions.OsoException
-
queryRuleOnce
public boolean queryRuleOnce(String rule, Object... args) throws Exceptions.OsoException
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
public void repl() throws Exceptions.OsoException, IOExceptionStart the Polar REPL.- Throws:
Exceptions.OsoExceptionIOException
-
repl
public void repl(String[] files) throws Exceptions.OsoException, IOException
Load the given files and start the Polar REPL.- Throws:
Exceptions.OsoExceptionIOException
-
main
public static void main(String[] args) throws Exceptions.OsoException, IOException
- Throws:
Exceptions.OsoExceptionIOException
-
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
public void registerConstant(Object value, String name) throws Exceptions.OsoException
Registers `value` as a Polar constant variable called `name`.- Throws:
Exceptions.OsoException
-
-