public class AddEnvironment extends Object implements Environment
Note this does not work perfectly, because of bad design of the
Environment class. The acquireValue method can end up
passing an instance of the wrapped environment to a parameter,
which means that subequent environment accesses made under the control
of that parameter will not pick up entries added to this environment.
A redesign of the Environment class is the only good way out of this.
Until then you have to hack round it by explicitly calling acquireValue
from this class on dependent variables before it gets done under control
of the variable they depend on.
| Constructor and Description |
|---|
AddEnvironment(Environment baseEnv,
Map<String,String> addMap)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
acquireValue(Parameter<?> par)
Obtains a legal value for a given parameter from the environment and
sets the parameter's value accordingly.
|
void |
clearValue(Parameter<?> par)
Clears a value for a given parameter.
|
static AddEnvironment |
createAddEnvironment(Environment baseEnv,
Map<String,String> addMap)
Returns an AddEnvironment based on a supplied base environment and
a map of key-value pairs.
|
PrintStream |
getErrorStream()
Returns an output stream into which error or logging output from
a task can be written.
|
String[] |
getNames()
Returns an array of parameter names which have been specified.
|
PrintStream |
getOutputStream()
Returns an output stream into which text output from a task can
be written.
|
public AddEnvironment(Environment baseEnv, Map<String,String> addMap)
baseEnv - base environmentaddMap - addional key-value pairs to add to this environmentpublic void acquireValue(Parameter<?> par) throws TaskException
Environment
This environment should obtain a value for the parameter par
in whatever way it sees fit, and must then call par's
Parameter.setValueFromString(uk.ac.starlink.task.Environment, java.lang.String) method so that the parameter
knows what its new value is. If the setValueFromString call
throws a ParameterValueException the environment may
try to get another value (for instance by re-prompting the user)
or may give up and re-throw the exception.
acquireValue in interface Environmentpar - the Parameter whose value is to be obtained and setTaskExceptionpublic void clearValue(Parameter<?> par)
EnvironmentclearValue in interface Environmentpar - the Parameter whose value is to be clearedpublic String[] getNames()
EnvironmentgetNames in interface Environmentpublic PrintStream getOutputStream()
EnvironmentgetOutputStream in interface Environmentpublic PrintStream getErrorStream()
EnvironmentgetErrorStream in interface Environmentpublic static AddEnvironment createAddEnvironment(Environment baseEnv, Map<String,String> addMap)
baseEnv - base environmentaddMap - addional key-value pairs to add to this environmentCopyright © 2025 Central Laboratory of the Research Councils. All Rights Reserved.