org.eclipse.ease.modules.platform

## Class PlatformModule

- java.lang.Object
- - org.eclipse.ease.modules.platform.PlatformModule

    public class PlatformModule
    extends java.lang.Object

Provides global platform functions like preferences, event bus or the command framework.

### Field Summary

Fields
`static java.lang.String` `MODULE_ID` Module identifier.

### Constructor Summary

Constructors
Constructor and Description
`PlatformModule()`

### Method Summary

All Methods Static Methods Concrete Methods
`static java.lang.Object` `adapt(java.lang.Object source, java.lang.Class<?> target)` Adapt object to target type.
`static void` `executeCommand(java.lang.String commandId, java.util.Map<java.lang.String,java.lang.String> parameters)` Execute a command from the command framework.
`static java.lang.Object` `getService(java.lang.Class<?> type)` Get a platform service.
`static java.lang.String` `getSystemProperty(java.lang.String key)` Get a system property value
`static void` `postEvent(java.lang.String topic, java.lang.Object data, long delay)` Post an event on the event broker.
`static java.lang.Object` `readPreferences(java.lang.String node, java.lang.String key, java.lang.Object defaultValue)` Read a preferences value.
`static java.lang.Process` `runProcess(java.lang.String name, java.lang.String[] args)` Run an external process.
`static org.osgi.service.event.Event` `waitForEvent(java.lang.String topic, long timeout)` Wait for a given event on the event bus.
`static void` `writePreferences(java.lang.String node, java.lang.String key, java.lang.Object value)` Set a preferences value.

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

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

### Field Detail

#### MODULE_ID

    public static final java.lang.String MODULE_ID

Module identifier.

See Also:
  Constant Field Values

### Constructor Detail

#### PlatformModule

    public PlatformModule()

### Method Detail

#### adapt

    public static java.lang.Object adapt(java.lang.Object source,
                                         java.lang.Class<?> target)

Adapt object to target type. Try to get an adapter for an object.

Parameters:
  `source` - object to adapt
  `target` - target class to adapt to
Returns:
  adapted object or `null`

#### getService

    public static java.lang.Object getService(java.lang.Class<?> type)

Get a platform service.

Parameters:
  `type` - service type
Returns:
  service instance or `null`

#### executeCommand

    public static void executeCommand(java.lang.String commandId,
                                      @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null")
                                      java.util.Map<java.lang.String,java.lang.String> parameters)
                               throws ExecutionException,
                                      NotDefinedException,
                                      NotEnabledException,
                                      NotHandledException

Execute a command from the command framework. As we have no UI available, we do not pass a control to the command. Hence HandlerUtil.getActive... commands will very likely fail.

Parameters:
  `commandId` - full id of the command to execute
  `parameters` - command parameters
Throws:
  `ExecutionException` - If the handler has problems executing this command.
  `NotDefinedException` - If the command you are trying to execute is not defined.
  `NotEnabledException` - If the command you are trying to execute is not enabled.
  `NotHandledException` - If there is no handler.

#### getSystemProperty

    public static java.lang.String getSystemProperty(java.lang.String key)

Get a system property value

Parameters:
  `key` - key to query
Returns:
  system property for key

#### runProcess

    public static java.lang.Process runProcess(java.lang.String name,
                                               @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null")
                                               java.lang.String[] args)
                                        throws java.io.IOException

Run an external process. The process is started in the background and a `FutureX` object is returned. Query the result for finished state, output and error streams of the executed process.

Parameters:
  `name` - program to run (with full path if necessary)
  `args` - program arguments
Returns:
  process object to track proces execution
Throws:
  `java.io.IOException` - if an I/O error occurs

#### readPreferences

    public static java.lang.Object readPreferences(java.lang.String node,
                                                   java.lang.String key,
                                                   @ScriptParameter(defaultValue="")
                                                   java.lang.Object defaultValue)

Read a preferences value. The defaultValue is optional, but contains type information if used. Provide instances of Boolean, Integer, Double, Float, Long, byte[], or String to get the appropriate return value of same type.

Parameters:
  `node` - node to read from
  `key` - key name to read from
  `defaultValue` - default value to use, if value is not set
Returns:
  preference value or `null`

#### writePreferences

    public static void writePreferences(java.lang.String node,
                                        java.lang.String key,
                                        java.lang.Object value)

Set a preferences value. Valid types for value are: Boolean, Integer, Double, Float, Long, byte[], and String.

Parameters:
  `node` - node to write to
  `key` - key to store to
  `value` - value to store

#### postEvent

    public static void postEvent(java.lang.String topic,
                                 @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null")
                                 java.lang.Object data,
                                 @ScriptParameter(defaultValue="0")
                                 long delay)

Post an event on the event broker. If delay is set, the event will be posted after the given amount of time asynchronously. In any case this method returns immediately.

Parameters:
  `topic` - topic to post
  `data` - topic data
  `delay` - delay to post this even in [ms]

#### waitForEvent

    public static org.osgi.service.event.Event waitForEvent(java.lang.String topic,
                                                            @ScriptParameter(defaultValue="0")
                                                            long timeout)
                                                     throws java.lang.InterruptedException

Wait for a given event on the event bus.

Parameters:
  `topic` - topic to subscribe for
  `timeout` - maximum time to wait for event in [ms]. Use 0 to wait without timeout.
Returns:
  posted event or `null` in case of a timeout
Throws:
  `java.lang.InterruptedException` - when the script thread gets interrupted