Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » how to add resources to a resource set ( how to add resources to a resource set )
how to add resources to a resource set [message #1799355] Wed, 05 December 2018 13:56 Go to next message
Sharmila D is currently offline Sharmila DFriend
Messages: 79
Registered: June 2018
Member
Hii

can anyone Please help me how to add resources to a resource set programatically in sirius.My resource set is already having rootobject.How I need to add resources to that existing resource set.

Iam having the following code snippet which works fine
final ResourceSet local_rs = new ResourceSetImpl();
final Resource local_resource = local_rs.
createResource(local_semanticModelURI);
global_domain.getCommandStack().execute(new RecordingCommand(global_domain) {

@Override
protected void doExecute() {
/* adding the contents of arEobject to resource */
local_res.getContents().add(global_autosarobj);
try {

//local_createdSession.save(local_monitor);
local_res.save(Collections.EMPTY_MAP);

} /*End of try*/
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}/*End of catch*/

}/* End of doExecute() */
});
this works fine for some cases for some cases it is showing error I feel iam doing something wrong

Iam thinking that I was not supposed to create a newResource set.
how to add resources to that existing resource set.:
Iam tried the below code by using session to get existing resource set.iam getting the resource set but if I try to add resources to thet throws an exception

Session local_createdSession = SessionManager.INSTANCE.
getSession(sessionResourceURI, local_monitor);

Iterator<Resource>local_it =local_createdSession.getSemanticResources().iterator();
//URI gt =URI.createPlatformResourceURI(local_descriptionFile.getFullPath().toOSString(),true);
while (local_res==null && local_it.hasNext()) {
Resource local_r = local_it.next();
if(local_semanticModelURI.equals(local_r.getURI()))
{
local_res=local_r;
}


}
global_domain.getCommandStack().execute(new RecordingCommand(global_domain) {

@Override
protected void doExecute() {
/* adding the contents of arEobject to resource */
local_res.getContents().add(global_autosarobj);
try {

//local_createdSession.save(local_monitor);
local_res.save(Collections.EMPTY_MAP);

} /*End of try*/
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}/*End of catch*/

}/* End of doExecute() */
});


it is throwing the exception if I go through session


java.lang.IllegalStateException: Cannot modify resource set without a write transaction
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting(TransactionChangeRecorder.java:348)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.appendNotification(TransactionChangeRecorder.java:302)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.processResourceNotification(TransactionChangeRecorder.java:272)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.notifyChanged(TransactionChangeRecorder.java:238)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
at org.eclipse.emf.common.notify.impl.NotificationImpl.dispatch(NotificationImpl.java:1027)
at org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUnique(NotifyingListImpl.java:299)
at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:303)
at org.eclipse.emf.common.util.ECollections.setEList(ECollections.java:191)
at org.eclipse.emf.ecore.change.impl.ResourceChangeImpl.process(ResourceChangeImpl.java:305)
at org.eclipse.emf.ecore.change.impl.ResourceChangeImpl.apply(ResourceChangeImpl.java:282)
at org.eclipse.emf.ecore.change.impl.ResourceChangeImpl.apply(ResourceChangeImpl.java:267)
at org.eclipse.emf.ecore.change.impl.ChangeDescriptionImpl.apply(ChangeDescriptionImpl.java:306)
at org.eclipse.emf.transaction.util.CompositeChangeDescription.apply(CompositeChangeDescription.java:135)
at org.eclipse.emf.transaction.impl.TransactionImpl.doRollback(TransactionImpl.java:570)
at org.eclipse.emf.transaction.impl.TransactionImpl.rollback(TransactionImpl.java:547)
at org.eclipse.emf.workspace.AbstractEMFOperation.rollback(AbstractEMFOperation.java:630)
at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:187)
at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:488)
at org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl.doExecute(WorkspaceCommandStackImpl.java:208)
at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:165)
at org.eclipse.sphinx.emf.workspace.domain.factory.ExtendedWorkspaceEditingDomainFactory$1.execute(ExtendedWorkspaceEditingDomainFactory.java:201)
at com.avin.arxml.generation.handlers.GenerateDesign.generateSiriusResource(GenerateDesign.java:505)


How I can add resources to existing resourceset
Re: how to add resources to a resource set [message #1799358 is a reply to message #1799355] Wed, 05 December 2018 15:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30351
Registered: July 2009
Senior Member
It looks like the rollback itself is failing. I doubt you should be doing a save during a command. I don't know the purpose of your new resource set. Shouldn't you be using the editing domain's resource set and shouldn't you do the create of the resource inside the doExecute?
Re: how to add resources to a resource set [message #1799405 is a reply to message #1799358] Thu, 06 December 2018 09:12 Go to previous messageGo to next message
Sharmila D is currently offline Sharmila DFriend
Messages: 79
Registered: June 2018
Member
HI
Ed Merks
Thanks for the reply

how to get the editing domain resource set.Please help me
Re: how to add resources to a resource set [message #1799414 is a reply to message #1799405] Thu, 06 December 2018 11:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30351
Registered: July 2009
Senior Member
I have a feeling you are working for a large corporation and that you should get help internally.

In any case, global_domain.getResourceSet() should do the trick.
Re: how to add resources to a resource set [message #1799465 is a reply to message #1799414] Fri, 07 December 2018 09:46 Go to previous messageGo to next message
Sharmila D is currently offline Sharmila DFriend
Messages: 79
Registered: June 2018
Member
HI
Ed Merks
Thanks for the reply

As you said I am getting the existing resource but I was not able to add resources to existing resource set.
Please find the below code
Session local_createdSession = SessionManager.INSTANCE.
getExistingSession(sessionResourceURI);
TransactionalEditingDomain local_domain = local_createdSession.
getTransactionalEditingDomain();
Resource Res= local_domain.getResourceSet().getResource(local_createPlatformResourceURI, true);
EObject local_rootObject1 = EcoreResourceUtil.getModelRoot(Res);
local_domain .getCommandStack().
execute(new RecordingCommand(local_domain ) {
@Override
protected void doExecute() {
Res.getContents.add(global_arEobject)
Res.save



}
});
when I try to add contents to existing rootobject it is throwing me error.
How to add resource contents to model.

am I doing correct ?
Please help me


[Updated on: Fri, 07 December 2018 09:48]

Report message to a moderator

Re: how to add resources to a resource set [message #1799470 is a reply to message #1799465] Fri, 07 December 2018 11:32 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6437
Registered: July 2009
Senior Member
Hi

A major problem for large modeling applications is avoiding different components updating models in a competitive fashion. Debugging these problems can be a huge PITA.

EMF Transaction solves many of these problems by imposing a very tight one-writer at a time straight jacket on what can be done. This is also a PITA, until you learn to live with it.

Each EMF Transaction-based framework has its policies for how to live within the one at a time discipline. You therefore should look for Sirius documentation, examples and correspondence on the Sirius forum to find the correct approach. This is not an EMF problem; it is an EMF Transaction protection.

Regards

Ed Willink
Previous Topic:Error with import after refactoring interface
Next Topic:Xcore and JUnit4/5
Goto Forum:
  


Current Time: Mon Aug 19 03:27:43 GMT 2019

Powered by FUDForum. Page generated in 0.02115 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top