Download Ecore.js from dist/ folder, and include it in your html along with underscore.js.
<script src="underscore.js"></script><script src="ecore.js"></script>
Alternatively you can use the dependency manager Bower to install Ecore.js in your project.
bower install ecore
Ecore.js is available on npm and can be use as a Node module. To install it simply use the following command from your terminal:
npm install ecore
Importing Ecore.js in a Node module is done as follow:
var Ecore = require('ecore');
// Resources contain model elements and are identified by a URI.var resourceSet = EcoreResourceSetcreate;var resource = resourceSetcreate uri: '/model.json' ;// EClass are used to define domain elements, they are identified// by name and a set of structural features (attributes and references).var User = EcoreEClasscreatename: 'User'eStructuralFeatures:// EAttributes are used to define domain elements// elements properties.EcoreEAttributecreatename: 'name'upperBound: 1eType: EcoreEString// EReferences are used to define links between domain// elements.EcoreEReferencescreatename: 'friends'upperBound: -1containment: falsereturn User;;// EPackages represent namespaces for a set of EClasses.// It's properties name, nsURI and nsPrefix must be set.var SamplePackage = EcoreEPackagecreatename: 'sample'nsURI: ''nsPrefix: 'sample'eClassifiers:User;// Packages must be added directly to the model's Resource.resourceaddSamplePackage;
Model Elements can also be created separately.
var User = EcoreEClasscreate name: 'User' ;var User_name = EcoreEAttributecreatename: 'name'eType: EcoreEString;var User_friends = EcoreEReferencecreatename: 'friends'upperBound: -1eType: User;Userget'eStructuralFeatures'addUser_name;Userget'eStructuralFeatures'addUser_friends;
var u1 = Usercreate name: 'u1' ;var u2 = Usercreate name: 'u2' ;u1get'friends'addu2;u1get'friends'each console.logfriend ;
JSON is the default serialization format supported by ecore.js. The JSON format is described here and looks like this:
"eClass" : "/model.json#//User""name" : "u1""friends" :"$ref" : '/u2.json#/' eClass: '/model.json#//User'"$ref" : '/u3.json#/' eClass: '/model.json#//User'
Support for XMI has been added in version 0.3.0. This support requires sax.js.
var resourceSet = EcoreResourceSetcreate;var resource = resourceSetcreate uri: 'test2.xmi' ;resourceparsedata EcoreXMI; // data being a string containing the XMI.resourcetoEcoreXMI true; // returns the XMI string
If you want to contribute to this project or simply build from the source, you first need to clone the project by executing the following command in your terminal.
> git clone
Once these are installed, go back to your terminal and enter the ecore.js directory.
> cd ecore.js
The tests are written using the mocha library. To run them, execute the following command:
> grunt test
Running a build will create a new distribution in the folder dist. This is done by executing the command:
> grunt build
That's it, you are now ready to contribute to the project.
This software is distributed under the terms of the Eclipse Public License 1.0 - http://www.eclipse.org/legal/epl-v10.html.