Search in sources :

Example 21 with IExtensionRegistry

use of org.eclipse.core.runtime.IExtensionRegistry in project knime-core by knime.

the class NodeExecutionJobManagerPool method collectJobManagerFactories.

private static void collectJobManagerFactories() {
    managerFactories = new LinkedHashMap<String, NodeExecutionJobManagerFactory>();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
    if (point == null) {
        // let's throw in the default manager - otherwise things fail badly
        managerFactories.put(getDefaultJobManagerFactory().getID(), getDefaultJobManagerFactory());
        LOGGER.error("Invalid extension point: " + EXT_POINT_ID);
        throw new IllegalStateException("ACTIVATION ERROR: " + " --> Invalid extension point: " + EXT_POINT_ID);
    }
    for (IConfigurationElement elem : point.getConfigurationElements()) {
        String jobMgr = elem.getAttribute(EXT_POINT_ATTR_JOBMGR);
        String decl = elem.getDeclaringExtension().getUniqueIdentifier();
        if (jobMgr == null || jobMgr.isEmpty()) {
            LOGGER.error("The extension '" + decl + "' doesn't provide the required attribute '" + EXT_POINT_ATTR_JOBMGR + "'");
            LOGGER.error("Extension " + decl + " ignored.");
            continue;
        }
        // try instantiating the job manager.
        NodeExecutionJobManagerFactory instance = null;
        try {
            // TODO: THE THREADED MANAGER NEEDS TO BE RE-WRITTEN!
            if (jobMgr.equals(getDefaultJobManagerFactory().getID())) {
                instance = getDefaultJobManagerFactory();
            } else {
                instance = (NodeExecutionJobManagerFactory) elem.createExecutableExtension(EXT_POINT_ATTR_JOBMGR);
            }
        } catch (UnsatisfiedLinkError ule) {
            // in case an implementation tries to load an external lib
            // when the factory class gets loaded
            LOGGER.error("Unable to load a library required for '" + jobMgr + "'");
            LOGGER.error("Either specify it in the -Djava.library.path " + "option at the program's command line, or");
            LOGGER.error("include it in the LD_LIBRARY_PATH variable.");
            LOGGER.error("Extension " + jobMgr + " ('" + decl + "') ignored.", ule);
        } catch (CoreException ex) {
            Throwable cause = ex.getStatus().getException();
            if (cause != null) {
                LOGGER.error("Problems during initialization of job manager (with id '" + jobMgr + "'): " + cause.getMessage(), ex);
                if (decl != null) {
                    LOGGER.error("Extension " + decl + " ignored.");
                }
            } else {
                LOGGER.error("Problems during initialization of job manager (with id '" + jobMgr + "')", ex);
                if (decl != null) {
                    LOGGER.error("Extension " + decl + " ignored.");
                }
            }
        } catch (Throwable t) {
            LOGGER.error("Problems during initialization of job manager (with id '" + jobMgr + "')", t);
            if (decl != null) {
                LOGGER.error("Extension " + decl + " ignored.");
            }
        }
        if (instance != null) {
            /*
                 * make sure the ThreadedJobManagerFactory is always the first
                 * in the list
                 */
            if ((instance instanceof ThreadPool) && managerFactories.size() > 0) {
                Map<String, NodeExecutionJobManagerFactory> old = managerFactories;
                managerFactories = new LinkedHashMap<String, NodeExecutionJobManagerFactory>();
                managerFactories.put(instance.getID(), instance);
                for (Map.Entry<String, NodeExecutionJobManagerFactory> e : old.entrySet()) {
                    managerFactories.put(e.getKey(), e.getValue());
                }
            } else {
                managerFactories.put(instance.getID(), instance);
            }
        }
    }
}
Also used : ThreadPool(org.knime.core.util.ThreadPool) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) NodeExecutionJobManagerFactory(org.knime.core.node.workflow.NodeExecutionJobManagerFactory) ThreadNodeExecutionJobManagerFactory(org.knime.core.node.exec.ThreadNodeExecutionJobManagerFactory) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 22 with IExtensionRegistry

use of org.eclipse.core.runtime.IExtensionRegistry in project knime-core by knime.

the class ExtensibleUtilityFactory method readRenderersFromExtensionPoint.

private void readRenderersFromExtensionPoint() {
    if (m_renderers != null) {
        return;
    }
    synchronized (m_logger) {
        if (m_renderers != null) {
            return;
        }
        Map<String, DataValueRendererFactory> renderers = new HashMap<String, DataValueRendererFactory>();
        IExtensionRegistry registry = Platform.getExtensionRegistry();
        IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
        assert point != null : "Invalid extension point id: " + EXT_POINT_ID;
        String defaultRendererId = null;
        for (IExtension ext : point.getExtensions()) {
            IConfigurationElement[] elements = ext.getConfigurationElements();
            for (IConfigurationElement valueClassElement : elements) {
                String valueClassName = valueClassElement.getAttribute("valueClass");
                if (!m_valueClass.getName().equals(valueClassName)) {
                    continue;
                }
                for (IConfigurationElement rendererClassElement : valueClassElement.getChildren()) {
                    boolean suggestAsDefault = Boolean.parseBoolean(rendererClassElement.getAttribute("suggestAsDefault"));
                    try {
                        DataValueRendererFactory rendererFactory = (DataValueRendererFactory) rendererClassElement.createExecutableExtension("rendererFactoryClass");
                        renderers.put(rendererFactory.getId(), rendererFactory);
                        if (suggestAsDefault || (defaultRendererId == null)) {
                            defaultRendererId = rendererFactory.getId();
                            CORE_DEFAULT_PREFS.put(getPreferenceKey(), defaultRendererId);
                        }
                    } catch (CoreException ex) {
                        m_logger.error("Could not load registered renderer factory " + rendererClassElement.getAttribute("rendererFactoryClass") + " for " + valueClassName + " from plug-in " + valueClassElement.getNamespaceIdentifier() + ": " + ex.getMessage(), ex);
                    }
                }
            }
        }
        m_renderers = renderers;
    }
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) IExtension(org.eclipse.core.runtime.IExtension) DataValueRendererFactory(org.knime.core.data.renderer.DataValueRendererFactory) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 23 with IExtensionRegistry

