use of com.genericworkflownodes.knime.cliwrapper.CLIElement in project GenericKnimeNodes by genericworkflownodes.
the class CTDHandlerTest method testCTDHandler.
@Test
public void testCTDHandler() throws ParserConfigurationException, SAXException, IOException {
SAXParserFactory spfac = SAXParserFactory.newInstance();
// Now use the parser factory to create a SAXParser object
SAXParser sp = spfac.newSAXParser();
CTDHandler handler = new CTDHandler(sp.getXMLReader());
sp.parse(TestDataSource.class.getResourceAsStream("test5.ctd"), handler);
INodeConfiguration config = handler.getNodeConfiguration();
assertEquals(2, config.getCLI().getCLIElement().size());
CLIElement firstCLIElement = config.getCLI().getCLIElement().get(0);
assertEquals("-i", firstCLIElement.getOptionIdentifier());
assertEquals(false, firstCLIElement.isList());
assertEquals(false, firstCLIElement.isRequired());
assertEquals(1, firstCLIElement.getMapping().size());
assertEquals("blastall.i", firstCLIElement.getMapping().get(0).getReferenceName());
CLIElement secondCLIElement = config.getCLI().getCLIElement().get(1);
assertEquals("-d", secondCLIElement.getOptionIdentifier());
assertEquals(false, secondCLIElement.isList());
assertEquals(false, secondCLIElement.isRequired());
assertEquals(1, secondCLIElement.getMapping().size());
assertEquals("blastall.d", secondCLIElement.getMapping().get(0).getReferenceName());
}
use of com.genericworkflownodes.knime.cliwrapper.CLIElement in project GenericKnimeNodes by genericworkflownodes.
the class CTDConfigurationReader method read.
@Override
public INodeConfiguration read(InputStream in) throws InvalidCTDFileException {
try {
// create schema and parser for validation and parsing
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema ctdSchema = schemaFactory.newSchema(SchemaProvider.class.getResource("CTD.xsd"));
SAXParserFactory spfac = SAXParserFactory.newInstance();
spfac.setValidating(false);
spfac.setSchema(ctdSchema);
SAXParser sp = spfac.newSAXParser();
CTDHandler handler = new CTDHandler(sp.getXMLReader());
sp.parse(in, handler);
m_config = handler.getNodeConfiguration();
} catch (Exception e) {
throw new InvalidCTDFileException("Failed to parse CTD file.", e);
}
// validate mappings of CLI config
for (CLIElement cliElement : m_config.getCLI().getCLIElement()) {
validateCLIElement(cliElement);
}
// validate mappings in OutputConverter
for (Relocator relocator : m_config.getRelocators()) {
validateRelocator(relocator);
}
// validate ports
for (Port port : m_config.getInputPorts()) {
validatePort(port);
}
for (Port port : m_config.getOutputPorts()) {
validatePort(port);
}
// return parsed and validated config
return m_config;
}
use of com.genericworkflownodes.knime.cliwrapper.CLIElement in project GenericKnimeNodes by genericworkflownodes.
the class CLIElementHandler method startElement.
@Override
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
if (TAG_CLIELEMENT.equals(name)) {
// we start a new element
m_currentElement = new CLIElement();
String isList = attributes.getValue(ATTR_ISLIST);
m_currentElement.setIsList((isList != null && "true".equals(isList)));
String isRequired = attributes.getValue(ATTR_REQUIRED);
m_currentElement.setRequired((isRequired != null && "true".equals(isRequired)));
m_currentElement.setOptionIdentifier(attributes.getValue(ATTR_OPTION_IDENTIFIER));
} else if (TAG_MAPPING.equals(name)) {
CLIMapping mapping = new CLIMapping();
String refName = attributes.getValue(ATTR_REFNAME);
mapping.setReferenceName(refName);
m_currentElement.getMapping().add(mapping);
}
}
use of com.genericworkflownodes.knime.cliwrapper.CLIElement in project GenericKnimeNodes by genericworkflownodes.
the class ParamHandler method transferValuesToConfig.
/**
* Translate all parameters extracted from the ParamXML file into the given
* INodeConfiguration.
*/
private void transferValuesToConfig() {
// add parameters
for (Entry<String, Parameter<?>> entry : m_extractedParameters.entrySet()) {
m_config.addParameter(entry.getKey(), entry.getValue());
}
// set ports
m_config.setInports(m_inputPorts);
m_config.setOutports(m_outputPorts);
// remove cli mappings of ignored parameters
if (m_config.getCLI() != null && !m_ignoredParameters.isEmpty()) {
Iterator<CLIElement> element_iterator = m_config.getCLI().getCLIElement().iterator();
while (element_iterator.hasNext()) {
CLIElement current_element = element_iterator.next();
// check the mapping elements
for (CLIMapping mapping : current_element.getMapping()) {
if (m_ignoredParameters.contains(mapping.getReferenceName())) {
// remove this element and stop the loop
element_iterator.remove();
break;
}
}
}
}
}
use of com.genericworkflownodes.knime.cliwrapper.CLIElement in project GenericKnimeNodes by genericworkflownodes.
the class CTDConfigurationWriter method writeCLI.
private void writeCLI() throws IOException {
streamPut("<cli>");
indent();
for (CLIElement elem : currentConfig.getCLI().getCLIElement()) {
streamPut(String.format("<clielement optionIdentifier=\"%s\" isList=\"%s\">", elem.getOptionIdentifier(), (elem.isList() ? "true" : "false")));
indent();
for (CLIMapping mapping : elem.getMapping()) {
streamPut(String.format("<mapping referenceName=\"%s\" />", mapping.getReferenceName()));
}
outdent();
streamPut("</clielement>");
}
outdent();
streamPut("</cli>");
}
Aggregations