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 |
Josef Freundorfer 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 #533744 is a reply to message #533214] |
Sun, 16 May 2010 14:53 |
Alan McMorran 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 |
Eclipse User |
|
|
|
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
|
|
| | |
Goto Forum:
Current Time: Thu Nov 14 05:04:31 GMT 2024
Powered by FUDForum. Page generated in 0.03297 seconds
|