private static Class < ? extends OrmLiteSqliteOpenHelper > lookupHelperClass ( Context context , Class < ? > componentClass ) { // see if we have the magic resource class name set Resources resources = context . getResources ( ) ; int resourceId = resources . getIdentifier ( HELPER_CLASS_RESOURCE_NAME , "string" , context . getPackageName ( ) ) ; if ( resourceId != 0 ) { String className = resources . getString ( resourceId ) ; try { @ SuppressWarnings ( "unchecked" ) Class < ? extends OrmLiteSqliteOpenHelper > castClass = ( Class < ? extends OrmLiteSqliteOpenHelper > ) Class . forName ( className ) ; return castClass ; } catch ( Exception e ) { throw new IllegalStateException ( "Could not create helper instance for class " + className , e ) ; } } // try walking the context class to see if we can get the OrmLiteSqliteOpenHelper from a generic parameter for ( Class < ? > componentClassWalk = componentClass ; componentClassWalk != null ; componentClassWalk = componentClassWalk . getSuperclass ( ) ) { Type superType = componentClassWalk . getGenericSuperclass ( ) ; if ( superType == null || ! ( superType instanceof ParameterizedType ) ) { continue ; } // get the generic type arguments Type [ ] types = ( ( ParameterizedType ) superType ) . getActualTypeArguments ( ) ; // defense if ( types == null || types . length == 0 ) { continue ; } for ( Type type : types ) { // defense if ( ! ( type instanceof Class ) ) { continue ; } Class < ? > clazz = ( Class < ? > ) type ; if ( OrmLiteSqliteOpenHelper . class . isAssignableFrom ( clazz ) ) { @ SuppressWarnings ( "unchecked" ) Class < ? extends OrmLiteSqliteOpenHelper > castOpenHelperClass = ( Class < ? extends OrmLiteSqliteOpenHelper > ) clazz ; return castOpenHelperClass ; } } } throw new IllegalStateException ( "Could not find OpenHelperClass because none of the generic parameters of class " + componentClass + " extends OrmLiteSqliteOpenHelper. You should use getHelper(Context, Class) instead." ) ; }
Lookup the helper class either from the resource string or by looking for a generic parameter .