protected void addIfMatching ( PackageScanFilter test , String fqn , Set < Class < ? > > classes ) { try { String externalName = fqn . substring ( 0 , fqn . indexOf ( ' ' ) ) . replace ( ' ' , ' ' ) ; Set < ClassLoader > set = getClassLoaders ( ) ; boolean found = false ; for ( ClassLoader classLoader : set ) { log . fine ( LogType . LOG , "Testing that class " + externalName + " matches criteria [" + test + "] using classloader:" + classLoader ) ; try { Class < ? > type = classLoader . loadClass ( externalName ) ; log . fine ( LogType . LOG , "Loaded the class: " + type + " in classloader: " + classLoader ) ; if ( test . matches ( type ) ) { log . fine ( LogType . LOG , "Found class: " + type + " which matches the filter in classloader: " + classLoader ) ; classes . add ( type ) ; } found = true ; break ; } catch ( ClassNotFoundException e ) { log . fine ( LogType . LOG , "Cannot find class '" + fqn + "' in classloader: " + classLoader + ". Reason: " + e , e ) ; } catch ( LinkageError e ) { log . fine ( LogType . LOG , "Cannot find the class definition '" + fqn + "' in classloader: " + classLoader + ". Reason: " + e , e ) ; } catch ( Exception e ) { log . severe ( LogType . LOG , "Cannot load class '" + fqn + "' in classloader: " + classLoader + ". Reason: " + e , e ) ; } } if ( ! found ) { // use debug to avoid being noisy in logs log . fine ( LogType . LOG , "Cannot find class '" + fqn + "' in any classloaders: " + set ) ; } } catch ( Exception e ) { log . warning ( LogType . LOG , "Cannot examine class '" + fqn + "' due to a " + e . getClass ( ) . getName ( ) + " with message: " + e . getMessage ( ) , e ) ; } }
Add the class designated by the fully qualified class name provided to the set of resolved classes if and only if it is approved by the Test supplied .