public TreeVisitor getVisitor()

in camel-upgrade-recipes/src/main/java/org/apache/camel/upgrade/camel41/XmlDslRecipe.java [73:109]


    public TreeVisitor<?, ExecutionContext> getVisitor() {
        return new AbstractCamelXmlVisitor() {

            @Override
            public Xml.Tag doVisitTag(final Xml.Tag tag, final ExecutionContext ctx) {
                Xml.Tag t = super.doVisitTag(tag, ctx);

                if (XML_BEAN_MATCHER.matches(getCursor()) && t.getChild("script").isPresent()) {
                    //type ans beanType has to be present in the attributes
                    //and their values has to be gathered
                    Optional<Xml.Attribute> typeAttr
                            = t.getAttributes().stream().filter(a -> "type".equals(a.getKeyAsString())).findAny();
                    Optional<Xml.Attribute> beanTypeAttr
                            = t.getAttributes().stream().filter(a -> "beanType".equals(a.getKeyAsString())).findAny();
                    //if values are not empty, migrate tag
                    if (typeAttr.isPresent() && !typeAttr.get().getValueAsString().isEmpty() && beanTypeAttr.isPresent()
                            && !beanTypeAttr.get().getValueAsString().isEmpty()) {
                        // gather attributes
                        List<Xml.Attribute> attrs = new ArrayList<>(t.getAttributes());
                        attrs.remove(typeAttr.get());
                        attrs.remove(beanTypeAttr.get());

                        //migrate values
                        Xml.Attribute.Value tmp = typeAttr.get().getValue();
                        attrs.add(typeAttr.get().withValue(beanTypeAttr.get().getValue()));
                        attrs.add(beanTypeAttr.get()
                                .withKey(new Xml.Ident(Tree.randomId(), "", Markers.EMPTY, "scriptLanguage")).withValue(tmp));

                        t = t.withAttributes(attrs);
                    }

                }

                return t;
            }
        };
    }