Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » New to JET can't access xsi:type value
New to JET can't access xsi:type value [message #76115] Wed, 21 March 2007 08:44 Go to next message
Eclipse UserFriend
Originally posted by: evaandoli.dodo.com.au

Hi,
I assume this will be a quick one for most of you
I have the following line in my XML file:
<rules xsi:type="com.ibridge.stepbystepmodel:DecisionNode" tag="WhichState">

and I want to access the type in my JET template.

I can access the 'tag' attribute using

<c:get select="$attrib/@tag" />

But I can't seem to get to the type, i have tried both:

<c:get select="$attrib/@type" />

and

<c:get select="$attrib/@xsi:type" />

Can anyone point me to the right syntax.

Thanks.
Re: New to JET can't access xsi:type value [message #76130 is a reply to message #76115] Wed, 21 March 2007 13:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Stu,

Please use the m2t newsgroup for JET2 questions. I've added it to the
"to" list, so you can continue to use this thread.


Stu wrote:
> Hi,
> I assume this will be a quick one for most of you
> I have the following line in my XML file:
> <rules xsi:type="com.ibridge.stepbystepmodel:DecisionNode" tag="WhichState">
>
> and I want to access the type in my JET template.
>
> I can access the 'tag' attribute using
>
> <c:get select="$attrib/@tag" />
>
> But I can't seem to get to the type, i have tried both:
>
> <c:get select="$attrib/@type" />
>
> and
>
> <c:get select="$attrib/@xsi:type" />
>
> Can anyone point me to the right syntax.
>
> Thanks.
>
>
>
Re: New to JET can't access xsi:type value [message #76146 is a reply to message #76130] Wed, 21 March 2007 14:50 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Stu:

Short answer: you can't. OK, you can't easily.

Explanation: JET is loading the XML file using EMF's XML/XMI
deserialization, and evaluating XPath expressions on the actual EObjects.
The xsi:type gets transformed into the EObject's eClass - unfortunately, the
eClass of an EObject is not an EFeature, and is thus invisible to the XPath
engine.

Work arounds:

It looks like the 'rules' feature declared type is an abstract type, and you
want to process the concrete sub-types differently. Here are a couple of
ways to do this:

a) If you just want to process DecisionNode elements, do the following. I'm
assuming $rulesContainer is a variable referring to the parent of the nodes

<c:iterate select="$rulesContainer/rules[self::DecisionNode]"
var="decisionNode">
...
</c:iterate>

the predicate [self::DecisionNode] filters the elements in the 'rules'
reference list to those whose eClass has the name 'DecisionNode'. If 'rules'
feature is a containment feature, and its containing EClass has no other
containment features that can contain DecisionNodes, then you could use the
expression $rulesContainer/DecisionNode

b) If you want to process all the rules, but do something different for each
type. Try:

<c:iterate select="$rulesContainer/rules" var="node">
<c:choose>
<c:when test="$node/self::DecisionNode">
... $node is a DecisionNode
</c:when>
<c:when test="$node/self::AnotherNode">
... $node is an AnotherNode
</c:when
</c:choose>
</c:iterate>

c) More time consuming, you could write an XPath function the returns the
eClass. Then you could do:

<c:get select="eclass($attr)"/>

To write an custom XPath function, you need to create a plug-in with a
org.eclipse.jet dependency, and an org.eclipse.jet.xpathFunctions extension.
Each function is implemented as a Java class implementing the interface
org.eclipse.jet.xpath.XPathFunction and the method Object evaluate(List
arguments). I have an example that I will be putting into the jet examples
plug-in when I have time. Let me know if you're interested in this route.

Paul

>
> Stu wrote:
>> Hi,
>> I assume this will be a quick one for most of you
>> I have the following line in my XML file:
>> <rules xsi:type="com.ibridge.stepbystepmodel:DecisionNode"
>> tag="WhichState">
>>
>> and I want to access the type in my JET template.
>>
>> I can access the 'tag' attribute using
>>
>> <c:get select="$attrib/@tag" />
>>
>> But I can't seem to get to the type, i have tried both:
>>
>> <c:get select="$attrib/@type" />
>>
>> and
>>
>> <c:get select="$attrib/@xsi:type" />
>>
>> Can anyone point me to the right syntax.
>>
>> Thanks.
>>
>>
>>
Re: New to JET can't access xsi:type value [message #76241 is a reply to message #76146] Thu, 22 March 2007 10:35 Go to previous message
Eclipse UserFriend
Originally posted by: evaandoli.dodo.com.au

Now that is not the simple reply I expected :-)

I guess I could add a derived attribute to the ecore model which returns the
java class.
(let me know if you think that is a bad idea)

Cheers,

Stuart



