Eclipse 建模框架 (EMF):如何从 Magicdraw UML2 导出中获取 DomainModel

发布于 2024-08-04 12:55:39 字数 1634 浏览 3 评论 0原文

我想使用 EMF 进行代码生成,因此我编写了一些方法来加载我自己生成的 UML2 文件。这适用于以下代码:

protected void registerResources() {
    resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);

    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);

    Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
    String resourcesJarPath = Thread.currentThread().getContextClassLoader().getResource("org.eclipse.uml2.uml.resources_2.2.0.v200805131030").toExternalForm();
    URI baseUri = URI.createURI(resourcesJarPath);
    uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), baseUri.appendSegment("libraries").appendSegment(""));
    uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), baseUri.appendSegment("metamodels").appendSegment(""));
    uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), baseUri.appendSegment("profiles").appendSegment(""));
}

public Package loadPackage(URI uri) {
    Resource resource = resourceSet.getResource(uri, true);
    return (Package) EcoreUtil.getObjectByType(resource.getContents(), UMLPackage.Literals.PACKAGE);
}

但现在,我想将 Magicdraw-Domainmodel 导出到 EMF UML2 XMI,在那里我得到 5 个文件。 1 个project.uml 和 4 个配置文件(UML_Standard_Profile.MagicDraw_Profile.DSL_Customization.profile.uml、UML_Standard_Profile.MagicDraw_Profile.profile.uml、UML_Standard_Profile.UML_Standard_Profile.profile.uml、UML_Standard_Profile.Validation_Profile.profile.uml)。 因此,如果我想使用 loadPackageclass 加载 project.uml,我的 Package 为 null。

有谁有示例应用程序,如何加载 MagicDraw 导出的 UML DomainModel?

多米尼克

I want to use the EMF for Code Generation, so I wrote some methods to load my UML2 File which I generated myself. This works fine with the following code:

protected void registerResources() {
    resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);

    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);

    Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
    String resourcesJarPath = Thread.currentThread().getContextClassLoader().getResource("org.eclipse.uml2.uml.resources_2.2.0.v200805131030").toExternalForm();
    URI baseUri = URI.createURI(resourcesJarPath);
    uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), baseUri.appendSegment("libraries").appendSegment(""));
    uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), baseUri.appendSegment("metamodels").appendSegment(""));
    uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), baseUri.appendSegment("profiles").appendSegment(""));
}

public Package loadPackage(URI uri) {
    Resource resource = resourceSet.getResource(uri, true);
    return (Package) EcoreUtil.getObjectByType(resource.getContents(), UMLPackage.Literals.PACKAGE);
}

But now, I wanted to export an Magicdraw-Domainmodel to an EMF UML2 XMI, and there I get 5 Files. One project.uml and 4 Profile Files (UML_Standard_Profile.MagicDraw_Profile.DSL_Customization.profile.uml, UML_Standard_Profile.MagicDraw_Profile.profile.uml, UML_Standard_Profile.UML_Standard_Profile.profile.uml, UML_Standard_Profile.Validation_Profile.profile.uml).
So if I want to load the project.uml with the loadPackageclass, my Package is null.

Does anyone have an example app, how to load an MagicDraw-exported UML DomainModel?

Dominik

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜是你 2024-08-11 12:55:39

您能否向我们展示 MagicDraw(如 XMI)中的 UML 模型的前几行?在这里,对于某些模型,我需要额外的内容

resourceSet.getPackageRegistry().put("http://www.eclipse.org/uml2/2.0.0/UML", UMLPackage.eINSTANCE);

来加载这些模型(诚然,这些模型来自 Eclipse 3.4.2 中的旧 MD 版本)。

Could you show us the first few lines of the UML model from MagicDraw (as XMI)? Here, for some models I need an additional

resourceSet.getPackageRegistry().put("http://www.eclipse.org/uml2/2.0.0/UML", UMLPackage.eINSTANCE);

to load those models (which admittedly come from an older MD version, in Eclipse 3.4.2).

菩提树下叶撕阳。 2024-08-11 12:55:39

来源: http://dev.eclipse.org/ newslists/news.eclipse.modeling.mdt.uml2/msg01517.html

对于 EMF UML

导入 org.eclipse.uml2.uml.util.UMLUtil;
Profile myProfile = UMLUtil.getProfile(MyProfilePackage.eINSTANCE, ... )

在电子邮件链中我发现了这一点,他们还展示了如何将其挂钩到模型 - 这应该对您也有帮助。

提问者似乎没有明白,但它对我来说很有意义,并且类似于您用于 IBM RSA 的方法。

IBM RSA:

File f = new File(...);
配置文件 p = UMLModeler.openProfile(f.getAbsolutePath());

Source: http://dev.eclipse.org/newslists/news.eclipse.modeling.mdt.uml2/msg01517.html

For EMF UML:

import org.eclipse.uml2.uml.util.UMLUtil;
Profile myProfile = UMLUtil.getProfile(MyProfilePackage.eINSTANCE, ... )

In the email chain I found on this they also showed how to hook it to a model - which should be helpful to you as well.

The question asker did not seem to get it, but it makes sense to me and is similar to the methods you use for IBM RSA.

IBM RSA:

File f = new File(...);
Profile p = UMLModeler.openProfile(f.getAbsolutePath());

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文