IntrospectionException.java

  1. package net.zer0bandwidth.android.lib.database.sqlitehouse.exceptions;

  2. import net.zer0bandwidth.android.lib.database.sqlitehouse.SQLiteHouse;

  3. /**
  4.  * Thrown by {@link SQLiteHouse} and its descendant classes whenever the process
  5.  * of reflexively constructing a database fails.
  6.  * @since zer0bandwidth-net/android 0.1.4 (#26)
  7.  */
  8. public class IntrospectionException
  9. extends RuntimeException
  10. {
  11. protected static final String DEFAULT_MESSAGE =
  12. "Failed to reflexively discover database information." ;

  13. /**
  14.  * Used when an attempt to use {@link Class#newInstance()} fails with an
  15.  * {@link InstantiationException}.
  16.  * @param cls the class being instantiated
  17.  * @param xCause the cause of the failure
  18.  * @return a new exception with the appropriate message
  19.  * @since zer0bandwidth-net/android 0.1.7 (#50)
  20.  */
  21. public static IntrospectionException instanceFailed(
  22. Class<?> cls, Throwable xCause )
  23. { return instanceFailed( cls.getCanonicalName(), xCause ) ; }

  24. /**
  25.  * Used when an attempt to create an instance of a schematic class fails.
  26.  * @param sClass the canonical name of the class being instantiated
  27.  * @param xCause the cause of the failure
  28.  * @return a new exception with the appropriate message
  29.  * @since zer0bandwidth-net/android 0.1.7 (#50)
  30.  */
  31. public static IntrospectionException instanceFailed(
  32. String sClass, Throwable xCause )
  33. {
  34. return new IntrospectionException( (new StringBuilder())
  35. .append( "Could not create instance of class [" )
  36. .append( sClass )
  37. .append( "]." )
  38. .toString()
  39. , xCause
  40. );
  41. }

  42. /**
  43.  * Used when an attempt to use {@link Class#newInstance()} fails with an
  44.  * {@link IllegalAccessException}.
  45.  * @param cls the class being instantiated
  46.  * @param xCause the cause of the failure
  47.  * @return a new exception with the appropriate message
  48.  * @since zer0bandwidth-net/android 0.1.7 (#50)
  49.  */
  50. public static IntrospectionException instanceForbidden(
  51. Class<?> cls, Throwable xCause )
  52. {
  53. return new IntrospectionException( (new StringBuilder())
  54. .append( "Instance constructor inaccessible for class [" )
  55. .append( cls.getCanonicalName() )
  56. .append( "]." )
  57. .toString()
  58. , xCause
  59. );
  60. }

  61. /**
  62.  * Used when something tries to process a class that does not implement the
  63.  * {@link net.zer0bandwidth.android.lib.database.sqlitehouse.SQLightable}
  64.  * interface.
  65.  * @param cls the unusable class
  66.  * @param xCause the root cause, if any
  67.  * @return a new exception with the appropriate message
  68.  * @since zer0bandwidth-net/android 0.1.7 (#50)
  69.  */
  70. public static IntrospectionException illegalClassSpecification(
  71. Class<?> cls, Throwable xCause )
  72. { return illegalClassSpecification( cls.getCanonicalName(), xCause ) ; }

  73. /**
  74.  * Used when something tries to process a class that does not implement the
  75.  * {@link net.zer0bandwidth.android.lib.database.sqlitehouse.SQLightable}
  76.  * interface.
  77.  * @param sClass the canonical name of the unusable class
  78.  * @param xCause the root cause, if any
  79.  * @return a new exception with the appropriate message
  80.  * @since zer0bandwidth-net/android 0.1.7 (#50)
  81.  */
  82. public static IntrospectionException illegalClassSpecification(
  83. String sClass, Throwable xCause )
  84. {
  85. return new IntrospectionException( (new StringBuilder())
  86. .append( "Class [" ).append( sClass )
  87. .append( "] does not implement SQLightable." )
  88. .toString()
  89. , xCause
  90. );
  91. }

  92. @SuppressWarnings("unused")
  93. public IntrospectionException()
  94. { super( DEFAULT_MESSAGE ) ; }

  95. public IntrospectionException( String sMessage )
  96. { super( sMessage ) ; }

  97. @SuppressWarnings("unused")
  98. public IntrospectionException( Throwable xCause )
  99. { super( DEFAULT_MESSAGE, xCause ) ; }

  100. public IntrospectionException( String sMessage, Throwable xCause )
  101. { super( sMessage, xCause ) ; }
  102. }