Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
ZhaoYong is currently offline ZhaoYongFriend
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 #480299 is a reply to message #480131] Fri, 14 August 2009 20:13 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
ZhaoYong wrote on Thu, 13 August 2009 21:40


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.


JET projects are plug-ins. They require a plug-in based environment (such as Eclipse) in order to run. So you can run a JET transformation from another plug-in, but not from a simple Java program.

I have updated the FAQ to try to make this clearer.

Paul
Re: Run JET template from java error [message #480631 is a reply to message #480299] Tue, 18 August 2009 02:14 Go to previous messageGo to next message
ZhaoYong is currently offline ZhaoYongFriend
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?
Re: Run JET template from java error [message #480653 is a reply to message #480631] Tue, 18 August 2009 06:48 Go to previous message
ZhaoYong is currently offline ZhaoYongFriend
Messages: 3
Registered: July 2009
Junior Member
I debug with jet source, it throw a exception, please note ///////:

public boolean doEvalCondition(TagInfo td, JET2Context context) throws
JET2TagException
{

String testXPath = getAttribute("test"); //$NON-NLS-1$
var = getAttribute("var"); ///////var is null
XPathContextExtender xpathExtender =
XPathContextExtender.getInstance(context);

// get the result of the xpath expression prior to casting to boolean,
in case we define a 'var'.
Object rawObject =
xpathExtender.resolveAsObject(xpathExtender.currentXPathCont extObject(),
testXPath);///////throw a exception which means not support
isVariableDefined function

boolean processContents = XPathUtil.xpathBoolean(rawObject);
if(processContents && var != null)
{
varAlreadySet = context.hasVariable(var);
if(varAlreadySet)
{
savedValue = context.getVariable(var);
}
context.setVariable(var, rawObject);
}

return processContents;
}
Previous Topic:resolving cross-references to imported model in xpand/xtend
Next Topic:[MTL] How to reverse lists ?
Goto Forum:
  


Current Time: Tue Apr 23 08:09:07 GMT 2024

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

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

Back to the top