JET root package not accessible [message #62385] |
Tue, 09 June 2009 15:42 |
Eclipse User |
|
|
|
Originally posted by: sebastien.bordes.gmail.com
Hello everybody,
I try to use JET to generate a lot of files with few templates.
I want to use the JET2Context object to retrieve the base EPackage of my
ecore file in order to do some special computing.
Here my code
....
context.logInfo(context.getVariable("ePackage").toString());
EPackage p = (EPackage)context.getVariable("ePackage");
String riri= PackageUtils.getRiri(p);
context.setVariable("riri", riri);
....
<ws:project name="{$riri}">
....
Here the output of the logInfo call:
[org.eclipse.emf.ecore.impl.EPackageImpl@1b1ba1b (name: model) (nsURI:
http://com.dede.toto/model/1.0, nsPrefix: com.dede.toto)]
The "ePackage" node is really a EPackage but the cast of the second line
EPackage p = (EPackage) send a ClassCastExeption...
Have you an idea to solve this problem...
I will send the toString content of the Epackage to my method and parse
it but it's quite ugly ...
Thank you
|
|
|
|
Re: JET root package not accessible [message #62482 is a reply to message #62457] |
Wed, 10 June 2009 07:06 |
Eclipse User |
|
|
|
Originally posted by: sebastien.bordes.gmail.com
Thank you Paul, it works !!
I didn't notice that NodeSetImpl implements NodeSet which extends Set
then Collection ...
You omit a (): here the correct line for people stuck like me
EPackage p =
(EPackage)((java.util.Collection)context.getVariable("ePackage ")).iterator().next();
Indeed I didn't pay attention to the open and close [] of the toString
output
Perhaps it this small trick should be added to the JET documentation...
Finally I start to appreciate JET :D it's quite powerful but hard to write
Seb.
Paul Elder a écrit :
> Bordes:
>
> The result of many XPath expression is a 'NodeSet' which is a
> subinterface of Set. Look carefully at the output of your logging, and
> notice the surrounding [ and ] characters - typically an indication that
> a Collection is being printed.
>
>> [org.eclipse.emf.ecore.impl.EPackageImpl@1b1ba1b (name: model) (nsURI:
>> http://com.dede.toto/model/1.0, nsPrefix: com.dede.toto)]
>
> I'd make the following changes:
>
> EPackage p =
> (EPackage)((java.util.Collection)context.getVariable("ePackage ")).iterator.next());
>
>
>
> Paul
>
|
|
|
Powered by
FUDForum. Page generated in 0.04432 seconds