Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTo] How to determine <unset> Integer
[QVTo] How to determine <unset> Integer [message #532903] Tue, 11 May 2010 14:16 Go to next message
Josef Freundorfer is currently offline Josef FreundorferFriend
Messages: 10
Registered: May 2010
Location: Germany
Junior Member
Hi,

I'm having some strange behaviour in QVTo. There is a Class XYZ at the source model, with an Attribute comConfigurationId : Integer.

It's allowed, that it isn't set. If I access this attribute, I just get 0, or the value of it.

For demonstration, the following Code Snippet:
log(self.repr());
if self.comConfigurationId.oclIsUndefined() then {
	log("undefined");
} endif;
if self.comConfigurationId.oclIsInvalid() then {
	log("invalid");
} endif;
if self.comConfigurationId.oclIsNew() then {
	log("new");
} endif;
if self.comConfigurationId.oclIsKindOf(Integer) then {
	log("kind of Integer");
} endif;
if self.comConfigurationId.oclIsTypeOf(Integer) then {
	log("type of Integer");
} endif;


It results in:
...XYZImpl@f3c717 (checksum: <unset>, timestamp: <unset>) (shortName: myXYZInstance, category: <unset>) (comConfigurationId: <unset>, comProcessingPeriod: 100.0, diagnosticAddress: 2, pduRConfigurationId: <unset>, responseAddress: [1234], sleepModeSupported: <unset>, wakeUpOverBusSupported: <unset>)
kind of Integer
type of Integer


But why? Isn't there an easy way, to check, if this item is set or not???

Many thanks,

Josef
Re: [QVTo] How to determine <unset> Integer [message #533199 is a reply to message #532903] Wed, 12 May 2010 14:38 Go to previous messageGo to next message
C. Kopf is currently offline C. KopfFriend
Messages: 37
Registered: November 2009
Member
Hi Josef,

I am just not sure about your isue:

I expect you are working on Autosar3x, so:

Do you mean something like the following:

We might have an autosar-model, wherein an "ArrayElement" element is defined. Its property "maxNumberOfElements" is of type Integer but may not be set at all. if so, you would like to handel it as if it is set to "0"? (I know it does not make sense for maxNumberOfElements, but this is just meant as an example)

And your problem is that you need a simple way to find out whether the input-property is set at all or not?!


I used for that purpose a check against null, here in pseudo-code :

if (self.property == null) than result.property := 0;
else result.property := self.property;


I am not sure whether this is what your are looking for.
Re: [QVTo] How to determine <unset> Integer [message #533214 is a reply to message #532903] Wed, 12 May 2010 14:59 Go to previous messageGo to next message
Josef Freundorfer is currently offline Josef FreundorferFriend
Messages: 10
Registered: May 2010
Location: Germany
Junior Member
Hi,

thanks for the answer, but it doesn't help.

I try to explain it in a different way.

Input Model -> Output Model
XYZ.someIntegerAttribute = <unset> -> nothing
XYZ.someIntegerAttribute = 0 -> 0
XYZ.someIntegerAttribute = 4711 -> 4711

The current behaviour is
XYZ.someIntegerAttribute = <unset> -> 0
XYZ.someIntegerAttribute = 0 -> 0
XYZ.someIntegerAttribute = 4711 -> 4711

I've to check, if someIntegerAttribute is 0 or <unset>, as there are several side-effects depending on this.

if(XYZ.someIntegerAttribute = null) then {
	log("isnull")
} else {
	log("isnotnull")
} endif;


also results in "isnotnull"

Do you have any other ideas?

Many thanks,

Josef
Re: [QVTo] How to determine <unset> Integer [message #533744 is a reply to message #533214] Sun, 16 May 2010 14:53 Go to previous messageGo to next message
Alan McMorran is currently offline Alan McMorranFriend
Messages: 55
Registered: July 2009
Member
If I'm interpreting you correctly your problem is with attributes that
have a primitive type but are unsettable? In this situation the
default EMF behaviour is for an eGet to return the default value (which
for integers is 0) and so your transform is not able to detect that the
attribute is unset as its type is an EInt and eGet will only ever
return an int, never null (and QVT doesn't seem to check if it is
unsettable)

My own way to get round this was a bit crude when I had to deal with it
for OCL, in which I used an Extended EvaluationEnvironment with an
additional operation, but the same thing could be done with QVT in a
Java blackbox with something like:

public boolean isSet(EObject obj, String attribute){
EStructuralFeature feature =
obj.eClass().getEStructuralFeature(attribute]);
if (feature==null) return false;
return obj.eIsSet(feature);
}

Then in the QVT you would do:

isSet(XYZ, "someIntegerAttribute)

This should work, not had a chance to actually check the code, but the
same approach works in OCL fine. I'll test it out over the next few
hours during my (long, long) flight

Alan

On 2010-05-12 16:59:26 +0200, Josef Freundorfer said:

> Hi,
>
> thanks for the answer, but it doesn't help.
>
> I try to explain it in a different way.
>
> Input Model -> Output Model
> XYZ.someIntegerAttribute = <unset> -> nothing
> XYZ.someIntegerAttribute = 0 -> 0
> XYZ.someIntegerAttribute = 4711 -> 4711
>
> The current behaviour is
> XYZ.someIntegerAttribute = <unset> -> 0
> XYZ.someIntegerAttribute = 0 -> 0
> XYZ.someIntegerAttribute = 4711 -> 4711
>
> I've to check, if someIntegerAttribute is 0 or <unset>, as there are
> several side-effects depending on this.
>
>
> if(XYZ.someIntegerAttribute = null) then {
> log("isnull")
> } else {
> log("isnotnull")
> } endif;
>
>
> also results in "isnotnull"
>
> Do you have any other ideas?
>
> Many thanks,
>
> Josef
Re: [QVTo] How to determine <unset> Integer [message #534372 is a reply to message #532903] Tue, 18 May 2010 21:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Alexander.Igdalov.gmail.com

Hi Josef,

oclIsUndefined() does something different - it checks whether the result
is null or is invalid. Other oclXYZ() operations won't help here for
similar reasons.

Try to call EMF's eIsSet like this:
self.eIsSet(a.eClass().getEStructuralFeature('comConfigurati onId'))

HTH,
- Alex.

Josef Freundorfer wrote:
> Hi,
>
> I'm having some strange behaviour in QVTo. There is a Class XYZ at the
> source model, with an Attribute comConfigurationId : Integer.
>
> It's allowed, that it isn't set. If I access this attribute, I just get
> 0, or the value of it.
>
> For demonstration, the following Code Snippet:
>
> log(self.repr());
> if self.comConfigurationId.oclIsUndefined() then {
> log("undefined");
> } endif;
> if self.comConfigurationId.oclIsInvalid() then {
> log("invalid");
> } endif;
> if self.comConfigurationId.oclIsNew() then {
> log("new");
> } endif;
> if self.comConfigurationId.oclIsKindOf(Integer) then {
> log("kind of Integer");
> } endif;
> if self.comConfigurationId.oclIsTypeOf(Integer) then {
> log("type of Integer");
> } endif;
>
>
> It results in:
>
> ..XYZImpl@f3c717 (checksum: <unset>, timestamp: <unset>) (shortName:
> myXYZInstance, category: <unset>) (comConfigurationId: <unset>,
> comProcessingPeriod: 100.0, diagnosticAddress: 2, pduRConfigurationId:
> <unset>, responseAddress: [1234], sleepModeSupported: <unset>,
> wakeUpOverBusSupported: <unset>)
> kind of Integer
> type of Integer
>
>
> But why? Isn't there an easy way, to check, if this item is set or not???
>
> Many thanks,
>
> Josef
Re: [QVTo] How to determine <unset> Integer [message #534373 is a reply to message #532903] Tue, 18 May 2010 21:32 Go to previous messageGo to next message
Josef Freundorfer is currently offline Josef FreundorferFriend
Messages: 10
Registered: May 2010
Location: Germany
Junior Member
Many thanks for your replies. I will try them out tomorrow and post my results.
icon14.gif  Re: [QVTo] How to determine <unset> Integer [message #534487 is a reply to message #532903] Wed, 19 May 2010 10:45 Go to previous message
Josef Freundorfer is currently offline Josef FreundorferFriend
Messages: 10
Registered: May 2010
Location: Germany
Junior Member
Finally I got it done. My final solution based on your postings Alex and Alan is, many thanks to you.

--needed for the classes
modeltype ECORE uses 'http://www.eclipse.org/emf/2002/Ecore';


--where you want to check it
if self.eIsSet('comConfigurationId') then
	parameterValues += self.comConfigurationId->toValue("bla")
endif;


--helper method
query OclAny::eIsSet(attribute : String) : Boolean {
	if (self.oclAsType(EObject).eIsSet(self.oclAsType(EObject).eClass().getEStructuralFeature(attribute))) then
		return true
	endif;
	return false;
}


Josef
Previous Topic:[ATL] Problem when loading UML Profile programmatically for ATL transformation
Next Topic:[SOLVED] [QVT] library can't see intermediate properties of source MM
Goto Forum:
  


Current Time: Thu Nov 14 05:04:31 GMT 2024

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

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

Back to the top