public static List < String > getDescriptorClassNameByInterface ( String interfaceName , String [ ] jarFileNames ) { if ( interfaceName == null || interfaceName . equals ( "" ) ) interfaceName = "IDescriptor" ; if ( ! interfaceName . equals ( "IDescriptor" ) && ! interfaceName . equals ( "IMolecularDescriptor" ) && ! interfaceName . equals ( "IAtomicDescriptor" ) && ! interfaceName . equals ( "IBondDescriptor" ) ) return null ; String [ ] jars ; if ( jarFileNames == null ) { String classPath = System . getProperty ( "java.class.path" ) ; jars = classPath . split ( File . pathSeparator ) ; } else { jars = jarFileNames ; } List < String > classlist = new ArrayList < String > ( ) ; for ( int i = 0 ; i < jars . length ; i ++ ) { logger . debug ( "Looking in " + jars [ i ] ) ; JarFile jarFile ; try { jarFile = new JarFile ( jars [ i ] ) ; Enumeration enumeration = jarFile . entries ( ) ; while ( enumeration . hasMoreElements ( ) ) { JarEntry jarEntry = ( JarEntry ) enumeration . nextElement ( ) ; if ( jarEntry . toString ( ) . indexOf ( ".class," ) != - 1 ) { String className = jarEntry . toString ( ) . replace ( ' ' , ' ' ) . replaceAll ( ".class," , "" ) ; if ( className . indexOf ( ' ' ) != - 1 ) continue ; Class klass = null ; try { klass = Class . forName ( className ) ; } catch ( ClassNotFoundException cnfe ) { logger . debug ( cnfe ) ; } catch ( NoClassDefFoundError ncdfe ) { logger . debug ( ncdfe ) ; } catch ( UnsatisfiedLinkError ule ) { logger . debug ( ule ) ; } if ( klass == null ) continue ; // check that its not abstract or an interface int modifer = klass . getModifiers ( ) ; if ( Modifier . isAbstract ( modifer ) || Modifier . isInterface ( modifer ) ) continue ; // get the interfaces implemented and see if one matches the one we're looking for Class [ ] interfaces = klass . getInterfaces ( ) ; for ( Class anInterface : interfaces ) { if ( anInterface . getName ( ) . equals ( interfaceName ) ) { classlist . add ( className ) ; break ; } } } } } catch ( IOException e ) { logger . error ( "Error opening the jar file: " + jars [ i ] ) ; logger . debug ( e ) ; } } return classlist ; }
Returns a list containing the classes that implement a specific interface .