Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Problems with dezerialization // regarding ObjectInputStream
Problems with dezerialization // regarding ObjectInputStream [message #461534] Thu, 11 January 2007 11:28 Go to next message
Eclipse UserFriend
Originally posted by: joerg.kuefen.gmx.de

Hello,

i have a problem when deserialing objects in an plugin based rcp application.

To tell things simple: I have a plugin which defines a base class, lets call it
ALPHA, beeing part of plugin A. Another plugin B implements a class BETA, which
extends the base class ALPHA.

I can serialize objects of type BETA to disc without any problems. When deserializing
the object I get a ClassNotFoundException. I think this occurs because of the
distributed classloaders in eclipse. So finaly i thought it would be possible to
solve that problems by creating a new class that extends the ObjectInputStream
class and overwrites ist resolveClass function. The problem is, that I have absolutly
no idea, how to access or to find the classloaders of all currently registered
plugins. Can anyone help me...

thanks,
jk
Re: Problems with dezerialization // regarding ObjectInputStream [message #461535 is a reply to message #461534] Thu, 11 January 2007 11:39 Go to previous messageGo to next message
Eclipse UserFriend
Hi Joerg,

you might try something like the following to set the ContextClassLoader


Thread thread = null;
ClassLoader classLoader = null;
try
{
thread = Thread.currentThread();

//////////////////////////////////////////////////////////// ////
Class clazz = Class.forName("com.yourpath.BETA");
classLoader = thread.getContextClassLoader();
thread.setContextClassLoader(clazz.getClassLoader() );

//////////////////////////////////////////////////////////// ////
// Your de-serialization goes here

//////////////////////////////////////////////////////////// ////
}// try
catch (Exception e)
{
// your Exception handling
}// catch (Exception e)
finally
{
thread.setContextClassLoader(classLoader);
}// finally





Kuefen wrote:

> Hello,
>
> i have a problem when deserialing objects in an plugin based rcp
> application.
>
> To tell things simple: I have a plugin which defines a base class, lets
> call it
> ALPHA, beeing part of plugin A. Another plugin B implements a class
> BETA, which
> extends the base class ALPHA.
>
> I can serialize objects of type BETA to disc without any problems. When
> deserializing
> the object I get a ClassNotFoundException. I think this occurs because
> of the
> distributed classloaders in eclipse. So finaly i thought it would be
> possible to
> solve that problems by creating a new class that extends the
> ObjectInputStream
> class and overwrites ist resolveClass function. The problem is, that I
> have absolutly
> no idea, how to access or to find the classloaders of all currently
> registered
> plugins. Can anyone help me...
>
> thanks,
> jk
Re: Problems with dezerialization // regarding ObjectInputStream [message #461537 is a reply to message #461535] Thu, 11 January 2007 11:57 Go to previous message
Eclipse UserFriend
Originally posted by: joerg.kuefen.gmx.de

Thanks to You for the very fast answer...

Though I am afraid that - because of my bad description - Your solution won't
work for the application it is actually mentioned for.

Well, it was my mistake that i didn't tell, that the plugin B is only a
example for much more classes extending ALPHA, all beeing deserialized by the
same function. There could be more than only one class extending ALPHA, each
of them may possibly be delivered in seperate plugins. So what i can not do
is searching the classloader matching a specific class. If a class GAMMA should
extend the functionality in the future I would have to touch the deserialization
code, which finaly is not the best solution regarding a modular plugin-concept.

Charle Kelly schrieb:
> Hi Joerg,
>
> you might try something like the following to set the ContextClassLoader
>
>
> Thread thread = null;
> ClassLoader classLoader = null;
> try
> {
> thread = Thread.currentThread();
>
> //////////////////////////////////////////////////////////// ////
> Class clazz = Class.forName("com.yourpath.BETA");
> classLoader = thread.getContextClassLoader();
> thread.setContextClassLoader(clazz.getClassLoader() );
>
> //////////////////////////////////////////////////////////// ////
> // Your de-serialization goes here
>
> //////////////////////////////////////////////////////////// ////
> }// try
> catch (Exception e)
> {
> // your Exception handling
> }// catch (Exception e)
> finally
> {
> thread.setContextClassLoader(classLoader);
> }// finally
>
>
>
>
>
> Kuefen wrote:
>
>> Hello,
>>
>> i have a problem when deserialing objects in an plugin based rcp
>> application.
>>
>> To tell things simple: I have a plugin which defines a base class,
>> lets call it
>> ALPHA, beeing part of plugin A. Another plugin B implements a class
>> BETA, which
>> extends the base class ALPHA.
>>
>> I can serialize objects of type BETA to disc without any problems.
>> When deserializing
>> the object I get a ClassNotFoundException. I think this occurs because
>> of the
>> distributed classloaders in eclipse. So finaly i thought it would be
>> possible to
>> solve that problems by creating a new class that extends the
>> ObjectInputStream
>> class and overwrites ist resolveClass function. The problem is, that I
>> have absolutly
>> no idea, how to access or to find the classloaders of all currently
>> registered
>> plugins. Can anyone help me...
>>
>> thanks,
>> jk
Previous Topic:Is there a standard TableViewSorter?
Next Topic:dispose hook
Goto Forum:
  


Current Time: Sun Mar 16 06:50:28 EDT 2025

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

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

Back to the top