Search in sources :

Example 71 with IConfigurationElement

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

the class RepositoryManager method readNodeSets.

/**
 * @param isInExpertMode
 */
private void readNodeSets(final IProgressMonitor monitor) {
    // 
    // Process the contributed node sets
    // 
    Iterator<IConfigurationElement> it = Stream.of(RepositoryManager.getExtensions(ID_NODE_SET)).flatMap(ext -> Stream.of(ext.getConfigurationElements())).filter(elem -> !"true".equalsIgnoreCase(elem.getAttribute("deprecated"))).iterator();
    while (it.hasNext()) {
        IConfigurationElement elem = it.next();
        try {
            Collection<DynamicNodeTemplate> dynamicNodeTemplates = RepositoryFactory.createNodeSet(m_root, elem);
            for (DynamicNodeTemplate node : dynamicNodeTemplates) {
                if (monitor.isCanceled()) {
                    return;
                }
                for (Listener l : m_loadListeners) {
                    l.newNode(m_root, node);
                }
                m_nodesById.put(node.getID(), node);
                String nodeName = node.getID();
                nodeName = nodeName.substring(nodeName.lastIndexOf('.') + 1);
                // Ask the root to lookup the category-container located
                // at
                // the given path
                IContainerObject parentContainer = m_root.findContainer(node.getCategoryPath());
                // the node to the repository root.
                if (parentContainer == null) {
                    LOGGER.warn("Invalid category-path for node " + "contribution: '" + node.getCategoryPath() + "' - adding to root instead");
                    m_root.addChild(node);
                } else {
                    // everything is fine, add the node to its parent
                    // category
                    parentContainer.addChild(node);
                }
            }
        } catch (Throwable t) {
            String message = "Node " + elem.getAttribute("factory-class") + "' from plugin '" + elem.getNamespaceIdentifier() + "' could not be created.";
            Bundle bundle = Platform.getBundle(elem.getNamespaceIdentifier());
            if ((bundle == null) || (bundle.getState() != Bundle.ACTIVE)) {
                // if the plugin is null, the plugin could not
                // be activated maybe due to a not
                // activateable plugin (plugin class cannot be found)
                message += " The corresponding plugin " + "bundle could not be activated!";
            }
            LOGGER.error(message, t);
        }
    }
}
Also used : Arrays(java.util.Arrays) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) FileNativeNodeContainerPersistor(org.knime.core.node.workflow.FileNativeNodeContainerPersistor) Category(org.knime.workbench.repository.model.Category) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) NodeLogger(org.knime.core.node.NodeLogger) Map(java.util.Map) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) Root(org.knime.workbench.repository.model.Root) Bundle(org.osgi.framework.Bundle) IExtension(org.eclipse.core.runtime.IExtension) AbstractContainerObject(org.knime.workbench.repository.model.AbstractContainerObject) NodeFactory(org.knime.core.node.NodeFactory) Iterator(java.util.Iterator) Collection(java.util.Collection) NodeModel(org.knime.core.node.NodeModel) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject) IContainerObject(org.knime.workbench.repository.model.IContainerObject) List(java.util.List) NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) Stream(java.util.stream.Stream) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) DynamicNodeTemplate(org.knime.workbench.repository.model.DynamicNodeTemplate) Platform(org.eclipse.core.runtime.Platform) Comparator(java.util.Comparator) Collections(java.util.Collections) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Bundle(org.osgi.framework.Bundle) IContainerObject(org.knime.workbench.repository.model.IContainerObject) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) DynamicNodeTemplate(org.knime.workbench.repository.model.DynamicNodeTemplate)

Example 72 with IConfigurationElement

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

the class OpenInteractiveWebViewAction method getViewClassByReflection.

