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);
}
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;
}
Aggregations