Search in sources :

Example 1 with MergePolicy

use of org.walkmod.merger.MergePolicy in project walkmod-core by walkmod.

the class DefaultConfigurationAdapter method prepare.

@Override
public void prepare() {
    Collection<ProviderConfig> providers = config.getProviderConfigurations();
    if (providers != null) {
        for (ProviderConfig pc : providers) {
            Object aux = config.getBean(pc.getType(), pc.getParameters());
            if (aux instanceof ConfigurationProvider) {
                ConfigurationProvider cp = ((ConfigurationProvider) aux);
                cp.init(config);
                cp.load();
            }
        }
    }
    Collection<MergePolicyConfig> mergePolicies = config.getMergePolicies();
    if (mergePolicies != null) {
        Map<String, MergeEngine> mergeEngines = new HashMap<String, MergeEngine>();
        config.setMergeEngines(mergeEngines);
        for (MergePolicyConfig mpc : mergePolicies) {
            MergeEngine me = new MergeEngine();
            mergeEngines.put(mpc.getName(), me);
            String dopTypeLabel = mpc.getDefaultObjectPolicy();
            Object dop = null;
            Object top = null;
            if (dopTypeLabel != null) {
                dop = config.getBean(dopTypeLabel, null);
            }
            if (dop != null && dop instanceof MergePolicy<?>) {
                me.setDefaultObjectMergePolicy((MergePolicy) dop);
            }
            String topTypeLabel = mpc.getDefaultTypePolicy();
            if (topTypeLabel != null) {
                top = config.getBean(topTypeLabel, null);
            }
            if ((top != null) && top instanceof MergePolicy<?>) {
                me.setDefaultTypeMergePolicy((MergePolicy) top);
            }
            Map<String, String> policyEntries = mpc.getPolicyEntries();
            Class<?> oType = null;
            Object pType = null;
            Map<Class<?>, MergePolicy> resolvedEntries = new HashMap<Class<?>, MergePolicy>();
            if (policyEntries != null && !policyEntries.isEmpty()) {
                for (Map.Entry<String, String> entry : policyEntries.entrySet()) {
                    try {
                        oType = config.getClassLoader().loadClass(entry.getKey());
                    } catch (ClassNotFoundException e) {
                        throw new WalkModException("Invalid policy entry for " + entry.getKey());
                    }
                    pType = config.getBean(entry.getValue(), null);
                    if (pType instanceof MergePolicy) {
                        resolvedEntries.put(oType, (MergePolicy) pType);
                    }
                }
            }
            me.setPolicyConfiguration(resolvedEntries);
        }
    }
}
Also used : MergePolicyConfig(org.walkmod.conf.entities.MergePolicyConfig) WalkModException(org.walkmod.exceptions.WalkModException) HashMap(java.util.HashMap) ProviderConfig(org.walkmod.conf.entities.ProviderConfig) ConfigurationProvider(org.walkmod.conf.ConfigurationProvider) MergeEngine(org.walkmod.merger.MergeEngine) MergePolicy(org.walkmod.merger.MergePolicy) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConfigurationProvider (org.walkmod.conf.ConfigurationProvider)1 MergePolicyConfig (org.walkmod.conf.entities.MergePolicyConfig)1 ProviderConfig (org.walkmod.conf.entities.ProviderConfig)1 WalkModException (org.walkmod.exceptions.WalkModException)1 MergeEngine (org.walkmod.merger.MergeEngine)1 MergePolicy (org.walkmod.merger.MergePolicy)1