com.eaio.nativecall
Class NativeCall

java.lang.Object
  |
  +--com.eaio.nativecall.NativeCall
Direct Known Subclasses:
IntCall, VoidCall

public abstract class NativeCall
extends Object

NativeCall loads the native library and prepares the matching Verifier.

Before being able to use NativeCall, the init() method must have been called:

 try {
     NativeCall.init();
 }
 catch (IOException ex) { ... }
 catch (SecurityException ex) { ... }
 catch (UnsatisfiedLinkError er) { ... }
 catch (sun.misc.ServiceConfigurationError) { ... }
 catch (UnsupportedOperationException) { ... }
 
After usage, each NativeCall object must be destroyed to release resources. This is done by calling the destroy() method. Failure to call this method might result in memory leaks.

Author:
Johann Burkard
See Also:
destroy(), init()

Constructor Summary
NativeCall(String function)
          Constructor for NativeCall.
NativeCall(String module, String function)
          Constructor for NativeCall.
 
Method Summary
protected  void check(Object[] params)
          Checks the supplied Object array for illegal/unsupported types.
protected  void checkParam(Object o)
          Checks one Object for illegal/unsupported types.
 void destroy()
          Releases acquired module handles.
 boolean equals(Object obj)
          Returns if this Object is equal to another Object.
protected  void finalize()
          Calls destroy().
 String getLastError()
          Returns a formatted String containing the last error code or null if the last call did not produce an error.
 int getLastErrorCode()
          Returns the error code that was returned during the last method call or 0 if the last method call did not produce an error.
 int hashCode()
          Returns the hashCode of this Object.
static void init()
          Before NativeCall may be used, this method must be called.
 String toString()
          Returns a String representation of this Object.
 StringBuffer toStringBuffer(StringBuffer in)
          Appends a String representation of this Object to the given StringBuffer or creates a new one if none is given.
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NativeCall

public NativeCall(String function)
           throws IllegalArgumentException,
                  NullPointerException
Constructor for NativeCall.

Parameters:
function - the name of the function to use, may not be null
Throws:
IllegalArgumentException - if the function could not be found
NullPointerException - if function is null
See Also:
Verifier.getDefaultModule(), NativeCall(String, String)

NativeCall

public NativeCall(String module,
                  String function)
           throws IllegalArgumentException,
                  NullPointerException
Constructor for NativeCall.

Parameters:
module - the name of the module the function is stored in, may be null
function - the name of the function to use, may not be null
Throws:
IllegalArgumentException - if the function could not be found
NullPointerException - if function is null
Method Detail

init

public static void init()
                 throws IOException,
                        SecurityException,
                        UnsatisfiedLinkError,
                        sun.misc.ServiceConfigurationError,
                        UnsupportedOperationException
Before NativeCall may be used, this method must be called. It loads the native library, prepares JNI field and method IDs and loads the matching Verifier.

Multiple calls are ignored.

Throws:
IOException - if an IOException occured during unpacking of the native library
SecurityException - if accessing system properties was forbidden by the SecurityManager
UnsatisfiedLinkError - if the NativeCall.dll could not be found
sun.misc.ServiceConfigurationError
UnsupportedOperationException - if no matching Verifier could be found

getLastErrorCode

public final int getLastErrorCode()
Returns the error code that was returned during the last method call or 0 if the last method call did not produce an error.

Returns:
the last error code or 0
See Also:
getLastError()

getLastError

public final String getLastError()
Returns a formatted String containing the last error code or null if the last call did not produce an error.

Returns:
a String or null if the last error code is 0
See Also:
getLastErrorCode()

destroy

public void destroy()
Releases acquired module handles. This method must be called if the instance is not used anymore. After this method is called, methods of this NativeCall Object cannot be called anymore.

Failure to call this method might result in memory leaks.

Updates the error code field. See getLastError().


check

protected void check(Object[] params)
              throws ClassCastException
Checks the supplied Object array for illegal/unsupported types.

During the verification, the contents of the array might be changed.

Parameters:
params - the Object array, may be null
Throws:
ClassCastException - if the type of one argument is not supported

checkParam

protected void checkParam(Object o)
                   throws ClassCastException
Checks one Object for illegal/unsupported types.

Parameters:
o - the Object, may be null
Throws:
ClassCastException - if the type of one argument is not supported

equals

public boolean equals(Object obj)
Returns if this Object is equal to another Object. The other Object must be an instance of the same type as this Object. Also, both the module and the function field must be equal.

Overrides:
equals in class Object
Parameters:
obj - the other Object
Returns:
if this and the other Object are equal
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Returns the hashCode of this Object. The hashCode is computed by XOR'ing the hash codes of the function and the module names.

Overrides:
hashCode in class Object
Returns:
the hashCode
See Also:
Object.hashCode()

finalize

protected void finalize()
                 throws Throwable
Calls destroy().

Overrides:
finalize in class Object
Throwable
See Also:
Object.finalize()

toString

public final String toString()
Returns a String representation of this Object.

Overrides:
toString in class Object
Returns:
a String, never null
See Also:
Object.toString(), toStringBuffer(StringBuffer)

toStringBuffer

public StringBuffer toStringBuffer(StringBuffer in)
Appends a String representation of this Object to the given StringBuffer or creates a new one if none is given.

Parameters:
in - the StringBuffer to append to, may be null
Returns:
a StringBuffer, never null