Xtext: How to react on external changes of the AST - xtext

We're currently testing the connection between the Language Server with an instance of the EMFCloud.ModelServer. We're able to save/edit our Semantic Model in the Model Server workspace as it is described in the following answer. Basically, the Language Server handles our custom language using *.abcl files and when the user saves changes in the file, the Language Server reacts on the didSave action and saves the AST (EMF model) in the Model Server (using XMI) in a file *.abc (foo.abcl converted to -> foo.abc). The AST (EMF model) is now available for other EMF modelling editors (i.e. a Theia tree editor) where we can, for example rename a node or change attributes in a different manner.
What we're currently trying to achieve now is the Language Server to react on changes done by other editors on our AST (*.abc files). To do so, the Language Server is subscribed to events on the Model Server and eventually receive a "fullUpdate" event indicating that the AST changed.
Our problem is how to proceed now. We can think about the following workflow:
Model Server sends new model to Language Server (via subscription
mechanism)
The Language Server replaces the AST with the new model
Serialize the new AST and cache it into a Document?
At this point the *.abcl file (opened by the editor) is not in sync with the internal AST
Maybe the Language Server forwards the serialization (text representation) to the editor ?
Maybe the Language Server overwrites the *.abcl file in the workspace ?
Some guidance would be really appreciated
EDIT: Posted also a question on Eclipse Forums

During research of the internals of the Language Server and after doing some testing, I've figured out a way how the Language Server can react when the semantic model (AST) is updated/changed externally by means of another editor (i.e. a tree editor). The following is a possible workflow:
The Model Server notifies an external change (i.e. full model
update) to the Language Server by sending a new full model instance. See subscribe method
Language Server reads a copy of the internal semantic model (AST).
Language Server replaces the contents of the semantic model copy
with the new full model instance.
Language Server serializes
(transforms from EMF to textual representation) the new full model
instance to a String object.
Language Server notifies the Language Server client about the update received and asks whether the changes are accepted.
If the user accepts the changes
the model serialization (String) is sent to the client to replace the current contents of the text representation (workspace/applyEdit LSP method). "null" is sent as version value so the client decides the new version.
client receives the changes and automatically sends a "didChange" notification back to the server with the new status of the text representation. This requests will trigger an internal build in the Language Server resulting in an update of the actual
semantic model (AST)
At this point the client + AST + Model Server model will be in sync.
user rejects the changes
At this point the client + AST will still be in sync
The model in the Model Server will not be in sync with the client + AST
Text editor will show different information as other editors

Related

How can I send Java object between client and server on Android and iOS?

I have a client and a server both written in Java and sharing Java classes that should be sent between each other. I'm not sure which libraries I can use for this on mobile because I don't know what Dalvik supports, what RoboVM supports etc. Not sure what Gluon Mobile can do for me in this case.
Specifically I have a file that looks like this:
class Data {
IntegerProperty int1 = new SimpleIntegerProperty(4);
ObjectProperty<Person> person = new SimpleObjectProperty();
ObservableList<Contact> contacts = FXCollections.observableArrayList();
// other properties
// also add the getters for the properties and the getters and setters for the values
}
Person and Contact are similar to the above - they contain mostly data properties and some methods for adding and removing from internal (private) lists etc. Basically they are like beans or POJOs only with properties wrappers. This is the data that needs to be sent between the server and the client but only the wrapped values are important - not the bindings. This leads me to the point about serialization: javaFX properties are not serializeable so it was suggested here to make such class as the above externalizeable and write and read the wrapped values.
Ultimately I don't care if i need to do this custom stuff (though it's a lot of work) or if there's a way around it. I need a method on the server like Data receiveDatafor(...) that the client can call, the server fetches the Data data and returns it. The client and server each have their own unrelated bindings to the Data object.
Currently we use RMI internally for desktop. I read that RMI isn't supported and it might not be that great of an option anyway but it does allow to just send java objects really easily. JavaEE has websockets which can transfer the binary form of the objects but it's JavaEE so I guess not supported. I'm not against JSONing and sending as Text but it seems more work than to just serialize - could be wrong. The communication method should support encryption for example when sending passwords. What are my options?
In terms of client-server communication you can have a look at Gluon Connect and Gluon CloudLink.
Gluon Connect
An open source library:
Gluon Connect is a client-side library that simplifies binding your data from any source and format to your JavaFX UI controls. It works by retrieving data from a data source and converting that data from a specific format into JavaFX observable lists and observable objects that can be used directly in JavaFX UI controls.
It is also part of the Charm dependencies, so you have it already included when you create a new Gluon project.
See the documentation on how to use to create a FileProvider or a RestProvider, and also the GluonConnectRestProvider sample.
As the doc already mentions: with a RestClient you can "convert" a REST endpoint into an ObservableList:
// create a RestClient to the specific URL
RestClient restClient = RestClient.create()
.requestMethod(RestClient.Method.GET)
.host("https://api.stackexchange.com")
.path("/2.2/errors");
// retrieve a list from the DataProvider
GluonObservableList<Error> errors = DataProvider
.retrieveList(restClient.buildListDataReader(Error.class));
// create a JavaFX ListView and populate it with the retrieved list
ListView<Error> lvErrors = new ListView<>(errors);
The Notes sample uses Gluon Connect for local storage of Notes and Settings.
Note that these samples make uses of JavaFX POJOs (i.e. Error, Note and Settings use properties).
Gluon CloudLink
Gluon CloudLink enables enterprise and mobile developers to easily connect their different services and applications together, enabling bi-directional communications between mobile apps, enterprise infrastructure, and cloud systems.
The data is stored in the cloud, and you (as administrator) can access to it through a Dashboard.
See documentation about it here.
Have a look at the PWS-GluonCloudLink-Whiteboard sample: a full demo of a back-end application (webapp-mobile) running on the cloud (Pivotal Web Services) and a mobile client (mobile app).
In the client side, once you get a valid GluonClient, you can retrieve an observable list of items:
public GluonObservableList<Item> retrieveItems() {
GluonObservableList<Item> items = DataProvider.retrieveList(gluonClient.createListDataReader("items", Item.class));
return items;
}
As you can see, in the client you don't deal with REST endpoints, json serializing... Everything is just JavaFX observables. The connection with the backend is set in CloudLink with the Dashboard application, defining a REST Connector.

