This repository has been archived by the owner on Jan 10, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57f036f
commit 54ed15e
Showing
8 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/com/structurizr/dsl/StructurizrDslScriptContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.structurizr.dsl; | ||
|
||
import com.structurizr.Workspace; | ||
import com.structurizr.util.StringUtils; | ||
|
||
import java.io.File; | ||
import java.util.Map; | ||
|
||
/** | ||
* Used to pass contextual information to DSL scripts when they are executed. | ||
*/ | ||
public class StructurizrDslScriptContext { | ||
|
||
private final File dslFile; | ||
private final Workspace workspace; | ||
private final Map<String,String> parameters; | ||
|
||
/** | ||
* Creates a new instance. | ||
* | ||
* @param dslFile a reference to the DSL file that loaded the script | ||
* @param workspace the workspace | ||
* @param parameters a map of name/value pairs representing parameters | ||
*/ | ||
public StructurizrDslScriptContext(File dslFile, Workspace workspace, Map<String,String> parameters) { | ||
this.dslFile = dslFile; | ||
this.workspace = workspace; | ||
this.parameters = parameters; | ||
} | ||
|
||
/** | ||
* Gets a reference to the DSL file that initiated this script context. | ||
* | ||
* @return a File instance | ||
*/ | ||
public File getDslFile() { | ||
return dslFile; | ||
} | ||
|
||
/** | ||
* Gets the current workspace. | ||
* | ||
* @return a Workspace instance | ||
*/ | ||
public Workspace getWorkspace() { | ||
return workspace; | ||
} | ||
|
||
/** | ||
* Gets the named parameter. | ||
* | ||
* @param name the parameter name | ||
* @return the parameter value (null if unset) | ||
*/ | ||
public String getParameter(String name) { | ||
return parameters.get(name); | ||
} | ||
|
||
/** | ||
* Gets the named parameter, with a default value if unset. | ||
* | ||
* @param name the parameter name | ||
* @param defaultValue the default value | ||
* @return the parameter value, or defaultValue if unset | ||
*/ | ||
public String getParameter(String name, String defaultValue) { | ||
String value = parameters.get(name); | ||
|
||
if (StringUtils.isNullOrEmpty(value)) { | ||
value = defaultValue; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters