Skip to content

Commit

Permalink
Implemented the converter factories for Cells --> POJO and POJO --> C…
Browse files Browse the repository at this point in the history
…ell for CDKCell3

TODO: It would be worth creating a CDKCellFactory to handle creation of CDK cells.

git-svn-id: https://community.knime.org/svn/nodes4knime/trunk@9238 cd80d6f6-f959-11df-8f91-f7e70cbaf77b
  • Loading branch information
swebb authored and egonw committed Nov 8, 2017
1 parent 4f1396f commit ac67dbe
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: KNIME CDK Integration
Bundle-SymbolicName: org.openscience.cdk.knime;singleton:=true
Bundle-Version: 1.5.600.qualifier
Bundle-Version: 1.5.700.qualifier
Bundle-Vendor: KNIME GmbH, Konstanz and EMBL-EBI, Cambridge
Bundle-ClassPath: knime-cdk.jar,
lib/cdk-bundle-1.5.13.jar,
Expand Down
12 changes: 12 additions & 0 deletions org.openscience/org.openscience.cdk.knime/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,16 @@
</serializer>
</DataType>
</extension>
<extension
point="org.knime.core.DataCellToJavaConverter">
<DataCellToJavaConverter
factoryClass="org.openscience.cdk.knime.type.snippets.java.CdkCellToJavaFactory">
</DataCellToJavaConverter>
</extension>
<extension
point="org.knime.core.JavaToDataCellConverter">
<JavaToDataCellConverter
factoryClass="org.openscience.cdk.knime.type.snippets.java.JavaToCdkCellFactory">
</JavaToDataCellConverter>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.openscience.cdk.knime.type.snippets.java;

import org.knime.core.data.convert.java.DataCellToJavaConverter;
import org.knime.core.data.convert.java.SimpleDataCellToJavaConverterFactory;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.knime.type.CDKAdapterCell;
import org.openscience.cdk.knime.type.CDKCell3;
import org.openscience.cdk.knime.type.CDKValue;

/**
* Allows access to a CDK Value in Java Snippets. As there is no CDKCellFactory this will
* create a {@link CDKAdapterCell} with a {@link CDKCell3}.
* <br></br>
* TODO: Create a cell factory!
*
* @author Samuel Webb, Lhasa Limited
* @since 1.5.700, 13/03/2017
*
*/
public class CdkCellToJavaFactory extends SimpleDataCellToJavaConverterFactory<CDKValue, IAtomContainer> {
public CdkCellToJavaFactory() {
super(CDKValue.class, IAtomContainer.class, new DataCellToJavaConverter<CDKValue, IAtomContainer>() {
@Override
public IAtomContainer convert(CDKValue structure) throws Exception {
return structure.getAtomContainer();
}
}, "IAtomContainer");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.openscience.cdk.knime.type.snippets.java;

import org.knime.core.data.DataCell;
import org.knime.core.data.convert.datacell.JavaToDataCellConverter;
import org.knime.core.data.convert.datacell.SimpleJavaToDataCellConverterFactory;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.knime.type.CDKAdapterCell;
import org.openscience.cdk.knime.type.CDKCell3;

/**
* Converts an IAtomContainer to a CDK Cell. The implementation is not safe to
* updates to CDK Cells as the choice in CDK Cell is currently hard coded. This
* should be replaced with a CDK Cell Factory.
*
* @author Samuel Webb, Lhasa Limited
* @since 1.5.700, 13/03/2017
*/
public class JavaToCdkCellFactory extends SimpleJavaToDataCellConverterFactory<IAtomContainer> {
// Constructor
public JavaToCdkCellFactory() {
super(IAtomContainer.class, CDKAdapterCell.RAW_TYPE, new JavaToDataCellConverter<IAtomContainer>() {
@Override
public DataCell convert(IAtomContainer structure) throws Exception {
return new CDKAdapterCell(new CDKCell3(structure));
}
}, "IAtomContainer");

}
}

0 comments on commit ac67dbe

Please sign in to comment.