Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Storing a FeaturePath(Serializing to file?)
Storing a FeaturePath [message #1252476] Fri, 21 February 2014 08:57 Go to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
Hello,

I'm in need to save a FeaturePath to a file (to be able to load it again, with the same model - no need to check for this!)
how can i do this as the FeaturePath and its underlying objects do not implement Serializable interface.

i already 'googled' but did not find any solutions (if i missed it and you know a link, let me know)

thanks in advance
Ludwig
Re: Storing a FeaturePath [message #1252487 is a reply to message #1252476] Fri, 21 February 2014 09:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Ludwig,

It's basically a list of EStructuralFeatures, which are EObjects and so
you could use EcoreUtil.getURI to represent a reference to them, and use
ResourceSet.getEObject to resolve those.

On 21/02/2014 9:57 AM, Ludwig Moser wrote:
> Hello,
>
> I'm in need to save a FeaturePath to a file (to be able to load it
> again, with the same model - no need to check for this!)
> how can i do this as the FeaturePath and its underlying objects do not
> implement Serializable interface.
>
> i already 'googled' but did not find any solutions (if i missed it and
> you know a link, let me know)
>
> thanks in advance
> Ludwig


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Storing a FeaturePath [message #1252637 is a reply to message #1252487] Fri, 21 February 2014 12:35 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
thanks for the fast reply.
your help solved my problem!

so now i set the featurePath to transient,
before saving i call my method prepareSaving so the featurepath is transformed to String[] of URI's
public void prepareSaving() {
		EStructuralFeature[] features = featurePath.getFeaturePath();
		featureURIs = new String[features.length];
		for (int i = 0; i < features.length; i++) {
			featureURIs[i] = EcoreUtil.getURI(features[i]).toString();
		}
	}


when loading from file i first load, then call reinit()
	public void reinit() {
		ResourceSet resSet = new ResourceSetImpl();
		EStructuralFeature[] features = new EStructuralFeature[featureURIs.length];
		for (int i = 0; i < featureURIs.length; i++) {
			features[i] = (EStructuralFeature) resSet.getEObject(URI.createURI(featureURIs[i]), false);
		}
		featurePath = FeaturePath.fromList(features);
	}


i post this here so if someone finds my question he also finds an answer (in code)
Re: Storing a FeaturePath [message #1252682 is a reply to message #1252637] Fri, 21 February 2014 13:31 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
I think Ed meant to let EMF handle the details of serialization, for
example by using dynamic EMF. You just create an EPackage with a single
EClass that has a reference many of type EStructuralFeature. Then:

EObject root = EcoreUtil.create(myFeaturePathClass);
root.eGet(path).addAll(allFeaturesInTheFeaturePath);

Resource res = ResourceSetImpl().getResource("toto.featurePath", false);
res.getContents().add(root);
res.save(System.out, Collections.EMPTY_MAP);

Maybe you want to register EcoreResourceFactory against the file extension.

Felix
Re: Storing a FeaturePath [message #1252838 is a reply to message #1252682] Fri, 21 February 2014 16:55 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Felix,

Indeed, ideally the thing would serialize in the same resource, and yes,
ideally you'd model it as a multi-valued reference to
EStructuralFeatures. A derived transient volatile attribute could be
used to provide a "convenience" get/setter than provided/accepted the
FeatureMap data structure. Then all would serialize as normal...


On 21/02/2014 2:31 PM, Felix Dorner wrote:
> I think Ed meant to let EMF handle the details of serialization, for
> example by using dynamic EMF. You just create an EPackage with a
> single EClass that has a reference many of type EStructuralFeature. Then:
>
> EObject root = EcoreUtil.create(myFeaturePathClass);
> root.eGet(path).addAll(allFeaturesInTheFeaturePath);
>
> Resource res = ResourceSetImpl().getResource("toto.featurePath", false);
> res.getContents().add(root);
> res.save(System.out, Collections.EMPTY_MAP);
>
> Maybe you want to register EcoreResourceFactory against the file
> extension.
>
> Felix


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Storing a FeaturePath [message #1255176 is a reply to message #1252838] Mon, 24 February 2014 06:52 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
i'm writing way more to my config than only the featurepath. but no more details come from EMF. its just the path to access the attribute. (i do not need any properties of an EClass saved or similar (this will be used later on import/export, but at that time i will use Resource for sure) )

So, Ed, is it incorrect to do it the way i do it?

[Updated on: Mon, 24 February 2014 06:52]

Report message to a moderator

Re: Storing a FeaturePath [message #1255177 is a reply to message #1252838] Mon, 24 February 2014 06:52 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
if i need to serialize feature paths I simply remember the Eclass the
path starts with and the feature names this is enough if you know the
EClass you start from.

Tom

On 21.02.14 17:55, Ed Merks wrote:
> Felix,
>
> Indeed, ideally the thing would serialize in the same resource, and yes,
> ideally you'd model it as a multi-valued reference to
> EStructuralFeatures. A derived transient volatile attribute could be
> used to provide a "convenience" get/setter than provided/accepted the
> FeatureMap data structure. Then all would serialize as normal...
>
>
> On 21/02/2014 2:31 PM, Felix Dorner wrote:
>> I think Ed meant to let EMF handle the details of serialization, for
>> example by using dynamic EMF. You just create an EPackage with a
>> single EClass that has a reference many of type EStructuralFeature. Then:
>>
>> EObject root = EcoreUtil.create(myFeaturePathClass);
>> root.eGet(path).addAll(allFeaturesInTheFeaturePath);
>>
>> Resource res = ResourceSetImpl().getResource("toto.featurePath", false);
>> res.getContents().add(root);
>> res.save(System.out, Collections.EMPTY_MAP);
>>
>> Maybe you want to register EcoreResourceFactory against the file
>> extension.
>>
>> Felix
>
Previous Topic:XSD Importer and FeatureMap
Next Topic:How to import UML?
Goto Forum:
  


Current Time: Fri Apr 19 05:07:12 GMT 2024

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

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

Back to the top