Search in sources :

Example 1 with MergePolicyConfigImpl

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

the class YAMLConfigurationProvider method load.

@Override
public void load() throws ConfigurationException {
    File file = new File(fileName);
    try {
        JsonNode node = null;
        if (file.exists() && file.length() > 0) {
            node = mapper.readTree(file);
            configuration.prepareInitializers();
            if (node.has("plugins")) {
                Iterator<JsonNode> it = node.get("plugins").iterator();
                Collection<PluginConfig> pluginList = new LinkedList<PluginConfig>();
                while (it.hasNext()) {
                    JsonNode current = it.next();
                    String pluginId = current.asText();
                    String[] split = pluginId.split(":");
                    if (split.length > 3) {
                    } else {
                        String groupId, artifactId, version;
                        groupId = split[0];
                        artifactId = split[1];
                        version = split[2];
                        PluginConfig plugin = new PluginConfigImpl();
                        plugin.setGroupId(groupId);
                        plugin.setArtifactId(artifactId);
                        plugin.setVersion(version);
                        pluginList.add(plugin);
                    }
                }
                configuration.setPlugins(pluginList);
            }
            if (node.has("modules")) {
                Iterator<JsonNode> it = node.get("modules").iterator();
                List<String> modules = new LinkedList<String>();
                configuration.setModules(modules);
                while (it.hasNext()) {
                    JsonNode current = it.next();
                    modules.add(current.asText());
                }
                configuration.setModules(modules);
            }
            if (node.has("merge-policies")) {
                Iterator<JsonNode> it = node.get("merge-policies").iterator();
                Collection<MergePolicyConfig> mergePolicies = new LinkedList<MergePolicyConfig>();
                while (it.hasNext()) {
                    JsonNode next = it.next();
                    if (next.has("policy")) {
                        MergePolicyConfig mergeCfg = new MergePolicyConfigImpl();
                        mergeCfg.setName(next.get("name").asText());
                        mergeCfg.setDefaultObjectPolicy(next.get("default-object-policy").asText());
                        mergeCfg.setDefaultTypePolicy(next.get("default-type-policy").asText());
                        if (next.has("policy")) {
                            Iterator<JsonNode> it2 = next.get("policy").iterator();
                            Map<String, String> policies = new HashMap<String, String>();
                            while (it2.hasNext()) {
                                JsonNode nextPolicy = it2.next();
                                String objectType = nextPolicy.get("object-type").asText();
                                String policyType = nextPolicy.get("policy-type").asText();
                                policies.put(objectType, policyType);
                            }
                            mergeCfg.setPolicyEntries(policies);
                        }
                        mergePolicies.add(mergeCfg);
                    }
                }
                configuration.setMergePolicies(mergePolicies);
            }
            if (node.has("conf-providers")) {
                Iterator<JsonNode> it = node.get("conf-providers").iterator();
                Collection<ProviderConfig> provConfigs = new LinkedList<ProviderConfig>();
                while (it.hasNext()) {
                    JsonNode next = it.next();
                    ProviderConfig provCfg = new ProviderConfigImpl();
                    provCfg.setType(next.get("type").asText());
                    provCfg.setParameters(converter.getParams(next));
                    provConfigs.add(provCfg);
                }
                configuration.setProviderConfigurations(provConfigs);
            }
            if (node.has("chains")) {
                Iterator<JsonNode> it = node.get("chains").iterator();
                Collection<ChainConfig> chains = new LinkedList<ChainConfig>();
                int i = 0;
                while (it.hasNext()) {
                    ChainConfig chainCfg = new ChainConfigImpl();
                    JsonNode current = it.next();
                    if (current.has("name")) {
                        chainCfg.setName(current.get("name").asText());
                    } else {
                        chainCfg.setName("chain_" + i);
                    }
                    if (current.has("reader")) {
                        JsonNode reader = current.get("reader");
                        chainCfg.setReaderConfig(converter.getReader(reader));
                    } else {
                        addDefaultReaderConfig(chainCfg);
                    }
                    if (current.has("writer")) {
                        JsonNode writer = current.get("writer");
                        chainCfg.setWriterConfig(converter.getWriter(writer));
                    } else {
                        addDefaultWriterConfig(chainCfg);
                    }
                    if (current.has("walker")) {
                        chainCfg.setWalkerConfig(converter.getWalker(current));
                    } else {
                        addDefaultWalker(chainCfg);
                        if (current.has("transformations")) {
                            WalkerConfig walkerCfg = chainCfg.getWalkerConfig();
                            walkerCfg.setTransformations(converter.getTransformationCfgs(current));
                        }
                    }
                    chains.add(chainCfg);
                }
                configuration.setChainConfigs(chains);
            } else if (node.has("transformations")) {
                Collection<ChainConfig> chains = new LinkedList<ChainConfig>();
                ChainConfig chainCfg = new ChainConfigImpl();
                chainCfg.setName("");
                addDefaultReaderConfig(chainCfg);
                addDefaultWalker(chainCfg);
                WalkerConfig walkerCfg = chainCfg.getWalkerConfig();
                walkerCfg.setTransformations(converter.getTransformationCfgs(node));
                addDefaultWriterConfig(chainCfg);
                chains.add(chainCfg);
                configuration.setChainConfigs(chains);
            }
        }
    } catch (JsonProcessingException e) {
        throw new ConfigurationException("Error parsing the " + fileName + " configuration", e);
    } catch (IOException e) {
        throw new ConfigurationException("Error reading the " + fileName + " configuration", e);
    }
    configuration.preparePlugins();
}
Also used : MergePolicyConfig(org.walkmod.conf.entities.MergePolicyConfig) HashMap(java.util.HashMap) ProviderConfig(org.walkmod.conf.entities.ProviderConfig) JsonNode(com.fasterxml.jackson.databind.JsonNode) PluginConfigImpl(org.walkmod.conf.entities.impl.PluginConfigImpl) ChainConfig(org.walkmod.conf.entities.ChainConfig) ConfigurationException(org.walkmod.conf.ConfigurationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) WalkerConfig(org.walkmod.conf.entities.WalkerConfig) ChainConfigImpl(org.walkmod.conf.entities.impl.ChainConfigImpl) IOException(java.io.IOException) MergePolicyConfigImpl(org.walkmod.conf.entities.impl.MergePolicyConfigImpl) LinkedList(java.util.LinkedList) PluginConfig(org.walkmod.conf.entities.PluginConfig) Collection(java.util.Collection) File(java.io.File) ProviderConfigImpl(org.walkmod.conf.entities.impl.ProviderConfigImpl)

