All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.vespa.model.builder.xml.dom.chains.ChainsBuilder Maven / Gradle / Ivy

There is a newer version: 8.409.18
Show newest version
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.builder.xml.dom.chains;

import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.text.XML;
import com.yahoo.config.model.producer.AnyConfigProducer;
import com.yahoo.config.model.producer.TreeConfigProducer;
import com.yahoo.vespa.model.container.component.chain.Chain;
import com.yahoo.vespa.model.container.component.chain.ChainedComponent;
import org.w3c.dom.Element;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author Tony Vaagenes
 * @author gjoranv
 */
public class ChainsBuilder, CHAIN extends Chain> {

    protected final List chains = new ArrayList<>();
    private final Map>> chainType2BuilderClass;

    // NOTE: The chain type string (key in chainType2BuilderClass) must match the xml tag name for the chain.
    public ChainsBuilder(DeployState deployState, TreeConfigProducer ancestor, List chainsElems,
                         Map> outerComponentTypeByComponentName,
                         Map>> chainType2BuilderClass) {

        this.chainType2BuilderClass = chainType2BuilderClass;
        readChains(deployState, ancestor, chainsElems, outerComponentTypeByComponentName);
     }

    public Collection getChains() {
        return Collections.unmodifiableCollection(chains);
    }

    private void readChains(DeployState deployState, TreeConfigProducer ancestor, List chainsElems,
                            Map> outerSearcherTypeByComponentName) {

        for (Map.Entry>>
                chainType : chainType2BuilderClass.entrySet()) {
            for (Element elemContainingChainElems : chainsElems) {
                for (Element chainElem : XML.getChildren(elemContainingChainElems, chainType.getKey())) {
                    readChain(deployState, ancestor, chainElem, chainType.getValue(), outerSearcherTypeByComponentName);
                }
            }
        }
    }

    private void readChain(DeployState deployState, TreeConfigProducer ancestor, Element chainElem,
                           Class> builderClass,
                           Map> outerSearcherTypeByComponentName) {

        DomChainBuilderBase builder =
                DomBuilderCreator.create(builderClass, outerSearcherTypeByComponentName);
        chains.add(builder.build(deployState, ancestor, chainElem));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy