[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools] Re: publishing extension points - help!
|
The argument on the createExecutableExtension refers to the attribute name in
your plugin.xml extension markup that specifies
the name of a Java class implementing the extension. Let's take a look at a
concrete example.
The Eclipse workbench defines an extension point "org.eclipse.ui.importWizards"
for adding new import wizards. The Eclipse workbench specifies that all new
implementations of an import wizard must implement org.eclipse.ui.IImportWizard
interface. It also specifies the "shape" of the extension markup for import
wizards. Below is an example.
<extension point="org.eclipse.ui.importWizards">
<wizard
id="com.xyz.ImportWizard1"
name="XYZ Web Scraper"
class="com.xyz.imports.ImportWizard1"
icon="./icons/import1.gif">
<description>
A simple engine that searches the Web and imports files
</description>
<selection class="org.eclipse.core.resources.IResource"/>
</wizard>
</extension>
As part of the extension markup, the workbench expects <wizard class="..."> to
specify the implementation class being added to the workbench as the new import
wizard. The rest of the attributes are for the most part used to describe how
the new wizard will appear in the UI (ie. labels, icons, etc). So at startup the
workbench would retrieve all the import wizars extension defined in the
plugin.xml (by calling the IPluginRegistry). It constructs its UI, and keeps
track of which UI element (ie. import wizard selection) corresponds to which
extension definition. So when the user picks a specific import wizard, the
workbench has the corresponding IConfigurationElement that actually represents
the desired import wizard extension.
The workbench would then do
IImportWizard wiz = (IImportWizard)
selectedCfig.createExecutableExtension("class");
The workbench knows it is expecting IImportWizard so it can declare a variable
of this type, and do the cast (real code would have some error handling to
handle bad extensions (case exceptions, etc)). The workbench knows it is
expecting the markup to contain <wizard class="..."> so it specifies "class" as
the argument. It so happens the above markup uses the string "class" as the
attribute name, but it could have been anything else, like "implementation",
"wizardClass", or any other attribute name). The implementation of
createExecutableExtension looks up the value of the attribute in the config
element (get "com.xyz.imports.ImportWizard1" in the above example), loads that
Java class (Class.forName(...)) and creates an instance of it (c.newInstance())
using default constructor. So to answer your question, createExecutableExtension
does not know it is creating an instance of IImportWizard. But the workbench
does and casts it as such.Once cast to the actual type, the workbench then
interacts with the new object using the "contract" defined by the IImportWizard
interface.
Hope this helps ... this same pattern (with variations) is repeated for handling
of all extension points in Eclipse (workbench, or any other).
> Hi Vlad,
>
> >
> > IFoo someFoo = (IFoo) cfg[0].createExecutableExtension("fooclass");
> >
>
> I have some more questions if you don't mind...
>
> What is "fooclass" in the call above (the docs say it is the name of a
> property but I don't get what property they're talking about)?
> And how does the createExecutableExtension method know to create an instance
> of the IFoo class from the configuration element?
>
> Thanks in advance,
> ted stockwell