Provides global platform functions like preferences, event bus or the command framework.
Method | Description |
---|---|
adapt() | Adapt object to target type. |
createScriptEngine() | Create a new script engine instance. |
executeCommand() | Execute a command from the command framework. |
executeSync() | Run a code fragment in a synchronized block. |
fork() | Fork a new script engine and execute provided resource. |
getService() | Get a platform service. |
getSharedObject() | Get an object from the shared object store. |
getSystemProperty() | Get a system property or environment value. |
join() | Wait for a script engine to shut down. |
listScriptEngines() | Retrieve a list of available script engines. |
notify() | Wakes up a single thread that is waiting on the monitor. |
notifyAll() | Wakes up all threads that are waiting on the monitor. |
postEvent() | Post an event on the event broker. |
readPreferences() | Read a preferences value. |
runProcess() | Run an external process. |
setSharedObject() | Add an object to the shared object store. |
wait() | Causes the current thread to wait until either another thread invokes the Object.notify() method or the Object.notifyAll() method for this object, or a specified amount of time has elapsed. |
waitForEvent() | Wait for a given event on the event bus. |
writePreferences() | Set a preferences value. |
Object adapt(Object source, Class<?> target)
Adapt object to target type. Try to get an adapter for an object.
adapted object or null
IScriptEngine createScriptEngine(String identifier)
Create a new script engine instance.
script engine instance (not started) or null
void executeCommand(String commandId, [Map<String, 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.
Object executeSync(Object monitor, Object code) throws ExecutionException
Run a code fragment in a synchronized block. Executes code within a synchronized block on the monitor object. The code object might be a String, File, IFile or any other object that can be adapted to IScriptable.
execution result of executed code
ScriptResult fork(Object resource, [String arguments], [String engineIdOrExtension])
Fork a new script engine and execute provided resource.
execution result
Object getService(Class<?> type)
Get a platform service.
service instance or null
Object getSharedObject(String key)
Get an object from the shared object store.
shared object or null
String getSystemProperty(String key)
Get a system property or environment value. First we try to look up a system property. If not found we query the environment for the key.
system property/environment variable for key
boolean join(IScriptEngine engine, [long timeout])
Wait for a script engine to shut down. If timeout is set to 0 this method will wait endlessly.
true
when engine is shut down
String[] listScriptEngines()
Retrieve a list of available script engines.
array of engine IDs
void notify(Object monitor)
Wakes up a single thread that is waiting on the monitor. Calls the java method monitor.notify().
void notifyAll(Object monitor)
Wakes up all threads that are waiting on the monitor. Calls the java method monitor.notifyAll().
void postEvent(String topic, [Object data], [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.
Object readPreferences(String node, String key, [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.
preference value or null
Process runProcess(String name, [String[] args], [String output], [String error]) throws IOException
Run an external process. The process is started in the background and a Process object is returned. Query the result for finished state, output
and error streams of the executed process. Output and error streams need to be consumed, otherwise the running process may stall (or even die) in case
that the buffers are full. Setting parameters output and error to null
will automatically discard the produced data.
process object to track process execution
void setSharedObject(String key, Object object, [boolean permanent], [boolean writable]) throws IllegalAccessException
Add an object to the shared object store. The shared object store allows to share java instances between several script engines. By default objects are
stored until the script engine providing it is terminated. This helps to avoid polluting the java heap. When permanent is set to true
, this object will be stored forever.
void wait(Object monitor, [long timeout]) throws InterruptedException
Causes the current thread to wait until either another thread invokes the Object.notify() method or the Object.notifyAll() method for this object, or a specified amount of time has elapsed. Calls the java method monitor.wait(timeout).
org.osgi.service.event.Event waitForEvent(String topic, [long timeout]) throws InterruptedException
Wait for a given event on the event bus.
posted event or null
in case of a timeout
void writePreferences(String node, String key, Object value) throws org.osgi.service.prefs.BackingStoreException
Set a preferences value. Valid types for value are: Boolean, Integer, Double, Float, Long, byte[], and String.