I'm working on a project where I have to build a graphical process modeler for a proprietary BPM (business process management) system made in java. I'm mentioning that the software is proprietary because it does not follow ANY international standards like BPEL, BPMN, XPDL, and this is a vital information for any answers I may get.
My intended approach is to use the eclipse GMF to create a standalone RCP application, similar to Bonita Studio, where business analysts will graphically model the business processes and deploy the process model into the web application.
This application has an internal wizard-like process modeler, very rudimentary. But this modeler has a functionality to import and export models in a custom, well defined XML format, which is also proprietary and has no international standards.
What I need is to persist the graphical model created with the eclipse gmf rcp application I'm developing into this custom XML format. This way I can simply invoque the import function in the web application and the process will be deployed. I also need to be able to do the reverse: open a custom process in this XML format into my eclipse RCP and show it in a graphical manner.
So, what I need is:
I need to save a graphical diagram in a custom XML format and open a custom XML file in this format and show it as graphical diagrams
Thank you very much for any help!
GMF is using EMF models to store its diagrams. As EMF Models are already able to map to XML, a XSL stylesheet transformation might be enough in most cases to map your model to your custom XML format and vice versa.
Daniel, I had this requirement for exporting diagram as XML and vice versa. I'll give you the procedure that I have followed below.
GUI to XML : - Use your model file in the below code to return the root element as java object.
Note : - Assuming GMF editor generates 2 files, one for model and one for the diagram, you have to choose the model file as input to the below code.
File model_file = new File(Path_to_your_model_file);
ResourceSet rs = new ResourceSetImpl();
URI fileUri = URI.createFileURI(model_file.getAbsolutePath());
Resource res = rs.getResource(fileUri, true);
Model model = res.getContents().get(0);
In the above line Model represent your root object of your ecore model. Now as you got the root object you can use it to get the all the values, references, etc
Using these you can manually write a java code to write a XML file.
XML to GUI : - This is pretty straight forward too
Create a new object for the root element for your model by using the below code.
ModelImpl model = (ModelImpl)ModelFactoryImpl.eINSTANCE.createModel(); // Replace Model with your model element name
You have to first parse the XML file using JAVA and read all the values step by step and assing the attributes to the model object step by step (for example : model.setName(doc.getDocumentElement().getAttribute("name")); and ChildObjImpl childObject = (ChildObj)ModelFactoryImpl.eINSTANCE.createChildObj();)
You can create all the different required objects that are supported by your code and then add them to the parent object (for example : model.getChildObject().add(childObject)); )
Once you have finished adding all the info from XML into these objects, you can use the root model object to create the model file as shown below
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi",new XMIResourceFactoryImpl());
Resource resource = resourceSet.createResource(URI.createFileURI(path_where_u_want_to_save_the_model_with_filename));
resource.getContents().add(dd);
resource.save(null);
Above code will generate the model fine, you can right click that file and generate the diagram file.
I don't know if there is a better way to do this, but this one worked for me well. Try it and let me know if you need further help.
Related
The vscode-antlr4 plugin for VisualStudio Code has a nice call-graph feature which visualizes (as a dendrogram) how grammar (and lexer) rules interact. You can save the graphic as SVG.
Is there a way to export the information as JSON? I wouldn't mind going into the plugin's code to find a way to do it.
My aim is to create reachability graphs for individual rules, i.e. graphs that show from which other rules a particular rule can be reached (transitively). The "calls" and "is-called" information from the call-graph feature would be a nice starting point.
The data for the call graph comes from a source context instance (for each grammar file there's a single source context to manage all details for it). See the function getReferenceGraph, which collects the relations into a map object. You can use that object to generate a JSON object from it. Or you create another function, taking this one as template, to generate the JSON directly, without the overhead required for the UI.
My question has two parts:
1) How can I create and/or modify and then store EMF ecore files (ecore metamodels with .ecore suffixes) from my scala/java code?
2) How can I create and/or modify an instance of an ecore file (i.e. a model conforming to an ecore metamodel) from my scala/java code?
I am looking to see if there are some possible ways of doing these, other that manipulating directly their corresponding XML files using XML API's.
Providing a code spinet or a reference to it is very much appreciated.
ps. As a background thought, I am wondering if I can use a single API for performing both of the above tasks, as we can look to an ecore file as a model/instance of Ecore.ecore.
Basic Concepts (Resource, ResourceSet, Resource Factory and Registry):
Before answering this question I will explain some concepts in ecore API. The First two concepts are Resource and ResourceSet. Resource is a program level representation of a persistent resource (like an ecore file), and ResourceSet is simply a set of these kind of resources. Each ecore metamodel document as well as a model document (which conforms to its metamodel) is a resource. Therefore the first step to work with these files is to provide a program level representation of them as resources in a resourceSet.
Another two concepts are Resource Factory and Registry. Factory classes are used to generate resources, and registries are keeping track of list of these factories in resourceSets. Depending on how our resource are stored, we can use different factories to manipulate them. For example, EcoreResourceFactoryImpl, XMLResourceFactoryImpl, and XMIResourceFactoryImpl are some examples of factory implementations that can be used to handle, respectively, ecore, xml, and xmi files. If we want to use these factories to handle resources in a resourceSet we need to put them in the registry list of resourceSet first. So, for each resourceSet that I mentioned above, there is a registry list.
With all the above being said, let's see how loading and modifying an ecore file (metamodel) and an instance file (model) happens in a java code.
First, We need to create a resourceSet to represent our persistent resources we would like to work with:
ResourceSet resourceSet = new ResourceSetImpl();
Then in the registry of this resourceSet, we need to register the Factories we want to work with:
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
Above two lines of code simply register EcoreResourceFactoryImpl and XMIResourceFactoryImpl as, respectively, ecore and xmi file factories (note that ecore and xmi are file extensions there). I assumed that my metamodel file extension is ecore and my model file extension is xmi.
After registering these Factories, we can now ask our ResourceSet to load our metamodel (i.e., ecore) file as below:
Resource myMetaModel= resourceSet.getResource(URI.createFileURI("./univ.ecore"), true);
univ.ecore is the name of my ecore file.
For loading a model file we need to take one further step! We need to first register one more thing in our resourceSet. That is to register the package of our ecore metamodel in the registry list of packages in our resource set. For doing this we need to first get a programming level representation of our ecore package as bellow:
EPackage univEPackage = (EPackage) myMetaModel.getContents().get(0);
And then, register this package in the registry list of packages of our resource set as below:
resourceSet.getPackageRegistry().put("http://gholizadeh.org", univEPackage);
We are now ready to load our model (xmi file). We use the following code for this:
Resource myModel = resourceSet.getResource( URI.createURI( "./univModel.xmi"), true);
Now we have brought both of our metamodel and model files to the programming level, and we can simply manipulate them in code.
Change the Metamodel:
For example, for creating a new Class in an ecore file, we use EcoreFactory API: we first obtain an instance of this class as below:
EcoreFactory theCoreFactory = EcoreFactory.eINSTANCE;
and then create an EClass as the following:
EClass adultEClass= theCoreFactory.createEClass();
Then for keeping this Class, we need to add it to the list of our loaded ecore package classifiers as bellow:
univEPackage.getEClassifiers().add(adultEClass);
For doing aditional changes you need to get more familiar with ecore API.
Change the Model:
for changing a model, we need to create objects of type EObject. Similar to EcoreFactory in the above, we need a factory to do this. But instead of EcoreFactory, we need an object factory. For each ecore package there is an specific object factory of type EFactory that we can get as the following:
EFactory univInstance = univEPackage.getEFactoryInstance();
Note that univEPackage in above code, represents our ecore package (see some paragraphs above). After doing this, we are ready to create objects for our model. For example
EObject adultObject = univInstance.create(adultEClass);
create an object of type adultEClass, in our model. Note that for persisting this newly created object we need to add it to the content of our resource (that represent our model, i.e., myModel). Since our persistent file is in xmi format and it has only one root we need to put all of our objects in a list and add this list to our resource:
EList<EObject> ModelObjects = new BasicEList<EObject>();
ModelObjects.add(adultObject);
myModel.getContents().addAll(ModelObjects);
Storing Model and Metamodel files:
Finally, after we modified our metamodel and model elements we need to store them again in their corresponding files. This is simply done by calling save method of their corresponding Resources:
myModel.save(null);
myMetaModel.save(null);
I have an emf model and i'd like to make a GMF editor to create instances of this metamodel.I'd like also some live constraints to avoid some connections between the components of my EMF model.e.g:My EMF consists of A,B,C,D components which derive from a General class called F and there is reference within F which connects F->F,as such this is able to provide me with connections in between the A,B,C,D components.
But when i am at the GMF editor i'd like a mechanism to avoid connection A->B and allow only connection A->C.
I read that this is able to be achieved with OCL language and link constraints that are able to be added at the gmfmap file.
But i couldn't find any tutorial with the vocabulary of OCL and examples doing that live validation
Any directions from someone?
After a deeper search I found a very useful and fast framework for validation. It is called Eugenia from the Epsilon group.
Eugenia lets you create all the appropriate files for the final GMF editor through a single file (extremely awesome,because otherwise you have to declare gfmtool, gmfgraph, etc by your own) and afterwards you can create a new EVL file which holds the constraints and the invariants of your model.The mapping is been doing easily by providing and extension point at your metamodel URI and all you have to do is to include your new plugin which containts the evl file at your final Eclipse configuration. http://www.eclipse.org/gmt/epsilon/doc/articles/evl-gmf-integration/
(Be careful, do not generate the diagram code as an RPC application because the RPC is not going to work. For any further information have a look here : http://giampow.blogspot.com/2010/06/eclipse-rcp-application-custom-problems.html )
I am trying to create Web Services from the Top-Down approach. I downloaded Eclipse and am using the WSDL gui editor in it to build my WSDL files.
I am splitting up my Services based on "modules". The Types I am adding to the WSDLs all need to reference common stuff, such as PersonEntity, AddressEntity, States enumeration (simple type), Countries enumeration (simple type), and AbstractEntity. Since those items are all common I created a seperate WSDL file (named Commons.wsdl) that contains the type information for those types.
I want to "import" that WSDL into my other WSDL files to use:
For example, I have an entity named RegistrationEntity which inherits from AbstractEntity and contains a PersonEntity as well as an AddressEntity. I'm not sure how to do this... I saw that the WSDL spec has "import" and "include" and am not sure which one to use. Also, how do I actually import (or include) the Commons.wsdl file so that I can use the Types defined within it?
Thanks!
Oh, and I'm not sure if I'm supposed to stick this stuff in a seperate WSDL but another type of file such as an xsd or something. I really wanna follow best practices so if that's the proper way to do it then I'd rather do that.
I found out that the problem I had was I was creating a WSDL file for my commons and using an inline scheme for that, rather than creating an XSD file to be imported by my other WSDLs.
So instead I just created an Commons.XSD as my "Common Schema".
I want to create GUI components from XSD files. The generated GUIs should be used for concrete xml instances of the corresponding schema with databinding to "interesting" elements or attributes content.
I have considered these solutions:
jaxfront. (commercial tool). This does not generate source code. This is important for me because I want communication between the generated GUIs and other components of the GUI.
Use xsd2emf and try to generate an editor from that. The generated model is to complex, as well as the generated editor and it is buggy.
Do it myself e.g. generate an xml from the xsd, load xml as dom, select the interessting parts and generate data binding using one method described at http://www.vogella.de/eclipse.html.
Has anyone another idea or already successfully solved that problem? I would prefer a free open source solution which generates a SWT GUI.
Have you looked at the Sapphire framework at eclipse?
With it you have to create a model based on a few simple java interface files with some annotations that would model your XSD. Then once you have the model defined, you create the SWT GUI with a single xml file (sdef file) that wires various property editors to your model. The property editors can be simple widgets like label, text, lists, combo boxes but also it can be complex editors like a GEF-based diagram editor. So basically if you have a few interfaces that describe your model, then can have a graphical editor for editing nodes in that model with less than 100 lines of XML.
See lines 22 to 121 of this sample file.