Home » Modeling » M2T (model-to-text transformation) » EMF Iterate through an String array
EMF Iterate through an String array [message #32443] |
Wed, 05 September 2007 11:25  |
Eclipse User |
|
|
|
Hi again,
I've been stuck on a problem even I know that the solution must be simple.
How can I iterate on a attribute of a class which is a String array to get
all the values from this array ?
I tried
<c:iterate select="$myClass/@myStringArray" var="myValue">
<c:get select="$myValue" />
</c:iterate>
but this only gets me the 1st value of the array.
Thank,
regards,
Tex
|
|
| | | | |
Re: EMF Iterate through an String array [message #33024 is a reply to message #32921] |
Thu, 06 September 2007 11:06   |
Eclipse User |
|
|
|
Tex:
But JET does not read the XMI file, EMF does. What JET sees is EObjects and
their corresponding EMF metadata (EClasses, EReferences and EAttributes).
JET has no idea how the model was represented on disk. It could be an XMI
file, as in your case, a relational data base (which you can do with Teneo),
or any number of other possibilities.
JET is attempting to map EReferences to XPath Elements, and EAttributes to
XPath Attributes. But, XPath does not have a concept of arrays, and so, an
Attribute that is an array is a problem. The only 'fix' I can imagine is, on
finding an array is to treat is like an XPath Element. I will investigate.
In the meantime, if you want to make progress with the way JET is currently
implemented, I can suggest the following work arounds (all involve modifying
your Ecore meta-model).
1) Instead of using arrays of simple types (e.g. String), create an EClass
to represent the object, have it define an attribute for the value, and then
create a multi-valued, containment EReference instead of an EAttribute
array.
2) If you are familiar with the EMF annotations for XML Schema, you may be
able to add the right annotations to get JET to look at the EAttribute as a
'simple' Element.
An example. I can describe your myClass example as the attached
texschema.xsd XML Schema.
If you create an EMF Project from this schema, you get a ECore model like
the attached texschema.ecore. In particular, not that the myArray attribute
has an ExtendedMetaData annotation that indicates that the attribute is to
be treated as an XML element. JET understands these. You may be able to just
hack one of these into your ECore model, and JET will magically understand
that the array attribute should be treated as an XPath element. (I say 'may'
because, I'm not sure whether EMFs extended meta data mechanism works if
there isn't extended metadata attached to the EPackage itself. My theory is
you could get away with just by hacking in the following annotation:
<eStructuralFeatures xsi:type="ecore:EAttribute" name="myArray"
unique="false"
upperBound="-1" eType="ecore:EDataType
http://www.eclipse.org/emf/2003/XMLType#//String">
<!-- start of hack --!>
<eAnnotations
source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
</eAnnotations>
<!-- end of hack --!>
</eStructuralFeatures>
Paul
"Tex Twil" <chaljan@hotmail.com> wrote in message
news:fbp078$q5v$1@build.eclipse.org...
> Hi,
> it seems that a string array is stored in a xmi file as I wrote before
> i.e.
>
> myClass
> String name
> String[] myArray
>
> An instance of this class is stored in xmi:
>
> <myClass name="This is my class">
> <myArray>A</myArray>
> <myArray>B</myArray>
> <myArray>C</myArray>
> </myClass>
>
> So it should be possible to iterate through those <myArray> to get the
> values. (see my other posts) :)
>
> Tex.
>
>
>
> "Paul Elder" <pelder@ca.ibm.com> a
|
|
| |
Re: EMF Iterate through an String array [message #33166 is a reply to message #33024] |
Thu, 06 September 2007 11:34   |
Eclipse User |
|
|
|
Thank you Paul,
I understand the problem better now.
I will try those solutions and let you know.
regards,
Tex
"Paul Elder" <pelder@ca.ibm.com> a écrit dans le message de
news:fbp53h$tig$1@build.eclipse.org...
> Tex:
>
> But JET does not read the XMI file, EMF does. What JET sees is EObjects
> and their corresponding EMF metadata (EClasses, EReferences and
> EAttributes). JET has no idea how the model was represented on disk. It
> could be an XMI file, as in your case, a relational data base (which you
> can do with Teneo), or any number of other possibilities.
>
> JET is attempting to map EReferences to XPath Elements, and EAttributes to
> XPath Attributes. But, XPath does not have a concept of arrays, and so, an
> Attribute that is an array is a problem. The only 'fix' I can imagine is,
> on finding an array is to treat is like an XPath Element. I will
> investigate.
>
> In the meantime, if you want to make progress with the way JET is
> currently implemented, I can suggest the following work arounds (all
> involve modifying your Ecore meta-model).
>
> 1) Instead of using arrays of simple types (e.g. String), create an EClass
> to represent the object, have it define an attribute for the value, and
> then create a multi-valued, containment EReference instead of an
> EAttribute array.
>
> 2) If you are familiar with the EMF annotations for XML Schema, you may be
> able to add the right annotations to get JET to look at the EAttribute as
> a 'simple' Element.
>
> An example. I can describe your myClass example as the attached
> texschema.xsd XML Schema.
>
> If you create an EMF Project from this schema, you get a ECore model like
> the attached texschema.ecore. In particular, not that the myArray
> attribute has an ExtendedMetaData annotation that indicates that the
> attribute is to be treated as an XML element. JET understands these. You
> may be able to just hack one of these into your ECore model, and JET will
> magically understand that the array attribute should be treated as an
> XPath element. (I say 'may' because, I'm not sure whether EMFs extended
> meta data mechanism works if there isn't extended metadata attached to the
> EPackage itself. My theory is you could get away with just by hacking in
> the following annotation:
>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="myArray"
> unique="false"
> upperBound="-1" eType="ecore:EDataType
> http://www.eclipse.org/emf/2003/XMLType#//String">
> <!-- start of hack --!>
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> </eAnnotations>
> <!-- end of hack --!>
> </eStructuralFeatures>
>
> Paul
>
> "Tex Twil" <chaljan@hotmail.com> wrote in message
> news:fbp078$q5v$1@build.eclipse.org...
>> Hi,
>> it seems that a string array is stored in a xmi file as I wrote before
>> i.e.
>>
>> myClass
>> String name
>> String[] myArray
>>
>> An instance of this class is stored in xmi:
>>
>> <myClass name="This is my class">
>> <myArray>A</myArray>
>> <myArray>B</myArray>
>> <myArray>C</myArray>
>> </myClass>
>>
>> So it should be possible to iterate through those <myArray> to get the
>> values. (see my other posts) :)
>>
>> Tex.
>>
>>
>>
>> "Paul Elder" <pelder@ca.ibm.com> a écrit dans le message de
>> news:fborgc$lms$1@build.eclipse.org...
>>> Tex:
>>>
>>> I wouldn't be surprised if JET does not handle attribute arrays
>>> properly.
>>> Please submit a defect:
>>>
>>> https://bugs.eclipse.org/bugs/enter_bug.cgi?product=M2T& version=unspecified&component=Jet&rep_platform=PC&am p;op_sys=Windows%20XP&priority=P3&bug_severity=norma l&bug_status=NEW&bug_file_loc=http%3A%2F%2F&shor t_desc=&comment=&commentprivacy=0&keywords=& dependson=&blocked=&maketemplate=Remember%20values%2 0as%20bookmarkable%20template&form_name=enter_bug&as signed_to=m2t.jet-inbox%40eclipse.org
>>>
>>> Paul
>>>
>>> "Tex Twil" <chaljan@hotmail.com> wrote in message
>>> news:fbomrm$csc$1@build.eclipse.org...
>>>> This was my first try but it doesn't work
>>>>
>>>> <c:iterate select="$currRoom/compartments" var="currCompartment" >
>>>> <c:get select="$currCompartment" />
>>>> </c:iterate>
>>>>
>>>> I realized that if I write an "@" in <c:iterate
>>>> select="$currRoom/@compartments" var="currCompartment" > I access the
>>>> value of the first compartment i.e. "A".
>>>>
>>>> Thanks
>>>> Tex
>>>>
>>>> "Tex Twil" <chaljan@hotmail.com> a écrit dans le message de
>>>> news:fbofon$1m7$1@build.eclipse.org...
>>>>> Hi,
>>>>> more details about my question. This is a part of my xmi EMF model:
>>>>>
>>>>> <rooms name="idRoom">
>>>>> <compartments>A</compartments>
>>>>> <compartments>B</compartments>
>>>>> <compartments>C</compartments>
>>>>> <compartments>D</compartments>
>>>>> </rooms>
>>>>>
>>>>> All I want is to iterate through the "compartments" of the current
>>>>> "room" access the A, B .. compartments. It's seems quite easy but I'm
>>>>> stuck. I tried
>>>>> $currRoom/child::compartments
>>>>> but it doesn't seem to work.
>>>>>
>>>>> Thanks
>>>>>
>>>>>
>>>>> "Tex Twil" <chaljan@hotmail.com> a écrit dans le message de
>>>>> news:fbmhp2$7ph$1@build.eclipse.org...
>>>>>> Hi again,
>>>>>> I've been stuck on a problem even I know that the solution must be
>>>>>> simple. How can I iterate on a attribute of a class which is a String
>>>>>> array to get all the values from this array ?
>>>>>>
>>>>>> I tried
>>>>>>
>>>>>> <c:iterate select="$myClass/@myStringArray" var="myValue">
>>>>>> <c:get select="$myValue" />
>>>>>> </c:iterate>
>>>>>>
>>>>>> but this only gets me the 1st value of the array.
>>>>>>
>>>>>> Thank,
>>>>>> regards,
>>>>>> Tex
>>>>>>
>>>>>
>>>>
>>>
>>>
>>
>
>
>
|
|
|
Re: EMF Iterate through an String array [message #33237 is a reply to message #33024] |
Fri, 07 September 2007 04:55   |
Eclipse User |
|
|
|
Hi Paul,
I'm not really familiar with EMF annotations for XML , nevertheless, I tried
your second solution.
I tried your "hack" and I attached an EAnnotation only to the myArray
attribute (kind -> element)
When I derive the ecore to the genmodel and then generate the Model code I
have some compilation errors, some of them saying that
org.eclipse.emf.ecore.xmi cannont be resolved.
When I do the same wih your attached ecore (where the EAnnotations are
everywhere) I don't have those errors. What am I doing wrong ?
regards,
Tex.
"Paul Elder" <pelder@ca.ibm.com> a écrit dans le message de
news:fbp53h$tig$1@build.eclipse.org...
> Tex:
>
> But JET does not read the XMI file, EMF does. What JET sees is EObjects
> and their corresponding EMF metadata (EClasses, EReferences and
> EAttributes). JET has no idea how the model was represented on disk. It
> could be an XMI file, as in your case, a relational data base (which you
> can do with Teneo), or any number of other possibilities.
>
> JET is attempting to map EReferences to XPath Elements, and EAttributes to
> XPath Attributes. But, XPath does not have a concept of arrays, and so, an
> Attribute that is an array is a problem. The only 'fix' I can imagine is,
> on finding an array is to treat is like an XPath Element. I will
> investigate.
>
> In the meantime, if you want to make progress with the way JET is
> currently implemented, I can suggest the following work arounds (all
> involve modifying your Ecore meta-model).
>
> 1) Instead of using arrays of simple types (e.g. String), create an EClass
> to represent the object, have it define an attribute for the value, and
> then create a multi-valued, containment EReference instead of an
> EAttribute array.
>
> 2) If you are familiar with the EMF annotations for XML Schema, you may be
> able to add the right annotations to get JET to look at the EAttribute as
> a 'simple' Element.
>
> An example. I can describe your myClass example as the attached
> texschema.xsd XML Schema.
>
> If you create an EMF Project from this schema, you get a ECore model like
> the attached texschema.ecore. In particular, not that the myArray
> attribute has an ExtendedMetaData annotation that indicates that the
> attribute is to be treated as an XML element. JET understands these. You
> may be able to just hack one of these into your ECore model, and JET will
> magically understand that the array attribute should be treated as an
> XPath element. (I say 'may' because, I'm not sure whether EMFs extended
> meta data mechanism works if there isn't extended metadata attached to the
> EPackage itself. My theory is you could get away with just by hacking in
> the following annotation:
>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="myArray"
> unique="false"
> upperBound="-1" eType="ecore:EDataType
> http://www.eclipse.org/emf/2003/XMLType#//String">
> <!-- start of hack --!>
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> </eAnnotations>
> <!-- end of hack --!>
> </eStructuralFeatures>
>
> Paul
>
> "Tex Twil" <chaljan@hotmail.com> wrote in message
> news:fbp078$q5v$1@build.eclipse.org...
>> Hi,
>> it seems that a string array is stored in a xmi file as I wrote before
>> i.e.
>>
>> myClass
>> String name
>> String[] myArray
>>
>> An instance of this class is stored in xmi:
>>
>> <myClass name="This is my class">
>> <myArray>A</myArray>
>> <myArray>B</myArray>
>> <myArray>C</myArray>
>> </myClass>
>>
>> So it should be possible to iterate through those <myArray> to get the
>> values. (see my other posts) :)
>>
>> Tex.
>>
>>
>>
>> "Paul Elder" <pelder@ca.ibm.com> a écrit dans le message de
>> news:fborgc$lms$1@build.eclipse.org...
>>> Tex:
>>>
>>> I wouldn't be surprised if JET does not handle attribute arrays
>>> properly.
>>> Please submit a defect:
>>>
>>> https://bugs.eclipse.org/bugs/enter_bug.cgi?product=M2T& version=unspecified&component=Jet&rep_platform=PC&am p;op_sys=Windows%20XP&priority=P3&bug_severity=norma l&bug_status=NEW&bug_file_loc=http%3A%2F%2F&shor t_desc=&comment=&commentprivacy=0&keywords=& dependson=&blocked=&maketemplate=Remember%20values%2 0as%20bookmarkable%20template&form_name=enter_bug&as signed_to=m2t.jet-inbox%40eclipse.org
>>>
>>> Paul
>>>
>>> "Tex Twil" <chaljan@hotmail.com> wrote in message
>>> news:fbomrm$csc$1@build.eclipse.org...
>>>> This was my first try but it doesn't work
>>>>
>>>> <c:iterate select="$currRoom/compartments" var="currCompartment" >
>>>> <c:get select="$currCompartment" />
>>>> </c:iterate>
>>>>
>>>> I realized that if I write an "@" in <c:iterate
>>>> select="$currRoom/@compartments" var="currCompartment" > I access the
>>>> value of the first compartment i.e. "A".
>>>>
>>>> Thanks
>>>> Tex
>>>>
>>>> "Tex Twil" <chaljan@hotmail.com> a écrit dans le message de
>>>> news:fbofon$1m7$1@build.eclipse.org...
>>>>> Hi,
>>>>> more details about my question. This is a part of my xmi EMF model:
>>>>>
>>>>> <rooms name="idRoom">
>>>>> <compartments>A</compartments>
>>>>> <compartments>B</compartments>
>>>>> <compartments>C</compartments>
>>>>> <compartments>D</compartments>
>>>>> </rooms>
>>>>>
>>>>> All I want is to iterate through the "compartments" of the current
>>>>> "room" access the A, B .. compartments. It's seems quite easy but I'm
>>>>> stuck. I tried
>>>>> $currRoom/child::compartments
>>>>> but it doesn't seem to work.
>>>>>
>>>>> Thanks
>>>>>
>>>>>
>>>>> "Tex Twil" <chaljan@hotmail.com> a écrit dans le message de
>>>>> news:fbmhp2$7ph$1@build.eclipse.org...
>>>>>> Hi again,
>>>>>> I've been stuck on a problem even I know that the solution must be
>>>>>> simple. How can I iterate on a attribute of a class which is a String
>>>>>> array to get all the values from this array ?
>>>>>>
>>>>>> I tried
>>>>>>
>>>>>> <c:iterate select="$myClass/@myStringArray" var="myValue">
>>>>>> <c:get select="$myValue" />
>>>>>> </c:iterate>
>>>>>>
>>>>>> but this only gets me the 1st value of the array.
>>>>>>
>>>>>> Thank,
>>>>>> regards,
>>>>>> Tex
>>>>>>
>>>>>
>>>>
>>>
>>>
>>
>
>
>
|
|
| | | | |
Goto Forum:
Current Time: Wed Apr 16 10:34:10 EDT 2025
Powered by FUDForum. Page generated in 0.04371 seconds
|