Plugins & class loaders [message #263097] |
Thu, 22 July 2004 06:50  |
Eclipse User |
|
|
|
Originally posted by: mbo.shift-think.net
Hi all
I have two plugins 'core' and 'entityMgmt'. The Core plugin is responsible
for providing the overall functions, that should be used
by the other plugins. This includes loading a class at runtime to establish
an 'initial context' for access to a remote session bean.
I have tried several things and am currently trying to work out the problems
I have with dynamically loading classes at runtime
(class not found exceptions) using a class loader (thanks to Ilya).
I am not really sure if I understood the overall concept of the plugin issue
and would appreciate help on this.
My current problem is that the 'initializePersonManager' returns a
NullPointerException, not idea what's wrong.
-----------------------------
ConnectionManager.java (core)
-----------------------------
package com.shiftthink.connect.fatClient.core;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import com.shiftthink.connect.entityMgmt.PersonManager;
import com.shiftthink.connect.entityMgmt.PersonManagerHome;
public class ConnectionManager
{
public static PersonManager initializePersonManager(PersonManager
mgr)
{
try
{
Context context = getInitialContext();
Object obj = context.lookup("PersonManager");
// Create a pMgrHome reference
PersonManagerHome pMgrHome = (PersonManagerHome)
PortableRemoteObject.
narrow(obj, PersonManagerHome.class);
mgr = pMgrHome.create();
return mgr;
}
catch (Exception ex)
{
System.out.println("INIT Problem: "+ex);
return null;
}
}
private static InitialContext getInitialContext()
{
class InitialContextGetter implements Runnable
{
InitialContext result;
public void run()
{
try
{
Hashtable env = new Hashtable();
env.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
env.put("java.naming.provider.url",
"localhost:1099");
result= new InitialContext(env);
} catch (NamingException e)
{
result=null;
}
}
}
ClassLoader loader =
PreferencesManager.getDefault().getClass().getClassLoader();
InitialContextGetter getter = new InitialContextGetter();
Thread getterThread = new Thread(getter);
getterThread.setContextClassLoader(loader);
getterThread.start();
try
{
getterThread.join();
} catch (Exception aEx)
{
aEx.printStackTrace();
}
return getter.result;
}
}
-----------------------------------
EntityApplication.java (entityMgmt)
-----------------------------------
And here is the code of a method of the other plugin that makes use of the
'core'
plugins classes and functions:
public PersonDto[] getPersonList()
{
// Create PersonManager instance (remotely) and try to
access data.
PersonManager pMgr = null;
PersonDto[] personlist = null;
try
{
pMgr =
ConnectionManager.initializePersonManager(pMgr);
personlist = pMgr.getAllPersons();
for(int i=0; i < personlist.length; i++)
{
System.out.println("Name: " +
personlist[i].getStDescriptivenameFind());
}
}
catch (ClassCastException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (RemoteException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (NamingException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (Exception exc)
{
System.out.println(exc.toString());
//exc.printStackTrace();
}
return personlist;
}
By the way: "PreferencesManager" is the 'plugin application' of the core
plugin.
Thanks for your help!
Cheers,
Michael
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06188 seconds