private static Class<?> getViewClassByReflection(final String className, final IConfigurationElement[] confElements) {
    Class<?> viewClass = null;
    try {
        for (IConfigurationElement element : confElements) {
            if (className.equals(element.getAttribute("viewClass"))) {
                viewClass = Platform.getBundle(element.getDeclaringExtension().getContributor().getName()).loadClass(element.getAttribute("viewClass"));
            }
        }
    } catch (Exception e) {
    /* do nothing */
    }
    if (viewClass != null) {
        try {
            Method isEnabledM = viewClass.getMethod("isEnabled");
            boolean isEnabled = (boolean) isEnabledM.invoke(null);
            return isEnabled ? viewClass : null;
        } catch (Exception e) {
            return viewClass;
        }
    }
    return null;
}
Also used : Method(java.lang.reflect.Method) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 73 with IConfigurationElement

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

the class DatabaseDriverLoader method loadDriversFromExtensionPoint.

/**
 * Loads all JDBC driver registered via the extension point.
 */
private static void loadDriversFromExtensionPoint() {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
    if (point == null) {
        throw new IllegalStateException("Invalid extension point id: " + EXT_POINT_ID);
    }
    for (IExtension ext : point.getExtensions()) {
        IConfigurationElement[] elements = ext.getConfigurationElements();
        for (IConfigurationElement e : elements) {
            String path = e.getAttribute("jarFile");
            String bundleId = e.getDeclaringExtension().getNamespaceIdentifier();
            Bundle bundle = Platform.getBundle(bundleId);
            URL jdbcUrl = FileLocator.find(bundle, new Path(path), null);
            if (jdbcUrl != null) {
                ClassLoader bundleClassLoader = bundle.adapt(BundleWiring.class).getClassLoader();
                try {
                    loadDriver(new File(FileLocator.toFileURL(jdbcUrl).getPath()), bundleClassLoader, false);
                } catch (IOException ex) {
                    LOGGER.error("Could not load JDBC driver '" + path + "': " + ex.getMessage(), ex);
                }
            } else {
                LOGGER.error("Could not find JDBC driver file '" + path + "' from plug-in '" + bundleId + "'");
            }
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) IOException(java.io.IOException) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) URL(java.net.URL) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtension(org.eclipse.core.runtime.IExtension) URLClassLoader(java.net.URLClassLoader) File(java.io.File) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 74 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement 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 75 with IConfigurationElement

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

the class DataTypeRegistry method availableDataTypes.

/**
 * Returns a collection with all known data types (that are registered at the extension point
 * <tt>org.knime.core.DataType</tt>).
 *
 * @return a (possibly empty) collection with data types
 */
public synchronized Collection<DataType> availableDataTypes() {
    // perform lazy initialization
    if (m_allDataTypes != null) {
        return m_allDataTypes;
    }
    List<DataType> types = new ArrayList<>();
    for (IConfigurationElement configElement : m_factories.values()) {
        try {
            DataCellFactory fac = (DataCellFactory) configElement.createExecutableExtension("factoryClass");
            types.add(fac.getDataType());
        } catch (CoreException e) {
            NodeLogger.getLogger(getClass()).error("Could not create data cell factory '" + configElement.getAttribute("factoryClass") + "' for '" + configElement.getAttribute("cellClass") + "' from plug-in '" + configElement.getNamespaceIdentifier() + "': " + e.getMessage(), e);
        }
    }
    m_allDataTypes = Collections.unmodifiableCollection(types);
    return types;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Aggregations

IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)189 CoreException (org.eclipse.core.runtime.CoreException)75 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)64 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)50 ArrayList (java.util.ArrayList)39 IExtension (org.eclipse.core.runtime.IExtension)30 IStatus (org.eclipse.core.runtime.IStatus)24 Status (org.eclipse.core.runtime.Status)24 HashMap (java.util.HashMap)16 HashSet (java.util.HashSet)16 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)11 List (java.util.List)9 Map (java.util.Map)9 Platform (org.eclipse.core.runtime.Platform)9 File (java.io.File)8 Collection (java.util.Collection)8 Stream (java.util.stream.Stream)8 LinkedList (java.util.LinkedList)7 Optional (java.util.Optional)5 IFile (org.eclipse.core.resources.IFile)5