Search in sources :

Example 11 with ConfigurationException

use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.

the class LanguageConfigurationProvider method lookUpDocument.

private Document lookUpDocument() {
    Document doc = null;
    URL url = null;
    if (configuration == null) {
        throw new ConfigurationException("Missing default values configuration");
    }
    String defaults = configuration.getDefaultLanguage();
    String fileName;
    if (defaults == null) {
        fileName = "default-config.xml";
    } else {
        fileName = "META-INF/walkmod/walkmod-" + defaults + "-" + suffixFileName;
    }
    File f = new File(fileName);
    if (f.exists()) {
        try {
            url = f.toURI().toURL();
        } catch (MalformedURLException e) {
            throw new ConfigurationException("Unable to load " + fileName, e);
        }
    }
    if (url == null) {
        url = configuration.getClassLoader().getResource(fileName);
    }
    InputStream is = null;
    if (url == null) {
        if (errorIfMissing) {
            throw new ConfigurationException("Could not open files of the name " + fileName);
        } else {
            LOG.info("Unable to locate default values configuration of the name " + f.getName() + ", skipping");
            return doc;
        }
    }
    try {
        is = url.openStream();
        InputSource in = new InputSource(is);
        in.setSystemId(url.toString());
        doc = DomHelper.parse(in, dtdMappings);
    } catch (Exception e) {
        throw new ConfigurationException("Unable to load " + fileName, e);
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            LOG.error("Unable to close input stream", e);
        }
    }
    if (doc != null) {
        LOG.debug("Walkmod configuration parsed");
    }
    return doc;
}
Also used : MalformedURLException(java.net.MalformedURLException) InputSource(org.xml.sax.InputSource) ConfigurationException(org.walkmod.conf.ConfigurationException) InputStream(java.io.InputStream) IOException(java.io.IOException) Document(org.w3c.dom.Document) File(java.io.File) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ConfigurationException(org.walkmod.conf.ConfigurationException)

Example 12 with ConfigurationException

use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.

the class XMLConfigurationProvider method loadWriter.

public void loadWriter(Element child, ChainConfig ac) {
    if ("writer".equals(child.getNodeName())) {
        WriterConfig wc = new WriterConfigImpl();
        String path = child.getAttribute("path");
        if ("".equals(path)) {
            throw new ConfigurationException("Invalid writer definition: " + "A path attribute must be specified");
        }
        wc.setPath(path);
        String type = child.getAttribute("type");
        if ("".equals(type)) {
            wc.setType(null);
        } else {
            wc.setType(type);
        }
        NodeList childs = child.getChildNodes();
        if (childs != null) {
            int max = childs.getLength();
            List<String> excludes = new LinkedList<String>();
            List<String> includes = new LinkedList<String>();
            for (int i = 0; i < max; i++) {
                Node n = childs.item(i);
                String nodeName = n.getNodeName();
                if ("exclude".equals(nodeName)) {
                    Element exclude = (Element) n;
                    excludes.add(exclude.getAttribute("wildcard"));
                } else if ("include".equals(nodeName)) {
                    Element include = (Element) n;
                    includes.add(include.getAttribute("wildcard"));
                } else if (!"param".equals(nodeName)) {
                    throw new ConfigurationException("Invalid writer definition. Only exclude or include tags are supported");
                }
            }
            if (!excludes.isEmpty()) {
                String[] excludesArray = new String[excludes.size()];
                int j = 0;
                for (String exclude : excludes) {
                    excludesArray[j] = exclude;
                    j++;
                }
                wc.setExcludes(excludesArray);
            }
            if (!includes.isEmpty()) {
                String[] includesArray = new String[includes.size()];
                int j = 0;
                for (String include : includes) {
                    includesArray[j] = include;
                    j++;
                }
                wc.setIncludes(includesArray);
            }
        }
        wc.setParams(getParams(child));
        ac.setWriterConfig(wc);
    }
}
Also used : ConfigurationException(org.walkmod.conf.ConfigurationException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) WriterConfigImpl(org.walkmod.conf.entities.impl.WriterConfigImpl) LinkedList(java.util.LinkedList) WriterConfig(org.walkmod.conf.entities.WriterConfig)

Example 13 with ConfigurationException

use of org.walkmod.conf.ConfigurationException 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 14 with ConfigurationException

use of org.walkmod.conf.ConfigurationException 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 15 with ConfigurationException

use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.

the class PluginsConfigurationProviderTest method testInvalidPlugins.

@Test
public void testInvalidPlugins() {
    IvyConfigurationProvider provider = new IvyConfigurationProvider();
    Configuration conf = new ConfigurationImpl();
    provider.init(conf);
    PluginConfig pc = new PluginConfigImpl();
    pc.setGroupId("foo");
    pc.setArtifactId("bar");
    pc.setVersion("10");
    conf.setPlugins(new LinkedList());
    conf.getPlugins().add(pc);
    Exception exception = null;
    try {
        provider.load();
    } catch (ConfigurationException e) {
        exception = e;
    }
    Assert.assertNotNull(exception);
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) Configuration(org.walkmod.conf.entities.Configuration) ConfigurationException(org.walkmod.conf.ConfigurationException) PluginConfigImpl(org.walkmod.conf.entities.impl.PluginConfigImpl) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) LinkedList(java.util.LinkedList) ConfigurationException(org.walkmod.conf.ConfigurationException) Test(org.junit.Test)

Aggregations

ConfigurationException (org.walkmod.conf.ConfigurationException)15 File (java.io.File)7 LinkedList (java.util.LinkedList)7 NodeList (org.w3c.dom.NodeList)6 IOException (java.io.IOException)5 URL (java.net.URL)5 Element (org.w3c.dom.Element)5 Node (org.w3c.dom.Node)5 PluginConfig (org.walkmod.conf.entities.PluginConfig)4 InputStream (java.io.InputStream)3 MalformedURLException (java.net.MalformedURLException)3 Document (org.w3c.dom.Document)3 WalkerConfig (org.walkmod.conf.entities.WalkerConfig)3 PluginConfigImpl (org.walkmod.conf.entities.impl.PluginConfigImpl)3 InputSource (org.xml.sax.InputSource)3 ChainConfig (org.walkmod.conf.entities.ChainConfig)2 ChainConfigImpl (org.walkmod.conf.entities.impl.ChainConfigImpl)2 ParserConfigImpl (org.walkmod.conf.entities.impl.ParserConfigImpl)2 WalkerConfigImpl (org.walkmod.conf.entities.impl.WalkerConfigImpl)2 JSONException (com.alibaba.fastjson.JSONException)1