[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)

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 ?