All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gs.dmn.ast.ReferenceVisitor Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2016 Goldman Sachs.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
 *
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations under the License.
 */
package com.gs.dmn.ast;

import com.gs.dmn.DRGElementReference;
import com.gs.dmn.runtime.DMNRuntimeException;

public interface ReferenceVisitor {
    // References
    default R visit(DRGElementReference reference, C context) {
        TDRGElement element = reference.getElement();
        R result;
        if (element == null) {
            result = null;
        } else if (element instanceof TInputData) {
            result = visitInputReference((DRGElementReference) reference, context);
        } else if (element instanceof TDecision) {
            result = visitDecisionReference((DRGElementReference) reference, context);
        } else if (element instanceof TBusinessKnowledgeModel) {
            result = visitBKMReference((DRGElementReference) reference, context);
        } else if (element instanceof TDecisionService) {
            result = visitDSReference((DRGElementReference) reference, context);
        } else if (element instanceof TKnowledgeSource) {
            result = visitSourceReference((DRGElementReference) reference, context);
        } else {
            throw new DMNRuntimeException(String.format("Not supported for class '%s'", element.getClass().getSimpleName()));
        }
        return result;
    }

    default R visitInvocable(DRGElementReference reference, C context) {
        TInvocable element = reference.getElement();
        R result;
        if (element == null) {
            throw new DMNRuntimeException(String.format("Cannot visit invocable '%s'", reference));
        } else if (element instanceof TBusinessKnowledgeModel) {
            result = visitBKMReference((DRGElementReference) reference, context);
        } else if (element instanceof TDecisionService) {
            result = visitDSReference((DRGElementReference) reference, context);
        } else {
            throw new DMNRuntimeException(String.format("Not supported type '%s'", element.getClass().getSimpleName()));
        }
        return result;
    }

    default R visitInputReference(DRGElementReference reference, C context) {
        return null;
    }

    default R visitDecisionReference(DRGElementReference reference, C context) {
        return null;
    }

    default R visitBKMReference(DRGElementReference reference, C context) {
        return null;
    }

    default R visitDSReference(DRGElementReference reference, C context) {
        return null;
    }

    default R visitSourceReference(DRGElementReference reference, C context) {
        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy