in camel-upgrade-recipes/src/main/java/org/apache/camel/upgrade/camel41/YamlDslRecipe.java [77:123]
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new AbstractCamelYamlVisitor() {
@Override
protected void clearLocalCache() {
//nothing to do
}
@Override
public Yaml.Mapping.Entry doVisitMappingEntry(Yaml.Mapping.Entry entry, ExecutionContext ctx) {
Yaml.Mapping.Entry e = super.doVisitMappingEntry(entry, ctx);
//getCursor().getParent() is mapping with 4 entries -> I can check the siblings
//parent(4) is beans
Cursor parent4 = getCursor().getParent(4);
//check that this mapping entry is currently under "beans" sequence
//parent(2) has to be mapping (represents the bean)
if (parent4 != null && parent4.getParent() != null && MATCHER_WITHOUT_ROUTE.matches(parent4)
&& getCursor().getParent().getValue() instanceof Yaml.Mapping) {
//get entries
Yaml.Mapping m = getCursor().getParent().getValue();
List<Yaml.Mapping.Entry> entries = m.getEntries();
Optional<Yaml.Mapping.Entry> typeEntry
= entries.stream().filter(me -> "type".equals(me.getKey().getValue())).findAny();
Optional<Yaml.Mapping.Entry> beanTypeEntry
= entries.stream().filter(me -> "beanType".equals(me.getKey().getValue())).findAny();
if (typeEntry.isPresent() && typeEntry.get().getValue() instanceof Yaml.Scalar
&& !((Yaml.Scalar) typeEntry.get().getValue()).getValue().isEmpty()
&& beanTypeEntry.isPresent() && beanTypeEntry.get().getValue() instanceof Yaml.Scalar
&& !((Yaml.Scalar) beanTypeEntry.get().getValue()).getValue().isEmpty()) {
//modify the current entry
if ("type".equals(e.getKey().getValue())) {
return e.withKey(((Yaml.Scalar) entry.getKey().copyPaste()).withValue("scriptLanguage"));
}
if ("beanType".equals(e.getKey().getValue())) {
return e.withKey(((Yaml.Scalar) entry.getKey().copyPaste()).withValue("type"));
}
}
}
return e;
}
};
}