use of org.eclipse.core.runtime.IExtensionRegistry in project xtext-core by eclipse.

the class Activator method initializeResourceServiceProviderRegistry.

private void initializeResourceServiceProviderRegistry(BundleContext context) {
    IExtensionRegistry eReg = Platform.getExtensionRegistry();
    String symbolicName = context.getBundle().getSymbolicName();
    new ContentResourceServiceProviderRegistryReader(eReg, symbolicName).readRegistry();
    new ExtensionResourceServiceProviderRegistryReader(eReg, symbolicName).readRegistry();
    new ProtocolResourceServiceProviderRegistryReader(eReg, symbolicName).readRegistry();
}
Also used : IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 24 with IExtensionRegistry

use of org.eclipse.core.runtime.IExtensionRegistry in project knime-core by knime.

the class MissingCellHandlerFactoryManager method registerExtensionPoints.

/**
 * Registers all extension point implementations.
 * @param extPointId id of the extension point
 * @param extPointAttrDf attribute of the factory class within the handler extension point
 */
protected void registerExtensionPoints(final String extPointId, final String extPointAttrDf) {
    try {
        final IExtensionRegistry registry = Platform.getExtensionRegistry();
        final IExtensionPoint point = registry.getExtensionPoint(extPointId);
        if (point == null) {
            LOGGER.error("Invalid extension point: " + extPointId);
            throw new IllegalStateException("ACTIVATION ERROR: " + " --> Invalid extension point: " + extPointId);
        }
        for (final IConfigurationElement elem : point.getConfigurationElements()) {
            final String operator = elem.getAttribute(extPointAttrDf);
            final String decl = elem.getDeclaringExtension().getUniqueIdentifier();
            if ((operator == null) || operator.isEmpty()) {
                LOGGER.error("The extension '" + decl + "' doesn't provide the required attribute '" + extPointAttrDf + "'");
                LOGGER.error("Extension " + decl + " ignored.");
                continue;
            }
            try {
                final MissingCellHandlerFactory factory = (MissingCellHandlerFactory) elem.createExecutableExtension(extPointAttrDf);
                addMissingCellHandlerFactory(factory);
            } catch (final Exception t) {
                LOGGER.error("Problems during initialization of missing value handler factory (with id '" + operator + "'.)");
                if (decl != null) {
                    LOGGER.error("Extension " + decl + " ignored.", t);
                }
            }
        }
    } catch (final Exception e) {
        LOGGER.error("Exception while registering MissingCellHandler extensions");
    }
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) DoNothingMissingCellHandlerFactory(org.knime.base.node.preproc.pmml.missingval.handlers.DoNothingMissingCellHandlerFactory) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 25 with IExtensionRegistry

use of org.eclipse.core.runtime.IExtensionRegistry in project knime-core by knime.

the class AbstractWizardNodeView method getAllWizardNodeViews.

/**
 * Queries extension point for additional {@link AbstractWizardNodeView} implementations.
 * @return A list with all registered view implementations.
 */
@SuppressWarnings("unchecked")
public static List<WizardNodeViewExtension> getAllWizardNodeViews() {
    List<WizardNodeViewExtension> viewExtensionList = new ArrayList<WizardNodeViewExtension>();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
    assert point != null : "Invalid extension point id: " + EXT_POINT_ID;
    for (IExtension ext : point.getExtensions()) {
        IConfigurationElement[] elements = ext.getConfigurationElements();
        for (IConfigurationElement viewElement : elements) {
            String viewClassName = viewElement.getAttribute("viewClass");
            String viewName = viewElement.getAttribute("name");
            String viewDesc = viewElement.getAttribute("description");
            Class<AbstractWizardNodeView<?, ?, ?>> viewClass;
            try {
                viewClass = (Class<AbstractWizardNodeView<?, ?, ?>>) Class.forName(viewClassName);
                viewExtensionList.add(new WizardNodeViewExtension(viewClass, viewName, viewDesc));
            } catch (ClassNotFoundException ex) {
                NodeLogger.getLogger(AbstractWizardNodeView.class).coding("Could not find implementation for " + viewClassName, ex);
            }
        }
    }
    return viewExtensionList;
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtension(org.eclipse.core.runtime.IExtension) ArrayList(java.util.ArrayList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Aggregations

IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)55 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)50 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)33 CoreException (org.eclipse.core.runtime.CoreException)25 IExtension (org.eclipse.core.runtime.IExtension)20 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)11 Platform (org.eclipse.core.runtime.Platform)9 Map (java.util.Map)8 Optional (java.util.Optional)8 Stream (java.util.stream.Stream)8 NodeLogger (org.knime.core.node.NodeLogger)8 Collection (java.util.Collection)7 List (java.util.List)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 DataTableSpec (org.knime.core.data.DataTableSpec)5 GlobalClassCreator (org.knime.core.eclipseUtil.GlobalClassCreator)5 SerializerMethodLoader (org.knime.core.internal.SerializerMethodLoader)5 File (java.io.File)4 Collections (java.util.Collections)4