Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Extended Metadata not working on loading a model
Extended Metadata not working on loading a model [message #519414] Mon, 08 March 2010 18:13 Go to next message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
Hi,

I followed the instructions of the EMF book Chapter 15.3.5 to customise
the persistence of my model but something's not working when loading it
back in.

Here's the code to create the options map:

private Map<Object, Object> getOptions() {
Map<Object, Object> options = new HashMap<Object, Object>();
options.put(XMLResource.OPTION_ENCODING, "UTF-8");

ExtendedMetaData ext = new
BasicExtendedMetaData(ExtendedMetaData.ANNOTATION_URI,
EPackage.Registry.INSTANCE, new HashMap<EModelElement,
EAnnotation>());

ext.setName(IArchimatePackage.Literals.ARCHIMATE_MODEL__FOLD ERS,
"folder");
ext.setName(IArchimatePackage.Literals.FOLDER__ELEMENTS, "element");

ext.setFeatureKind(IArchimatePackage.Literals.ARCHIMATE_ELEM ENT__DOCUMENTATION,

ExtendedMetaData.ELEMENT_FEATURE);

options.put(XMLResource.OPTION_EXTENDED_META_DATA, ext);

return options;
}

When I use these options to save the Resource everything works as expected:

ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.createResource(uri);
resource.getContents().add(model);
Map<Object, Object> options = getOptions();
resource.save(options);


However, using the same set of options to load I get the error "Feature
'folder' not found.":

ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.createResource(uri);
Map<Object, Object> options = getOptions();
resource.load(options);

Phil
Re: Extended Metadata not working on loading a model [message #519426 is a reply to message #519414] Mon, 08 March 2010 18:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Phillipus,

Comments below.


Phillipus wrote:
> Hi,
>
> I followed the instructions of the EMF book Chapter 15.3.5 to
> customise the persistence of my model but something's not working when
> loading it back in.
>
> Here's the code to create the options map:
>
> private Map<Object, Object> getOptions() {
> Map<Object, Object> options = new HashMap<Object, Object>();
> options.put(XMLResource.OPTION_ENCODING, "UTF-8");
>
> ExtendedMetaData ext = new
> BasicExtendedMetaData(ExtendedMetaData.ANNOTATION_URI,
> EPackage.Registry.INSTANCE, new HashMap<EModelElement,
> EAnnotation>());
>
> ext.setName(IArchimatePackage.Literals.ARCHIMATE_MODEL__FOLD ERS,
> "folder");
> ext.setName(IArchimatePackage.Literals.FOLDER__ELEMENTS, "element");
>
> ext.setFeatureKind(IArchimatePackage.Literals.ARCHIMATE_ELEM ENT__DOCUMENTATION,
>
> ExtendedMetaData.ELEMENT_FEATURE);
>
> options.put(XMLResource.OPTION_EXTENDED_META_DATA, ext);
>
> return options;
> }
>
> When I use these options to save the Resource everything works as
> expected:
>
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource = resourceSet.createResource(uri);
> resource.getContents().add(model);
> Map<Object, Object> options = getOptions();
> resource.save(options);
>
>
> However, using the same set of options to load I get the error
> "Feature 'folder' not found.":
Maybe you need to indicate explicitly that the "folder" and "element"
features are ELEMENT_FEATUREs.
>
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource = resourceSet.createResource(uri);
> Map<Object, Object> options = getOptions();
> resource.load(options);
>
> Phil


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Extended Metadata not working on loading a model [message #519433 is a reply to message #519426] Mon, 08 March 2010 19:01 Go to previous messageGo to next message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
On 08/03/2010 18:46, Ed Merks wrote:
> Phillipus,
>
> Comments below.
>
>
> Phillipus wrote:
>> Hi,
>>
>> I followed the instructions of the EMF book Chapter 15.3.5 to
>> customise the persistence of my model but something's not working when
>> loading it back in.
>>
>> Here's the code to create the options map:
>>
>> private Map<Object, Object> getOptions() {
>> Map<Object, Object> options = new HashMap<Object, Object>();
>> options.put(XMLResource.OPTION_ENCODING, "UTF-8");
>>
>> ExtendedMetaData ext = new
>> BasicExtendedMetaData(ExtendedMetaData.ANNOTATION_URI,
>> EPackage.Registry.INSTANCE, new HashMap<EModelElement, EAnnotation>());
>>
>> ext.setName(IArchimatePackage.Literals.ARCHIMATE_MODEL__FOLD ERS,
>> "folder");
>> ext.setName(IArchimatePackage.Literals.FOLDER__ELEMENTS, "element");
>>
>> ext.setFeatureKind(IArchimatePackage.Literals.ARCHIMATE_ELEM ENT__DOCUMENTATION,
>>
>> ExtendedMetaData.ELEMENT_FEATURE);
>>
>> options.put(XMLResource.OPTION_EXTENDED_META_DATA, ext);
>>
>> return options;
>> }
>>
>> When I use these options to save the Resource everything works as
>> expected:
>>
>> ResourceSet resourceSet = new ResourceSetImpl();
>> Resource resource = resourceSet.createResource(uri);
>> resource.getContents().add(model);
>> Map<Object, Object> options = getOptions();
>> resource.save(options);
>>
>>
>> However, using the same set of options to load I get the error
>> "Feature 'folder' not found.":
> Maybe you need to indicate explicitly that the "folder" and "element"
> features are ELEMENT_FEATUREs.
>>
>> ResourceSet resourceSet = new ResourceSetImpl();
>> Resource resource = resourceSet.createResource(uri);
>> Map<Object, Object> options = getOptions();
>> resource.load(options);
>>
>> Phil

Thanks once again Ed, that's exactly it!

Some things to note:

1. You don't need to set this explicitly for saving the Resource, only
loading it.
2. The EMF book omits this information. The example code there is as
follows (p.483 of the 2nd edition):

ext.setQualified(EPO2Package.eINSTANCE, false);
ext.setName(EPO2Package.Literals.PURCHASE_ORDER, "order");
ext.setName(EPO2Package.Literals.PURCHASE_ORDER__ITEMS, "item");
ext.setFeatureKind(EPO2Package.Literals.PURCHASE_ORDER__COMM ENT,
ExtendedMetaData.ELEMENT_FEATURE);

The "items" element becomes "item", just like my "folders" becomes
"folder". Then the authors say to only use the same set of options to
load but not the explicit setting of ELEMENT_FEATURE.

Is it an omission of the book?

Cheers,


Phil
Re: Extended Metadata not working on loading a model [message #519435 is a reply to message #519433] Mon, 08 March 2010 19:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Phillipus,

Comments below.

Phillipus wrote:
> On 08/03/2010 18:46, Ed Merks wrote:
>> Phillipus,
>>
>> Comments below.
>>
>>
>> Phillipus wrote:
>>> Hi,
>>>
>>> I followed the instructions of the EMF book Chapter 15.3.5 to
>>> customise the persistence of my model but something's not working when
>>> loading it back in.
>>>
>>> Here's the code to create the options map:
>>>
>>> private Map<Object, Object> getOptions() {
>>> Map<Object, Object> options = new HashMap<Object, Object>();
>>> options.put(XMLResource.OPTION_ENCODING, "UTF-8");
>>>
>>> ExtendedMetaData ext = new
>>> BasicExtendedMetaData(ExtendedMetaData.ANNOTATION_URI,
>>> EPackage.Registry.INSTANCE, new HashMap<EModelElement, EAnnotation>());
>>>
>>> ext.setName(IArchimatePackage.Literals.ARCHIMATE_MODEL__FOLD ERS,
>>> "folder");
>>> ext.setName(IArchimatePackage.Literals.FOLDER__ELEMENTS, "element");
>>>
>>> ext.setFeatureKind(IArchimatePackage.Literals.ARCHIMATE_ELEM ENT__DOCUMENTATION,
>>>
>>>
>>> ExtendedMetaData.ELEMENT_FEATURE);
>>>
>>> options.put(XMLResource.OPTION_EXTENDED_META_DATA, ext);
>>>
>>> return options;
>>> }
>>>
>>> When I use these options to save the Resource everything works as
>>> expected:
>>>
>>> ResourceSet resourceSet = new ResourceSetImpl();
>>> Resource resource = resourceSet.createResource(uri);
>>> resource.getContents().add(model);
>>> Map<Object, Object> options = getOptions();
>>> resource.save(options);
>>>
>>>
>>> However, using the same set of options to load I get the error
>>> "Feature 'folder' not found.":
>> Maybe you need to indicate explicitly that the "folder" and "element"
>> features are ELEMENT_FEATUREs.
>>>
>>> ResourceSet resourceSet = new ResourceSetImpl();
>>> Resource resource = resourceSet.createResource(uri);
>>> Map<Object, Object> options = getOptions();
>>> resource.load(options);
>>>
>>> Phil
>
> Thanks once again Ed, that's exactly it!
I'm such a good guesser. :-P
>
> Some things to note:
>
> 1. You don't need to set this explicitly for saving the Resource, only
> loading it.
> 2. The EMF book omits this information. The example code there is as
> follows (p.483 of the 2nd edition):
>
> ext.setQualified(EPO2Package.eINSTANCE, false);
> ext.setName(EPO2Package.Literals.PURCHASE_ORDER, "order");
> ext.setName(EPO2Package.Literals.PURCHASE_ORDER__ITEMS, "item");
> ext.setFeatureKind(EPO2Package.Literals.PURCHASE_ORDER__COMM ENT,
> ExtendedMetaData.ELEMENT_FEATURE);
>
> The "items" element becomes "item", just like my "folders" becomes
> "folder". Then the authors say to only use the same set of options to
> load but not the explicit setting of ELEMENT_FEATURE.
>
> Is it an omission of the book?
It sounds like it.
>
> Cheers,
>
>
> Phil


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Extended Metadata not working on loading a model [message #519548 is a reply to message #519435] Tue, 09 March 2010 09:59 Go to previous messageGo to next message
walnut23  is currently offline walnut23 Friend
Messages: 23
Registered: March 2010
Junior Member
Hi Phil,

I am trying to serialize my model instances and couldn't get that working.

Can you please tell me where i should use the following code to persist a model instance?
ResourceSet resourceSet = new ResourceSetImpl();
>> Resource resource = resourceSet.createResource(uri);
>> resource.getContents().add(model);
>> Map<Object, Object> options = getOptions();
>> resource.save(options);

I have generated the code using genmodel.

Please help as it is urgent.

Thanks!
Re: Extended Metadata not working on loading a model [message #519590 is a reply to message #519548] Tue, 09 March 2010 07:08 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Generally these types of settings should be placed in the resource
factory so no matter where the logic is to create the resource and to
load and save it, the same options will kick in. Does your model have a
generated XyzResourceFactoryImpl in the util package? If not, you can
change the GenPackage's Resource Type property so one will be generated;
note the plugin.xml won't be updated to reflect that, so delete it and
regenerate it.


walnut23 wrote:
> Hi Phil,
>
> I am trying to serialize my model instances and couldn't get that
> working.
> Can you please tell me where i should use the following code to
> persist a model instance?
> ResourceSet resourceSet = new ResourceSetImpl();
>>> Resource resource = resourceSet.createResource(uri);
>>> resource.getContents().add(model);
>>> Map<Object, Object> options = getOptions();
>>> resource.save(options);
>
> I have generated the code using genmodel.
>
> Please help as it is urgent.
>
> Thanks!


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Extended Metadata not working on loading a model [message #519597 is a reply to message #519590] Tue, 09 March 2010 12:19 Go to previous messageGo to next message
walnut23  is currently offline walnut23 Friend
Messages: 23
Registered: March 2010
Junior Member
Thanks Ed Merks!

I have a xyzResourceFactoryImp that extends XMLResourceFactoryImp.

Should i include this in the plugin?
<extension point = "org.eclipse.emf.ecore.extension_parser">
<parser type="*"
class="org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl "/>
</extension>

Is there any way i can save this resource (model instances) conforming to the XSD that is specific to my project?

Thanks!
Re: Extended Metadata not working on loading a model [message #519621 is a reply to message #519548] Tue, 09 March 2010 14:06 Go to previous messageGo to next message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
On 09/03/2010 09:59, walnut23 wrote:
> Hi Phil,
>
> I am trying to serialize my model instances and couldn't get that working.
> Can you please tell me where i should use the following code to persist
> a model instance?
> ResourceSet resourceSet = new ResourceSetImpl();
>>> Resource resource = resourceSet.createResource(uri);
>>> resource.getContents().add(model);
>>> Map<Object, Object> options = getOptions();
>>> resource.save(options);
>
> I have generated the code using genmodel.
>
> Please help as it is urgent.
>
> Thanks!

Hi,

I have a very simple case of open/save and just put that code in my
Persistence manager class which is called by the application's "Save"
and "Open" actions. Ed is right about putting that in a Resource
Factory, though, and this is detailed in the EMF book (p.486).

Phil
Re: Extended Metadata not working on loading a model [message #519634 is a reply to message #519621] Tue, 09 March 2010 14:45 Go to previous messageGo to next message
walnut23  is currently offline walnut23 Friend
Messages: 23
Registered: March 2010
Junior Member
Thankyou very much phil!

I don't have the 2nd edition. Is this explained in 2nd edition?

Re: Extended Metadata not working on loading a model [message #519661 is a reply to message #519634] Tue, 09 March 2010 15:27 Go to previous messageGo to next message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
On 09/03/2010 14:45, walnut23 wrote:
> Thankyou very much phil!
>
> I don't have the 2nd edition. Is this explained in 2nd edition?
>
>

Hi,

I edited the Resource Factory so it's as follows:

public class MyResourceFactory extends ResourceFactoryImpl {

private Map<Object, Object> options;

public MyResourceFactory() {
super();
}

@Override
public Resource createResource(URI uri) {
MyResource result = new MyResource(uri);
result.getDefaultLoadOptions().putAll(getOptions());
result.getDefaultSaveOptions().putAll(getOptions());
return result;
}

private Map<Object, Object> getOptions() {
if(options == null) {
options = new HashMap<Object, Object>();
options.put(XMLResource.OPTION_ENCODING, "UTF-8");

ExtendedMetaData ext = new
BasicExtendedMetaData(ExtendedMetaData.ANNOTATION_URI,
EPackage.Registry.INSTANCE, new
HashMap<EModelElement, EAnnotation>());

ext.setName(IArchimatePackage.Literals.ARCHIMATE_MODEL,
"model");


ext.setFeatureKind(IArchimatePackage.Literals.ARCHIMATE_MODE L__FOLDERS,
ExtendedMetaData.ELEMENT_FEATURE); // have to do this explicitly

ext.setName(IArchimatePackage.Literals.ARCHIMATE_MODEL__FOLD ERS, "folder");


ext.setFeatureKind(IArchimatePackage.Literals.FOLDER__ELEMEN TS,
ExtendedMetaData.ELEMENT_FEATURE); // have to do this explicitly
ext.setName(IArchimatePackage.Literals.FOLDER__ELEMENTS,
"element");


ext.setFeatureKind(IArchimatePackage.Literals.ARCHIMATE_ELEM ENT__DOCUMENTATION,
ExtendedMetaData.ELEMENT_FEATURE);

options.put(XMLResource.OPTION_EXTENDED_META_DATA, ext);
}

return options;
}
}
Re: Extended Metadata not working on loading a model [message #519799 is a reply to message #519597] Tue, 09 March 2010 20:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
If you derived your model from an XSD, I'd expect you to have a
generated resource implementation that already does that (just like what
you get for the Library XML Schema tutorial).

walnut23 wrote:
> Thanks Ed Merks!
>
> I have a xyzResourceFactoryImp that extends XMLResourceFactoryImp.
>
> Should i include this in the plugin?
> <extension point = "org.eclipse.emf.ecore.extension_parser">
> <parser type="*"
>
> class="org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl "/>
> </extension>
>
> Is there any way i can save this resource (model instances) conforming
> to the XSD that is specific to my project?
> Thanks!


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Extended Metadata not working on loading a model [message #519860 is a reply to message #519661] Wed, 10 March 2010 09:27 Go to previous messageGo to next message
walnut23  is currently offline walnut23 Friend
Messages: 23
Registered: March 2010
Junior Member
Thankyou so much Phil! It helped me a lot.

Re: Extended Metadata not working on loading a model [message #520790 is a reply to message #519860] Mon, 15 March 2010 11:02 Go to previous messageGo to next message
walnut23  is currently offline walnut23 Friend
Messages: 23
Registered: March 2010
Junior Member
Hi,

Now that i have my model instances serialized like this,
<?xml version="1.0" encoding="UTF-8"?>
<prototype:Diagram xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:prototype="http://prototype.nat.bt.com">
<ProductOfferings Identifier="id1" Item="10" Description="desc1" LongDescription="longde" TariffType="type1" TariffName="name1" TariffIdentifier="tariff1"/>
<Tariffs TariffName="traiifname" Identifier="id2" Price="100" Association="//@ProductOfferings.0"/>
<Tariffs TariffName="name3" Identifier="id3" Price="200" Association="//@ProductOfferings.0"/>
</prototype:Diagram>

I am using XSLT to transform this XML to another XML schema. Is there a way we can use EMF to save this model instance directly in the appropriate XML schema instead of using XSLT?

Please help!
Re: Extended Metadata not working on loading a model [message #520807 is a reply to message #520790] Mon, 15 March 2010 12:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
It's a long thread. I'm not sure you've shown the model. You can use
extended meta data annotations to affect the element names if that's
what you're asking.

walnut23 wrote:
> Hi,
>
> Now that i have my model instances serialized like this,
> <?xml version="1.0" encoding="UTF-8"?>
> <prototype:Diagram xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:prototype="http://prototype.nat.bt.com">
> <ProductOfferings Identifier="id1" Item="10" Description="desc1"
> LongDescription="longde" TariffType="type1" TariffName="name1"
> TariffIdentifier="tariff1"/>
> <Tariffs TariffName="traiifname" Identifier="id2" Price="100"
> Association="//@ProductOfferings.0"/>
> <Tariffs TariffName="name3" Identifier="id3" Price="200"
> Association="//@ProductOfferings.0"/>
> </prototype:Diagram>
>
> I am using XSLT to transform this XML to another XML schema. Is there
> a way we can use EMF to save this model instance directly in the
> appropriate XML schema instead of using XSLT?
>
> Please help!


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Extended Metadata not working on loading a model [message #520851 is a reply to message #520807] Mon, 15 March 2010 10:30 Go to previous messageGo to next message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
On 15/03/2010 12:48, Ed Merks wrote:
> It's a long thread. I'm not sure you've shown the model. You can use
> extended meta data annotations to affect the element names if that's
> what you're asking.
>
> walnut23 wrote:
>> Hi,
>>
>> Now that i have my model instances serialized like this,
>> <?xml version="1.0" encoding="UTF-8"?>
>> <prototype:Diagram xmi:version="2.0"
>> xmlns:xmi="http://www.omg.org/XMI"
>> xmlns:prototype="http://prototype.nat.bt.com">
>> <ProductOfferings Identifier="id1" Item="10" Description="desc1"
>> LongDescription="longde" TariffType="type1" TariffName="name1"
>> TariffIdentifier="tariff1"/>
>> <Tariffs TariffName="traiifname" Identifier="id2" Price="100"
>> Association="//@ProductOfferings.0"/>
>> <Tariffs TariffName="name3" Identifier="id3" Price="200"
>> Association="//@ProductOfferings.0"/>
>> </prototype:Diagram>
>>
>> I am using XSLT to transform this XML to another XML schema. Is there
>> a way we can use EMF to save this model instance directly in the
>> appropriate XML schema instead of using XSLT?
>>
>> Please help!

I think he wants to save it in a completely different way rather than
just change the element names. My guess is that this would require
writing a whole persistence mechanism for this case?
Re: Extended Metadata not working on loading a model [message #520856 is a reply to message #520851] Mon, 15 March 2010 15:31 Go to previous messageGo to next message
walnut23  is currently offline walnut23 Friend
Messages: 23
Registered: March 2010
Junior Member
You are right Phil. I want to change it in a completely different format conforming to another XML schema. Is it advisable to do that using customised EMF persistance or just live with the way we are doing now(i.e using XSLT to change the XML instance we got from EMF to another XML schema)?

Thanks!
Re: Extended Metadata not working on loading a model [message #520864 is a reply to message #520856] Mon, 15 March 2010 15:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
I'm sure you could produce an arbitrary format writing specialized
serialization and deserialization code, but that would be a lot of
work. You might create a model for the target XML Schema format and
write two way transformation between your current model and that target one.


walnut23 wrote:
> You are right Phil. I want to change it in a completely different
> format conforming to another XML schema. Is it advisable to do that
> using customised EMF persistance or just live with the way we are
> doing now(i.e using XSLT to change the XML instance we got from EMF
> to another XML schema)?
>
> Thanks!
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Extended Metadata not working on loading a model [message #520875 is a reply to message #520864] Mon, 15 March 2010 16:08 Go to previous messageGo to next message
walnut23  is currently offline walnut23 Friend
Messages: 23
Registered: March 2010
Junior Member
Thanks for the response Ed!
I am not very clear what you mean by "two way transformation" . Could you please explain? It helps a lot!

Thanks!
Re: Extended Metadata not working on loading a model [message #520882 is a reply to message #520875] Mon, 15 March 2010 16:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
You can generate an EMF model for the schema. You could then write code
that given an instance of your current model, produces an instance of
the target, and vice versa. You could use that for saving and loading
the target and mapping that to and from the model you really want.


walnut23 wrote:
> Thanks for the response Ed!
> I am not very clear what you mean by "two way transformation" . Could
> you please explain? It helps a lot!
>
> Thanks!


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Extended Metadata not working on loading a model [message #520901 is a reply to message #520882] Mon, 15 March 2010 16:38 Go to previous messageGo to next message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
On 15/03/2010 16:22, Ed Merks wrote:
> You can generate an EMF model for the schema. You could then write code
> that given an instance of your current model, produces an instance of
> the target, and vice versa. You could use that for saving and loading
> the target and mapping that to and from the model you really want.
>
>
> walnut23 wrote:
>> Thanks for the response Ed!
>> I am not very clear what you mean by "two way transformation" . Could
>> you please explain? It helps a lot!
>>
>> Thanks!

Cunning, very cunning!
Re: Extended Metadata not working on loading a model [message #521029 is a reply to message #520882] Tue, 16 March 2010 09:38 Go to previous message
walnut23  is currently offline walnut23 Friend
Messages: 23
Registered: March 2010
Junior Member
Thanks Ed! Will try this option.

I am using EMF and GMF to generate the models.I beleieve the following is the piece of code(autogenerated in XXXEditor.java) that actually does the persistance work while entering the property values via the editor.Just curious to know whether all the values are saved as java objects by the framework and then persisted? If so is it just one java object or one for each model ?


@Override
public void doSave(IProgressMonitor progressMonitor) {
// Save only resources that have actually changed.
//
final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);

// Do the work within an operation because this is a long running activity that modifies the workbench.
//
WorkspaceModifyOperation operation =
new WorkspaceModifyOperation() {
// This is the method that gets invoked when the operation runs.
//
@Override
public void execute(IProgressMonitor monitor) {
// Save the resources to the file system.
//
boolean first = true;
for (Resource resource : editingDomain.getResourceSet().getResources()) {
if ((first || !resource.getContents().isEmpty() || isPersisted(resource)) && !editingDomain.isReadOnly(resource)) {
try {
long timeStamp = resource.getTimeStamp();
resource.save(saveOptions);
if (resource.getTimeStamp() != timeStamp) {
savedResources.add(resource);
}
}
catch (Exception exception) {
resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
}
first = false;
}
}
}
};

updateProblemIndication = false;
try {
// This runs the options, and shows progress.
//
new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

// Refresh the necessary state.
//
((BasicCommandStack)editingDomain.getCommandStack()).saveIsD one();
firePropertyChange(IEditorPart.PROP_DIRTY);
}
catch (Exception exception) {
// Something went wrong that shouldn't.
//
PrototypeEditorPlugin.INSTANCE.log(exception);
}
updateProblemIndication = true;
updateProblemIndication();
}

/**
* This returns whether something has been persisted to the URI of the specified resource.
* The implementation uses the URI converter from the editor's resource set to try to open an input stream.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected boolean isPersisted(Resource resource) {
boolean result = false;
try {
InputStream stream = editingDomain.getResourceSet().getURIConverter().createInput Stream(resource.getURI());
if (stream != null) {
result = true;
stream.close();
}
}
catch (IOException e) {
// Ignore
}
return result;
}

Thanks!
Re: Extended Metadata not working on loading a model [message #521056 is a reply to message #521029] Tue, 16 March 2010 06:06 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
All the persistence is done using reflection via the classes in the
org.eclipse.emf.ecore.xmi plugin. You can have complete control by
controling the resource implementation created by your resource factory.


walnut23 wrote:
> Thanks Ed! Will try this option.
>
> I am using EMF and GMF to generate the models.I beleieve the following
> is the piece of code(autogenerated in XXXEditor.java) that actually
> does the persistance work while entering the property values via the
> editor.Just curious to know whether all the values are saved as java
> objects by the framework and then persisted? If so is it just one java
> object or one for each model ?
>
>
> @Override
> public void doSave(IProgressMonitor progressMonitor) {
> // Save only resources that have actually changed.
> //
> final Map<Object, Object> saveOptions = new HashMap<Object,
> Object>();
> saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED,
> Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
>
> // Do the work within an operation because this is a long
> running activity that modifies the workbench.
> //
> WorkspaceModifyOperation operation =
> new WorkspaceModifyOperation() {
> // This is the method that gets invoked when the
> operation runs.
> //
> @Override
> public void execute(IProgressMonitor monitor) {
> // Save the resources to the file system.
> //
> boolean first = true;
> for (Resource resource :
> editingDomain.getResourceSet().getResources()) {
> if ((first ||
> !resource.getContents().isEmpty() || isPersisted(resource)) &&
> !editingDomain.isReadOnly(resource)) {
> try {
> long timeStamp = resource.getTimeStamp();
> resource.save(saveOptions);
> if (resource.getTimeStamp() !=
> timeStamp) {
> savedResources.add(resource);
> }
> }
> catch (Exception exception) {
> resourceToDiagnosticMap.put(resource,
> analyzeResourceProblems(resource, exception));
> }
> first = false;
> }
> }
> }
> };
>
> updateProblemIndication = false;
> try {
> // This runs the options, and shows progress.
> //
> new ProgressMonitorDialog(getSite().getShell()).run(true,
> false, operation);
>
> // Refresh the necessary state.
> //
>
> ((BasicCommandStack)editingDomain.getCommandStack()).saveIsD one();
> firePropertyChange(IEditorPart.PROP_DIRTY);
> }
> catch (Exception exception) {
> // Something went wrong that shouldn't.
> //
> PrototypeEditorPlugin.INSTANCE.log(exception);
> }
> updateProblemIndication = true;
> updateProblemIndication();
> }
>
> /**
> * This returns whether something has been persisted to the URI of
> the specified resource.
> * The implementation uses the URI converter from the editor's
> resource set to try to open an input stream. * <!--
> begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> protected boolean isPersisted(Resource resource) {
> boolean result = false;
> try {
> InputStream stream =
> editingDomain.getResourceSet().getURIConverter().createInput
> Stream(resource.getURI());
> if (stream != null) {
> result = true;
> stream.close();
> }
> }
> catch (IOException e) {
> // Ignore
> }
> return result;
> }
>
> Thanks!


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:problem loading XMI
Next Topic:[CDO] Authentication OK, but what about authorization
Goto Forum:
  


Current Time: Thu Mar 28 23:43:41 GMT 2024

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

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

Back to the top