qartal
qartal

Reputation: 2074

EMF/UML and OCL API for Scala

A part of an application I am developing in Scala needs to read and parse EMF/UML models along with OCL expressions defined over these models. My OCL expressions are pretty much query expression defined over these EMT/UML models.

My Questions:

1) What are the API options in order to read and parse EMF/UML models?

2) What are the API options in order to parse and evaluate OCL expressions (queries) over EMF/UML models.

Upvotes: 1

Views: 350

Answers (1)

sbegaudeau
sbegaudeau

Reputation: 1544

To get started with EMF and UML, you need at least a dependency to the following jars:

  • org.eclipse.emf.common
  • org.eclipse.emf.ecore
  • org.eclipse.uml2.uml

Then you can load your first EMF model with the following code:

File file = new File("path")
ResourceSet resourceSet = new ResourceSetImpl();

// Register the various metamodels that will be used, here we are using UML
resourceSet.getPackageResgitry().put(UMLPackage.NS_URI, UMLPackage.eINSTANCE);

// Load the resource
URI uri = URI.createFileURI(file.getAbsolutePath());
Resource resource = resourceSet.getResource(uri, false);

// Iterate on the content of the whole resource
TreeIterator<EObject> iterator = resource.getAllContents();
while (iterator.hasNext()) {
    EObject eObject = iterator.next();
}

Parsing and evaluating OCL code on EObjects (EMF basic element) would be a bit more complicated, you can have a look at OCL's documentation and wiki for more information: https://wiki.eclipse.org/OCL#Example_Code

Upvotes: 2

Related Questions