How to save UML2 model as XMI (standalone) [message #625856] |
Mon, 07 January 2008 23:33 |
Eclipse User |
|
|
|
Originally posted by: jlansing.spawar.navy.mil
When I save my Model (from a standalone Java app) I don't get the top level
xmi:XMI element. Instead, the uml:Model element is at the top level.
I've tried using both .xmi and .uml extensions. (Interesting differences
result, but this isn't one of them).
My code is this:
public void save(Model model, String pathName) {
URI uri = URI.createURI("file:///" + pathName.replace('\\', '/'));
ResourceSetImpl resourceSet = new ResourceSetImpl();
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
UMLPackage.eINSTANCE);
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(Ecore2XMLResource.FILE_EXTENSION,
Ecore2XMLResource.Factory.INSTANCE);
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(XMI2UMLResource.FILE_EXTENSION,
XMI2UMLResource.Factory.INSTANCE);
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
Resource resource = resourceSet.createResource(uri);
resource.getContents().add(model);
try {
resource.save(null);
} catch (IOException e) {
e.printStackTrace();
}
}
Obviously I've tried to mash together all the examples in the documentation
and what I've found in this newsgroup, but I'm still not getting it.
|
|
|
Powered by
FUDForum. Page generated in 0.02600 seconds