Export breeze entities in the server side to json

I am looking for a way to export breeze entities on the server side to a json string which a breezejs manager can import from the client side. I looked all over the breeze APIs (both public and internal source code) but I couldn't find an obvious way of achieving this. There is a possibility of getting the desired results by using BreezeSharp (a .NET breeze client) on the server side but I would like to see if this is achievable with using the breeze server APIs only.
First you need to determine the shape of the bundle to be imported, i.e. something that manager.importEntities will understand. I don't think the format is documented, but you can reverse-engineer it by using:
var exported = manager.exportEntities(['Customer', 'Product'], {asString:true, includeMetadata:false});
Then pretty-print the value of exported to see the data format. See EntityManager.exportEntities for more info.
Once you have that, you can re-create it on the server. In C#, you can build it up using Dictionary and List objects, then serialize it using Json.NET.
An alternative approach would be to have your webhook just tell the client to initiate a query to retrieve the data from the server.

HTTP Server in iOS to list files Documents directory

I am trying to create an HTTP Server inside my iOS application, to develop something like Xender application. Right now I Succeed to setup HTTP Server inside my Application and hosting any HTML file there, that can be loaded on another Device/System using IP and Port.
But, I want to Link that HTML to my application database to populate data on that HTML file, followed by making it dynamic so that It can be opened from another device or system.
Ultimately, I need to Query on SQLITE database of application from
HTML file, Is there any way to do such thing?
Can I connect SQLITE to frontend of HTML? In case of Web apps these things can be done using any server side scripting languages like PHP, by connecting with Databases like MySQL. But, Here My case is HTML and Sqlite.
EDIT
I found Is it possible to access an SQLite database from JavaScript? . but this is all about Client side local storage, but I think in my case its on Server side SQLITE.
You have to create template HTML files and provide a set of variables for it. Then, when the file is requested in your server, you load it into memory.
Now you do some RegEx magic to get the query parameters, do your SQL stuff and then replace the corresponding variables in your HTML string and finally serve it to the client.
Your would need to define your own non-logical "scripting" language that is able to tell your application what data is requested and where to output possibly returned data.
I think this is quite hard work and you should possibly try to find a better solution that is probably already done by others.
EDIT
You could use Node.js and this interpreter but it's not maintained anymore. But their might be similar projects.
EDIT II
I've found the neu.Node, which sounds quite promising. They haven't done anything in 4 months, but they seem to be well organized and documented.

TIBCO - Generate WSDL Dynamically

I have a WebService that is a service dispacher and it has a Body with the type anyType, so that way I have only one webservice and my client only needs to know the schema to put in the Body for the specific service that he is calling.
Now the problem is that everytime I create a new service or modify an existing one, I need to send the new schema for them. I need a way so I can generate the WSDL with the body replaced with the schema of the desired service, so I don't have to resend the schema everytime it changes.
Thanks in advance!
BTW I'm using Tibco Designer, if it matters :P
Create an XSLT that expects the generic WSDL as an input and takes a path to a schema as a parameter. Use the XSLT to generate the WSDL you want for your consumers.

nested type provider

I have one type provider that connects to the network to retrieve data.
And produce (the fiction we call) 'static type' through type providers mechanism.
Of course, I might not always be connected. I might be raging in a private jet with satellite connection down.
Has anyone experience building an "offline type provider" which take (somehow) a type (from a type provider) as an input, stores its definition on disk, and provides you later with said type definition for easy access while on your way to Koh Phangan ?
Since types are not allowed as parameter to TP, I was thinking in providing assembly name + type name to be offlined.
You can enhance your original type provider to work both in online and offline modes. I.e. provider tries to connect to data source and fetch schema, if successful schema is cached on disk (in some format that provider can understand). After that provider exposes types using schema information on disk. If for some reason connection to data source is not available - provider checks if cached schema exists and if yes - uses it. For example standard type providers (LINQ2SQL or EF) allow you to specify schema file that can be used if direct connection to database is not possible.
This is a tricky aspect of writing F# type providers. But I think the main problem is that when you're developing in a private jet and you're using type providers to access some external data source, then you won't be able to access the data.
Schema caching -
If the type provider supports some form of schema caching (i.e. by storing the schema in a XML file like LINQ to SQL mentioned by #desco), then you'll be able to write some code and compile it, but you still won't be able to test the code. I think this makes schema caching less useful for the private-jet scenario. However, it is useful in scenario where you build code on a build server that does not have access to the schema.
Local data - For the private-jet scenario, you probably need some sort of local data (or a subset), to be actually able to test the code you write and then you can often point the type provider to your local copy (database, CSV or XML file etc.).
Meta-provider - I think the idea of having meta-provider is pretty cool - it should work to some extent - you would be able to cache the schema, but you probably wouldn't be able to cache the data (perhaps the values of properites, but I guess methods would not work). I think it should be possible to just pass the name of the provider to mock as an argument to your meta-provider. Something like:
type CachedDB =
SchemaCachingProvider<"FSharp.Data.TypeProviders.dll", "SqlDataConnection", "..">
I'm not aware of any plans for doing something like this, but if you started, I'm sure the FSharpX people would be interested in looking at it :-).

Resources