blob: fbdefd0afb0f7be36563890a20ded7a579c7d4ac (
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
49
50
51
52
53
54
55
56
57
58
|
// 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;
import com.yahoo.config.model.builder.xml.XmlHelper;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.component.ComponentSpecification;
import com.yahoo.vespa.model.container.PlatformBundles;
import org.w3c.dom.Element;
import java.util.Arrays;
import java.util.List;
/**
* This object builds a bundle instantiation spec from an XML element.
*
* @author gjoranv
*/
public class BundleInstantiationSpecificationBuilder {
public static BundleInstantiationSpecification build(Element spec) {
ComponentSpecification id = XmlHelper.getIdRef(spec);
ComponentSpecification classId = getComponentSpecification(spec, "class");
ComponentSpecification bundle = getComponentSpecification(spec, "bundle");
BundleInstantiationSpecification instSpec = new BundleInstantiationSpecification(id, classId, bundle);
validate(instSpec);
return bundle == null ? setBundleForSearchAndDocprocComponents(instSpec) : instSpec;
}
private static BundleInstantiationSpecification setBundleForSearchAndDocprocComponents(BundleInstantiationSpecification spec) {
if (PlatformBundles.isSearchAndDocprocClass(spec.getClassName()))
return spec.inBundle(PlatformBundles.searchAndDocprocBundle);
else
return spec;
}
private static void validate(BundleInstantiationSpecification instSpec) {
List<String> forbiddenClasses = Arrays.asList(
SearchHandler.HANDLER_CLASS,
"com.yahoo.processing.handler.ProcessingHandler");
for (String forbiddenClass: forbiddenClasses) {
if (forbiddenClass.equals(instSpec.getClassName())) {
throw new IllegalArgumentException("Setting up " + forbiddenClass + " manually is not supported");
}
}
}
//null if missing
private static ComponentSpecification getComponentSpecification(Element spec, String attributeName) {
return (spec.hasAttribute(attributeName)) ?
new ComponentSpecification(spec.getAttribute(attributeName)) :
null;
}
}
|