Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » EBoolean
EBoolean [message #902804] Mon, 20 August 2012 14:02 Go to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
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 14:39]

Report message to a moderator

Re: EBoolean [message #902826 is a reply to message #902804] Mon, 20 August 2012 16:00 Go to previous messageGo to next message
Fernanda R.F. is currently offline Fernanda R.F.Friend
Messages: 64
Registered: May 2012
Member
Hi Kosala,

I found this example in ATL wiki:

t : ClassDiagram!Attribute (
          name <- s.name,
          owner <- s.owner,
          isPrivate <- true,
          type <- s.type


So, I think your code is right, could you post the error that you're getting?

Re: EBoolean [message #902911 is a reply to message #902826] Tue, 21 August 2012 06:34 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
Hi Fernanda,

Thanks for your response. I do not get any error, but "isLoaded" attribute at transformation output object does not contain true. It is always false.

In this case "isLoaded" is set with transient property true (at the ecore model), since i do not need it to be persisted.

I do not understand why this transient field is not set from the atl transformation? How to slove this issue?

Really appriciate any advice.

Kosala

[Updated on: Tue, 21 August 2012 08:42]

Report message to a moderator

Re: EBoolean [message #902938 is a reply to message #902911] Tue, 21 August 2012 10:28 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
Hi all,


I use the following code to capture the transformed object.

public EObject getModelObjects() throws ATLCoreException, IOException {
getPackage_eINSTANCE().getClass();
//setting outputStream to inputStream
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;
}




In here, outModel has proper values for "isLoaded" attribute, but return object does not.

Do you have any clue?

Thanks
Kosala
Re: EBoolean [message #902972 is a reply to message #902938] Tue, 21 August 2012 13:20 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
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 #902975 is a reply to message #902972] Tue, 21 August 2012 13:31 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
You're serializing the model in a stream and then reload it from there so you lose the transient value...
Can't you extract to a resource directly instead of serializing ?
Re: EBoolean [message #902985 is a reply to message #902975] Tue, 21 August 2012 14:10 Go to previous message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
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
Previous Topic:Determine if an unsettable attribute 'isSet'
Next Topic:Milan Milanovic's code running problem
Goto Forum:
  


Current Time: Fri Apr 26 05:38:49 GMT 2024

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

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

Back to the top