chrriis.dj.nativeswing.swtimpl
Class NativeInterface

java.lang.Object
  extended by chrriis.dj.nativeswing.swtimpl.NativeInterface

public abstract class NativeInterface
extends Object

The native interface, which establishes the link between the peer VM (native side) and the local side.

Author:
Christopher Deckers

Constructor Summary
NativeInterface()
           
 
Method Summary
static void addNativeInterfaceListener(NativeInterfaceListener listener)
          Add a native interface listener.
static void close()
          Close the native interface, which destroys the native side (peer VM).
protected static void computeMessageID(Message message, boolean isTargetNativeSide)
           
protected static NativeInterfaceConfiguration createConfiguration()
           
static NativeInterfaceConfiguration getConfiguration()
          Get the configuration, which allows to modify some parameters.
protected static NativeInterface getInstance()
           
protected static int getMessageID(Message message)
           
protected static Class<?>[] getNativeClassPathReferenceClasses(NativeInterfaceConfiguration nativeInterfaceConfiguration)
           
protected static String[] getNativeClassPathReferenceResources(NativeInterfaceConfiguration nativeInterfaceConfiguration)
           
static NativeInterfaceListener[] getNativeInterfaceListeners()
          Get all the native interface listeners.
protected static String[] getPeerVMParams(NativeInterfaceConfiguration nativeInterfaceConfiguration)
           
static void initialize()
          Initialize the native interface, but do not open it.
static boolean isEventPumpRunning()
          Indicate if events are being pumped (by a call to runEventPump).
static boolean isInitialized()
          Indicate whether the native interface is initialized.
static boolean isInProcess()
           
protected static boolean isMessageSyncExec(Message message)
           
protected static boolean isMessageUI(Message message)
           
protected static boolean isMessageValid(Message message)
           
static boolean isOpen()
          Indicate whether the native interface is open.
static boolean isUIThread(boolean isNativeSide)
          Indicate if the current thread is the user interface thread.
static void main(String[] args)
          The main method that is called by the native side (peer VM).
static void open()
          Open the native interface, which creates the peer VM that handles the native side of the native integration.
static void printStackTraces()
          Print the stack traces to system err, including the ones from the peer VM when applicable.
static void printStackTraces(PrintStream printStream)
          Print the stack traces to a print stream, including the ones from the peer VM when applicable.
static void printStackTraces(PrintWriter printWriter)
          Print the stack traces to a print writer, including the ones from the peer VM when applicable.
static void removeNativeInterfaceListener(NativeInterfaceListener listener)
          Remove a native interface listener.
static void runEventPump()
          Run the native event pump.
protected static Object runMessageCommand(CommandMessage commandMessage)
           
protected static Object runMessageCommand(LocalMessage commandMessage)
           
protected static void setMessageArgs(CommandMessage message, Object... args)
           
protected static void setMessageSyncExec(Message message, boolean isSyncExec)
           
protected static void setMessageUI(Message message, boolean isUI)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NativeInterface

public NativeInterface()
Method Detail

getInstance

protected static NativeInterface getInstance()

isOpen

public static boolean isOpen()
Indicate whether the native interface is open.

Returns:
true if the native interface is open, false otherwise.

close

public static void close()
Close the native interface, which destroys the native side (peer VM). Note that the native interface can be re-opened later.


getConfiguration

public static NativeInterfaceConfiguration getConfiguration()
Get the configuration, which allows to modify some parameters.


isInitialized

public static boolean isInitialized()
Indicate whether the native interface is initialized.

Returns:
true if the native interface is initialized, false otherwise.

isInProcess

public static boolean isInProcess()

initialize

public static void initialize()
Initialize the native interface, but do not open it. This method sets some properties and registers a few listeners to keep track of certain states necessary for the good functioning of the framework.
This method is automatically called if open() is used. It should be called early in the program, the best place being as the first call in the main method.


printStackTraces

public static void printStackTraces()
Print the stack traces to system err, including the ones from the peer VM when applicable.


printStackTraces

public static void printStackTraces(PrintStream printStream)
Print the stack traces to a print stream, including the ones from the peer VM when applicable.


printStackTraces

public static void printStackTraces(PrintWriter printWriter)
Print the stack traces to a print writer, including the ones from the peer VM when applicable.


open

public static void open()
Open the native interface, which creates the peer VM that handles the native side of the native integration.
Initialization takes place if the interface was not already initialized. If initialization was not explicitely performed, this method should be called early in the program, the best place being as the first call in the main method.


isUIThread

public static boolean isUIThread(boolean isNativeSide)
Indicate if the current thread is the user interface thread.

Returns:
true if the current thread is the user interface thread.
Throws:
IllegalStateException - when the native interface is not alive.

runEventPump

public static void runEventPump()
Run the native event pump. Certain platforms require this method call at the end of the main method to function properly, so it is suggested to always add it.


isEventPumpRunning

public static boolean isEventPumpRunning()
Indicate if events are being pumped (by a call to runEventPump).

Returns:
true if events are being pumped.

addNativeInterfaceListener

public static void addNativeInterfaceListener(NativeInterfaceListener listener)
Add a native interface listener.

Parameters:
listener - the native listener to add.

removeNativeInterfaceListener

public static void removeNativeInterfaceListener(NativeInterfaceListener listener)
Remove a native interface listener.

Parameters:
listener - the native listener to remove.

getNativeInterfaceListeners

public static NativeInterfaceListener[] getNativeInterfaceListeners()
Get all the native interface listeners.

Returns:
the native interface listeners.

createConfiguration

protected static NativeInterfaceConfiguration createConfiguration()

runMessageCommand

protected static Object runMessageCommand(LocalMessage commandMessage)

runMessageCommand

protected static Object runMessageCommand(CommandMessage commandMessage)
                                   throws Exception
Throws:
Exception

isMessageSyncExec

protected static boolean isMessageSyncExec(Message message)

setMessageSyncExec

protected static void setMessageSyncExec(Message message,
                                         boolean isSyncExec)

getPeerVMParams

protected static String[] getPeerVMParams(NativeInterfaceConfiguration nativeInterfaceConfiguration)

getNativeClassPathReferenceClasses

protected static Class<?>[] getNativeClassPathReferenceClasses(NativeInterfaceConfiguration nativeInterfaceConfiguration)

getNativeClassPathReferenceResources

protected static String[] getNativeClassPathReferenceResources(NativeInterfaceConfiguration nativeInterfaceConfiguration)

getMessageID

protected static int getMessageID(Message message)

isMessageValid

protected static boolean isMessageValid(Message message)

setMessageArgs

protected static void setMessageArgs(CommandMessage message,
                                     Object... args)

computeMessageID

protected static void computeMessageID(Message message,
                                       boolean isTargetNativeSide)

setMessageUI

protected static void setMessageUI(Message message,
                                   boolean isUI)

isMessageUI

protected static boolean isMessageUI(Message message)

main

public static void main(String[] args)
                 throws Exception
The main method that is called by the native side (peer VM).

Parameters:
args - the arguments that are passed to the peer VM.
Throws:
Exception