Example 2 with MergePolicyConfigImpl

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

the class XMLConfigurationProvider method loadMergePolicies.

private void loadMergePolicies() {
    Element rootElement = document.getDocumentElement();
    NodeList children = rootElement.getChildNodes();
    int childSize = children.getLength();
    Collection<MergePolicyConfig> mergePolicies = new LinkedList<MergePolicyConfig>();
    for (int i = 0; i < childSize; i++) {
        Node childNode = children.item(i);
        if ("merge-policies".equals(childNode.getNodeName())) {
            Element child = (Element) childNode;
            NodeList policiesNodes = child.getChildNodes();
            int policiesSize = policiesNodes.getLength();
            for (int j = 0; j < policiesSize; j++) {
                Node policyNode = policiesNodes.item(j);
                if ("policy".equals(policyNode.getNodeName())) {
                    Element policyElem = (Element) policyNode;
                    MergePolicyConfig policy = new MergePolicyConfigImpl();
                    policy.setName(policyElem.getAttribute("name"));
                    String defaultOP = policyElem.getAttribute("default-object-policy");
                    if (!"".equals(defaultOP.trim())) {
                        policy.setDefaultObjectPolicy(defaultOP);
                    } else {
                        policy.setDefaultObjectPolicy(null);
                    }
                    String defaultTP = policyElem.getAttribute("default-type-policy");
                    if (!"".equals(defaultTP)) {
                        policy.setDefaultTypePolicy(defaultTP);
                    } else {
                        policy.setDefaultTypePolicy(null);
                    }
                    NodeList entriesNodes = policyElem.getChildNodes();
                    int entriesSize = entriesNodes.getLength();
                    Map<String, String> policyEntries = new HashMap<String, String>();
                    policy.setPolicyEntries(policyEntries);
                    mergePolicies.add(policy);
                    for (int k = 0; k < entriesSize; k++) {
                        Node entry = entriesNodes.item(k);
                        if ("policy-entry".equals(entry.getNodeName())) {
                            Element entryElem = (Element) entry;
                            String otype = entryElem.getAttribute("object-type");
                            String ptype = entryElem.getAttribute("policy-type");
                            if (!("".equals(otype.trim())) && !("".equals(ptype.trim()))) {
                                policyEntries.put(otype, ptype);
                            }
                        }
                    }
                }
            }
        }
    }
    configuration.setMergePolicies(mergePolicies);
}
Also used : MergePolicyConfig(org.walkmod.conf.entities.MergePolicyConfig) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) MergePolicyConfigImpl(org.walkmod.conf.entities.impl.MergePolicyConfigImpl) LinkedList(java.util.LinkedList)

