How to read transient EAttibute? [message #902981] |
Tue, 21 August 2012 13:57 |
Kosala Yapa 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 |
Ed Merks Messages: 33137 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
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.02886 seconds