javaeclipseeclipse-plugineclipse-cdteclipse-mars

Can I add factory class to custom extension point


Creating the extension point: Picture

Attach to extension point class: Picture

Can I add factory class to the custom extension point, which returns a different class depending on some rule?


Solution

  • To make your class a factory it can implement the IExecutableExtensionFactory class, The Eclipse extension manager will call the

    public Object create() throws CoreException
    

    method to ask your factory to create the extension class.

    Many factory classes also implement IExecutableExtension which has the single method:

    public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException
    

    The extension manager will call setInitializationData before calling create. It gives you the entire configuration element from the plugin.xml so you can look at any attributes you want.