EBoolean [message #902804] |
Mon, 20 August 2012 10:02  |
Eclipse User |
|
|
|
Hi all,
At transformation, I need to assign a boolean variable to true.
isLoaded is EBoolean EAttribute.
at transformation i defined,
isLoaded<-true,
but this vale (true) cannot be find within the object.
I am just wondering, if this is a right way to assign a boolean attribute?
This is my rule:
rule rule_getDevice{
from
a: source!DeviceItem
to
p:target!Device
do{
p.name <- a.Name;
p.s7DeviceReference<-a.DeviceReference;
p.isSelectedWithinStep7<- a.IsSelected;
p.isLoaded<-false;
if (a.IsSelected = 'true'){
p.isLoaded<-true;
p.HeadModule<-a.ModuleList.ModuleItem->select(mi|mi.getSlotValue()='0')->collect(e|thisModule.rule_getHeadModule(e))->first();
p.Slot<-a.ModuleList.ModuleItem->select(mi|mi.getSlotValue()<>'0')->sortedBy(mi|mi.getSlotValue().toInteger())->collect(e|thisModule.rule_getSlot(e));
}
}
}
Thanks in advance!
Kosala
[Updated on: Mon, 20 August 2012 10:39] by Moderator
|
|
|
|
|
|
Re: EBoolean [message #902972 is a reply to message #902938] |
Tue, 21 August 2012 09:20   |
Eclipse User |
|
|
|
I found the issue.
The transformation is working, but the problem is transient variable does not support serialization.
I can find the right value of isLoaded field in outModel, but not in the return object.
here is my code:
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;
}
any advice is appriciated.
Thanks
Kosala
|
|
|
|
Re: EBoolean [message #902985 is a reply to message #902975] |
Tue, 21 August 2012 10:10  |
Eclipse User |
|
|
|
Hi Sylvain,
Yes you are right.
I am using IExtractor (org.eclipse.m2m.atl.core.IExtractor), which does not support extracting to a resource. Do you have any clue on a possible Extractor?
IExtractor extractor = new EMFExtractor();
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
resourceSet.getPackageRegistry().put(getPackage_eNS_URI(),getPackage_eINSTANCE());
extractor.extract(outModel,"filePath");
Thanks
Kosala
|
|
|
Powered by
FUDForum. Page generated in 0.05531 seconds