Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTo] 'null' as a result object(how to use null as an explicite object of an abstract type?)
[QVTo] 'null' as a result object [message #516612] Wed, 24 February 2010 15:09 Go to next message
C. Kopf is currently offline C. KopfFriend
Messages: 37
Registered: November 2009
Member
Hello again everybody,

QVTo and me, we get used to each other, so far.
Doing some more work of coding M2M-Tranformations using QVTo, I found the following issue:

I am using the following code. (Ideas as comments inline.)


mapping ARSEPGenIA::ARPackage::arpackage2module() : Module {
	name := self.sName;
	declarations:= self.elements.map packageableElements2moduleElement(result)->asOrderedSet();
}

/** Here we check the Type of each PackageableElement and choose the mapping which fits best. PackageableElement is an Interface or Abstract Class, ModuleElement is an Abstract Class.
**/
mapping ARSEPGenI::PackageableElement::packageableElements2moduleElement(inout module:Module) : ModuleElement{
             // we need to do this in the init-part due to initialize a non-abstract return object:
	init {
                          //case 1:
		if(self.oclIsTypeOf(SenderReceiverInterface))
			then {
				result := self.oclAsType(SenderReceiverInterface).map senderReceiverInterface2messagePortType(); //object MessagePortType{}
			}
			else //case 2:
			if (self.oclIsTypeOf(ARSEPComponents::AtomicSCT))
				then {
					result := self.oclAsType(AtomicSCT).map atomicSCT2Component(); //object Component{}
				}
                                                     //so far everything works fine!
				else // default case for all types of PackageableElements not explicitly mapped above
				if(true)
					then {
						result := null; //THIS DOES NOT WORK!!!
						module.annotations += object TS::SampleAnnotation{value := "No mapping rule exist for the following PackageableElement: "+self.shortName+" of type "+self.metaClassName()+" details: "+self.repr()};
					}
				endif
			endif
		endif;
	}
}


The idea was: tranforming a ARPackage to a Module, we would like to add an annotation for each not mapped member of 'elements' (all not directly mapped subtypes of PackageableElement).
In "Meta Object Facility (MOF) 2.0 Query/View/Transformation
Specification - final adopted specification", chapter 8.1.17 says: "The literal null is a specific literal value that complies to any type. It can be explicitly returned by an operation (...)" but using it, as seen above, the QVT interpreter returns inc onsole:
" org.eclipse.m2m.internal.qvt.oml.evaluator.QvtRuntimeExcepti on: Cannot instantiate type ModuleElement
at ArtopToTS3::PackageableElement::packageableElements2moduleEl ement(ArtopToTS3.qvto:61) (...)"

line 61 is marked in the code above with "THIS DOES NOT WORK!!!"

Any ideas how to solve this?
Is my intention and understanding of the Specification correct?
Is this a challenge to QVTo-plugin?
Is there an other cause for this error?

Thanks again for your help!


Cheers,

Chris

[Updated on: Wed, 24 February 2010 15:11]

Report message to a moderator

Re: [QVTo] 'null' as a result object [message #516674 is a reply to message #516612] Wed, 24 February 2010 18:05 Go to previous messageGo to next message
PBarendrecht is currently offline PBarendrechtFriend
Messages: 36
Registered: November 2009
Location: Eindhoven, Netherlands
Member
Hi Chris,

As far as I know, one can assign the "null"-value to any object. I assigned null to a result of one of my own mappings, it did work without any problems.

Therefore I think the problem lies with your datatype, ModuleElement. You wrote that this is an abstract class, I am not sure whether one can assign values to such a class. Maybe it is in the QVT or OCL documentation, I will take a look at it.

Furthermore, your "else if then" construct is a bit long-winded. You can just use "else { ... }" instead of "else if(true) then { ... } endif;". However, maybe the "if(true)" part is a simplified version of your code to test the code after that, I don't know.

Pieter
Re: [QVTo] 'null' as a result object [message #516753 is a reply to message #516612] Thu, 25 February 2010 00:10 Go to previous messageGo to next message
Alex Mising name is currently offline Alex Mising nameFriend
Messages: 51
Registered: August 2009
Member
QVTo is attempting to instantiate ModuleElement because at the end of the "init" section "result" is null. This behavior is prescribed by the QVT spec. It fails because ModuleElement is abstract and thus cannot be instantiated. If you want to skip mapping for a particular condition you are better off using a "when" guard. Direct return from mapping might be another way, but this is not supported in QVTo yet. The only other (ugly) workaround I am aware of would be to assign something temporary to result in the "init" section (to defeat auto-instantiation) and cleanup / assign null in "end" section.

[Updated on: Thu, 25 February 2010 00:13]

Report message to a moderator

Re: [QVTo] 'null' as a result object [message #516827 is a reply to message #516753] Thu, 25 February 2010 09:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Alexander.Igdalov.gmail.com

Hi All,

Alex, I agree. An alternative workaround could be skipping the mapping
invocation in the calling code, i.e. in
mapping ARSEPGenIA::ARPackage::arpackage2module(). The code would then
look like:

mapping ARSEPGenIA::ARPackage::arpackage2module() : Module {
name := self.sName;
if (self.oclIsTypeOf(SenderReceiverInterface) or
self.oclIsTypeOf(ARSEPComponents::AtomicSCT)) {
declarations:= self.elements.map
packageableElements2moduleElement(result)->asOrderedSet();
} else {
declarations:=null;
annotations += object TTCN3::SampleAnnotation{value := "No mapping
rule exist for the following PackageableElement: "+self.shortName+" of
type "+metaClassName()+" details: "+repr()};
}
}

Perhaps, the mapping
ARSEPGenI::PackageableElement::packageableElements2moduleEle ment() could
be completely eliminated with its logic moved to
mapping ARSEPGenIA::ARPackage::arpackage2module()...

Cheers,
- Alex.

Alex wrote:
> QVTo is attempting to instantiate ModuleElement because at the end of
> the "init" section "result" is null. This is the behavior prescribed by
> QVT spec. If you want to skip mapping for a particular condition you are
> better off using a "when" guard. Direct return from mapping might be
> another way, but this is not supported in QVTo yet. The only other
> (ugly) workaround I am aware of would be to assign something temporary
> to result in the "init" section (to defeat auto-instantiation) and
> cleanup / assign null in "end" section.
icon14.gif  Re: [QVTo] 'null' as a result object [message #517144 is a reply to message #516612] Fri, 26 February 2010 11:47 Go to previous message
C. Kopf is currently offline C. KopfFriend
Messages: 37
Registered: November 2009
Member
Wow, thanks for all your help, you gave me a lot of input.
Surprised

First of all: Pieter, you got it right. The abstract type was the problem. Thanks also for your comments on the if-else cases, I did not know it and yes it looks a bit more shiny Smile

Also thanks to Alex and Alexander, I tried to figure out your ideas, so I think the solution I have found is just what you meant.

For if anybody else needs something alike, I will give the solutions code below:

mapping ARTOPGenIA::ARPackage::arpackage2module() : Module {
	name := self.shortName;	
	self.elements->forEach(elem) {
		if (elem.oclIsKindOf(SenderReceiverInterface)) then { //self.elements.oclIsTypeOf(SenderReceiverInterface) or 
			declarations+= elem.oclAsType(SenderReceiverInterface).map senderReceiverInterface2messagePortType();
		}else
			if (elem.oclIsTypeOf(ARSEPComponents::AtomicSCT))
				then {
					declarations+= elem.oclAsType(AtomicSCT).map atomicSCT2Component();
				}
				else // default case for PackageableElements not directly matched
					{
						annotations += object TS::SampleAnnotation{value := "No mapping rule exist for the following PackageableElement: "+elem.shortName+" of type "+elem.metaClassName()+" details: "+elem.repr()};
					}
			endif
		endif;
	}
}





Thanks again for all your help. It entailed the solution. Cool
Previous Topic:[ATL] The simpliest ATL-Sample doesnt launch
Next Topic:Re: Trace in Medini QVT
Goto Forum:
  


Current Time: Thu Sep 19 06:45:51 GMT 2019

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

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

Back to the top