public org . jbundle . util . osgi . ClassFinder getClassFinder ( Object context ) { if ( ! classServiceAvailable ) return null ; try { if ( classFinder == null ) { Class . forName ( "org.osgi.framework.BundleActivator" ) ; // This tests to see if osgi exists //classFinder = (org.jbundle.util.osgi.ClassFinder)org.jbundle.util.osgi.finder.ClassFinderActivator.getClassFinder(context, -1); try { // Use reflection so the smart jvm's don't try to retrieve this class. Class < ? > clazz = Class . forName ( "org.jbundle.util.osgi.finder.ClassFinderActivator" ) ; // This tests to see if osgi exists if ( clazz != null ) { java . lang . reflect . Method method = clazz . getMethod ( "getClassFinder" , Object . class , int . class ) ; if ( method != null ) classFinder = ( org . jbundle . util . osgi . ClassFinder ) method . invoke ( null , context , - 1 ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } } return classFinder ; } catch ( ClassNotFoundException ex ) { classServiceAvailable = false ; // Osgi is not installed, no need to keep trying return null ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; return null ; } }
Doesn t need to be static since this is only created once