com.coi.tools.os.win
Class NativeLibException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by com.coi.tools.os.win.NativeLibException
All Implemented Interfaces:
java.io.Serializable

public class NativeLibException
extends java.lang.Exception

A exception class which will be used from the native part of system dependent classes to signal exceptions. The native methods writes only symbolic error messages, the language dependant mapping will be done in this class.

Author:
Klaus Bartz
See Also:
Serialized Form

Field Summary
private  java.util.ArrayList<java.lang.String> args
          Additional arguments.
private  int libErr
          Internal error as number.
private  java.lang.String libErrString
          Internal error message; contains most the symbolic error name.
private static java.util.HashMap<java.lang.String,java.util.ResourceBundle> messageResourceBundles
          Map of founded resource bundles which contains the localized error messages.
private  int osErr
          OS error as number.
private  java.lang.String osErrString
          OS error string; if possible localized.
private static long serialVersionUID
           
 
Constructor Summary
NativeLibException()
          The constructor.
NativeLibException(int libErr, int osErr, java.lang.String libString, java.lang.String osString)
          Creates a NativeLibException with the given values.
NativeLibException(java.lang.String message)
          Creates a NativeLibException with the given message.
NativeLibException(java.lang.String message, java.lang.Throwable cause)
          Creates a NativeLibException with the given message and cause.
NativeLibException(java.lang.Throwable cause)
          Creates a NativeLibException with the given cause.
 
Method Summary
 void addArgument(java.lang.String arg)
          Adds a string to the internal argument list.
static void addResourceBundle(java.lang.String bundlePath)
          Adds a resource bundle which contains localized error messages.
 java.util.ArrayList<java.lang.String> getArguments()
          Returns the internal argument list.
 int getLibErr()
          Returns the number of the internal handled error.
 java.lang.String getLibMessage()
          Returns the message of the internal handled error.
 java.lang.String getLocalizedLibMessage()
          Returns the localized message of the internal handled error.
 java.lang.String getMessage()
           
private  java.lang.String getMsg(java.lang.String s)
          Searches the resource bundles for a string which coresponds to the given string as key.
 int getOsErr()
          Returns the number of the system error.
 java.lang.String getOsMessage()
          Returns the message of the system error.
private static java.lang.String replaceString(java.lang.String destination, java.lang.String what, java.lang.String with)
          Returns a string resulting from replacing all occurrences of what in this string with with.
 java.lang.String reviseMsgWithArgs(java.lang.String msg)
          Revise placeholder in the given message with the setted arguments
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

messageResourceBundles

private static final java.util.HashMap<java.lang.String,java.util.ResourceBundle> messageResourceBundles
Map of founded resource bundles which contains the localized error messages.


libErr

private int libErr
Internal error as number.


osErr

private int osErr
OS error as number.


libErrString

private java.lang.String libErrString
Internal error message; contains most the symbolic error name.


osErrString

private java.lang.String osErrString
OS error string; if possible localized.


args

private java.util.ArrayList<java.lang.String> args
Additional arguments.

Constructor Detail

NativeLibException

public NativeLibException()
The constructor.


NativeLibException

public NativeLibException(java.lang.String message)
Creates a NativeLibException with the given message.

Parameters:
message - to be used

NativeLibException

public NativeLibException(java.lang.Throwable cause)
Creates a NativeLibException with the given cause.

Parameters:
cause - to be used

NativeLibException

public NativeLibException(java.lang.String message,
                          java.lang.Throwable cause)
Creates a NativeLibException with the given message and cause.

Parameters:
message - message to be used
cause - cause to be used

NativeLibException

public NativeLibException(int libErr,
                          int osErr,
                          java.lang.String libString,
                          java.lang.String osString)
Creates a NativeLibException with the given values.

Parameters:
libErr - identifier of the internal handled error
osErr - system error number
libString - message for the internal handled error
osString - system error message
Method Detail

addResourceBundle

public static void addResourceBundle(java.lang.String bundlePath)
Adds a resource bundle which contains localized error messages. The bundlePath should contain a string with which the bundle is loadable with ResourceBundle.getBundle, may be the full class path to a ListResourceBundle. The localize is done by getBundle, therefore the path should not contain the locale substring. At a call to getMessage the bundle is searched with the libErrString as key. If it exist, the value of it is used by getMessage, else the libErrString self.

Parameters:
bundlePath - path of bundle without locale

getMessage

public java.lang.String getMessage()
Overrides:
getMessage in class java.lang.Throwable

getLibErr

public int getLibErr()
Returns the number of the internal handled error.

Returns:
the number of the internal handled error

getLibMessage

public java.lang.String getLibMessage()
Returns the message of the internal handled error.

Returns:
the messager of the internal handled error

getLocalizedLibMessage

public java.lang.String getLocalizedLibMessage()
Returns the localized message of the internal handled error.

Returns:
the localized message of the internal handled error

getOsErr

public int getOsErr()
Returns the number of the system error.

Returns:
the number of the system error

getOsMessage

public java.lang.String getOsMessage()
Returns the message of the system error.

Returns:
the messager of the system error

addArgument

public void addArgument(java.lang.String arg)
Adds a string to the internal argument list.

Parameters:
arg - string to be added to the internal argument list

getArguments

public java.util.ArrayList<java.lang.String> getArguments()
Returns the internal argument list.

Returns:
the internal argument list

reviseMsgWithArgs

public java.lang.String reviseMsgWithArgs(java.lang.String msg)
Revise placeholder in the given message with the setted arguments

Parameters:
msg - message to be revised
Returns:
revised message

getMsg

private java.lang.String getMsg(java.lang.String s)
Searches the resource bundles for a string which coresponds to the given string as key.

Parameters:
s - string which should be used as keys for the resource bundle
Returns:
the founded message as int value

replaceString

private static java.lang.String replaceString(java.lang.String destination,
                                              java.lang.String what,
                                              java.lang.String with)
Returns a string resulting from replacing all occurrences of what in this string with with. In opposite to the String.replaceAll method this method do not use regular expression or other methods which are only available in JRE 1.4 and later.

Parameters:
destination - string for which the replacing should be performed
what - what string should be replaced
with - with what string what should be replaced
Returns:
a new String object if what was found in the given string, else the given string self