uk.ac.starlink.ttools.task
Class AddEnvironment

java.lang.Object
  extended by uk.ac.starlink.ttools.task.AddEnvironment
All Implemented Interfaces:
Environment

public class AddEnvironment
extends Object
implements Environment

Environment implementation which wraps a base environment instance and adds some extra entries as specified by a given map.

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.

Since:
2013
Author:
Mark Taylor

Constructor Summary
AddEnvironment(Environment baseEnv, Map<String,String> addMap)
          Constructor.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AddEnvironment

public AddEnvironment(Environment baseEnv,
                      Map<String,String> addMap)
Constructor.

Parameters:
baseEnv - base environment
addMap - addional key-value pairs to add to this environment
Method Detail

acquireValue

public void acquireValue(Parameter par)
                  throws TaskException
Description copied from interface: Environment
Obtains a legal value for a given parameter from the environment and sets the parameter's value accordingly.

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.

Specified by:
acquireValue in interface Environment
Parameters:
par - the Parameter whose value is to be obtained and set
Throws:
TaskException

clearValue

public void clearValue(Parameter par)
Description copied from interface: Environment
Clears a value for a given parameter.

Specified by:
clearValue in interface Environment
Parameters:
par - the Parameter whose value is to be cleared

getNames

public String[] getNames()
Description copied from interface: Environment
Returns an array of parameter names which have been specified. The result is not necessarily an exhaustive list of all parameters whose values can be retrieved from this environment, since an interactive environment may be able to prompt the user for values, but it can give a list of values provided explicitly or without interactive prompts.

Specified by:
getNames in interface Environment
Returns:
array of names of known supplied parameters

getOutputStream

public PrintStream getOutputStream()
Description copied from interface: Environment
Returns an output stream into which text output from a task can be written. This would correspond to standard output for a terminal-based application.

Specified by:
getOutputStream in interface Environment
Returns:
a stream for text output

getErrorStream

public PrintStream getErrorStream()
Description copied from interface: Environment
Returns an output stream into which error or logging output from a task can be written. This would correspodnd to standard error for a terminal-based application.

Specified by:
getErrorStream in interface Environment
Returns:
a stream for error output

createAddEnvironment

public 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. If the supplied base environment is a TableEnvironment instance, the returned value will be as well.

Parameters:
baseEnv - base environment
addMap - addional key-value pairs to add to this environment
Returns:
Environment or TableEnvironment instance with additional entries


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.