Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Converting query result for EMF serialization?
Converting query result for EMF serialization? [message #59938] Thu, 31 July 2008 20:47 Go to next message
Marc Moser is currently offline Marc MoserFriend
Messages: 66
Registered: July 2009
Member
Hi all,

I have some trouble serializing the evaluation result in an EMF
context.

In general, the evaluation of an OCL expression returns an instance of
java.lang.Object. In my context however, I can restrict the possible
return values to be either an EObject or some (serializable)
EDataType.

What I would like to do is create a structural feature in an EClass
that can hold the evaluation result of the OCL expression. Now, as far
as I understand it, I have several problems:

1) I would probably need two structural features, an EReference (for
EClass) as well as an EAttribute (for EDataType), with the constraint
that only one of them is set at a given time.

2) This would work for EReferences, because EObject is a serializable
common supertype of all EClasses. It would however not work for the
EAttribute because there is no hierarchy in EDataTypes and EJavaObject
is not serializable. Now, I would definitely not want to have an
EAttribute for every possible EDataType...

Am I missing something? Can anyone give me a hint how I could achieve
my goal?

Best regards,

Marc
Re: Converting query result for EMF serialization? [message #59962 is a reply to message #59938] Thu, 31 July 2008 21:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Marc,

This is really an Ecore modeling question, so I'm replying to the EMF
newsgroup, also. Probably somebody there will have a better suggestion
than this:

Becuse, ultimately, EMF's XML serialization needs to convert data types
to strings, try defining the attribute for data-type results as type
EString and use the appropriate EFactory to convert your query results
to/from strings. Probably, you will also need an EReference of
EDataType type to persist the information about the type of the value
that you have encoded as a string, so that you can later convert it
using the right EFactory. You should be able to determine the
particular EDataType from the type of the OCLExpression that you are
evaluating.

So, you would have something like:

<EClass> QueryResult
<EReference> objectResult : EObject
<EAttribute> valueResult : EString
<EReference> valueType : EDataType

HTH,

Christian


Marc Moser wrote:
> Hi all,
>
> I have some trouble serializing the evaluation result in an EMF
> context.
>
> In general, the evaluation of an OCL expression returns an instance of
> java.lang.Object. In my context however, I can restrict the possible
> return values to be either an EObject or some (serializable)
> EDataType.
>
> What I would like to do is create a structural feature in an EClass
> that can hold the evaluation result of the OCL expression. Now, as far
> as I understand it, I have several problems:
>
> 1) I would probably need two structural features, an EReference (for
> EClass) as well as an EAttribute (for EDataType), with the constraint
> that only one of them is set at a given time.
>
> 2) This would work for EReferences, because EObject is a serializable
> common supertype of all EClasses. It would however not work for the
> EAttribute because there is no hierarchy in EDataTypes and EJavaObject
> is not serializable. Now, I would definitely not want to have an
> EAttribute for every possible EDataType...
>
> Am I missing something? Can anyone give me a hint how I could achieve
> my goal?
>
> Best regards,
>
> Marc
Re: Converting query result for EMF serialization? [message #59980 is a reply to message #59962] Thu, 31 July 2008 21:54 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Guys,

Comments below.


Christian W. Damus wrote:
> Hi, Marc,
>
> This is really an Ecore modeling question, so I'm replying to the EMF
> newsgroup, also. Probably somebody there will have a better
> suggestion than this:
>
> Becuse, ultimately, EMF's XML serialization needs to convert data
> types to strings, try defining the attribute for data-type results as
> type EString and use the appropriate EFactory to convert your query
> results to/from strings. Probably, you will also need an EReference
> of EDataType type to persist the information about the type of the
> value that you have encoded as a string, so that you can later convert
> it using the right EFactory. You should be able to determine the
> particular EDataType from the type of the OCLExpression that you are
> evaluating.
>
> So, you would have something like:
>
> <EClass> QueryResult
> <EReference> objectResult : EObject
> <EAttribute> valueResult : EString
> <EReference> valueType : EDataType
>
> HTH,
>
> Christian
>
>
> Marc Moser wrote:
>> Hi all,
>>
>> I have some trouble serializing the evaluation result in an EMF
>> context.
>>
>> In general, the evaluation of an OCL expression returns an instance of
>> java.lang.Object. In my context however, I can restrict the possible
>> return values to be either an EObject or some (serializable)
>> EDataType.
>>
>> What I would like to do is create a structural feature in an EClass
>> that can hold the evaluation result of the OCL expression. Now, as far
>> as I understand it, I have several problems:
>>
>> 1) I would probably need two structural features, an EReference (for
>> EClass) as well as an EAttribute (for EDataType), with the constraint
>> that only one of them is set at a given time.
The change model takes this type of approach, but it also records the
feature and hence knows the EDataType that's needed to encode and decode
the string representation of the data value.
>>
>> 2) This would work for EReferences, because EObject is a serializable
>> common supertype of all EClasses. It would however not work for the
>> EAttribute because there is no hierarchy in EDataTypes and EJavaObject
>> is not serializable. Now, I would definitely not want to have an
>> EAttribute for every possible EDataType...
You could use EJavaObject, but that assumes the value is
java.io.Serializeable and it produces a horrible unreadable result.
>>
>> Am I missing something? Can anyone give me a hint how I could achieve
>> my goal?
Perhaps you could encode the data value using an instance of
SimpleAnyType, which is an EObject, and hence you'd only need an
EReference. The idea would be to use XMLTypeFactory.eINSTANCE to create
it, set the instance type to the appropriate EDataType of the value, and
then use setValue to record the value of the type.
>>
>> Best regards,
>>
>> Marc


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[Announce] MDT OCL 1.2.1 M200807301501 is available
Next Topic:Carriage return in OCL expressions
Goto Forum:
  


Current Time: Fri Apr 19 21:34:18 GMT 2024

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

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

Back to the top