Using Xtext DSL as a rule engine on runtime [message #1821429] |
Wed, 12 February 2020 17:26  |
Eclipse User |
|
|
|
Dear Xtext experts,
Thanks a lot for such an awesome technology and tools built around it!
We are using an Xtext technology to build a custom DSL which allow us to use different conditions as part of a rule engine and get a result of such conditions by running a DSL interpreter on runtime.
Example of such condition is here:
if(doSomething()) {
return true;
} else {
return false;
}
To run an interpreter we just create a model from our string conditions, load it as resource, get model and run interpreter.
Here it's a way we create and load our resource with a condition string:
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
resourceSet.createResource(URI.createURI(UUID.randomUUID().toString());
InputStream inputStream = new ByteArrayInputStream("condition as string");
resource.load(inputStream, resourceSet.getLoadOptions());
Could you help me with the following questions:
1. Do we use a ResourceSet in a proper way? Maybe some pieces of advice?
2. Do you see any possible issues (out of memory, timings etc)
Thanks in advance!
|
|
|
|
|
Re: Using Xtext DSL as a rule engine on runtime [message #1821706 is a reply to message #1821568] |
Tue, 18 February 2020 15:55  |
Eclipse User |
|
|
|
Adding to Christians comments
> XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
You could just do - XtextResourceSet resourceSet = new XtextResourceSet()
> resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
ECoreUtil#resolveAll() gets called internally, which tries to resolve all the proxies in your model. It might not be a good idea to load the complete model in the memory right at the start, especially if its a deep hierarchy
> esourceSet.createResource(URI.createURI(UUID.randomUUID().toString());
The file extension in the URI is required for getting the Resource Factory. It needs to be registered if you are running your application in standalone mode
> resource.load(inputStream, resourceSet.getLoadOptions());
resource.load(new StringInputStream("condition as string"));
Hope this helps.
|
|
|
Powered by
FUDForum. Page generated in 0.03483 seconds