aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomV20ClientsBuilder.java
blob: 74e3ac581c46af03933518a8b18f2cb5bfeb6d5e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.builder.xml.dom;

import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.text.XML;
import com.yahoo.vespa.model.clients.Clients;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
 * Builds the Clients plugin
 *
 * @author vegardh
 */
public class DomV20ClientsBuilder {

    // The parent docproc plugin to register data with.
    private final Clients clients;

    DomV20ClientsBuilder(Clients clients, String version) {
        if ( ! version.equals("2.0"))
            throw new IllegalArgumentException("Version '" + version + "' of 'clients' not supported.");
        this.clients = clients;
    }

    public void build(Element spec) {
        NodeList children = spec.getElementsByTagName("load-types");
        for (int i = 0; i < children.getLength(); i++) {
            createLoadTypes((Element) children.item(i), clients);
        }
    }

    private void createLoadTypes(Element element, Clients clients) {
        for (Element e : XML.getChildren(element, "type")) {
            String priority = e.getAttribute("default-priority");
            clients.getLoadTypes().addType(e.getAttribute("name"), priority.length() > 0 ? priority : null);
        }
    }

}