Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » When is a (plugin) class loaded?
When is a (plugin) class loaded? [message #260098] Fri, 09 July 2004 09:51 Go to next message
Eclipse UserFriend
Originally posted by: cenedese.nospam.indel.ch

Hi

In the articles is stated that a plugin class is loaded if a member
function
is called. I have also seen something like "the user should never
explicitely
instantiate a plugin with 'new MyPlugin()'" or similar. I have a plugin
where
I do MyPlugin.getDefault() and the class is loaded. But I have another
plugin
where when I do the same it just returns null, no class is loaded. How can
I
make this work? Why is a class loaded simply by calling the static
getDefault()?

Thanks

bye Fabi
Re: When is a (plugin) class loaded? [message #260186 is a reply to message #260098] Fri, 09 July 2004 11:13 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.NO.SPAM.us.ibm.com

Your plugin class must be specified as the class for the plugin in the
plugin.xml file. The plugin classloaders know to automatically
instantiate an instance of the plugin class the first time a class from
the plugin is referenced. Since you do APlugin.getDefault(), you are
referencing a class within the plugin, so the plugin gets loaded and an
instance of the plugin class is created.

The key is that within the constructor of the plugin class, you assigned
"this" to a static variable within the plugin class. getDefault() is
just a static method that returns that variable.

So the sequence when calling APlugin.getDefault() is:

1) The first access to APlugin causes the class loader to start loading
APlugin class, but then it notes that this class is in the plugin
"APlugin" so it goes to activate the plugin.
2) Activates the plugin by creating an instance of the plugin class
specified in the plugin.xml (which in this case is APlugin.class).
3) The constructor of APlugin assigns "this" to a static variable.
4) The class loader returns, and getDefault() executes, which just
returns the previously set value of the static variable.



--
Thanks, Rich Kulp

Previous Topic:calling external App through plug-in
Next Topic:Initiliaze Perspective
Goto Forum:
  


Current Time: Sat May 10 14:21:50 EDT 2025

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

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

Back to the top