org.eclipse.ease.modules

## Class AbstractEnvironment

- java.lang.Object
- - org.eclipse.ease.modules.AbstractScriptModule
  - - org.eclipse.ease.modules.AbstractEnvironment

All Implemented Interfaces:
  IEnvironment, IScriptModule

Direct Known Subclasses:
  EnvironmentModule, NativeEnvironment

    public abstract class AbstractEnvironment
    extends AbstractScriptModule
    implements IEnvironment

### Constructor Summary

Constructors
Constructor and Description
`AbstractEnvironment()`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `addModuleListener(IModuleListener listener)`
`static IEnvironment` `getEnvironment(IScriptEngine engine)`
`Object` `getModule(String name)` Resolves a loaded module and returns the Java instance.
`<T,U extends Class<T>> T` `getModule(U clazz)` Resolves a loaded module by its class.
`List<Object>` `getModules()` Retrieve a list of loaded modules.
`void` `initialize(IScriptEngine engine, IEnvironment environment)` Provides script engine and environment instances.
`String` `listModules()` List all available (visible) modules.
`Object` `loadModule(String identifier)` Load a module.
`void` `print(Object text, boolean lineFeed)` Write a message to the output stream of the script engine.
`void` `printError(Object text)` Write a message to the error stream of the script engine.
`String` `readInput(boolean blocking)` Read a single line of data from the default input stream of the script engine.
`void` `removeModuleListener(IModuleListener listener)`

### Methods inherited from class org.eclipse.ease.modules.AbstractScriptModule

`getScriptEngine`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.eclipse.ease.modules.IEnvironment

`getScriptEngine, wrap`

### Constructor Detail

#### AbstractEnvironment

    public AbstractEnvironment()

### Method Detail

#### loadModule

    public final Object loadModule(String identifier)

Load a module. Loading a module generally enhances the script environment with new functions and variables. If a module was already loaded before, it gets refreshed and moved to the top of the module stack. When a module is loaded, all its dependencies are loaded too. So loading one module might change the whole module stack.

Specified by:
  `loadModule` in interface `IEnvironment`
Parameters:
  `name` - name of module to load
Returns:
  loaded module instance

#### initialize

    public void initialize(IScriptEngine engine,
                           IEnvironment environment)

Description copied from interface: `IScriptModule`
Provides script engine and environment instances.

Specified by:
  `initialize` in interface `IScriptModule`
Overrides:
  `initialize` in class `AbstractScriptModule`
Parameters:
  `engine` - script engine this module is loaded in
  `environment` - environment module that tracks this module

#### listModules

    public final String listModules()

List all available (visible) modules. Returns a list of visible modules. Loaded modules are indicated.

Returns:
  string containing module information

#### getModule

    public final Object getModule(String name)

Resolves a loaded module and returns the Java instance. Will only query previously loaded modules.

Specified by:
  `getModule` in interface `IEnvironment`
Parameters:
  `name` - name of the module to resolve
Returns:
  resolved module instance or `null`

#### getModule

    public <T,U extends Class<T>> T getModule(U clazz)

Resolves a loaded module by its class.

Specified by:
  `getModule` in interface `IEnvironment`
Parameters:
  `clazz` - module class to look resolve
Returns:
  resolved module instance or `null`

#### getModules

    public List<Object> getModules()

Description copied from interface: `IEnvironment`
Retrieve a list of loaded modules. The returned list is read only.

Specified by:
  `getModules` in interface `IEnvironment`
Returns:
  list of modules (might be empty)

#### print

    public final void print(@ScriptParameter(defaultValue="")
                            Object text,
                            @ScriptParameter(defaultValue="true")
                            boolean lineFeed)

Write a message to the output stream of the script engine.

Specified by:
  `print` in interface `IEnvironment`
Parameters:
  `text` - message to write
  `lineFeed` - `true` to add a line feed after the text

#### printError

    public final void printError(@ScriptParameter(defaultValue="")
                                 Object text)

Write a message to the error stream of the script engine.

Parameters:
  `text` - message to write

#### addModuleListener

    public void addModuleListener(IModuleListener listener)

Specified by:
  `addModuleListener` in interface `IEnvironment`

#### removeModuleListener

    public void removeModuleListener(IModuleListener listener)

Specified by:
  `removeModuleListener` in interface `IEnvironment`

#### readInput

    public String readInput(@ScriptParameter(defaultValue="true")
                            boolean blocking)
                     throws IOException

Read a single line of data from the default input stream of the script engine. Depending on the blocking parameter this method will wait for user input or return immediately with available data.

Parameters:
  `blocking` - `true` results in a blocking call until data is available, `false` returns in any case
Returns:
  string data from input stream or `null`
Throws:
  `IOException` - when reading on the input stream fails

#### getEnvironment

    public static IEnvironment getEnvironment(IScriptEngine engine)