Search in sources :

Example 76 with IExtensionPoint

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

the class NodeFactoryExtensionManager method collectNodeSetFactoryExtensions.

private void collectNodeSetFactoryExtensions() {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(ID_NODE_SET);
    CheckUtils.checkState(point != null, "Invalid extension point: %s", ID_NODE_SET);
    m_nodeSetFactoryExtensions = // 
    Arrays.stream(point.getExtensions()).flatMap(// 
    ext -> Stream.of(ext.getConfigurationElements())).parallel().map(// 
    NodeSetFactoryExtension::from).filter(// 
    Optional::isPresent).map(// 
    Optional::get).collect(Collectors.toList());
    for (NodeSetFactoryExtension nodeSetFactoryExtension : m_nodeSetFactoryExtensions) {
        nodeSetFactoryExtension.getClassNameToFactoryMap().keySet().stream().forEach(clName -> m_factoryNameToNodeSetFactoryExtensionMap.put(clName, nodeSetFactoryExtension));
    }
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) Optional(java.util.Optional) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 77 with IExtensionPoint

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

the class NodeFactoryExtensionManager method collectNodeFactoryExtensions.

private void collectNodeFactoryExtensions() {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(ID_NODE);
    CheckUtils.checkState(point != null, "Invalid extension point: %s", ID_NODE);
    @SuppressWarnings("null") Iterator<IConfigurationElement> it = // 
    Arrays.stream(point.getExtensions()).flatMap(ext -> Stream.of(ext.getConfigurationElements())).iterator();
    while (it.hasNext()) {
        try {
            NodeFactoryExtension nodeFactoryExtension = new NodeFactoryExtension(it.next());
            m_factoryNameToNodeFactoryExtensionMap.put(nodeFactoryExtension.getFactoryClassName(), nodeFactoryExtension);
        } catch (IllegalArgumentException iae) {
            LOGGER.error(iae.getMessage(), iae);
        }
    }
}
Also used : NodeFactory(org.knime.core.node.NodeFactory) NodeSetFactory(org.knime.core.node.NodeSetFactory) Arrays(java.util.Arrays) Iterator(java.util.Iterator) Collection(java.util.Collection) NodeModel(org.knime.core.node.NodeModel) Collectors(java.util.stream.Collectors) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) Stream(java.util.stream.Stream) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) NodeLogger(org.knime.core.node.NodeLogger) Map(java.util.Map) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) Optional(java.util.Optional) Platform(org.eclipse.core.runtime.Platform) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CheckUtils(org.knime.core.node.util.CheckUtils) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 78 with IExtensionPoint

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

the class PortTypeRegistry method availablePortTypes.

/**
 * Returns a collection with all known data types (that registered at the extension point
 * <tt>org.knime.core.DataType</tt>. The returned collection is not sorted in any particular order.
 *
 * @return a (possibly empty) collection with data types
 */
public synchronized Collection<PortType> availablePortTypes() {
    // perform lazy initialization
    if (!m_allPortTypesRead) {
        IExtensionRegistry registry = Platform.getExtensionRegistry();
        IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
        Stream.of(point.getExtensions()).flatMap(ext -> Stream.of(ext.getConfigurationElements())).filter(e -> getObjectClass(e.getAttribute("objectClass")).isPresent()).forEach(e -> createPortTypes(e));
        m_allPortTypesRead = true;
    }
    return m_allPortTypes.values();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SerializerMethodLoader(org.knime.core.internal.SerializerMethodLoader) HashMap(java.util.HashMap) CoreException(org.eclipse.core.runtime.CoreException) PortObjectSpecSerializer(org.knime.core.node.port.PortObjectSpec.PortObjectSpecSerializer) BufferedDataTable(org.knime.core.node.BufferedDataTable) Stream(java.util.stream.Stream) PortObjectSerializer(org.knime.core.node.port.PortObject.PortObjectSerializer) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) NodeLogger(org.knime.core.node.NodeLogger) Map(java.util.Map) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) Optional(java.util.Optional) Platform(org.eclipse.core.runtime.Platform) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 79 with IExtensionPoint

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

the class TableStoreFormatRegistry method createInstance.

