Home » Modeling » M2T (model-to-text transformation) » Run JET template from java error
Run JET template from java error [message #480131] |
Fri, 14 August 2009 01:40 |
ZhaoYong Messages: 3 Registered: July 2009 |
Junior Member |
|
|
Hi,
I am using jet to generate code from a xml model.
I have created a JET transformation project , then coded my own jet
template and xml model , then new a JET transformation and run it
successfully.
Now, in order to abtain more flexibilities, I want to run the jet template
from java. I
have read the JET FAQ "M2T-JET-FAQ/How do I run a JET template from Java?"
,
url:http://wiki.eclipse.org/M2T-JET-FAQ/How_do_I_run_a_JET_t emplate_from_Java%3F
Based on the discription of this faq, I invoke the JET API in my java
class.
First, I create a eclipse plugin project(not jet transformation project),
and config it depends jet plugins
, then code some java class to invoke jet API directly.But I got the
following error:
Exception in thread "main" java.lang.NullPointerException
at
org.eclipse.jet.taglib.TagLibraryManager.getTagLibrary(TagLi braryManager.java:89)
at
org.eclipse.jet.internal.runtime.TagFactoryImpl.createRuntim eTag(TagFactoryImpl.java:61)
at
com.neusoft.unieap.dc.jet.domain.DomainMainTemplate.generate (DomainMainTemplate.java:83)
at test.JETTest.transformation4DO(JETTest.java:30)
at test.JETTest.main(JETTest.java:19)
I search some information about the error and read a mail ,url:
http://dev.eclipse.org/newslists/news.eclipse.technology.emf t/msg01659.html
http://dev.eclipse.org/newslists/news.eclipse.technology.emf t/msg01743.html
The response is "Looking at your stack trace, it seems you are trying to
run an EMFT JET
template directly from a Java program (Transform.main()). EMFT JET doesn't
work that way...."
Now, I confused:
1 Can I run a run jet template from java? Or from a eclipse plugin project?
2 If it's ok, how to resolve the problem?
Thanks a lot.
|
|
| |
Re: Run JET template from java error [message #480631 is a reply to message #480299] |
Tue, 18 August 2009 02:14 |
ZhaoYong Messages: 3 Registered: July 2009 |
Junior Member |
|
|
OK, thinks for your response, I see.
I have run a jet transformation in a plug-in project successfully,
but I got an other problem when try to run a template in java,
Maybe I don't set the variable correctly.
Run a jet transformation as below:
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("org.eclipse.jet.resource.project.name","com.company.sample.petstore.product ");
IProgressMonitor monitor = new NullProgressMonitor();
JET2Platform.runTransformOnObject("com.company.sample.jet", getDoDoc(),
variables, monitor);
But jet transformation's start template is fixed,
in order to run different templates in java(plug-in project), I do the
following steps:
1 create JET2Context and set model(xml) on it
2 create JET2Writer(new BodyContentWriter())
3 use _jet_domain class(generated by jet engine) as template class
4 invoke _jet_domain generate method
But I get nothing from the writer(BodyContentWriter.getContent()),
I debug the _jet_domain class, it returns false when excute this
expression:
'<c:if
test="isVariableDefined('org.eclipse.jet.resource.project.name') ">',
I alread set the variable when create JET2Context as below:
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("org.eclipse.jet.resource.project.name","com.company.sample.petstore.product ");
JET2Context context = new JET2Context(getDoDoc(), copiedVariables);
Now, I don't konw how to do?
|
|
| |
Goto Forum:
Current Time: Tue Apr 23 08:09:07 GMT 2024
Powered by FUDForum. Page generated in 0.03036 seconds
|