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);
}
}
}
Aggregations