private static TableStoreFormatRegistry createInstance() {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
    List<TableStoreFormat> formatList = Stream.of(point.getExtensions()).flatMap(ext -> Stream.of(ext.getConfigurationElements())).map(cfe -> readFormat(cfe)).filter(f -> f != null).sorted(Comparator.comparing(f -> f.getClass().getSimpleName(), (a, b) -> {
        // sort formats so that the "KNIME standard" format comes first.
        if (Objects.equals(a, b)) {
            return 0;
        } else if (DefaultTableStoreFormat.class.getName().equals(a)) {
            return -1;
        } else if (DefaultTableStoreFormat.class.getName().equals(b)) {
            return +1;
        } else {
            return a.compareTo(b);
        }
    })).collect(Collectors.toList());
    boolean hasFallback = formatList.stream().anyMatch(f -> f.getClass().equals(DefaultTableStoreFormat.class));
    CheckUtils.checkState(hasFallback, "No fallback table format registered, expected '%s' but not present in '%s'", DefaultTableStoreFormat.class.getName(), StringUtils.join(formatList.stream().map(f -> f.getClass().getName()).iterator(), ", "));
    return new TableStoreFormatRegistry(formatList);
}
Also used : KNIMEConstants(org.knime.core.node.KNIMEConstants) DataTableSpec(org.knime.core.data.DataTableSpec) CoreException(org.eclipse.core.runtime.CoreException) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) DefaultTableStoreFormat(org.knime.core.data.container.DefaultTableStoreFormat) Objects(java.util.Objects) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) List(java.util.List) Stream(java.util.stream.Stream) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) NodeLogger(org.knime.core.node.NodeLogger) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Optional(java.util.Optional) Platform(org.eclipse.core.runtime.Platform) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) Comparator(java.util.Comparator) CheckUtils(org.knime.core.node.util.CheckUtils) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) DefaultTableStoreFormat(org.knime.core.data.container.DefaultTableStoreFormat) DefaultTableStoreFormat(org.knime.core.data.container.DefaultTableStoreFormat) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 80 with IExtensionPoint

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

the class ImagePortObject method collectImageContentFactories.

private static Map<String, ImageContentFactory> collectImageContentFactories() {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(ImageContentFactory.EXT_POINT_ID);
    if (point == null) {
        LOGGER.error("Invalid extension point: " + ImageContentFactory.EXT_POINT_ID);
        return Collections.emptyMap();
    }
    Map<String, ImageContentFactory> resultList = new HashMap<>();
    for (IConfigurationElement elem : point.getConfigurationElements()) {
        String imageContentCLName = elem.getAttribute(ImageContentFactory.EXT_POINT_ATTR_CLASS_NAME);
        String decl = elem.getDeclaringExtension().getUniqueIdentifier();
        if (imageContentCLName == null || imageContentCLName.isEmpty()) {
            LOGGER.error("The extension '" + decl + "' doesn't provide the required attribute '" + ImageContentFactory.EXT_POINT_ATTR_CLASS_NAME + "' - ignoring it");
            continue;
        }
        ImageContentFactory instance = null;
        try {
            instance = (ImageContentFactory) elem.createExecutableExtension(ImageContentFactory.EXT_POINT_ATTR_CLASS_NAME);
        } catch (Throwable t) {
            LOGGER.error("Problems during initialization of image content factory (with id '" + imageContentCLName + "'.)", t);
            if (decl != null) {
                LOGGER.error("Extension " + decl + " ignored.");
            }
        }
        if (instance != null) {
            // We do not want to add invalid image content impls to this list.
            resultList.put(instance.getImageContentClass().getName(), instance);
        }
    }
    // add the image content implementations from core
    resultList.put(PNGImageContent.class.getName(), new ImageContentFactory() {

        @Override
        public Class<? extends ImageContent> getImageContentClass() {
            return PNGImageContent.class;
        }

        @Override
        public ImageContent create(final InputStream in) throws IOException {
            return new PNGImageContent(in);
        }
    });
    return Collections.unmodifiableMap(resultList);
}
Also used : PNGImageContent(org.knime.core.data.image.png.PNGImageContent) HashMap(java.util.HashMap) PortObjectZipInputStream(org.knime.core.node.port.PortObjectZipInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) PNGImageContent(org.knime.core.data.image.png.PNGImageContent) ImageContent(org.knime.core.data.image.ImageContent) ImageContentFactory(org.knime.core.data.image.ImageContentFactory) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Aggregations

IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)187 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)160 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)107 IExtension (org.eclipse.core.runtime.IExtension)92 CoreException (org.eclipse.core.runtime.CoreException)70 ArrayList (java.util.ArrayList)29 HashMap (java.util.HashMap)17 Platform (org.eclipse.core.runtime.Platform)17 Stream (java.util.stream.Stream)16 List (java.util.List)15 NodeLogger (org.knime.core.node.NodeLogger)15 Map (java.util.Map)14 Optional (java.util.Optional)14 Collection (java.util.Collection)9 Bundle (org.osgi.framework.Bundle)9 Collectors (java.util.stream.Collectors)8 IOException (java.io.IOException)6 Collections (java.util.Collections)6 LinkedList (java.util.LinkedList)6 Objects (java.util.Objects)6