Home » Modeling » OCL » Converting query result for EMF serialization?
Converting query result for EMF serialization? [message #59938] |
Thu, 31 July 2008 16:47  |
Eclipse User |
|
|
|
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 17:34   |
Eclipse User |
|
|
|
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 17:54  |
Eclipse User |
|
|
|
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
|
|
|
Goto Forum:
Current Time: Sun May 11 11:34:14 EDT 2025
Powered by FUDForum. Page generated in 0.03235 seconds
|