Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Plugins & class loaders
Plugins & class loaders [message #263097] Thu, 22 July 2004 06:50 Go to next message
Eclipse UserFriend
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
Re: Plugins & class loaders [message #263202 is a reply to message #263097] Thu, 22 July 2004 11:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: chaves.nospam.inf.ufsc.br.ok

With no stack traces for the NPE it will be hard to help.

Michael Boeni wrote:

> 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
Re: Plugins & class loaders [message #263228 is a reply to message #263097] Thu, 22 July 2004 11:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: chris.eclipsefaq.org

Michael Boeni wrote:

> 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.

Launch your runtime workbench under Debug mode (use F11, for instance).
Then set a breakpoint on NullPointerException. In the Debug perspective
find the Breakpoints view, and click on the J! button in the toolbar.
Choose NullPointerException. (Re)run your workbench. When the NPE happens
see if you see what is wrong...

Chris
Re: Plugins & class loaders [message #263256 is a reply to message #263228] Thu, 22 July 2004 12:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mbo.shift-think.net

Hi all

Here is where i get the 'nullPointerException':

ClassLoader loader =
PreferencesManager.getDefault().getClass().getClassLoader();

Cheers,
Michael

"Chris Laffra" <chris@eclipsefaq.org> wrote in message
news:cdom8c$atk$1@eclipse.org...
> Michael Boeni wrote:
>
> > 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.
>
> Launch your runtime workbench under Debug mode (use F11, for instance).
> Then set a breakpoint on NullPointerException. In the Debug perspective
> find the Breakpoints view, and click on the J! button in the toolbar.
> Choose NullPointerException. (Re)run your workbench. When the NPE happens
> see if you see what is wrong...
>
> Chris
>
Re: Plugins & class loaders [message #263258 is a reply to message #263228] Thu, 22 July 2004 12:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mbo.shift-think.net

By the way, here is the code of PreferencesManager:

package com.shiftthink.connect.fatClient.core;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;

/**
* @author mbo
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class PreferencesManager extends AbstractUIPlugin
{

private static PreferencesManager prefsMgr;

public PreferencesManager()
{
prefsMgr = this;
}

protected void initializeDefaultPreferences(IPreferenceStore store)
{
store.setDefault("connectServerURL", "connect.shift-think.com:1099");

}

public static PreferencesManager getDefault()
{
return prefsMgr;
}



}



"Chris Laffra" <chris@eclipsefaq.org> wrote in message
news:cdom8c$atk$1@eclipse.org...
> Michael Boeni wrote:
>
> > 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.
>
> Launch your runtime workbench under Debug mode (use F11, for instance).
> Then set a breakpoint on NullPointerException. In the Debug perspective
> find the Breakpoints view, and click on the J! button in the toolbar.
> Choose NullPointerException. (Re)run your workbench. When the NPE happens
> see if you see what is wrong...
>
> Chris
>
Re: Plugins & class loaders [message #263295 is a reply to message #263256] Thu, 22 July 2004 13:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: chris.eclipsefaq.org

Michael Boeni wrote:

> Hi all

> Here is where i get the 'nullPointerException':

> ClassLoader loader =
> PreferencesManager.getDefault().getClass().getClassLoader();

> Cheers,
> Michael

This means your preferencemanager is being used before it is created.
When do you think it should be created?

Chris
Re: Plugins & class loaders [message #263332 is a reply to message #263295] Thu, 22 July 2004 15:37 Go to previous messageGo to next message
Eclipse UserFriend
If you create a manifest for the PreferencesManager plugin you can make it
get initialized the first time it is accessed. That you fix your problem.

"Chris Laffra" <chris@eclipsefaq.org> wrote in message
news:cdouq4$rod$1@eclipse.org...
> Michael Boeni wrote:
>
> > Hi all
>
> > Here is where i get the 'nullPointerException':
>
> > ClassLoader loader =
> > PreferencesManager.getDefault().getClass().getClassLoader();
>
> > Cheers,
> > Michael
>
> This means your preferencemanager is being used before it is created.
> When do you think it should be created?
>
> Chris
>
Re: Plugins & class loaders [message #263382 is a reply to message #263258] Thu, 22 July 2004 17:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.NO.SPAM.us.ibm.com

Did you:

1) Specify PreferencesManager as the class="" in the plugin.xml
2) Do you have have a manifest file? If you do, then the plugin.xml
class="" will be ignored.

If one of the above is not correct, your PreferencsManager would not be
used as the Plugin instance of your plugin.

But if all you wanted was the classloader from PreferencesManager you
didn't need to do getDefault(), this would be sufficient:

PreferencesManager.class.getClassLoader()


--
Thanks, Rich Kulp

Re: Plugins & class loaders [message #263431 is a reply to message #263382] Fri, 23 July 2004 04:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mbo.shift-think.net

Hello all

I do not have a manifest file but I have now specified the 'class='
attribute in plugin.xml. Now I get the following exceptions:

java.lang.NoClassDefFoundError: org/jboss/logging/Logger

at org.jnp.interfaces.NamingContext.<clinit>(NamingContext.java:102)

at
org.jnp.interfaces.NamingContextFactory.getInitialContext(Na mingContextFacto
ry.java:41)

at javax.naming.spi.NamingManager.getInitialContext(NamingManag er.java:662)

at javax.naming.InitialContext.getDefaultInitCtx(InitialContext .java:243)

at javax.naming.InitialContext.init(InitialContext.java:219)

at javax.naming.InitialContext.<init>(InitialContext.java:195)

at
com.shiftthink.connect.fatClient.core.ConnectionManager$1$In itialContextGett
er.run(ConnectionManager.java:64)

at java.lang.Thread.run(Thread.java:534)

java.lang.NullPointerException

at
com.shiftthink.connect.fatClient.core.ConnectionManager.init ializePersonMana
ger(ConnectionManager.java:36)

at
com.shiftthink.connect.fatClient.entityMgmt.EntityApplicatio n.getPersonList(
EntityApplication.java:85)

at
com.shiftthink.connect.fatClient.entityMgmt.EntityApplicatio n.run(EntityAppl
ication.java:59)

at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.
java:335)

at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:273)

at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:129)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39
)

at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl
..java:25)

at java.lang.reflect.Method.invoke(Method.java:324)

at org.eclipse.core.launcher.Main.basicRun(Main.java:183)

at org.eclipse.core.launcher.Main.run(Main.java:644)

at org.eclipse.core.launcher.Main.main(Main.java:628)

INIT Problem: java.lang.NullPointerException

java.lang.NullPointerException





"Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in message
news:cdpbec$gkr$2@eclipse.org...
> Did you:
>
> 1) Specify PreferencesManager as the class="" in the plugin.xml
> 2) Do you have have a manifest file? If you do, then the plugin.xml
> class="" will be ignored.
>
> If one of the above is not correct, your PreferencsManager would not be
> used as the Plugin instance of your plugin.
>
> But if all you wanted was the classloader from PreferencesManager you
> didn't need to do getDefault(), this would be sufficient:
>
> PreferencesManager.class.getClassLoader()
>
>
> --
> Thanks, Rich Kulp
> 
>
Re: Plugins & class loaders [message #263500 is a reply to message #263431] Fri, 23 July 2004 10:40 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.NO.SPAM.us.ibm.com

Do you know where the org.jboss.logging.Logger is? You are missing the
jar for it.


--
Thanks, Rich Kulp

Previous Topic:Updating to 3.0
Next Topic:Edit workbench preference page
Goto Forum:
  


Current Time: Thu May 08 00:14:33 EDT 2025

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

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

Back to the top