Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 328094 - Problem using Java static functions and enums with scripted data source
Summary: Problem using Java static functions and enums with scripted data source
Status: VERIFIED WORKSFORME
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: BIRT (show other bugs)
Version: 2.5.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 2.6.2   Edit
Assignee: Birt-ReportEngine-inbox@eclipse.org CLA
QA Contact: Xiaoying Gu CLA
URL:
Whiteboard: Obsolete
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-19 02:25 EDT by Tim CLA
Modified: 2010-11-05 05:35 EDT (History)
2 users (show)

See Also:


Attachments
ValuationEnum class to reproduce problem (1.07 KB, text/plain)
2010-10-20 05:54 EDT, Tim CLA
no flags Details
The example that works fine in 2.5.2 and 2.6.1 release (9.25 KB, application/x-zip-compressed)
2010-10-21 02:18 EDT, Xiaoying Gu CLA
no flags Details
Sample RCP app to reproduce (19.90 KB, application/octet-stream)
2010-10-21 03:37 EDT, Tim CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tim CLA 2010-10-19 02:25:46 EDT
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
Comment 1 Xiaoying Gu CLA 2010-10-20 05:04:23 EDT
Would you please attache the class ValuationEnum for me to reproduce?
Comment 2 Tim CLA 2010-10-20 05:54:03 EDT
Created attachment 181268 [details]
ValuationEnum class to reproduce problem
Comment 3 Tim CLA 2010-10-20 05:57:19 EDT
I attached the ValuationEnum class. However it is probably not required as the problem occurs with every enum and every static function.

Cheers,
Tim
Comment 4 Xiaoying Gu CLA 2010-10-21 02:16:22 EDT
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.
Comment 5 Xiaoying Gu CLA 2010-10-21 02:18:25 EDT
Created attachment 181359 [details]
The example that works fine in 2.5.2 and 2.6.1 release
Comment 6 Tim CLA 2010-10-21 03:36:30 EDT
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.
Comment 7 Tim CLA 2010-10-21 03:37:41 EDT
Created attachment 181363 [details]
Sample RCP app to reproduce
Comment 8 Gang Liu CLA 2010-11-02 05:05:00 EDT
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);
.......
}
Comment 9 Xiaoying Gu CLA 2010-11-04 04:08:19 EDT
Verified in daily build 20101104-0630.
Comment 10 Tim CLA 2010-11-05 05:35:29 EDT
OK, thanks for investigating this.
Is there any documentation available for these things (i.e. which property is valid in which scope etc.)?