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

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

The newest version!
package com.structurizr.dsl;

import com.structurizr.model.*;

final class ElementsParser extends AbstractParser {

    private final static int DESCRIPTION_INDEX = 1;
    private final static int TECHNOLOGY_INDEX = 1;

    void parseDescription(ElementsDslContext context, Tokens tokens) {
        // description 
        if (tokens.hasMoreThan(DESCRIPTION_INDEX)) {
            throw new RuntimeException("Too many tokens, expected: description ");
        }

        if (!tokens.includes(DESCRIPTION_INDEX)) {
            throw new RuntimeException("Expected: description ");
        }

        String description = tokens.get(DESCRIPTION_INDEX);
        for (Element element : context.getElements()) {
            element.setDescription(description);
        }
    }

    void parseTechnology(ElementsDslContext context, Tokens tokens) {
        // technology 
        if (tokens.hasMoreThan(TECHNOLOGY_INDEX)) {
            throw new RuntimeException("Too many tokens, expected: technology ");
        }

        if (!tokens.includes(TECHNOLOGY_INDEX)) {
            throw new RuntimeException("Expected: technology ");
        }

        String technology = tokens.get(TECHNOLOGY_INDEX);
        for (Element element : context.getElements()) {
            if (element instanceof Container) {
                ((Container)element).setTechnology(technology);
            } else if (element instanceof Component) {
                ((Component)element).setTechnology(technology);
            } else if (element instanceof DeploymentNode) {
                ((DeploymentNode)element).setTechnology(technology);
            } else if (element instanceof InfrastructureNode) {
                ((InfrastructureNode)element).setTechnology(technology);
            }
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy