| Summary: | Problem using Java static functions and enums with scripted data source | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | z_Archived | Reporter: | Tim <tim.warode> | ||||||||
| Component: | BIRT | Assignee: | Birt-ReportEngine-inbox <Birt-ReportEngine-inbox> | ||||||||
| Status: | VERIFIED WORKSFORME | QA Contact: | Xiaoying Gu <bluesoldier> | ||||||||
| Severity: | normal | ||||||||||
| Priority: | P3 | CC: | bluesoldier, hustlg | ||||||||
| Version: | 2.5.2 | ||||||||||
| Target Milestone: | 2.6.2 | ||||||||||
| Hardware: | PC | ||||||||||
| OS: | Windows XP | ||||||||||
| Whiteboard: | Obsolete | ||||||||||
| Attachments: |
|
||||||||||
Would you please attache the class ValuationEnum for me to reproduce? Created attachment 181268 [details]
ValuationEnum class to reproduce problem
I attached the ValuationEnum class. However it is probably not required as the problem occurs with every enum and every static function. Cheers, Tim Hi, I can not reproduce this issue with 2.5.2 release build. Please find my attached example, which used both static function and the Enum class you provided: enumValue = ValuationEnum.FAIL; birtVersion = BIRTRow.getVersion(); The script dataset works fine. Created attachment 181359 [details]
The example that works fine in 2.5.2 and 2.6.1 release
Thanks for your answer. I think my problem may be related to the deployment inside an RCP application. I made a small example RCP app which can be used to reproduce the problem. Created attachment 181363 [details]
Sample RCP app to reproduce
I'd investigated the RCP sample. I found user set application class load in each task in Viewer.java, it's not correct. User should set it at report engine level instead of task level.
public void widgetSelected(SelectionEvent e) {
IReportEngineFactory factory = (IReportEngineFactory) Platform .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
EngineConfig config = new EngineConfig();
HashMap appcontext = config.getAppContext();
appcontext.put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, ValuationEnum.class.getClassLoader());
config.setAppContext(appcontext);
IReportEngine engine = factory.createReportEngine(config);
.......
}
Verified in daily build 20101104-0630. OK, thanks for investigating this. Is there any documentation available for these things (i.e. which property is valid in which scope etc.)? |
Hi, I have BIRT (2.5.2) deployed in our Eclipse RCP application (based on Eclipse 3.5). I am using a scripted data source. When I now try to access static functions in a static way or Enums which are located in one of the plugins of my RCP app, I get errors. This is what I do in a script part: importPackage(Packages.de.micronova.exam.report); var x = ProjectHome.getRootProject(session); or importPackage(Packages.de.micronova.exam.report.enumeration); if (x.equals(ValuationEnum.FAIL)) { ... } and I get this error: WARNUNG: A BIRT exception occurred: Error evaluating Javascript expression. Script engine error: ReferenceError: "ValuationEnum" is not defined. (/report/method[@name="initialize"]#65) Script source: , line: 0, text: __bm_OPEN(). See next exception for more information. Error evaluating Javascript expression. Script engine error: ReferenceError: "ValuationEnum" is not defined. (/report/method[@name="initialize"]#65) Script source: , line: 0, text: __bm_OPEN() org.eclipse.birt.data.engine.core.DataException: A BIRT exception occurred: Error evaluating Javascript expression. Script engine error: ReferenceError: "ValuationEnum" is not defined. (/report/method[@name="initialize"]#65) Script source: , line: 0, text: __bm_OPEN(). See next exception for more information. Error evaluating Javascript expression. Script engine error: ReferenceError: "ValuationEnum" is not defined. (/report/method[@name="initialize"]#65) Script source: , line: 0, text: __bm_OPEN() at org.eclipse.birt.data.engine.core.DataException.wrap(DataException.java:118) at org.eclipse.birt.data.engine.script.ScriptEvalUtil.evaluateJSAsExpr(ScriptEvalUtil.java:773) at org.eclipse.birt.data.engine.script.JSMethodRunner.runScript(JSMethodRunner.java:76) at org.eclipse.birt.report.engine.script.internal.DtEScriptExecutor.handleJS(DtEScriptExecutor.java:90) at org.eclipse.birt.report.engine.script.internal.DataSetScriptExecutor.handleJS(DataSetScriptExecutor.java:219) at org.eclipse.birt.report.engine.script.internal.ScriptDataSetScriptExecutor.handleOpen(ScriptDataSetScriptExecutor.java:88) at org.eclipse.birt.data.engine.impl.ScriptDataSetRuntime.open(ScriptDataSetRuntime.java:80) at org.eclipse.birt.data.engine.impl.PreparedScriptDSQuery$ScriptDSQueryExecutor$CustomDataSet.open(PreparedScriptDSQuery.java:244) at org.eclipse.birt.data.engine.impl.PreparedScriptDSQuery$ScriptDSQueryExecutor.executeOdiQuery(PreparedScriptDSQuery.java:220) at org.eclipse.birt.data.engine.impl.QueryExecutor.execute(QueryExecutor.java:1045) at org.eclipse.birt.data.engine.impl.ServiceForQueryResults.executeQuery(ServiceForQueryResults.java:232) at org.eclipse.birt.data.engine.impl.QueryResults.getResultIterator(QueryResults.java:158) at org.eclipse.birt.report.engine.data.dte.QueryResultSet.<init>(QueryResultSet.java:98) at org.eclipse.birt.report.engine.data.dte.DteDataEngine.doExecuteQuery(DteDataEngine.java:168) at org.eclipse.birt.report.engine.data.dte.AbstractDataEngine.execute(AbstractDataEngine.java:265) at org.eclipse.birt.report.engine.executor.ExecutionContext.executeQuery(ExecutionContext.java:1875) at org.eclipse.birt.report.engine.executor.QueryItemExecutor.executeQuery(QueryItemExecutor.java:80) at org.eclipse.birt.report.engine.executor.DataItemExecutor.execute(DataItemExecutor.java:75) at org.eclipse.birt.report.engine.internal.executor.dup.SuppressDuplicateItemExecutor.execute(SuppressDuplicateItemExecutor.java:43) at org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportItemExecutor.execute(WrappedReportItemExecutor.java:46) at org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportItemExecutor.execute(LocalizedReportItemExecutor.java:34) at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:65) at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26) at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140) at org.eclipse.birt.report.engine.layout.html.HTMLInlineStackingLM.resumeLayout(HTMLInlineStackingLM.java:111) at org.eclipse.birt.report.engine.layout.html.HTMLInlineStackingLM.layoutNodes(HTMLInlineStackingLM.java:160) at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26) at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140) at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:70) at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26) at org.eclipse.birt.report.engine.layout.html.HTMLTableLM.layoutChildren(HTMLTableLM.java:132) at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140) at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:70) at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:90) at org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.layout(HTMLReportLayoutEngine.java:99) at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:170) at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:75) at de.micronova.exam.reporting.job.ReportingJob.run(ReportingJob.java:197) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55) Caused by: org.eclipse.birt.core.exception.CoreException: Error evaluating Javascript expression. Script engine error: ReferenceError: "ValuationEnum" is not defined. (/report/method[@name="initialize"]#65) Script source: , line: 0, text: __bm_OPEN() at org.eclipse.birt.core.script.JavascriptEvalUtil.wrapRhinoException(JavascriptEvalUtil.java:299) at org.eclipse.birt.core.script.JavascriptEvalUtil.evaluateRawScript(JavascriptEvalUtil.java:102) at org.eclipse.birt.core.script.JavascriptEvalUtil.evaluateScript(JavascriptEvalUtil.java:134) at org.eclipse.birt.data.engine.script.ScriptEvalUtil.evaluateJSAsExpr(ScriptEvalUtil.java:769) ... 37 more Caused by: org.mozilla.javascript.EcmaError: ReferenceError: "ValuationEnum" is not defined. (/report/method[@name="initialize"]#65) at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3557) at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3535) at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3620) at org.mozilla.javascript.ScriptRuntime.nameOrFunction(ScriptRuntime.java:1718) at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1657) at org.mozilla.javascript.gen.c46._c1(/report/method[@name="initialize"]:65) at org.mozilla.javascript.gen.c46.call(/report/method[@name="initialize"]) at org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:108) at org.mozilla.javascript.gen.c13._c1(:2) at org.mozilla.javascript.gen.c13.call() at org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:108) at org.mozilla.javascript.gen.c8._c0(:0) at org.mozilla.javascript.gen.c8.call() at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401) at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003) at org.mozilla.javascript.gen.c8.call() at org.mozilla.javascript.gen.c8.exec() at org.eclipse.birt.core.script.JavascriptEvalUtil.evaluateRawScript(JavascriptEvalUtil.java:95) ... 39 more Importing the enum or class with importClass does not work as well: importClass(Packages.de.micronova.exam.report.enumeration.ValuationEnum); if (x.equals(ValuationEnum.FAIL)) { ... } gets me this: Function importClass must be called with a class; had "[JavaPackage de.micronova.exam.report.enumeration.ValuationEnum]" instead. (/report/method[@name="initialize"]#2) Note, that at least the first variant (importPackage) worked just fine with Eclipse 3.3 and BIRT 2.2.2. Now, with Eclipse 3.5 and BIRT 2.5.2 I cannot use my Enums anymore. For static functions, it worked to create instances of the class and use them to call static functions: importPackage( Packages.org.eclipse.core.runtime ); var reportdatamodel = Platform.getBundle("de.exam.reportdatamodel"); var projectHome = reportdatamodel.loadClass("de.micronova.exam.report.ProjectHome"); var inst = projectHome.newInstance(); var x = inst.getRootProject(session); Do I miss something there or has something changed here? Any idea what can be done? Cheers, Tim