Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » ClassLoader Problem in Event Handler(Two different class loaders used for the type of data item values.)
icon5.gif  ClassLoader Problem in Event Handler [message #760392] Fri, 02 December 2011 09:31 Go to next message
Christian Weisskopf is currently offline Christian Weisskopf
Messages: 2
Registered: December 2011
Location: Zurich, Switzerland
Junior Member

Hi,

I have an Eclipse project with a report file and a class extending DataItemEventAdapter.

@Override
public void onRender(IDataItemInstance data, IReportContext reportContext) throws ScriptException {
	Object value = data.getValue();
	...
}


Since I'm using the EMF ODA driver, the 'value' in this example is of the type 'org.eclipse.emf.oda.ecore.impl.ResultSet.JavaObject'. Logical step for me is to add the required plug-in (org.eclipse.emf.oda.ecore) as a dependency, so I have the required classes in my class path.

index.php/fa/6313/0/

Now to my problem: When running my report (in designer/preview mode) with this handler and the two lines below, I get a ClassCastException for 'JavaObject'.

...
Object value = data.getValue();
JavaObject myObject = (JavaObject) value;
...


I tried the following to see where the problem is.

try {
	Object value = data.getValue();
	System.out.println("Value CL = " + value.getClass().getClassLoader());
	JavaObject reference = new JavaObject(null);
	System.out.println("Reference CL = " + reference .getClass().getClassLoader());
	reference = (JavaObject) value;
} ...


The two objects are not loaded by the same class loader. One is loaded by BIRT, one is loaded by the default OSGI loader. The code above produces the following output:

Value CL = org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@1417a47
Reference CL = org.eclipse.birt.core.framework.URLClassLoader@1713428

java.lang.ClassCastException: org.eclipse.emf.oda.ecore.impl.ResultSet$JavaObject cannot be cast to org.eclipse.emf.oda.ecore.impl.ResultSet$JavaObject
	at my.Handler.onRender(Handler.java:24)


Am I doing it wrong? Is this a specific problem with the EMF ODA driver? I can't possibly be the first person to try something like that.

Any advice in this matter is appreciated.

Thanks,
Chris
Re: ClassLoader Problem in Event Handler [message #760537 is a reply to message #760392] Fri, 02 December 2011 18:09 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

This looks like it may be a bug. Where did you add the dependency?
It may have to be added to the report engine plugin.

Jason

On 12/2/2011 4:31 AM, Christian Weisskopf wrote:
> Hi,
>
> I have an Eclipse project with a report file and a class extending DataItemEventAdapter.
>
> @Override
> public void onRender(IDataItemInstance data, IReportContext reportContext) throws ScriptException {
> Object value = data.getValue();
> ...
> }
>
> Since I'm using the EMF ODA driver, the 'value' in this example is of the type 'org.eclipse.emf.oda.ecore.impl.ResultSet.JavaObject'. Logical step for me is to add the required plug-in (org.eclipse.emf.oda.ecore) as a dependency, so I have the required classes in my class path.
>
>
>
> Now to my problem: When running my report (in designer/preview mode) with this handler and the two lines below, I get a ClassCastException for 'JavaObject'.
>
> ...
> Object value = data.getValue();
> JavaObject myObject = (JavaObject) value;
> ...
>
> I tried the following to see where the problem is.
>
> try {
> Object value = data.getValue();
> System.out.println("Value CL = " + value.getClass().getClassLoader());
> JavaObject reference = new JavaObject(null);
> System.out.println("Reference CL = " + reference .getClass().getClassLoader());
> reference = (JavaObject) value;
> } ...
>
> The two objects are not loaded by the same class loader. One is loaded by BIRT, one is loaded by the default OSGI loader. The code above produces the following output:
>
> Value CL = org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@1417a47
> Reference CL = org.eclipse.birt.core.framework.URLClassLoader@1713428
>
> java.lang.ClassCastException: org.eclipse.emf.oda.ecore.impl.ResultSet$JavaObject cannot be cast to org.eclipse.emf.oda.ecore.impl.ResultSet$JavaObject
> at my.Handler.onRender(Handler.java:24)
>
> Am I doing it wrong? Is this a specific problem with the EMF ODA driver? I can't possibly be the first person to try something like that.
>
> Any advice in this matter is appreciated.
>
> Thanks,
> Chris
Re: ClassLoader Problem in Event Handler [message #762484 is a reply to message #760537] Thu, 08 December 2011 06:50 Go to previous message
Christian Weisskopf is currently offline Christian Weisskopf
Messages: 2
Registered: December 2011
Location: Zurich, Switzerland
Junior Member

Jason,

Thanks for your answer.

My problems were fixed after adding the report engine plugin to my workspace and adding the required dependencies there. Thanks!

-Chris
Previous Topic:BIRT 3.7 - dynamic image from byte[] bound to column
Next Topic:vector rendering of svg in pdf
Goto Forum:
  


Current Time: Tue Sep 16 11:31:10 GMT 2014

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

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