|
|
Re: Is it possible to retrieve attributes and references from JET using XPath? [message #44167 is a reply to message #44077] |
Wed, 16 April 2008 13:15 |
Paul Elder Messages: 849 Registered: July 2009 |
Senior Member |
|
|
Roshan:
JETs XPath engine can see any EReference or EAttribute feature implemented
by an EObject's EClass. Since $Book is an EClass instance, its EClass is
EClass itself. Looking at Javadoc for EClass gives you a hint to the
available features:
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. emf.doc/references/javadoc/org/eclipse/emf/ecore/EClass.html
A representation of the model object 'EClass'.
The following features are supported:
a.. Abstract
b.. Interface
c.. ESuper Types
d.. EOperations
e.. EAll Attributes
f.. EAll References
g.. EReferences
h.. EAttributes
i.. EAll Containments
j.. EAll Operations
k.. EAll Structural Features
l.. EAll Super Types
m.. EID Attribute
n.. EStructural Features
o.. EGeneric Super Types
p.. EAll Generic Super Types
(Plus all the features defined on super classes).
The trick is getting the right name for use in the XPath expressions. The
names listed above are not valid Java or XML names. EMF goes through a name
mangling process to arrive at the feature name that JET can actually see.
This is done by removing all spaces, and making the first letter lower case.
So, for EALL Attributes, you get eAllAttributes. A handy way to find the
names is to look at the implementation class (EClassImpl, in this case), and
use the field names for these features.
Next, if the feature is an EAttribute, you have to add an @ in front of the
name.
So, you code should be:
<c:iterate select="$Book/eAllAttributes" var="$EAtt" >
<c:get select="$EAtt/@name" />
</c:iterate>
<c:iterate select="$Book/eAllAttributes" var="$EAtt" >
<c:get select="$EAtt/@name" />
</c:iterate>
Paul
"Roshan Soni" <roshan.soni1@gmail.com> wrote in message
news:ab20266fb5d8d68abcd311720ca23a1c$1@www.eclipse.org...
> Hi,
>
> I am trying to iterate through the list of attributes from my eCore. Say
> I had my Book EObject. is there some way through some xpath functions to
> list all of the attribute names, typename. I also want to do the same for
> references.
> So I want to do something like this:
>
> My Model:
>
> Book-Attributes= "name", "pageNum"
> -Reference= "Author"
>
> Author-Attributes= "name"
>
> In JET I'd like to print out information about my model.
> This doesn't work, but I think it explains what I'm trying to do.
> The variable $Book is actually passed into the transformation as the
> EClass object.
>
> <c:iterate select="$Book/EAllAttributes" var="$EAtt" >
> <c:get select="$EAtt/@name" />
> </c:iterate>
> <c:iterate select="$Book/EAllAttributes" var="$EAtt" >
> <c:get select="$EAtt/@name" />
> </c:iterate>
>
> I can do this using Java or maybe create a custom XPath function/JETtag,
> but it'd be cleaner and less work if I could use the XPath functions
> included with JET.
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03732 seconds