Example 3 with MergePolicyConfigImpl

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

the class LanguageConfigurationProvider method loadMergePolicies.

private void loadMergePolicies() {
    Element rootElement = document.getDocumentElement();
    NodeList children = rootElement.getChildNodes();
    int childSize = children.getLength();
    Collection<MergePolicyConfig> mergePolicies = configuration.getMergePolicies();
    if (mergePolicies == null) {
        mergePolicies = new LinkedList<MergePolicyConfig>();
        configuration.setMergePolicies(mergePolicies);
    }
    MergePolicyConfig policy = null;
    for (int j = 0; j < childSize; j++) {
        Node childNode = children.item(j);
        if ("policy".equals(childNode.getNodeName())) {
            Element policyElem = (Element) childNode;
            policy = new MergePolicyConfigImpl();
            policy.setName(DEFAULT_MERGE_ENGINE_NAME);
            String defaultOP = policyElem.getAttribute("default-object-policy");
            if (!"".equals(defaultOP.trim())) {
                policy.setDefaultObjectPolicy(defaultOP);
            } else {
                policy.setDefaultObjectPolicy(null);
            }
            String defaultTP = policyElem.getAttribute("default-type-policy");
            if (!"".equals(defaultTP)) {
                policy.setDefaultTypePolicy(defaultTP);
            } else {
                policy.setDefaultTypePolicy(null);
            }
            NodeList entriesNodes = policyElem.getChildNodes();
            int entriesSize = entriesNodes.getLength();
            Map<String, String> policyEntries = new HashMap<String, String>();
            policy.setPolicyEntries(policyEntries);
            for (int k = 0; k < entriesSize; k++) {
                Node entry = entriesNodes.item(k);
                if ("policy-entry".equals(entry.getNodeName())) {
                    Element entryElem = (Element) entry;
                    String otype = entryElem.getAttribute("object-type");
                    String ptype = entryElem.getAttribute("policy-type");
                    if (!("".equals(otype.trim())) && !("".equals(ptype.trim()))) {
                        policyEntries.put(otype, ptype);
                    }
                }
            }
        }
    }
    if (policy != null) {
        mergePolicies.add(policy);
    }
}
Also used : MergePolicyConfig(org.walkmod.conf.entities.MergePolicyConfig) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) MergePolicyConfigImpl(org.walkmod.conf.entities.impl.MergePolicyConfigImpl)

Aggregations

HashMap (java.util.HashMap)3 MergePolicyConfig (org.walkmod.conf.entities.MergePolicyConfig)3 MergePolicyConfigImpl (org.walkmod.conf.entities.impl.MergePolicyConfigImpl)3 LinkedList (java.util.LinkedList)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 File (java.io.File)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 ConfigurationException (org.walkmod.conf.ConfigurationException)1 ChainConfig (org.walkmod.conf.entities.ChainConfig)1 PluginConfig (org.walkmod.conf.entities.PluginConfig)1 ProviderConfig (org.walkmod.conf.entities.ProviderConfig)1 WalkerConfig (org.walkmod.conf.entities.WalkerConfig)1 ChainConfigImpl (org.walkmod.conf.entities.impl.ChainConfigImpl)1 PluginConfigImpl (org.walkmod.conf.entities.impl.PluginConfigImpl)1