how to add resources to a resource set programatically in sirius [message #1799347] |
Wed, 05 December 2018 11:33 |
Sharmila D Messages: 81 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
[Updated on: Wed, 05 December 2018 11:46] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04667 seconds