[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.modeling.mdt.uml2.uml] Re: Problem with XMI import from case (Enterprise Architect)
|
Peter,
You'll need to use the UML resource implementation instead of the default
XMI one if you want the serialization to look as expected. That is, as
outlined in the FAQ (see
http://wiki.eclipse.org/index.php/MDT-UML2-UML-FAQ#What.27s_required_to_load_a_UML_.28.uml.29_resource_from_a_standalone_application.3F),
you'll need to register the UML resource factory like this:
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
There are several threads in the old newgroup (eclipse.tools.uml2) on the
subject of parsing XMI files as UML... try searching for "XMI2UML".
Kenn
"Peter Jackson" <klinham@xxxxxxxxx> wrote in message
news:b2490cd6841d5dd06b4b3c111df63fb8$1@xxxxxxxxxxxxxxxxxx
> Thanks for your answer, but some part is still unclear to me:
>
>> If I name your sample file abc.xmi, I can use "Open With->UML Model
>> Editor" and it loads with errors complaining about the bad enum values
>> but this version with that problem corrected loads fine:
>
> positive, but I want it to be loaded by my class, ideally I would like to
> run eclipse headless..
>
>> Be sure to load and save using the right type of resource implementation;
>> there's one for reading UML serialized as standard XMI and one for saving
>> as .uml
>
> Now I'm confused. Where is the part about resource implementations ? From
> what I observed it's the right way to read UML model
>
>
> // Create a resource set.
> ResourceSet resourceSet = new ResourceSetImpl();
>
> // Register the default resource factory -- only needed for
> // stand-alone!
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
> .put(Resource.Factory.Registry.DEFAULT_EXTENSION,
> new XMIResourceFactoryImpl());
>
> // Register the package to ensure it is available during loading.
> //
> resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,UMLPackage.eINSTANCE);
>
> // Register the package -- only needed for stand-alone!
> UMLPackage umlPackage = UMLPackage.eINSTANCE;
>
> // Get the URI of the model file.
> URI fileURI = URI.createFileURI("c:\\mymodel.xml");
> // Demand load the resource for this file.
> Resource resource = resourceSet.getResource(fileURI, true);
> // Process resources
>
>
> And with saving:
>
>
> // Create a resource set.
> ResourceSet resourceSet = new ResourceSetImpl();
> UMLFactory factory = UMLFactory.eINSTANCE;
>
> // Register the default resource factory -- only needed for stand-alone!
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,
> new XMIResourceFactoryImpl());
>
> // Register the package to ensure it is available during loading.
> //
> resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE); // Get the URI of the model file.
> URI fileURI = URI.createFileURI(new File("c:\\exported_model.uml")
> .getAbsolutePath());
>
> // Create model by hand just for testing purposes
> Model model = factory.createModel();
> // Populate model // ...
>
> // Create a resource for this file.
> Resource resource = resourceSet.createResource(fileURI);
>
> // Add the book and writer objects to the contents.
> resource.getContents().add(model);
>
> // Save the contents of the resource to the file system.
> try {
> resource.save(Collections.EMPTY_MAP);
> } catch (IOException e) {
> }
>
> If i didn't get the picture could you point me to some doc ?
>
>