001package org.hl7.fhir.validation.instance.utils;
002
003import org.hl7.fhir.r5.elementmodel.Element;
004import org.hl7.fhir.r5.model.StructureDefinition;
005
006public class ResolvedReference {
007
008    private Element resource;
009    private Element focus;
010    private boolean external;
011    private NodeStack stack;
012
013    public ResolvedReference setResource(Element resource) {
014        this.resource = resource;
015        return this;
016    }
017
018    public Element getResource() {
019        return resource;
020    }
021
022    public ResolvedReference setFocus(Element focus) {
023        this.focus = focus;
024        return this;
025    }
026
027    public boolean isExternal() {
028        return external;
029    }
030
031    public ResolvedReference setExternal(boolean external) {
032        this.external = external;
033        return this;
034    }
035
036    public ResolvedReference setStack(NodeStack stack) {
037        this.stack = stack;
038        return this;
039    }
040
041    public NodeStack getStack() {
042        return stack;
043    }
044
045    public String getType() {
046        return focus.fhirType();
047    }
048
049    public Element getFocus() {
050        return focus;
051    }
052
053    public ValidatorHostContext hostContext(ValidatorHostContext hostContext, StructureDefinition profile) {
054        if (external) {
055            return hostContext.forRemoteReference(profile, resource);
056        } else {
057            return hostContext.forLocalReference(profile, resource);
058        }
059    }
060}