Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsCorrect use of workaround for namespace handling?
https://www.eclipse.org/forums/index.php/mv/msg/18563/59506/#msg_59506
I use JET (0.9.2) to load a UML model created in RSARTE (by specifying the
model loader org.eclipse.jet.xml under plugin.xml ->
org.eclipse.jet.transform -> modelLoader.
After discovering the XPath caveats in JET, I have tried in different ways
to navigate through the model using XPath expressions. I have two
questions:
1) I'm trying different ways of selecting node sets and I have tried the
tips from:
I would, for example, like to iterate over all packagedElements that are
of xmi:type = "uml:Class".
The advice, as I interpret it, is to use the XPath select statement:
<c:iterate select="//packagedElement[self::Class]" >
... Do something interesting
</c:iterate>
but this does not result in any selected nodes. What can I have missed
that causes the suggestions to fail in my case?
2) The XPath implementation does not support the id function, and I'm
again interpreting the post linked above as saying that there exists
workarounds for this.
The base_Class attribute of the following Capsule node contains the id of
the packagedElement above. I would like to navigate from the Capsule node
to the packagedElement.
Thanks,
Lars]]>No real name2009-04-15T13:34:46-00:00Re: Correct use of workaround for namespace handling?
https://www.eclipse.org/forums/index.php/mv/msg/18563/59579/#msg_59579
> 1) I'm trying different ways of selecting node sets and I have tried the
> tips from:
This assumes that, instead of the XML model loader, you use the EMF model
loader (org.eclipse.jet.emf). With the EMF model loader, JET is loading
the UML model using the UML2 APIs - these ones:
In this case, XPath steps first try to match a 'feature name'. Failing
that, they take a look at the eContents of the current object, and try to
match a contained object whose eClass().getName() equals the step name.
The bottom line: if you use the EMF loader, you can stop looking at the
XMI representation of your UML model, and start looking at it from the
perspective of the UML2 API. Advantages:
* the XMI omits all values that are defaults - the UML2 API lets you see
them
* with the UML2 API, you can use steps to follow non-containment
references (for example, if $prop is a UML Property, the $prop/type/@name
is equivalent to prop.getType().getName()). With the XMI, you'd have to be
chasing things down via their GUIDs - very ugly indeed.
Final tip. If switching to the EMF model loader from the XML/XMI view of
the work, most of your XPaths will work unmodified, except for:
* any references to xmi:type and xmi:id will be broken - the UML2 API does
not reveal the 'id' of an EObject (you have to dig for this), and the
xmi:type translates into the eObject.eClass().getName().
* there are subtle differences in the meaning of the initial / in XPath
expresions. With XML, it is the org.w3c.dom.Document object. With EMF, it
is the org.eclipse.emf.ecore.resource.Resource object. This main
difference is what the first 'step' is from /.
With an XMI serialization of the model, there is a single root element,
matched by /XMI or /Model or /Package, depending on how your model is
rooted on a Package or a Model, and whether any Stereotypes are applied.
With the EMF serialization, there may be multiple children directly of of
/. The first one is always the UML Package or Model that forms the root of
the model. Any subsequent elements are stereotypes. You can use the
following expressions to match the Model/Package:
/Model - matches a Model object only
/Package - matches a Package object only
/contents[1] - matches the first contained child (a Package or a Model)
/*[1] - matches the first contained child (a Package or a Model)
You can match all the stereotype applications by an expresion such as:
/contents[position() > 1] - you'll need to escape the > with \ in a tag
such as:
<c:iterate select="/contents[position() \> 1]" var="st">
<c:setVariable var="element"
select="$st/*[starts-with(local-name(),'base_')]
Stereotype <c:get select="name($st)"/> applies to <c:get
select="name($element)"/> with qualified name <c:get
select="$element/@qualifiedName"/>
</c:iterate>
> I have a model containing several nodes such as in this snippet:
> I would, for example, like to iterate over all packagedElements that are
> of xmi:type = "uml:Class".
> The advice, as I interpret it, is to use the XPath select statement:
> <c:iterate select="//packagedElement[self::Class]" >
> ... Do something interesting
> </c:iterate>
This will work if you use the EMF model loader...
> 2) The XPath implementation does not support the id function, and I'm
> again interpreting the post linked above as saying that there exists
> workarounds for this.
No, it does not. But, if you follow my suggestion, and load the model via
EMF and you don't have to follow those GUID references. And, as an added
bonus, you can follow non-local references (those to other files/profiles).
> The base_Class attribute of the following Capsule node contains the id of
> the packagedElement above. I would like to navigate from the Capsule node
> to the packagedElement.
I make some suggestions on custom XPath functions for accessing
stereotypes.
> Thanks,
> Lars
Paul]]>Paul Elder2009-04-21T20:36:40-00:00Re: Correct use of workaround for namespace handling?
https://www.eclipse.org/forums/index.php/mv/msg/18563/59653/#msg_59653
> This assumes that, instead of the XML model loader, you use the EMF model
> loader (org.eclipse.jet.emf). With the EMF model loader, JET is loading
> the UML model using the UML2 APIs - these ones:
OK, I started using this approach but didn't (and still don't) find
everything that I need to extract by looking at the dump.xml produced by
the transformation when I use the EMF model loader.
For example, I am most interesed in capsules and their state machines, but
the XML dump does not reveal the code executed in the transision (the
effect). Nor can I see in the dump what triggers the transition. When I
use the XML model loader all of this becomes visible. This was the reason
I felt compelled to switch.
> In this case, XPath steps first try to match a 'feature name'. Failing
> that, they take a look at the eContents of the current object, and try to
> match a contained object whose eClass().getName() equals the step name.
> The bottom line: if you use the EMF loader, you can stop looking at the
> XMI representation of your UML model, and start looking at it from the
> perspective of the UML2 API. Advantages:
> * the XMI omits all values that are defaults - the UML2 API lets you see
> them
> * with the UML2 API, you can use steps to follow non-containment
> references (for example, if $prop is a UML Property, the $prop/type/@name
> is equivalent to prop.getType().getName()). With the XMI, you'd have to be
> chasing things down via their GUIDs - very ugly indeed.
Yes, it quickly becomes quite messy with lots of ugly iterations over
attributes. (Actually, the messiness sort of snuck up on me..)
> Final tip. If switching to the EMF model loader from the XML/XMI view of
> the work, most of your XPaths will work unmodified, except for:
> <snip>
Great! Am I correct in believing that this means that I can still extract
the effect and trigger of a transition and the Entry and Exit code of
states using XPath expressions, even though I cannot see it in the dump?
I find it somewhat difficult to sort out how my XPath expressions should
look if they do not immediately correspond to what I see in the dump
produced. How, for example would I iterate over all states belonging to
the statemachine in the variable $stm and print out their respective entry
and exit code?
Lars]]>No real name2009-04-22T10:53:32-00:00Re: Correct use of workaround for namespace handling?
https://www.eclipse.org/forums/index.php/mv/msg/18563/59677/#msg_59677
Just an addition that I forgot to my other follow-up post. The suggested
example below does not seem to produce what I need.
>> The base_Class attribute of the following Capsule node contains the id of
>> the packagedElement above. I would like to navigate from the Capsule node
>> to the packagedElement.
templates/test.jet(27,6): <c:get select="$capsule/base_Class/@name">
Error: XPath expression returned no result
What am I misunderstanding?
Cheers,
Lars]]>No real name2009-04-22T11:16:05-00:00Re: Correct use of workaround for namespace handling?
https://www.eclipse.org/forums/index.php/mv/msg/18563/59725/#msg_59725
> OK, I started using this approach but didn't (and still don't) find
> everything that I need to extract by looking at the dump.xml produced by
> the transformation when I use the EMF model loader.
To quote myself in another of today's posts:
The c:dump tag is incapable of displaying all the information found in
object network such as an ECore model. The best it can do is traverse the
containment features, and show the values of EAttribute features.
It cannot:
* show you non-containment EReferece features
* EReference features that are derived from others (such as eAttributes,
eAllAttributes, ...)
c:dump was intended to be a quick and dirty 'let me see the structure of
my input, and any annotations I've placed on it (via c:set)'. It is
certainly not a reliable and complete serialization of the input model.
Bottom line: when using an EMF-based model as input, don't look at the XML
either in the input document or that produced by c:dump. Look at the Java
API for the model.
<snip>
> Great! Am I correct in believing that this means that I can still extract
> the effect and trigger of a transition and the Entry and Exit code of
> states using XPath expressions, even though I cannot see it in the dump?
Yes. Stop looking at the dump. Get familiar with the UML2 API instead. If
you can see it in your UML model, JET can see it. The only place were JET
needs some assistance is in stereotypes.
I wrote the following advice on navigating the UML2 API in the IBM
Redbooks "Strategic Reuse with Asset Based Development". It provides some
tips on how to find the names of reference and attribute features by
looking at your UML model in the IBM Rational modeling tools. Here's a
link to the section
> I find it somewhat difficult to sort out how my XPath expressions should
> look if they do not immediately correspond to what I see in the dump
> produced. How, for example would I iterate over all states belonging to
> the statemachine in the variable $stm and print out their respective entry
> and exit code?
I work on the same floor as the team that puts together the IBM Rational's
modeling tools. I remember my first attempt to make sense of the nearly
1000 pages that are the UML2 spec. Even after 5+ years, I still get
confused by it, and I figure other mortals (even those smarter than me)
would be confused, too.
Some of the features of JETs navigation of models are intended to make
this simpler. In particular, I decided that:
* In a tool like RSA, it is much more evident what the type of an UML
element is than what its containing feature is. In RSA, the model
explorer/project explorer shows icons representing UML element types
(Package, Class, Property, Interface, Region, ...). If you select any one
of these, the Properties view kindly tells you what kind of object it is
in the title bar.
So, the XPath engine tries to let you navigate that way. Assuming you get
the 'stereotype' function I suggested early working, you could write
expressions like:
If $sm referred to a StateMachine, then you could do things like:
$sm/Region
or
$sm/Region/State
$sm/Region/PseudoState
With state machines, however, there is no substitute for knowing a bit of
the API. For example, if $state is a State, you'd want to be able to write:
$state/incoming
and
$state/outgoing
In the limited play I have done with state machines, I have found much
more useful to use incoming and outgoing, than to try and find Transitions
directly (where ever they may be).
> Thanks,
> Lars
Glad to help,
Paul]]>Paul Elder2009-04-22T13:22:28-00:00Re: Correct use of workaround for namespace handling?
https://www.eclipse.org/forums/index.php/mv/msg/18563/59749/#msg_59749
> I can print out the value of the base_Class attribute:
!@#$. This not what I expected. Typically, those GUIDs in an attribute in
the XMI serialization indicate an EReference feature. It looks like this
is not the case. To navigate from this stereotype application to the
applied class, it looks like a custom XPath function would need to be
created.
In the meantime, take a look at my response to your previous post. I may
make such a function unnecessary.
Paul]]>Paul Elder2009-04-22T13:32:15-00:00Re: Correct use of workaround for namespace handling?
https://www.eclipse.org/forums/index.php/mv/msg/18563/59889/#msg_59889
> Yes. Stop looking at the dump. Get familiar with the UML2 API instead. If
> you can see it in your UML model, JET can see it. The only place were JET
> needs some assistance is in stereotypes.
Got it. I stopped :)
> I wrote the following advice on navigating the UML2 API in the IBM
> Redbooks "Strategic Reuse with Asset Based Development". It provides some
> tips on how to find the names of reference and attribute features by
> looking at your UML model in the IBM Rational modeling tools. Here's a
> link to the section
> http://www.redbooks.ibm.com/redbooks/SG247529/wwhelp/wwhimpl /api.htm?href=18-6-6.htm
Read that, it helped and I now understand much better how to navigate
around the non-stereotype things.
> So, the XPath engine tries to let you navigate that way. Assuming you get
> the 'stereotype' function I suggested early working, you could write
> expressions like:
> /Model//Class[stereotype(., 'UMLRealTime::Capsule')]/StateMachine
OK, this is where I'm at now. Instead of trying to jump as I described in
an earlier post, I should use the stereotype function as a filter of
sorts. That should also give me access to stereotype attributes that I
will need such as:
I also tried to add the extension directly to the JET project by going to
plugin.xml -> Extensions -> Adding new xpathFunctions and creating the
stereotype function there instead.
This may be more due to my lack of Eclipse skills but when I then try to
use the two jet snippets above the Xpath expression returns no results:
templates/capsuleTemplates/genPort.pml.jet(36,2): <c:get
select="stereotype($port, 'UMLRealTime::RTPort')/@isConjugate">
Error: XPath expression returned no result
(The Capsule snippet iteration produces nothing)
Does JET not know about the function or am I using it wrong?
Thanks!
/Lars]]>No real name2009-04-23T14:22:10-00:00Re: Correct use of workaround for namespace handling?
https://www.eclipse.org/forums/index.php/mv/msg/18563/60088/#msg_60088
As an addition to what I wrote previously, here is some more info on what
I've tried so far:
First of all, I'm using the org.eclipse.jet.emf model loader.
> I also tried to add the extension directly to the JET project by going to
> plugin.xml -> Extensions -> Adding new xpathFunctions and creating the
> stereotype function there instead.
> This may be more due to my lack of Eclipse skills but when I then try to
> use the two jet snippets above the Xpath expression returns no results:
> templates/capsuleTemplates/genPort.pml.jet(36,2): <c:get
> select="stereotype($port, 'UMLRealTime::RTPort')/@isConjugate">
> Error: XPath expression returned no result
> (The Capsule snippet iteration produces nothing)
To clarify, I can iterate over all classes and get their names:
<c:iterate select="/Model//Class" var="class" >
<c:get select="$class/@name" />
</c:iterate>
However, I cannot use the stereotype function to get only those classes
which are also a capsule:
> You can match all the stereotype applications by an expresion such as:
>
> /contents[position() > 1] - you'll need to escape the > with \ in a tag
> such as:
>
<c:iterate select="/contents[position() \> 1]" var="st">
<c:setVariable var="element"
select="$st/*[starts-with(local-name(),'base_')]" />
Stereotype <c:get select="name($st)"/> applies to <c:get
select="name($element)"/> with qualified name <c:get
select="$element/@qualifiedName"/>
</c:iterate>
This produces the following:
...
Stereotype contents applies to with qualified name
Stereotype contents applies to with qualified name
Stereotype contents applies to with qualified name
...
Are these symptoms related?
> Does JET not know about the function or am I using it wrong?
I'm now assuming that JET must know about the function, because if I
change the name I get an error:
Error: Unknown function name: stereotype3
Unknown function name: stereotype3
Therefore, I'm probably using it wrong or I have failed to make some
setting somewhere?
Thanks a lot for your help, I'm getting nowhere fast...
/Lars]]>No real name2009-04-28T08:19:08-00:00Re: Correct use of workaround for namespace handling?
https://www.eclipse.org/forums/index.php/mv/msg/18563/60227/#msg_60227
I finally went an installed RSART, and tried things there. Something is
not working as I would expect (the RSART profiles are not loading properly
from within JET). Either RSART has a special incantation that the
org.eclipse.jet.emf loader is not using, or the org.eclipse.jet.emf loader
is doing something wrong.
I will take a more detailed look, and see if I can figure out what is
happening and report back.
If this is critical for you, I would suggest that you contact IBM Rational
support.
Paul]]>Paul Elder2009-04-30T15:11:20-00:00Re: Correct use of workaround for namespace handling?
https://www.eclipse.org/forums/index.php/mv/msg/18563/60325/#msg_60325
An update. After chatting with a few people more knowledgeable than me,
and some experimentation, I have an way of moving you forward. I'll attach
some examples at the end.
The solution involves creating a JET 'model loader' specific to IBM
Rational .emx (UML models) and epx (UML profiles) files. You must:
1) create a plug-in with the code I'll attach.
2) export it as a 'deployable plug-in'
3) install it in your RSARTE plugins directory and restart
4) reference it in your JET transformation.
The code itself is fairly simple, but it makes use of RSARTE APIs (rather
than just open source APIs), so I can't put it into JET itself.
--- my example code ---
I created a plug-in project named 'com.ibm.example.rsx.jetloader'. It has
not UI dependencies and no activator (questions asked in the wizard).
I added dependencies on two plug-ins:
* org.eclipse.jet - to define the model loader
* com.ibm.xtools.modeler.ui - to access the public APIs to load the
emx/.epx files
I created an 'org.eclipse.jet.modelLoaders' extension to declare the
loader to JET. I gave the loader the ID 'uml2', so, if you use my sample
as is, the fully qualified model loader ID is
'com.ibm.example.rsx.jetloader.uml2'
public Object loadFromString(String serializedModel, String kind)
throws IOException {
throw new UnsupportedOperationException();
}
}
----- end class RsxUml2ModelLoader contents -----]]>Paul Elder2009-05-01T15:13:34-00:00Re: Correct use of workaround for namespace handling?
https://www.eclipse.org/forums/index.php/mv/msg/18563/60349/#msg_60349
You asked about this code snippet.
<c:iterate select="/contents[position() > 1]" var="st">
<c:setVariable var="element"
select="$st/*[starts-with(local-name(),'base_')]" />
Stereotype <c:get select="name($st)"/> applies to <c:get
select="name($element)"/> with qualified name <c:get
select="$element/@qualifiedName"/>
</c:iterate>
In short, it doesn't work as I intended. In particular, the XPath name()
function doesn't give the type of an UML element, it containing feature.
In the case case of the stereotype applications, they are all contained
directly in the EMF Resource, so JET returns 'contents'. Similarly,
name($element) doesn't work as I had wanted.
What's needed is yet another XPath function - one that returns the EClass
of an EObject. A proposed implementation is in this message:
But when I look at the message on-line, the source is all in a single
line, so I'm pasting it in at the end of this message.
With these funcions available
<c:iterate select="/contents[position() > 1]" var="st">
<c:setVariable var="element"
select="$st/base_Class" />
Stereotype <c:get select="eClass($st)/@name"/> applies to <c:get
select="eClass($element)/@name"/> with qualified name <c:get
select="$element/@qualifiedName"/>
</c:iterate>
Finally, the upcoming version of JET (which won't make it into RSARTE for
some time) defines implementations of eClass() and of stereotype() - it
calls them 'emf.eClass' and 'uml2.stereotype', respectively. Don't use
those names, and on some sunny day in the future, you can throw away your
custom versions.
Paul
---- class EClassFunction contents ----
package org.eclipse.jet.examples.functions;
/**
* Implement an XPath function that returns the EClass of an object (if it
is an EObject).
*
*/
public class EClassFunction implements XPathFunction {
}]]>Paul Elder2009-05-01T15:30:21-00:00Re: Correct use of workaround for namespace handling?
https://www.eclipse.org/forums/index.php/mv/msg/18563/60506/#msg_60506
> An update. After chatting with a few people more knowledgeable than me,
> and some experimentation, I have an way of moving you forward. I'll attach
> some examples at the end.
> The solution involves creating a JET 'model loader' specific to IBM
> Rational .emx (UML models) and epx (UML profiles) files. You must:
> 1) create a plug-in with the code I'll attach.
> 2) export it as a 'deployable plug-in'
> 3) install it in your RSARTE plugins directory and restart
> 4) reference it in your JET transformation.
Fantastic! The new model loader is working great with our models and
templates, and we seem to have everything working without any changes from
when using the emf loader. In addition, the stereotype function now works
as described in other posts.