"Paul Elder" <pelder@ca.ibm.com> wrote in message
news:etrgok$sdo$1@utils.eclipse.org...
> Stu:
>
> Short answer: you can't. OK, you can't easily.
>
> Explanation: JET is loading the XML file using EMF's XML/XMI
> deserialization, and evaluating XPath expressions on the actual EObjects.
> The xsi:type gets transformed into the EObject's eClass - unfortunately,
> the eClass of an EObject is not an EFeature, and is thus invisible to the
> XPath engine.
>
> Work arounds:
>
> It looks like the 'rules' feature declared type is an abstract type, and
> you want to process the concrete sub-types differently. Here are a couple
> of ways to do this:
>
> a) If you just want to process DecisionNode elements, do the following.
> I'm assuming $rulesContainer is a variable referring to the parent of the
> nodes
>
> <c:iterate select="$rulesContainer/rules[self::DecisionNode]"
> var="decisionNode">
> ...
> </c:iterate>
>
> the predicate [self::DecisionNode] filters the elements in the 'rules'
> reference list to those whose eClass has the name 'DecisionNode'. If
> 'rules' feature is a containment feature, and its containing EClass has no
> other containment features that can contain DecisionNodes, then you could
> use the expression $rulesContainer/DecisionNode
>
> b) If you want to process all the rules, but do something different for
> each type. Try:
>
> <c:iterate select="$rulesContainer/rules" var="node">
> <c:choose>
> <c:when test="$node/self::DecisionNode">
> ... $node is a DecisionNode
> </c:when>
> <c:when test="$node/self::AnotherNode">
> ... $node is an AnotherNode
> </c:when
> </c:choose>
> </c:iterate>
>
> c) More time consuming, you could write an XPath function the returns the
> eClass. Then you could do:
>
> <c:get select="eclass($attr)"/>
>
> To write an custom XPath function, you need to create a plug-in with a
> org.eclipse.jet dependency, and an org.eclipse.jet.xpathFunctions
> extension. Each function is implemented as a Java class implementing the
> interface org.eclipse.jet.xpath.XPathFunction and the method Object
> evaluate(List arguments). I have an example that I will be putting into
> the jet examples plug-in when I have time. Let me know if you're
> interested in this route.
>
> Paul
>
>>
>> Stu wrote:
>>> Hi,
>>> I assume this will be a quick one for most of you
>>> I have the following line in my XML file:
>>> <rules xsi:type="com.ibridge.stepbystepmodel:DecisionNode"
>>> tag="WhichState">
>>>
>>> and I want to access the type in my JET template.
>>>
>>> I can access the 'tag' attribute using
>>>
>>> <c:get select="$attrib/@tag" />
>>>
>>> But I can't seem to get to the type, i have tried both:
>>>
>>> <c:get select="$attrib/@type" />
>>>
>>> and
>>>
>>> <c:get select="$attrib/@xsi:type" />
>>>
>>> Can anyone point me to the right syntax.
>>>
>>> Thanks.
>>>
>>>
>>>
>
>
Re: New to JET can't access xsi:type value [message #603759 is a reply to message #76115] Wed, 21 March 2007 13:10 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Stu,

Please use the m2t newsgroup for JET2 questions. I've added it to the
"to" list, so you can continue to use this thread.


Stu wrote:
> Hi,
> I assume this will be a quick one for most of you
> I have the following line in my XML file:
> <rules xsi:type="com.ibridge.stepbystepmodel:DecisionNode" tag="WhichState">
>
> and I want to access the type in my JET template.
>
> I can access the 'tag' attribute using
>
> <c:get select="$attrib/@tag" />
>
> But I can't seem to get to the type, i have tried both:
>
> <c:get select="$attrib/@type" />
>
> and
>
> <c:get select="$attrib/@xsi:type" />
>
> Can anyone point me to the right syntax.
>
> Thanks.
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: New to JET can't access xsi:type value [message #603761 is a reply to message #76130] Wed, 21 March 2007 14:50 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Stu:

Short answer: you can't. OK, you can't easily.

Explanation: JET is loading the XML file using EMF's XML/XMI
deserialization, and evaluating XPath expressions on the actual EObjects.
The xsi:type gets transformed into the EObject's eClass - unfortunately, the
eClass of an EObject is not an EFeature, and is thus invisible to the XPath
engine.

Work arounds:

It looks like the 'rules' feature declared type is an abstract type, and you
want to process the concrete sub-types differently. Here are a couple of
ways to do this:

a) If you just want to process DecisionNode elements, do the following. I'm
assuming $rulesContainer is a variable referring to the parent of the nodes

<c:iterate select="$rulesContainer/rules[self::DecisionNode]"
var="decisionNode">
...
</c:iterate>

the predicate [self::DecisionNode] filters the elements in the 'rules'
reference list to those whose eClass has the name 'DecisionNode'. If 'rules'
feature is a containment feature, and its containing EClass has no other
containment features that can contain DecisionNodes, then you could use the
expression $rulesContainer/DecisionNode

b) If you want to process all the rules, but do something different for each
type. Try:

<c:iterate select="$rulesContainer/rules" var="node">
<c:choose>
<c:when test="$node/self::DecisionNode">
... $node is a DecisionNode
</c:when>
<c:when test="$node/self::AnotherNode">
... $node is an AnotherNode
</c:when
</c:choose>
</c:iterate>

