Search in sources :

Example 1 with XMLTreeCreator

use of org.knime.core.node.port.pmml.XMLTreeCreator in project knime-core by knime.

the class PMMLPreprocPortObjectView method create.

private void create() {
    // serialize port object
    synchronized (m_lock) {
        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            TransformerHandler handler = PMMLPreprocPortObject.createTransformerHandlerForSave(out);
            for (PMMLPreprocOperation op : m_portObject.getOperations()) {
                String writeElement = op.getClass().getName();
                String locationElement = op.getTransformElement().toString();
                handler.startElement(null, null, writeElement, null);
                handler.startElement(null, null, locationElement, null);
                op.save(handler, new ExecutionMonitor());
                handler.endElement(null, null, locationElement);
                handler.endElement(null, null, writeElement);
                handler.endDocument();
            }
            out.close();
            SAXParserFactory saxFac = SAXParserFactory.newInstance();
            SAXParser parser = saxFac.newSAXParser();
            XMLTreeCreator treeCreator = new XMLTreeCreator();
            parser.parse(new InputSource(new ByteArrayInputStream(out.toByteArray())), treeCreator);
            m_tree.setModel(new DefaultTreeModel(treeCreator.getTreeNode()));
            add(new JScrollPane(m_tree));
            revalidate();
        } catch (Exception e) {
            // log and return a "error during saving" component
            LOGGER.error("PMML Preproc contains errors", e);
            PMMLPreprocPortObjectView.this.add(new JLabel("PMML Preproc contains errors: " + e.getMessage()));
        }
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) TransformerHandler(javax.xml.transform.sax.TransformerHandler) InputSource(org.xml.sax.InputSource) XMLTreeCreator(org.knime.core.node.port.pmml.XMLTreeCreator) JLabel(javax.swing.JLabel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParser(javax.xml.parsers.SAXParser) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 JLabel (javax.swing.JLabel)1 JScrollPane (javax.swing.JScrollPane)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1 SAXParser (javax.xml.parsers.SAXParser)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 TransformerHandler (javax.xml.transform.sax.TransformerHandler)1 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)1 XMLTreeCreator (org.knime.core.node.port.pmml.XMLTreeCreator)1 InputSource (org.xml.sax.InputSource)1