| Problems creating Papyrus models [message #1097210] |
Thu, 29 August 2013 07:35  |
Han G Messages: 11 Registered: August 2013 |
Junior Member |
|
|
Hi,
I am trying to create a Papyrus model (*.uml, *.di and *.notation files) as is done here http://www.eclipse.org/forums/index.php/t/366898/
My snippet looks like this:
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel;
import org.eclipse.papyrus.uml.tools.model.UmlModel;
...
UmlModel umlModel = new UmlModel();
DiModel diModel = new DiModel();
NotationModel notationModel = new NotationModel();
ModelSet modelSet = new ModelSet();
try {
modelSet.registerModel(umlModel);
modelSet.registerModel(diModel);
modelSet.registerModel(notationModel);
modelSet.createModels(URI.createPlatformResourceURI(<some path>, true));
}
catch (Exception e) {
e.printStackTrace();
}
...
But this doesn't do anything (no resources are created and no exceptions thrown). I tried to create the UML model alone with:
UmlModel umlModel = new UmlModel();
umlModel.initializeEmptyModel();
umlModel.createModel(URI.createPlatformResourceURI("", true));
But this throws a NullPointerException at initializeEmptyModel() (if I remove this call, the NullPointerException is thrown at createModel(...))
Any ideas what I might have missed? I cannot create any model (DiModel or NotationModel) either without getting NullPointerExceptions.
Thanks for help
Han
|
|
|
|
| Re: Problems creating Papyrus models [message #1097237 is a reply to message #1097210] |
Thu, 29 August 2013 08:21   |
Christian W. Damus Messages: 603 Registered: July 2009 |
Senior Member |
|
|
Hi,
Is it possible that creating models requires services that are obtained
from the ServicesRegistry? You might try creating an
ExtensionServicesRegistry, asking it for the ModelSet (which will
actually be a more specialized implementation, such as for lazy-loading
or even CDO support), and using that. Of course, the service registry
would have be disposed when you've finished.
HTH,
Christian
On 2013-08-29 11:35:18 +0000, Han G said:
> Hi,
> I am trying to create a Papyrus model (*.uml, *.di and *.notation
> files) as is done here http://www.eclipse.org/forums/index.php/t/366898/
>
> My snippet looks like this:
>
> import org.eclipse.papyrus.infra.core.resource.ModelSet;
> import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
> import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel;
> import org.eclipse.papyrus.uml.tools.model.UmlModel;
>
> ..
>
> UmlModel umlModel = new UmlModel();
> DiModel diModel = new DiModel();
> NotationModel notationModel = new NotationModel();
> ModelSet modelSet = new ModelSet();
> try {
> modelSet.registerModel(umlModel);
> modelSet.registerModel(diModel);
> modelSet.registerModel(notationModel);
> modelSet.createModels(URI.createPlatformResourceURI(<some path>, true));
> }
> catch (Exception e) {
> e.printStackTrace();
> }
>
> ..
>
>
> But this doesn't do anything (no resources are created and no
> exceptions thrown). I tried to create the UML model alone with:
>
>
> UmlModel umlModel = new UmlModel();
> umlModel.initializeEmptyModel();
> umlModel.createModel(URI.createPlatformResourceURI("", true));
>
>
> But this throws a NullPointerException at initializeEmptyModel() (if I
> remove this call, the NullPointerException is thrown at
> createModel(...))
>
> Any ideas what I might have missed? I cannot create any model (DiModel
> or NotationModel) either without getting NullPointerExceptions.
>
> Thanks for help
> Han
|
|
|
|
| Re: Problems creating Papyrus models [message #1097277 is a reply to message #1097237] |
Thu, 29 August 2013 09:30   |
Camille Letavernier Messages: 285 Registered: February 2011 |
Senior Member |
|
|
Hi,
For the ModelSet tests, I use the following code:
ModelSet modelSet = new DiResourceSet();
modelSet.createsModels(diFile);
ServicesRegistry registry = new ExtensionServicesRegistry(org.eclipse.papyrus.infra.core.Activator.PLUGIN_ID);
try {
registry.add(ModelSet.class, Integer.MAX_VALUE, modelSet);
registry.startRegistry();
} catch (ServiceException ex) {
//Ignore
}
IModelCreationCommand creationCommand = new CreateUMLModelCommand();
creationCommand.createModel(modelSet);
modelSet.save(new NullProgressMonitor());
This initializes basic Papyrus model (di + notation + uml), with a root Model in the UML resource
It relies on a little bit of deprecated code, as you're now supposed to use EMF URIs instead of Eclipse IFiles, and the DiResourceSet itself is deprecated, but you could replace it with the following code:
ModelSet modelSet = new ModelSet();
ModelsReader reader = new ModelsReader(); //Standard ModelsReader for Di + UML + Notation
reader.readModel(modelSet);
modelSet.createModels(diURI); //Use an EMF URI instead of an Eclipse IFile
ServicesRegistry registry = new ExtensionServicesRegistry(org.eclipse.papyrus.infra.core.Activator.PLUGIN_ID);
try {
registry.add(ModelSet.class, Integer.MAX_VALUE, modelSet);
registry.startRegistry();
} catch (ServiceException ex) {
//Ignore
}
IModelCreationCommand creationCommand = new CreateUMLModelCommand();
creationCommand.createModel(modelSet);
modelSet.save(new NullProgressMonitor());
I didn't test the second snippet, but it should work, without using any deprecated code.
Regards,
Camille
|
|
|
|
Powered by
FUDForum. Page generated in 0.01513 seconds