Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Save level?
Save level? [message #414998] Tue, 27 November 2007 21:35 Go to next message
exquisitus is currently offline exquisitusFriend
Messages: 211
Registered: July 2009
Senior Member
Hello.

I defined my model as genmodel file and generated Java source. In application I create my Objects tree and
some of attributes was filed. After that I tried to save model to file. Model was saved but not complete. Save
method which I used:

Resource resource = new ResourceSetImpl().createResource(uri);
Map<String, Object> options = new HashMap<String, Object>();
options.put( XMLResource.OPTION_PROCESS_DANGLING_HREF, XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD );
EObject toSave = model.getStages().get(0).getActivities().get(0).getTasks().g et(0)
resource.getContents().add(toSave);
try {
resource.save(options);
} catch (IOException ioe) {}


This is example when I saved Task:

<?xml version="1.0" encoding="ASCII"?>
<org.uz.iie.gs.wwPP.eclipse.model:Task xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:org.uz.iie.gs.wwPP.eclipse.model="org.uz.iie.gs.wwPP.eclipse.model " id="TASK_1_1_1"
name="TASK1">
<steps id="STEP_1_1_1_1" name="STEP_1"/>
<steps id="STEP_1_1_1_2" name="STEP_2"/>
</org.uz.iie.gs.wwPP.eclipse.model:Task>

Unfortunately save didn't complete, because Steps contain nested elements which didn't save. When I directly
saved nested ArtifactsList element:

Resource resource = new ResourceSetImpl().createResource(uri);
Map<String, Object> options = new HashMap<String, Object>();
options.put( XMLResource.OPTION_PROCESS_DANGLING_HREF, XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD );
EObject toSave = model.getStages().get(0).getActivities().get(0).getTasks().g et(0).getArtifactsIn();
resource.getContents().add(toSave);
try {
resource.save(options);
} catch (IOException ioe) {}


the result was:

<?xml version="1.0" encoding="ASCII"?>
<org.uz.iie.gs.wwPP.eclipse.model:ArtifactsList xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:org.uz.iie.gs.wwPP.eclipse.model="org.uz.iie.gs.wwPP.eclipse.model " id="ARTIFACTS_LIST_IN_1_1_1"
name="In" maxSize="1"/>

What I should change if I want to save complete emf model as xml file? Do save method has possibility to set
level which can be save from emf model?

Best regards,
Tomasz
Re: Save level? [message #415012 is a reply to message #414998] Wed, 28 November 2007 11:57 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Tomasz,

Comments below.

exquisitus wrote:
> Hello.
>
> I defined my model as genmodel file and generated Java source. In application I create my Objects tree and
> some of attributes was filed. After that I tried to save model to file. Model was saved but not complete. Save
> method which I used:
>
That makes me wonder about whether you are using containment
references. It's very important that every object as eResource() !=
null. Without that, you'll get exceptions while saving and these
dangling references will disappear.
> Resource resource = new ResourceSetImpl().createResource(uri);
> Map<String, Object> options = new HashMap<String, Object>();
> options.put( XMLResource.OPTION_PROCESS_DANGLING_HREF, XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD );
>
Another hint to me that you have some dangling reference issues.
> EObject toSave = model.getStages().get(0).getActivities().get(0).getTasks().g et(0)
> resource.getContents().add(toSave);
> try {
> resource.save(options);
> } catch (IOException ioe) {}
>
>
> This is example when I saved Task:
>
> <?xml version="1.0" encoding="ASCII"?>
> <org.uz.iie.gs.wwPP.eclipse.model:Task xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:org.uz.iie.gs.wwPP.eclipse.model="org.uz.iie.gs.wwPP.eclipse.model " id="TASK_1_1_1"
> name="TASK1">
> <steps id="STEP_1_1_1_1" name="STEP_1"/>
> <steps id="STEP_1_1_1_2" name="STEP_2"/>
> </org.uz.iie.gs.wwPP.eclipse.model:Task>
>
> Unfortunately save didn't complete, because Steps contain nested elements which didn't save. When I directly
> saved nested ArtifactsList element:
>
You say "contain" nested elements, but I'll bet the reference isn't
marked as a containment reference, i.e., EReference.containment == true....
> Resource resource = new ResourceSetImpl().createResource(uri);
> Map<String, Object> options = new HashMap<String, Object>();
> options.put( XMLResource.OPTION_PROCESS_DANGLING_HREF, XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD );
> EObject toSave = model.getStages().get(0).getActivities().get(0).getTasks().g et(0).getArtifactsIn();
> resource.getContents().add(toSave);
> try {
> resource.save(options);
> } catch (IOException ioe) {}
>
>
> the result was:
>
> <?xml version="1.0" encoding="ASCII"?>
> <org.uz.iie.gs.wwPP.eclipse.model:ArtifactsList xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:org.uz.iie.gs.wwPP.eclipse.model="org.uz.iie.gs.wwPP.eclipse.model " id="ARTIFACTS_LIST_IN_1_1_1"
> name="In" maxSize="1"/>
>
> What I should change if I want to save complete emf model as xml file? Do save method has possibility to set
> level which can be save from emf model?
>
It sounds like you simply intended it to be a containment reference but
didn't mark it that way in the model...
> Best regards,
> Tomasz
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Save level? [message #415124 is a reply to message #415012] Fri, 30 November 2007 12:38 Go to previous message
exquisitus is currently offline exquisitusFriend
Messages: 211
Registered: July 2009
Senior Member
Ed Merks pisze:
> Tomasz,
>
> Comments below.
>
> exquisitus wrote:
>> Hello.
>>
>> I defined my model as genmodel file and generated Java source. In
>> application I create my Objects tree and
>> some of attributes was filed. After that I tried to save model to
>> file. Model was saved but not complete. Save
>> method which I used:
>>
> That makes me wonder about whether you are using containment
> references. It's very important that every object as eResource() !=
> null. Without that, you'll get exceptions while saving and these
> dangling references will disappear.
>> Resource resource = new ResourceSetImpl().createResource(uri);
>> Map<String, Object> options = new HashMap<String, Object>();
>> options.put( XMLResource.OPTION_PROCESS_DANGLING_HREF,
>> XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD );
>>
> Another hint to me that you have some dangling reference issues.
>> EObject toSave =
>> model.getStages().get(0).getActivities().get(0).getTasks().g et(0)
>> resource.getContents().add(toSave);
>> try {
>> resource.save(options);
>> } catch (IOException ioe) {}
>>
>>
>> This is example when I saved Task:
>>
>> <?xml version="1.0" encoding="ASCII"?>
>> <org.uz.iie.gs.wwPP.eclipse.model:Task xmi:version="2.0"
>> xmlns:xmi="http://www.omg.org/XMI"
>> xmlns:org.uz.iie.gs.wwPP.eclipse.model="org.uz.iie.gs.wwPP.eclipse.model "
>> id="TASK_1_1_1"
>> name="TASK1">
>> <steps id="STEP_1_1_1_1" name="STEP_1"/>
>> <steps id="STEP_1_1_1_2" name="STEP_2"/>
>> </org.uz.iie.gs.wwPP.eclipse.model:Task>
>>
>> Unfortunately save didn't complete, because Steps contain nested
>> elements which didn't save. When I directly
>> saved nested ArtifactsList element:
>>
> You say "contain" nested elements, but I'll bet the reference isn't
> marked as a containment reference, i.e., EReference.containment == true....
>> Resource resource = new ResourceSetImpl().createResource(uri);
>> Map<String, Object> options = new HashMap<String, Object>();
>> options.put( XMLResource.OPTION_PROCESS_DANGLING_HREF,
>> XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD );
>> EObject toSave =
>> model.getStages().get(0).getActivities().get(0).getTasks().g et(0).getArtifactsIn();
>>
>> resource.getContents().add(toSave);
>> try {
>> resource.save(options);
>> } catch (IOException ioe) {}
>>
>>
>> the result was:
>>
>> <?xml version="1.0" encoding="ASCII"?>
>> <org.uz.iie.gs.wwPP.eclipse.model:ArtifactsList xmi:version="2.0"
>> xmlns:xmi="http://www.omg.org/XMI"
>> xmlns:org.uz.iie.gs.wwPP.eclipse.model="org.uz.iie.gs.wwPP.eclipse.model "
>> id="ARTIFACTS_LIST_IN_1_1_1"
>> name="In" maxSize="1"/>
>>
>> What I should change if I want to save complete emf model as xml file?
>> Do save method has possibility to set
>> level which can be save from emf model?
>>
> It sounds like you simply intended it to be a containment reference but
> didn't mark it that way in the model...
>> Best regards,
>> Tomasz
>>
Thank you Ed.

Best regards,
Tom
Previous Topic:What techniques are EMF applying to improve performace and reduce memory footprint?
Next Topic:Restrict combo box objects values in properties view to a single resource
Goto Forum:
  


Current Time: Thu Apr 25 15:30:12 GMT 2024

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

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

Back to the top