findClass<T> method

  1. @override
Class<T>? findClass<T>(
  1. String className, [
  2. ProtectionDomain? domain
])
override

Finds and loads a class without caching (used internally by loadClass).

Type Parameters:

  • T: The expected class type for type safety

Parameters:

  • className: The fully qualified class name to locate
  • domain: Optional protection domain for security context

Returns:

  • A newly created Class<T> instance if found
  • null if the class cannot be located

Implementation Contract

This method is called by loadClass when a class is not found in the cache. Implementations should:

  • Perform the actual class discovery and loading
  • Create appropriate Class instances with metadata
  • Handle security checks and domain validation
  • NOT perform caching (handled by loadClass)

Example Implementation

@override
Class<T>? findClass<T>(String className, [ProtectionDomain? domain]) async {
  final declaration = await _typeDiscovery.findByQualifiedName(className);
  if (declaration == null) return null;
  
  return Class.declared<T>(declaration, domain ?? ProtectionDomain.current());
}

Throws:

Implementation

@override
Class<T>? findClass<T>(String className, [ProtectionDomain? domain]) {
  _checkClosed();

  try {
    // Try qualified name lookup first
    var declaration = TypeDiscovery.findByQualifiedName(className);

    // Fallback to simple name lookup
    declaration ??= TypeDiscovery.findBySimpleName(className);

    if (declaration == null) {
      return null;
    }

    return Class.declared<T>(declaration, domain ?? ProtectionDomain.current());
  } catch (e) {
    rethrow;
  }
}