com.yahoo.vespa.model.builder.xml.dom.chains.DomChainsBuilder Maven / Gradle / Ivy
// 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.config.model.producer.AnyConfigProducer;
import com.yahoo.config.model.producer.TreeConfigProducer;
import com.yahoo.vespa.model.builder.xml.dom.VespaDomBuilder;
import com.yahoo.vespa.model.builder.xml.dom.chains.ComponentsBuilder.ComponentType;
import com.yahoo.vespa.model.container.component.chain.Chain;
import com.yahoo.vespa.model.container.component.chain.ChainedComponent;
import com.yahoo.vespa.model.container.component.chain.Chains;
import org.w3c.dom.Element;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* NOTE: This class _must_ be abstract, due to calling subclass method in ctor.
* @author Tony Vaagenes
* @author gjoranv
*/
public abstract
class DomChainsBuilder, CHAIN extends Chain, CHAINS extends Chains>
extends VespaDomBuilder.DomConfigProducerBuilderBase
{
private final Collection> allowedComponentTypes;
protected DomChainsBuilder(Collection> allowedComponentTypes) {
this.allowedComponentTypes = new ArrayList<>(allowedComponentTypes);
}
protected abstract CHAINS newChainsInstance(TreeConfigProducer parent);
@Override
protected final CHAINS doBuild(DeployState deployState, TreeConfigProducer parent, Element chainsElement) {
CHAINS chains = newChainsInstance(parent);
List allChainElements = allChainElements(deployState, chainsElement);
if (! allChainElements.isEmpty()) {
ComponentsBuilder outerComponentsBuilder = readOuterComponents(deployState, chains, allChainElements);
ChainsBuilder chainsBuilder = readChains(deployState, chains, allChainElements,
outerComponentsBuilder.getComponentTypeByComponentName());
addOuterComponents(chains, outerComponentsBuilder);
addChains(chains, chainsBuilder);
}
return chains;
}
private List allChainElements(DeployState deployState, Element chainsElement) {
List chainsElements = new ArrayList<>();
chainsElements.add(chainsElement);
return chainsElements;
}
private ComponentsBuilder readOuterComponents(DeployState deployState, TreeConfigProducer ancestor, List chainsElems) {
return new ComponentsBuilder<>(deployState, ancestor, allowedComponentTypes, chainsElems, null);
}
protected abstract
ChainsBuilder readChains(DeployState deployState, TreeConfigProducer ancestor, List allChainsElems,
Map> outerComponentTypeByComponentName);
private void addOuterComponents(CHAINS chains, ComponentsBuilder outerComponentsBuilder) {
assert (outerComponentsBuilder.getOuterComponentReferences().isEmpty());
for (ChainedComponent> outerComponent : outerComponentsBuilder.getComponentDefinitions()) {
chains.add(outerComponent);
}
}
private void addChains(CHAINS chains, ChainsBuilder chainsBuilder) {
for (CHAIN chain : chainsBuilder.getChains()) {
chains.add(chain);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy