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

com.structurizr.dsl.FindRelationshipParser Maven / Gradle / Ivy

The newest version!
package com.structurizr.dsl;

import com.structurizr.model.Element;
import com.structurizr.model.Relationship;

final class FindRelationshipParser extends AbstractParser {

    private static final String GRAMMAR = "!relationship ";

    private final static int IDENTIFIER_INDEX = 1;

    Relationship parse(DslContext context, Tokens tokens) {
        // !relationship 

        if (tokens.hasMoreThan(IDENTIFIER_INDEX)) {
            throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
        }

        if (!tokens.includes(IDENTIFIER_INDEX)) {
            throw new RuntimeException("Expected: " + GRAMMAR);
        }

        Relationship relationship;

        String s = tokens.get(IDENTIFIER_INDEX);
        if (s.startsWith("Relationship://")) {
            relationship = context.getWorkspace().getModel().getRelationshipWithCanonicalName(s);
        } else {
            relationship = context.getRelationship(s);
        }

        if (relationship == null) {
            throw new RuntimeException("A relationship identified by \"" + s + "\" could not be found");
        }

        return relationship;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy