# Class SimulatorHookExecutor

java.lang.Object
com.codename1.system.SimulatorHookExecutor

public final class SimulatorHookExecutor extends Object

Cross-platform registry of named actions that the JavaSE simulator exposes.

The simulator scans cn1libs (and the app itself) for `META-INF/codenameone/simulator-hooks.properties` files; each hook declared there is registered here under `namespace:itemN` keys. The JavaSE port hooks into `CN.execute(String)` / `CN.canExecute(String)` so cross-platform code (such as a CN1 UnitTest under `common/`) can invoke a hook via the same `execute` it would use for any other URL, with no JavaSE-only import.

On Android, iOS, JavaScript and other production targets this registry is always empty, so `execute` returns `false` and `isRegistered` is always `false` -- the "running outside a simulator" signal.

Hooks can be menu-backed (shipped with a label and visible in the simulator's menu bar) or API-only (no label, callable by URL only). Tests that want behavioral coverage of cn1lib internals lean on the API-only form so the menu UX stays focused on actions a human would click.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static boolean`
  `execute(String hookId)`
  Invokes the action registered under `hookId`.
  `static boolean`
  `isRegistered(String hookId)`
  Returns `true` if a hook with the given id is registered.
  `static void`
  `register(Map<String,Runnable> registered)`
  Replaces the entire registry.
  `static Collection<String>`
  `registeredIds()`
  Diagnostic view of every registered id.

  ### Methods inherited from class Object

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

- ## Method Details

  - ### execute

    public static boolean execute(String hookId)

    Invokes the action registered under `hookId`. Returns `true` if a hook with that id was found and dispatched, `false` otherwise. Invocation is delegated to whatever the registering code configured (the JavaSE port wraps each hook in `Display.callSeriallyAndWait`, so menu actions and tests run on the CN1 EDT and the call is synchronous from off-EDT callers).

    ###### Parameters

    - `hookId`: opaque id of the form `namespace:hook` (the exact value the hook author chose in the properties file).

  - ### isRegistered

    public static boolean isRegistered(String hookId)
    Returns `true` if a hook with the given id is registered. Useful for tests that want to skip themselves gracefully when running on a platform that doesn't expose the relevant cn1lib hook.

  - ### registeredIds

    public static Collection<String> registeredIds()
    Diagnostic view of every registered id. Returns an unmodifiable snapshot -- never null. Intended for tests/inspectors; ordinary app code shouldn't need this.

  - ### register

    public static void register(Map<String,Runnable> registered)
    Replaces the entire registry. The JavaSE port calls this every time it rebuilds the simulator menu (e.g., after a reload). On non-simulator targets nothing calls it and the registry stays empty.