aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/documentmodel/OwnedStructDataType.java
blob: 761a1f0963c1bc334e8b2d7012621965d51acf79 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.documentmodel;

import com.yahoo.document.DocumentType;
import com.yahoo.document.StructDataType;

/**
 * Model for StructDataType declared in a specific document
 *
 * @author arnej
 **/
public final class OwnedStructDataType extends StructDataType implements OwnedType {

    private final String ownerName;
    private final String uniqueName;
    private boolean overrideId = false;

    public OwnedStructDataType(String name, DocumentType document) {
        this(name, document.getName());
    }

    public OwnedStructDataType(String name, String owner) {
        super(name);
        this.ownerName = owner;
        this.uniqueName = name + "@" + owner;
    }

    public void enableOverride() {
        this.overrideId = true;
    }

    @Override
    public String getOwnerName() {
        return ownerName;
    }

    @Override
    public String getUniqueName() {
        return uniqueName;
    }

    @Override
    public String getName() {
        return overrideId ? uniqueName : super.getName();
    }

    @Override
    public int getId() {
        return overrideId ? getUniqueId() : super.getId();
    }

    @Override
    public String toString() {
        return "{OwnedStructDataType "+uniqueName+" id="+getId()+" uid="+getUniqueId()+" enable override="+overrideId+"}";
    }
}