Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to read transient EAttibute?
How to read transient EAttibute? [message #902981] Tue, 21 August 2012 13:57 Go to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
Hi All,

I have transient EAttribute "isLoaded" in my targetMetamodel.


protected IModel inModel;
protected IModel outModel;



public void loadModels(String inputModelPath) throws ATLCoreException {
EMFModelFactory factory = new EMFModelFactory();
IInjector injector = new EMFInjector();

IReferenceModel sourceMetamodel = factory.newReferenceModel();
injector.inject(sourceMetamodel, this.getSourceMetamodelPath());

IReferenceModel targetMetamodel = factory.newReferenceModel();
injector.inject(targetMetamodel, getPackage_eNS_URI());

this.inModel = factory.newModel(sourceMetamodel);
injector.inject(inModel, inputModelPath);

this.outModel = factory.newModel(targetMetamodel);
}





public EObject getModelObjects() throws ATLCoreException, IOException {
getPackage_eINSTANCE().getClass();

final PipedOutputStream outputStream = new PipedOutputStream();
PipedInputStream inputStream = new PipedInputStream(outputStream);

//read from outputStream
new Thread(new Runnable() {
public void run() {
try {

(new EMFExtractor()).extract(outModel, outputStream, null);

} catch (ATLCoreException e) {
e.printStackTrace();
}
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();


//load EObject from inputStream
XMIResourceImpl resource = new XMIResourceImpl();
resource.load(inputStream, new HashMap<Object,Object>());
EObject obj = resource.getContents().get(0);

// return EObject
return obj;
}


When I debug this program, the proper values can be found in outModel at getModelObjects() method.

Problem: I need to read outModel and return it as an object. For that I use PipedStream and XMIResourceImpl. isLoaded is transient and it does not support serialization therefore i always get false, which is the default.

Is there any way to read outModel to return as an object without serialization, since i need to capture transient variables?

Thanks in advance!
Kosala
Re: How to read transient EAttibute? [message #902989 is a reply to message #902981] Tue, 21 August 2012 14:28 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26215
Registered: July 2009
Senior Member
Kosala,

It's expect that all serializers respect isTransient by not serializing
that data. If you want to override that, you'd have to specialize
XMLSaveImpl/XMISaveImpl. In particular, the Lookup class has a
featureKind method guarded like this:

protected int featureKind(EStructuralFeature f)
{
if (f.isTransient())
{
return TRANSIENT;
}




On 21/08/2012 3:57 PM, Kosala Yapa wrote:
> Hi All,
>
> I have transient EAttribute "isLoaded" in my targetMetamodel.
>
>
> protected IModel inModel;
> protected IModel outModel;
>
>
>
> public void loadModels(String inputModelPath) throws ATLCoreException {
> EMFModelFactory factory = new EMFModelFactory();
> IInjector injector = new EMFInjector();
>
> IReferenceModel sourceMetamodel = factory.newReferenceModel();
> injector.inject(sourceMetamodel, this.getSourceMetamodelPath());
>
> IReferenceModel targetMetamodel = factory.newReferenceModel();
> injector.inject(targetMetamodel, getPackage_eNS_URI());
>
> this.inModel = factory.newModel(sourceMetamodel);
> injector.inject(inModel, inputModelPath);
>
> this.outModel = factory.newModel(targetMetamodel);
> }
>
>
>
>
>
> public EObject getModelObjects() throws ATLCoreException, IOException {
> getPackage_eINSTANCE().getClass();
>
> final PipedOutputStream outputStream = new PipedOutputStream();
> PipedInputStream inputStream = new PipedInputStream(outputStream);
>
> //read from outputStream
> new Thread(new Runnable() {
> public void run() {
> try {
>
> (new EMFExtractor()).extract(outModel, outputStream, null);
>
> } catch (ATLCoreException e) {
> e.printStackTrace();
> }
> try {
> outputStream.close();
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> }).start();
>
>
> //load EObject from inputStream
> XMIResourceImpl resource = new XMIResourceImpl();
> resource.load(inputStream, new HashMap<Object,Object>());
> EObject obj = resource.getContents().get(0);
>
> // return EObject
> return obj;
> }
>
>
> When I debug this program, the proper values can be found in outModel
> at getModelObjects() method.
>
> Problem: I need to read outModel and return it as an object. For that
> I use PipedStream and XMIResourceImpl. isLoaded is transient and it
> does not support serialization therefore i always get false, which is
> the default.
>
> Is there any way to read outModel to return as an object without
> serialization, since i need to capture transient variables?
>
> Thanks in advance!
> Kosala
Re: How to read transient EAttibute? [message #903131 is a reply to message #902989] Wed, 22 August 2012 07:40 Go to previous message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
Thanks a mil Ed.

I solved the issue, without serialization.


I wanted to capture an object from outModel which is IModel.

here is my code.

EMFModel m= (EMFModel)outModel;
Resource resource = m.getResource();
EObject obj=resource.getContents().get(0);

Kosala
Previous Topic:Xcore for Indigo
Next Topic:[CDO/Hibernate] Default values are not recognized
Goto Forum:
  


Current Time: Sun Nov 23 17:24:43 GMT 2014

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

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