blob: 6d98ab44d0b9e6642479ec20008fa10406f22058 (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.xml.document;
import com.yahoo.config.model.producer.AnyConfigProducer;
import com.yahoo.config.model.producer.TreeConfigProducer;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.osgi.provider.model.ComponentModel;
import com.yahoo.text.XML;
import com.yahoo.vespa.model.container.ContainerCluster;
import com.yahoo.vespa.model.container.component.Component;
import org.w3c.dom.Element;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Handles the document bindings (concrete document types). Register the concrete document factories as components.
*
* @author vegardh
* @since 5.1.10
*/
public class DocumentFactoryBuilder {
private static final String CONCRETE_DOC_FACTORY_CLASS = "ConcreteDocumentFactory";
public static void buildDocumentFactories(ContainerCluster cluster, Element spec) {
Map<String, String> types = new LinkedHashMap<>();
for (Element e : XML.getChildren(spec, "document")) {
String type = e.getAttribute("type");
String clazz = e.getAttribute("class");
// Empty pkg is forbidden in the documentgen Mojo.
if (clazz.indexOf('.')<0) throw new IllegalArgumentException("Malformed class for <document> binding, must be a full class with package: "+clazz);
String pkg = clazz.substring(0, clazz.lastIndexOf('.'));
String concDocFactory=pkg+"."+CONCRETE_DOC_FACTORY_CLASS;
String bundle = e.getAttribute("bundle");
Component<AnyConfigProducer, ComponentModel> component = new Component<>(
new ComponentModel(BundleInstantiationSpecification.fromStrings(concDocFactory, concDocFactory, bundle)));
if (!cluster.getComponentsMap().containsKey(component.getComponentId())) cluster.addComponent(component);
types.put(type, concDocFactory);
}
cluster.concreteDocumentTypes().putAll(types);
}
}
|