use of com.structurizr.model.Element in project dsl by structurizr.
the class StaticViewAnimationStepParser method parse.
void parse(DslContext context, StaticView view, Tokens tokens, int startIndex) {
// <identifier> [identifier...]
List<Element> elements = new ArrayList<>();
for (int i = startIndex; i < tokens.size(); i++) {
String elementIdentifier = tokens.get(i);
Element element = context.getElement(elementIdentifier);
if (element == null) {
throw new RuntimeException("The element \"" + elementIdentifier + "\" does not exist");
}
elements.add(element);
}
view.addAnimation(elements.toArray(new Element[0]));
}
use of com.structurizr.model.Element in project dsl by structurizr.
the class DynamicViewContentParser method parseRelationship.
void parseRelationship(DynamicViewDslContext context, Tokens tokens) {
// <identifier> -> <identifier> [description] [technology]
DynamicView view = context.getView();
if (tokens.hasMoreThan(TECHNOLOGY_INDEX)) {
throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
}
if (!tokens.includes(DESTINATION_IDENTIFIER_INDEX)) {
throw new RuntimeException("Expected: " + GRAMMAR);
}
String sourceId = tokens.get(SOURCE_IDENTIFIER_INDEX);
String destinationId = tokens.get(DESTINATION_IDENTIFIER_INDEX);
Element sourceElement = context.getElement(sourceId);
if (sourceElement == null) {
throw new RuntimeException("The source element \"" + sourceId + "\" does not exist");
}
if (!(sourceElement instanceof StaticStructureElement)) {
throw new RuntimeException("The source element \"" + sourceId + "\" should be a static structure element");
}
Element destinationElement = context.getElement(destinationId);
if (destinationElement == null) {
throw new RuntimeException("The destination element \"" + destinationId + "\" does not exist");
}
if (!(destinationElement instanceof StaticStructureElement)) {
throw new RuntimeException("The destination element \"" + destinationId + "\" should be a static structure element");
}
String description = "";
if (tokens.includes(DESCRIPTION_INDEX)) {
description = tokens.get(DESCRIPTION_INDEX);
}
String technology = "";
if (tokens.includes(TECHNOLOGY_INDEX)) {
technology = tokens.get(TECHNOLOGY_INDEX);
}
if (!sourceElement.hasEfferentRelationshipWith(destinationElement) && !destinationElement.hasEfferentRelationshipWith(sourceElement)) {
new ExplicitRelationshipParser().parse(context, tokens);
}
view.add((StaticStructureElement) sourceElement, description, technology, (StaticStructureElement) destinationElement);
}
use of com.structurizr.model.Element in project dsl by structurizr.
the class DynamicViewParser method parse.
DynamicView parse(DslContext context, Tokens tokens) {
// dynamic <*|software system identifier|container identifier> [key] [description] {
Workspace workspace = context.getWorkspace();
String key = "";
String description = "";
DecimalFormat format = new DecimalFormat("000");
if (tokens.hasMoreThan(DESCRIPTION_INDEX)) {
throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
}
if (!tokens.includes(SCOPE_IDENTIFIER_INDEX)) {
throw new RuntimeException("Expected: " + GRAMMAR);
}
if (tokens.includes(DESCRIPTION_INDEX)) {
description = tokens.get(DESCRIPTION_INDEX);
}
DynamicView view;
String scopeIdentifier = tokens.get(SCOPE_IDENTIFIER_INDEX);
if (WILDCARD.equals(scopeIdentifier)) {
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = VIEW_TYPE + "-" + format.format(workspace.getViews().getDynamicViews().size() + 1);
}
validateViewKey(key);
view = workspace.getViews().createDynamicView(key, description);
} else {
Element element = context.getElement(scopeIdentifier);
if (element == null) {
throw new RuntimeException("The software system or container \"" + scopeIdentifier + "\" does not exist");
}
if (element instanceof SoftwareSystem) {
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = removeNonWordCharacters(element.getName()) + "-" + VIEW_TYPE + "-" + format.format(workspace.getViews().getDynamicViews().size() + 1);
}
validateViewKey(key);
view = workspace.getViews().createDynamicView((SoftwareSystem) element, key, description);
} else if (element instanceof Container) {
Container container = (Container) element;
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = removeNonWordCharacters(container.getSoftwareSystem().getName()) + "-" + removeNonWordCharacters(container.getName()) + "-" + VIEW_TYPE + "-" + format.format(workspace.getViews().getDynamicViews().size() + 1);
}
validateViewKey(key);
view = workspace.getViews().createDynamicView((Container) element, key, description);
} else {
throw new RuntimeException("The element \"" + scopeIdentifier + "\" is not a software system or container");
}
}
view.setExternalBoundariesVisible(true);
return view;
}
use of com.structurizr.model.Element in project dsl by structurizr.
the class IdentifiersRegister method register.
void register(String identifier, Relationship relationship) {
if (StringUtils.isNullOrEmpty(identifier)) {
identifier = UUID.randomUUID().toString();
}
identifier = identifier.toLowerCase();
Element e = elementsByIdentifier.get(identifier);
Relationship r = relationshipsByIdentifier.get(identifier);
if ((e == null && r == null) || (r == relationship)) {
relationshipsByIdentifier.put(identifier, relationship);
} else {
throw new RuntimeException("The identifier \"" + identifier + "\" is already in use");
}
}
use of com.structurizr.model.Element in project dsl by structurizr.
the class SystemContextViewParser method parse.
SystemContextView parse(DslContext context, Tokens tokens) {
// systemContext <software system identifier> [key] [description] {
Workspace workspace = context.getWorkspace();
SoftwareSystem softwareSystem;
String key = "";
String description = "";
if (tokens.hasMoreThan(DESCRIPTION_INDEX)) {
throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
}
if (!tokens.includes(SOFTWARE_SYSTEM_IDENTIFIER_INDEX)) {
throw new RuntimeException("Expected: " + GRAMMAR);
}
String softwareSystemIdentifier = tokens.get(SOFTWARE_SYSTEM_IDENTIFIER_INDEX);
Element element = context.getElement(softwareSystemIdentifier);
if (element == null) {
throw new RuntimeException("The software system \"" + softwareSystemIdentifier + "\" does not exist");
}
if (element instanceof SoftwareSystem) {
softwareSystem = (SoftwareSystem) element;
} else {
throw new RuntimeException("The element \"" + softwareSystemIdentifier + "\" is not a software system");
}
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = removeNonWordCharacters(softwareSystem.getName()) + "-" + VIEW_TYPE;
}
validateViewKey(key);
if (tokens.includes(DESCRIPTION_INDEX)) {
description = tokens.get(DESCRIPTION_INDEX);
}
SystemContextView view = workspace.getViews().createSystemContextView(softwareSystem, key, description);
view.setEnterpriseBoundaryVisible(true);
return view;
}
Aggregations