aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/query/Properties.java
blob: d4fc4d57cd6e5efd8bfe1f81b99e690caa16f5f0 (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
59
60
61
62
63
64
65
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query;

import com.yahoo.processing.request.CompoundName;
import com.yahoo.search.Query;

import java.util.Map;

/**
 * Object properties keyed by name which can be looked up using default values and
 * with conversion to various primitive wrapper types.
 * <p>
 * Multiple property implementations can be chained to provide unified access to properties
 * backed by multiple sources as a Chain of Responsibility.
 * <p>
 * For better performance, prefer CompoundName argument constants over Strings.
 * <p>
 * Properties can be cloned. Cloning a properties instance returns a new instance
 * which chains new instances of all chained instances. The content within each instance
 * is cloned to the extent determined appropriate by that implementation.
 * <p>
 * This base class simply passes all access on to the next in chain.
 *
 * @author bratseth
 */
public abstract class Properties extends com.yahoo.processing.request.Properties {

    @Override
    public Properties chained() { return (Properties)super.chained(); }

    @Override
    public Properties clone() {
        return (Properties)super.clone();
    }

    /**
     * Returns the query owning this property object.
     * Only guaranteed to work if this instance is accessible as query.properties()
     */
    public Query getParentQuery() {
        if (chained() == null) {
            throw new RuntimeException("getParentQuery should only be called on a properties instance accessible as query.properties()");
        } else {
            return chained().getParentQuery();
        }
    }

    /**
     * Invoked during deep cloning of the parent query.
     */
    public void setParentQuery(Query query) {
        if (chained() != null)
            chained().setParentQuery(query);
    }

    /**
     * Throws IllegalInputException if the given key cannot be set to the given value.
     * This default implementation just passes to the chained properties, if any.
     */
    public void requireSettable(CompoundName name, Object value, Map<String, String> context) {
        if (chained() != null)
            chained().requireSettable(name, value, context);
    }

}