Re: New to JET can't access xsi:type value [message #5172] |
Wed, 21 March 2007 09:10  |
Eclipse User |
|
|
|
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 #6366 is a reply to message #5172] |
Wed, 21 March 2007 10:50   |
Eclipse User |
|
|
|
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 #6479 is a reply to message #6366] |
Thu, 22 March 2007 06:35  |
Eclipse User |
|
|
|
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.
>>>
>>>
>>>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03060 seconds