Search in sources :

Example 1 with ParserConfigImpl

use of org.walkmod.conf.entities.impl.ParserConfigImpl in project walkmod-core by walkmod.

the class AbstractChainConfigurationProvider method addDefaultWalker.

public void addDefaultWalker(ChainConfig ac) {
    WalkerConfig wc = new WalkerConfigImpl();
    wc.setType(null);
    wc.setParserConfig(new ParserConfigImpl());
    ac.setWalkerConfig(wc);
}
Also used : ParserConfigImpl(org.walkmod.conf.entities.impl.ParserConfigImpl) WalkerConfig(org.walkmod.conf.entities.WalkerConfig) WalkerConfigImpl(org.walkmod.conf.entities.impl.WalkerConfigImpl)

Example 2 with ParserConfigImpl

use of org.walkmod.conf.entities.impl.ParserConfigImpl in project walkmod-core by walkmod.

the class JSONConfigParser method getWalker.

public WalkerConfig getWalker(JsonNode current) {
    WalkerConfig walkerCfg = new WalkerConfigImpl();
    if (current.has("type")) {
        walkerCfg.setType(current.get("type").asText());
    }
    if (current.has("parser")) {
        ParserConfig parserCfg = new ParserConfigImpl();
        JsonNode parserNode = current.get("parser");
        parserCfg.setType(parserNode.get("type").asText());
        parserCfg.setParameters(getParams(parserNode));
        walkerCfg.setParserConfig(parserCfg);
    }
    walkerCfg.setTransformations(getTransformationCfgs(current));
    if (current.has("root-namespace")) {
        walkerCfg.setRootNamespace(current.get("root-namespace").asText());
    }
    walkerCfg.setParams(getParams(current));
    return walkerCfg;
}
Also used : ParserConfigImpl(org.walkmod.conf.entities.impl.ParserConfigImpl) JsonNode(com.fasterxml.jackson.databind.JsonNode) WalkerConfigImpl(org.walkmod.conf.entities.impl.WalkerConfigImpl)

Example 3 with ParserConfigImpl

use of org.walkmod.conf.entities.impl.ParserConfigImpl in project walkmod-core by walkmod.

the class XMLConfigurationProvider method loadWalkerConfig.

public void loadWalkerConfig(Element element, ChainConfig ac) {
    NodeList children;
    Node walkerNode = element;
    if ("walker".equals(walkerNode.getNodeName())) {
        WalkerConfig wc = new WalkerConfigImpl();
        String type = ((Element) walkerNode).getAttribute("type");
        if ("".equals(type)) {
            wc.setType(null);
        } else {
            wc.setType(type);
        }
        wc.setParams(getParams((Element) walkerNode));
        wc.setRootNamespace(((Element) walkerNode).getAttribute("root-namespace"));
        children = walkerNode.getChildNodes();
        if (children.getLength() > 3) {
            throw new ConfigurationException("Invalid walker definition in the " + "architecture" + ac.getName() + ". Please, verify the dtd");
        }
        int max = children.getLength();
        int transformationIndex = wc.getParams().size();
        if (transformationIndex < max) {
            final String nodeName = children.item(transformationIndex).getNodeName();
            if (("parser").equals(nodeName)) {
                loadParserConfig((Element) children.item(transformationIndex), wc);
                transformationIndex = 1;
            } else {
                wc.setParserConfig(new ParserConfigImpl());
            }
        } else {
            wc.setParserConfig(new ParserConfigImpl());
        }
        if (transformationIndex < max) {
            loadTransformationConfigs((Element) children.item(transformationIndex), wc);
        }
        ac.setWalkerConfig(wc);
    } else {
        throw new ConfigurationException("Invalid architecture definition. " + "A walker element must be defined in the architecture element " + ac.getName());
    }
}
Also used : ParserConfigImpl(org.walkmod.conf.entities.impl.ParserConfigImpl) ConfigurationException(org.walkmod.conf.ConfigurationException) WalkerConfig(org.walkmod.conf.entities.WalkerConfig) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) WalkerConfigImpl(org.walkmod.conf.entities.impl.WalkerConfigImpl)

Example 4 with ParserConfigImpl

use of org.walkmod.conf.entities.impl.ParserConfigImpl in project walkmod-core by walkmod.

the class XMLConfigurationProvider method loadChains.

