Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » JET root package not accessible
JET root package not accessible [message #62385] Tue, 09 June 2009 15:42 Go to next message
Eclipse UserFriend
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 #62457 is a reply to message #62385] Wed, 10 June 2009 00:44 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
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
Re: JET root package not accessible [message #62482 is a reply to message #62457] Wed, 10 June 2009 07:06 Go to previous message
Eclipse UserFriend
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
>
Previous Topic:[Announce] M2T XPAND 0.7.0RC4 is available
Next Topic:[Announce] M2T XPAND 0.7.0RC5 is available
Goto Forum:
  


Current Time: Fri Dec 27 01:23:50 GMT 2024

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

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

Back to the top