summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomHandlerBuilder.java
blob: 39a3ab553d2c5ab3d2b41ac954b7a371ea8f7437 (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
41
42
43
44
45
46
47
48
// Copyright 2016 Yahoo Inc. 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.container.bundle.BundleInstantiationSpecification;
import com.yahoo.osgi.provider.model.ComponentModel;
import com.yahoo.text.XML;
import com.yahoo.config.model.producer.AbstractConfigProducer;
import com.yahoo.vespa.model.container.component.Component;
import com.yahoo.vespa.model.container.component.Handler;
import com.yahoo.vespa.model.container.xml.BundleInstantiationSpecificationBuilder;
import org.w3c.dom.Element;

/**
 * @author gjoranv
 * @since 5.1.6
 */
public class DomHandlerBuilder extends VespaDomBuilder.DomConfigProducerBuilder<Handler> {
    private final boolean legacyMode;

    public DomHandlerBuilder(boolean legacyMode) {
        this.legacyMode = legacyMode;
    }

    public DomHandlerBuilder() {
        this(false);
    }

    @Override
    protected Handler doBuild(AbstractConfigProducer ancestor, Element handlerElement) {
        Handler<? super Component<?, ?>> handler = getHandler(handlerElement);

        for (Element binding : XML.getChildren(handlerElement, "binding"))
            handler.addServerBindings(XML.getValue(binding));

        for (Element clientBinding : XML.getChildren(handlerElement, "clientBinding"))
            handler.addClientBindings(XML.getValue(clientBinding));

        DomComponentBuilder.addChildren(ancestor, handlerElement, handler);

        return handler;
    }

    protected Handler<? super Component<?, ?>> getHandler(Element handlerElement) {
        BundleInstantiationSpecification bundleSpec = BundleInstantiationSpecificationBuilder.build(handlerElement, legacyMode);
        return new Handler<>(
                new ComponentModel(bundleSpec));
    }
}