public void loadChains() throws ConfigurationException {
    Element rootElement = document.getDocumentElement();
    NodeList children = rootElement.getChildNodes();
    int childSize = children.getLength();
    for (int i = 0; i < childSize; i++) {
        Node childNode = children.item(i);
        if (childNode instanceof Element) {
            Element child = (Element) childNode;
            final String nodeName = child.getNodeName();
            if ("chain".equals(nodeName)) {
                ChainConfig ac = new ChainConfigImpl();
                if ("".equals(child.getAttribute("name"))) {
                    if (i == 0) {
                        ac.setName("chain_" + (i + 1));
                    } else {
                        ac.setName("chain_" + (i + 1));
                    }
                } else {
                    ac.setName(child.getAttribute("name"));
                }
                NodeList childrenModel = child.getChildNodes();
                ac.setParameters(getParams(child));
                int index = 0;
                if ("reader".equals(childrenModel.item(index).getNodeName())) {
                    loadReaderConfig((Element) childrenModel.item(index), ac);
                    index++;
                } else {
                    addDefaultReaderConfig(ac);
                }
                if (index >= childrenModel.getLength()) {
                    throw new ConfigurationException("Invalid architecture definition for the " + "element" + ac.getName());
                }
                if ("walker".equals(childrenModel.item(index).getNodeName())) {
                    loadWalkerConfig((Element) childrenModel.item(index), ac);
                    index++;
                } else if ("transformation".equals(childrenModel.item(index).getNodeName())) {
                    addDefaultWalker(ac, child);
                } else {
                    throw new ConfigurationException("Invalid transformation chain. A walker or at least one transformation must be specified");
                }
                if (index > childrenModel.getLength()) {
                    throw new ConfigurationException("Invalid architecture definition for the " + "element" + ac.getName());
                }
                boolean found = false;
                while (index < childrenModel.getLength() && !found) {
                    if ("writer".equals(childrenModel.item(index).getNodeName())) {
                        found = true;
                        loadWriter((Element) childrenModel.item(index), ac);
                    }
                    index++;
                }
                if (!found) {
                    addDefaultWriterConfig(ac);
                }
                configuration.addChainConfig(ac);
            } else if ("transformation".equals(nodeName)) {
                ChainConfig ac = new ChainConfigImpl();
                ac.setName("default");
                List<TransformationConfig> transformationConfigs = getTransformationItems(rootElement, true);
                WalkerConfig wc = new WalkerConfigImpl();
                wc.setType(null);
                wc.setParserConfig(new ParserConfigImpl());
                wc.setTransformations(transformationConfigs);
                addDefaultReaderConfig(ac);
                ac.setWalkerConfig(wc);
                addDefaultWriterConfig(ac);
                configuration.addChainConfig(ac);
                i = i + transformationConfigs.size() - 1;
            }
        }
    }
    LOG.debug("Transformation chains loaded");
}
Also used : ParserConfigImpl(org.walkmod.conf.entities.impl.ParserConfigImpl) WalkerConfig(org.walkmod.conf.entities.WalkerConfig) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ChainConfigImpl(org.walkmod.conf.entities.impl.ChainConfigImpl) WalkerConfigImpl(org.walkmod.conf.entities.impl.WalkerConfigImpl) ChainConfig(org.walkmod.conf.entities.ChainConfig) ConfigurationException(org.walkmod.conf.ConfigurationException) List(java.util.List) LinkedList(java.util.LinkedList) NodeList(org.w3c.dom.NodeList)

Example 5 with ParserConfigImpl

use of org.walkmod.conf.entities.impl.ParserConfigImpl in project walkmod-core by walkmod.

the class XMLConfigurationProvider method loadParserConfig.

public void loadParserConfig(Element element, WalkerConfig wc) {
    final String nodeName = element.getNodeName();
    if ("parser".equals(nodeName)) {
        ParserConfig pc = new ParserConfigImpl();
        if ("".equals(element.getAttribute("type"))) {
            pc.setType(null);
        } else {
            pc.setType(element.getAttribute("type"));
        }
        pc.setParameters(getParams(element));
    }
}
Also used : ParserConfigImpl(org.walkmod.conf.entities.impl.ParserConfigImpl) ParserConfig(org.walkmod.conf.entities.ParserConfig)

Aggregations

ParserConfigImpl (org.walkmod.conf.entities.impl.ParserConfigImpl)6 WalkerConfigImpl (org.walkmod.conf.entities.impl.WalkerConfigImpl)5 WalkerConfig (org.walkmod.conf.entities.WalkerConfig)4 LinkedList (java.util.LinkedList)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 ConfigurationException (org.walkmod.conf.ConfigurationException)2 ChainConfig (org.walkmod.conf.entities.ChainConfig)2 ChainConfigImpl (org.walkmod.conf.entities.impl.ChainConfigImpl)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 List (java.util.List)1 Test (org.junit.Test)1 Configuration (org.walkmod.conf.entities.Configuration)1 MergePolicyConfig (org.walkmod.conf.entities.MergePolicyConfig)1 ParserConfig (org.walkmod.conf.entities.ParserConfig)1 ReaderConfig (org.walkmod.conf.entities.ReaderConfig)1 TransformationConfig (org.walkmod.conf.entities.TransformationConfig)1 WriterConfig (org.walkmod.conf.entities.WriterConfig)1 ConfigurationImpl (org.walkmod.conf.entities.impl.ConfigurationImpl)1