我在Scala中开发的应用程序的一部分需要读取和解析EMF / UML模型以及在这些模型上定义的OCL表达式。我的OCL表达式几乎是在这些EMT / UML模型上定义的查询表达式。
我的问题:
1)为了读取和解析EMF / UML模型,有哪些API选项?
2)为了在EMF / UML模型上解析和评估OCL表达式(查询),有哪些API选项。
答案 0 :(得分:1)
要开始使用EMF和UML,您至少需要依赖以下jar:
然后您可以使用以下代码加载第一个EMF模型:
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();
}
在EObjects(EMF基本元素)上解析和评估OCL代码会有点复杂,您可以查看OCL的文档和wiki以获取更多信息:https://wiki.eclipse.org/OCL#Example_Code