Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Problems creating Papyrus models
Problems creating Papyrus models [message #1097210] Thu, 29 August 2013 07:35 Go to next message
Han G is currently offline 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 #1097231 is a reply to message #1097210] Thu, 29 August 2013 08:14 Go to previous messageGo to next message
Han G is currently offline Han G
Messages: 11
Registered: August 2013
Junior Member
Oh no!
I forgot the save call:
modelSet.save(monitor);

But now I get a BasicEList$BasicIndexOutOfBoundsException: index=0, size=0...
I noticed that it is caused by the DiModel (not adding diModel to the modelSet will produce the *.uml and .*notation files without errors)

Any ideas?
Re: Problems creating Papyrus models [message #1097237 is a reply to message #1097210] Thu, 29 August 2013 08:21 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 701
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 #1097268 is a reply to message #1097237] Thu, 29 August 2013 09:19 Go to previous messageGo to next message
Han G is currently offline Han G
Messages: 11
Registered: August 2013
Junior Member
Quote:

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


I don't know much about ServiceRegistries but according to http://wiki.eclipse.org/Papyrus_Developer_Guide/How_To_Code_Examples I can get a ModelSet by
EObject eobject = ...; // You should know how to get your EObject :-)
ModelSet modelSet = ServiceUtilsForResource.getInstance().getModelSet(eobject.eResource());


where eobject would be a org.eclipse.uml2.uml.Model (which I created previously). But the registry call throws a ServiceNotFoundException. Do I really need a registry for just creating the files? It worked perfectly for the *.uml and *.notation file, just the *.di file breaks the save operation...

Regards,
Han
Re: Problems creating Papyrus models [message #1097277 is a reply to message #1097237] Thu, 29 August 2013 09:30 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille Letavernier
Messages: 399
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
Re: Problems creating Papyrus models [message #1097296 is a reply to message #1097277] Thu, 29 August 2013 09:59 Go to previous message
Han G is currently offline Han G
Messages: 11
Registered: August 2013
Junior Member
Hi,
your second snippet worked like a charm!

Thanks a lot and best regards
Han
Previous Topic:Never ending exceptions in the version 0.10.0
Next Topic:How to show Additional Resources in Model Explorer
Goto Forum:
  


Current Time: Thu Apr 17 14:35:54 EDT 2014

Powered by FUDForum. Page generated in 0.02365 seconds