blob: 8f1413c8c63a659166bb62c1f82991c681513845 (
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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.pagetemplates;
import com.yahoo.search.pagetemplates.model.*;
import java.util.HashMap;
import java.util.Map;
/**
* Creates references from all placeholders to the choices which resolves them.
* If a placeholder is encountered which is not resolved by any choice, an IllegalArgumentException is thrown.
*
* @author bratseth
*/
class PlaceholderReferenceCreatingVisitor extends PageTemplateVisitor {
private Map<String, MapChoice> placeholderIdToChoice=new HashMap<>();
public PlaceholderReferenceCreatingVisitor(Map<String, MapChoice> placeholderIdToChoice) {
this.placeholderIdToChoice=placeholderIdToChoice;
}
@Override
public void visit(Placeholder placeholder) {
MapChoice choice=placeholderIdToChoice.get(placeholder.getId());
if (choice==null)
throw new IllegalArgumentException(placeholder + " is not referenced by any choice");
placeholder.setValueContainer(choice);
}
}
|