Search in sources :

Example 1 with ImageContentFactory

use of org.knime.core.data.image.ImageContentFactory 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)

Example 2 with ImageContentFactory

use of org.knime.core.data.image.ImageContentFactory in project knime-core by knime.

the class ImagePortObject method load.

/**
 * {@inheritDoc}
 */
@Override
protected void load(final PortObjectZipInputStream in, final PortObjectSpec spec, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    ZipEntry nextEntry = in.getNextEntry();
    String contentClName = nextEntry.getName();
    ImageContentFactory imageContentFactory = getRegisteredImageContentFactories().get(contentClName);
    if (imageContentFactory == null) {
        throw new IOException("No image content factory for class name '" + contentClName + "' registered.");
    }
    m_content = imageContentFactory.create(in);
    in.close();
    m_spec = (ImagePortObjectSpec) spec;
}
Also used : ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) ImageContentFactory(org.knime.core.data.image.ImageContentFactory)

Aggregations

IOException (java.io.IOException)2 ImageContentFactory (org.knime.core.data.image.ImageContentFactory)2 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 ZipEntry (java.util.zip.ZipEntry)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)1 ImageContent (org.knime.core.data.image.ImageContent)1 PNGImageContent (org.knime.core.data.image.png.PNGImageContent)1 PortObjectZipInputStream (org.knime.core.node.port.PortObjectZipInputStream)1