c) More time consuming, you could write an XPath function the returns the
eClass. Then you could do:

<c:get select="eclass($attr)"/>

To write an custom XPath function, you need to create a plug-in with a
org.eclipse.jet dependency, and an org.eclipse.jet.xpathFunctions extension.
Each function is implemented as a Java class implementing the interface
org.eclipse.jet.xpath.XPathFunction and the method Object evaluate(List
arguments). I have an example that I will be putting into the jet examples
plug-in when I have time. Let me know if you're interested in this route.

Paul

>
> Stu wrote:
>> Hi,
>> I assume this will be a quick one for most of you
>> I have the following line in my XML file:
>> <rules xsi:type="com.ibridge.stepbystepmodel:DecisionNode"
>> tag="WhichState">
>>
>> and I want to access the type in my JET template.
>>
>> I can access the 'tag' attribute using
>>
>> <c:get select="$attrib/@tag" />
>>
>> But I can't seem to get to the type, i have tried both:
>>
>> <c:get select="$attrib/@type" />
>>
>> and
>>
>> <c:get select="$attrib/@xsi:type" />
>>
>> Can anyone point me to the right syntax.
>>
>> Thanks.
>>
>>
>>
Re: New to JET can't access xsi:type value [message #603793 is a reply to message #76146] Thu, 22 March 2007 10:35 Go to previous message
Stu Plu is currently offline Stu PluFriend
Messages: 44
Registered: July 2009
Member
Now that is not the simple reply I expected :-)

I guess I could add a derived attribute to the ecore model which returns the
java class.
(let me know if you think that is a bad idea)

Cheers,

Stuart



"Paul Elder" <pelder@ca.ibm.com> wrote in message
news:etrgok$sdo$1@utils.eclipse.org...
> Stu:
>
> Short answer: you can't. OK, you can't easily.
>
> Explanation: JET is loading the XML file using EMF's XML/XMI
> deserialization, and evaluating XPath expressions on the actual EObjects.
> The xsi:type gets transformed into the EObject's eClass - unfortunately,
> the eClass of an EObject is not an EFeature, and is thus invisible to the
> XPath engine.
>
> Work arounds:
>
> It looks like the 'rules' feature declared type is an abstract type, and
> you want to process the concrete sub-types differently. Here are a couple
> of ways to do this:
>
> a) If you just want to process DecisionNode elements, do the following.
> I'm assuming $rulesContainer is a variable referring to the parent of the
> nodes
>
> <c:iterate select="$rulesContainer/rules[self::DecisionNode]"
> var="decisionNode">
> ...
> </c:iterate>
>
> the predicate [self::DecisionNode] filters the elements in the 'rules'
> reference list to those whose eClass has the name 'DecisionNode'. If
> 'rules' feature is a containment feature, and its containing EClass has no
> other containment features that can contain DecisionNodes, then you could
> use the expression $rulesContainer/DecisionNode
>
> b) If you want to process all the rules, but do something different for
> each type. Try:
>
> <c:iterate select="$rulesContainer/rules" var="node">
> <c:choose>
> <c:when test="$node/self::DecisionNode">
> ... $node is a DecisionNode
> </c:when>
> <c:when test="$node/self::AnotherNode">
> ... $node is an AnotherNode
> </c:when
> </c:choose>
> </c:iterate>
>
> c) More time consuming, you could write an XPath function the returns the
> eClass. Then you could do:
>
> <c:get select="eclass($attr)"/>
>
> To write an custom XPath function, you need to create a plug-in with a
> org.eclipse.jet dependency, and an org.eclipse.jet.xpathFunctions
> extension. Each function is implemented as a Java class implementing the
> interface org.eclipse.jet.xpath.XPathFunction and the method Object
> evaluate(List arguments). I have an example that I will be putting into
> the jet examples plug-in when I have time. Let me know if you're
> interested in this route.
>
> Paul
>
>>
>> Stu wrote:
>>> Hi,
>>> I assume this will be a quick one for most of you
>>> I have the following line in my XML file:
>>> <rules xsi:type="com.ibridge.stepbystepmodel:DecisionNode"
>>> tag="WhichState">
>>>
>>> and I want to access the type in my JET template.
>>>
>>> I can access the 'tag' attribute using
>>>
>>> <c:get select="$attrib/@tag" />
>>>
>>> But I can't seem to get to the type, i have tried both:
>>>
>>> <c:get select="$attrib/@type" />
>>>
>>> and
>>>
>>> <c:get select="$attrib/@xsi:type" />
>>>
>>> Can anyone point me to the right syntax.
>>>
>>> Thanks.
>>>
>>>
>>>
>
>
Previous Topic:JDOUserException while initializing datastore
Next Topic:Newbie: teneo configuration question
Goto Forum:
  


Current Time: Fri Mar 29 07:41:20 GMT 2024

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

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

Back to the top